-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] implement mask blur for textures #51183
Changes from all commits
35843e8
0ff9413
81b2a32
88c766b
11da599
abd12a4
66c4d38
3233ee2
6868bd4
2277ce1
22246b5
5c33bde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #include "impeller/entity/contents/color_source_contents.h" | ||
| #include "impeller/entity/contents/filters/color_filter_contents.h" | ||
| #include "impeller/entity/contents/filters/filter_contents.h" | ||
| #include "impeller/entity/contents/filters/gaussian_blur_filter_contents.h" | ||
| #include "impeller/entity/contents/solid_color_contents.h" | ||
| #include "impeller/entity/geometry/geometry.h" | ||
|
|
||
|
|
@@ -121,6 +122,34 @@ std::shared_ptr<Contents> Paint::WithColorFilter( | |
| absorb_opacity); | ||
| } | ||
|
|
||
| std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would defer to @bdero to review the mask blur implementation. Overall code looks reasonable to me. |
||
| std::shared_ptr<TextureContents> texture_contents) const { | ||
| Scalar expand_amount = GaussianBlurFilterContents::CalculateBlurRadius( | ||
| GaussianBlurFilterContents::ScaleSigma(sigma.sigma)); | ||
| texture_contents->SetSourceRect( | ||
gaaclarke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| texture_contents->GetSourceRect().Expand(expand_amount, expand_amount)); | ||
| auto mask = std::make_shared<SolidColorContents>(); | ||
| mask->SetColor(Color::White()); | ||
| std::optional<Rect> coverage = texture_contents->GetCoverage({}); | ||
| std::shared_ptr<Geometry> geometry; | ||
| if (coverage) { | ||
| texture_contents->SetDestinationRect( | ||
| coverage.value().Expand(expand_amount, expand_amount)); | ||
| geometry = Geometry::MakeRect(coverage.value()); | ||
| } | ||
| mask->SetGeometry(geometry); | ||
| auto descriptor = texture_contents->GetSamplerDescriptor(); | ||
| texture_contents->SetSamplerDescriptor(descriptor); | ||
| std::shared_ptr<FilterContents> blurred_mask = | ||
| FilterContents::MakeGaussianBlur(FilterInput::Make(mask), sigma, sigma, | ||
| Entity::TileMode::kDecal, style, | ||
| geometry); | ||
|
|
||
| return ColorFilterContents::MakeBlend( | ||
| BlendMode::kSourceIn, | ||
| {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)}); | ||
| } | ||
|
|
||
| std::shared_ptr<FilterContents> Paint::MaskBlurDescriptor::CreateMaskBlur( | ||
| std::shared_ptr<ColorSourceContents> color_source_contents, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a path for creating a mask blur from a color source contents. If we created a TiledTextureContents (which is a color source contents) instead of a TextureContents for drawImageRect calls with a mask blur descriptor, then could we pass it into this function and have it just work?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, we have to essentially create a transparent halo around the texture to make the blending work correctly. That requires modifying texcoords. The path below doesn't know anything about that, just expanding geometry which would stretch the image.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, not a transparent halo, but sampling outside of the image based on whatever the sampler settings are.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's a bug in the existing path, then. And that same issue actually applies to all the ColorSource types (except for solid colors, of course). One easy solution for that would be to amend the effect transform of the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yea, that would explain some of the stretching I saw of gradients. I'll file an issue.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const std::shared_ptr<ColorFilter>& color_filter) const { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.