Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Feb 27, 2024

issue: flutter/flutter#134178

This doesn't yet do textures since there is a bug in rendering mask blurs with textures.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@gaaclarke gaaclarke marked this pull request as ready for review February 27, 2024 23:04
return static_cast<int>(std::round(radius * scalar));
}

class GeometryExtractor : public TypedContentsVisitor<ColorSourceContents> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach feels really fragile. We should have the geometry when we construct the mask blur, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, in our current implementation we do. There is also a bug in our current implementation where it seems to only work for ColorSourceContents, which isn't what we want.

It isn't as fragile as it seems since the compiler is supporting it. If another subclass of ColorSourceContents is introduced, the visitor will have a compile error were you just implement the standard Visitor pattern and it will work.

The way this could break is if we introduce a new Contents that has a geometry that isn't a ColorSourceContents. But this way is probably more robust to that change than relying on having a ColorSourceContents when we create the blur.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, passing in the geometry as part of the filterinput and as a separate parameter can create the opportunity for them to differ which would be a logical error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just seems like way too much code to support mask blurs, which are only supported in relatively limited configrations. For example, we don't need to worry about mask blurs on arbitrary filers, its always going to be on a paint for a draw call, which means we should always have the geometry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to worry about mask blurs on arbitrary filers

What's enforcing that? Why doesn't our API enforce that? I worry that trying to ignore what the API allows creates oversights like with what happened with mask blur filters on textures. That's the downside to doing it the other way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests enforce it, same as it ever was!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdero I chatted with jonah and what we decided to do is just reduce the scope of the Visitor so that it only goes as far as ColorSourceContents. That's all I need to implement what I want and cuts down a lot of the code. If we need an more expansive visitor in the future we can implement that similarly to what I've done here.

I wish I understood the wizardry that std::variant uses to implement their visitor since it would resolve this issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might also be able to simplify the visitor further too, if you're limiting the scope to just the work needed to land this change. In that case, you don't even need to know what you are visiting, just whether or not it has a geometry you can use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay @jonahwilliams, please take a look, I removed all the subclasses of ColorSourceContents and FilterContents. I don't need to know anything below that to implement what we need.

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #51018 at sha f435867

@gaaclarke gaaclarke changed the title [Impeller] implements blur style inner [Impeller] implements blur styles inner and outer Feb 27, 2024
@gaaclarke
Copy link
Member Author

I added outer too since I'm waiting on reviews and it wasn't a big change.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #51018 at sha 3222841

virtual void SetRenderingMode(Entity::RenderingMode rendering_mode);

// |Contents|
void Visit(ContentsVisitor* visitor) override { visitor->Visit(this); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need overrides on all of the filter subtypes still?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks, I missed some of them. I think I have them all now.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #51018 at sha aeeb2ef

@gaaclarke
Copy link
Member Author

@jonahwilliams @bdero ready for review

Scalar sigma_y,
Entity::TileMode tile_mode,
BlurStyle blur_style,
const std::shared_ptr<Geometry>& geometry);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uber-nit: I might call this something like "mask_geometry", to clarify that it is the geometry for the mask and not the destination geometry/rect of the filter.

return FilterContents::MakeGaussianBlur(
FilterInput::Make(color_source_contents), sigma, sigma, style,
Entity::TileMode::kDecal);
Entity::TileMode::kDecal, color_source_contents->GetGeometry());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to set the geometry for the FilterContents::MakeGaussianBlur a few lines below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unnecessary to make the tests pass. Could I hit that with a gradient?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, setting any ColorSource other than solid color should trigger it.

Copy link
Member Author

@gaaclarke gaaclarke Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding it, but it doesn't render correctly. I'll have to do a followup to add that and address the rendering bug.

TEST_P(AiksTest, GaussianBlurStyleInnerGradient) {
  Canvas canvas;
  canvas.Scale(GetContentScale());

  canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)});

  Paint paint;
  paint.color = Color::Green();
  paint.mask_blur_descriptor = Paint::MaskBlurDescriptor{
      .style = FilterContents::BlurStyle::kInner,
      .sigma = Sigma(30),
  };

  std::vector<Color> colors = {Color{0.0, 0.7, 0.8, 1.0},
                               Color{0.0, 0.8, 0.7, 1.0}};
  std::vector<Scalar> stops = {0.0, 1.0};

  paint.color_source =
      ColorSource::MakeLinearGradient({0, 0}, {200, 200}, std::move(colors),
                                      std::move(stops), Entity::TileMode::kRepeat, {});

  canvas.DrawPath(PathBuilder()
                      .MoveTo({200, 200})
                      .LineTo({300, 400})
                      .LineTo({100, 400})
                      .Close()
                      .TakePath(),
                  paint);

  // Draw another thing to make sure the clip area is reset.
  Paint red;
  red.color = Color::Red();
  canvas.DrawRect(Rect::MakeXYWH(0, 0, 200, 200), red);

  ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
Screenshot 2024-02-29 at 5 42 23 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue filed: flutter/flutter#144449

Entity::TileMode tile_mode) {
FilterContents::BlurStyle blur_style,
Entity::TileMode tile_mode,
const std::shared_ptr<Geometry>& geometry) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional, but you could re-arrange the params so that blur_style (mask_blur_style?) and mask_geometry happen last and default them to normal/nullptr - here and in the ctor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaaclarke
Copy link
Member Author

#51018 (review)

Filed an issue since it doesnt' render correctly: flutter/flutter#144449

@gaaclarke gaaclarke requested a review from bdero March 1, 2024 01:47
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #51018 at sha 3b37134

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 4, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 4, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 4, 2024

auto label is removed for flutter/engine/51018, due to - The status or check suite Mac mac_clang_tidy has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 4, 2024
@auto-submit auto-submit bot merged commit 0d8588b into flutter:main Mar 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants