| Flutter Impeller |

Public Member Functions | Public Attributes | List of all members
impeller::Paint::MaskBlurDescriptor Struct Reference

`#include <paint.h>`

## Public Member Functions
std::shared_ptr< FilterContents > | CreateMaskBlur (std::shared_ptr< ColorSourceContents > color_source_contents, const std::shared_ptr< ColorFilter > &color_filter) const
std::shared_ptr< FilterContents > | CreateMaskBlur (std::shared_ptr< TextureContents > texture_contents) const
std::shared_ptr< FilterContents > | CreateMaskBlur (const FilterInput::Ref &input, bool is_solid_color, const Matrix &ctm) const

## Public Attributes
FilterContents::BlurStyle | style
Sigma | sigma
bool | respect_ctm = true

## Detailed Description

Definition at line 48 of file paint.h.

## Member Function Documentation

## ◆ CreateMaskBlur() [1/3]

std::shared_ptr< FilterContents > impeller::Paint::MaskBlurDescriptor::CreateMaskBlur | ( | const FilterInput::Ref & | input,
|  | bool | is_solid_color,
|  | const Matrix & | ctm
| ) |  | const

Definition at line 205 of file paint.cc.

208 {
209 Vector2 blur_sigma(sigma.sigma, sigma.sigma);
210 if (!respect_ctm) {
211 blur_sigma /= Vector2(ctm.GetBasisX().Length(), ctm.GetBasisY().Length());
212 }
213 if (is_solid_color) {
214 return FilterContents::MakeGaussianBlur(input, Sigma(blur_sigma.x),
215 Sigma(blur_sigma.y),
216 Entity::TileMode::kDecal, style);
217 }
218 return FilterContents::MakeBorderMaskBlur(input, Sigma(blur_sigma.x),
219 Sigma(blur_sigma.y), style);
220 }

References impeller::Matrix::GetBasisX(), impeller::Matrix::GetBasisY(), impeller::Entity::kDecal, impeller::Vector3::Length(), impeller::FilterContents::MakeBorderMaskBlur(), impeller::FilterContents::MakeGaussianBlur(), impeller::Paint::style, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ CreateMaskBlur() [2/3]

std::shared_ptr< FilterContents > impeller::Paint::MaskBlurDescriptor::CreateMaskBlur | ( | std::shared_ptr< ColorSourceContents > | color_source_contents,
|  | const std::shared_ptr< ColorFilter > & | color_filter
| ) |  | const

1. Create an opaque white mask of the original geometry.
2. Blur the mask.
3. Replace the geometry of the original color source with a rectangle that covers the full region of the blurred mask. Note that geometry is in local bounds.
4. Apply the user set color filter on the GPU, if applicable.
5. Composite the color source with the blurred mask.

Definition at line 155 of file paint.cc.

157 {
158 // If it's a solid color and there is no color filter, then we can just get
159 // away with doing one Gaussian blur.
160 if (color_source_contents->IsSolidColor() && !color_filter) {
161 return FilterContents::MakeGaussianBlur(
162 FilterInput::Make(color_source_contents), sigma, sigma,
163 Entity::TileMode::kDecal, style, color_source_contents->GetGeometry());
164 }
165
166 /// 1. Create an opaque white mask of the original geometry.
167
168 auto mask = std::make_shared<SolidColorContents>();
169 mask->SetColor(Color::White());
170 mask->SetGeometry(color_source_contents->GetGeometry());
171
172 /// 2. Blur the mask.
173
174 auto blurred_mask = FilterContents::MakeGaussianBlur(
175 FilterInput::Make(mask), sigma, sigma, Entity::TileMode::kDecal, style,
176 color_source_contents->GetGeometry());
177
178 /// 3. Replace the geometry of the original color source with a rectangle that
179 /// covers the full region of the blurred mask. Note that geometry is in
180 /// local bounds.
181
182 auto expanded_local_bounds = blurred_mask->GetCoverage({});
183 if (!expanded_local_bounds.has_value()) {
184 expanded_local_bounds = Rect();
185 }
186 color_source_contents->SetGeometry(
187 Geometry::MakeRect(*expanded_local_bounds));
188 std::shared_ptr<Contents> color_contents = color_source_contents;
189
190 /// 4. Apply the user set color filter on the GPU, if applicable.
191
192 if (color_filter) {
193 color_contents = color_filter->WrapWithGPUColorFilter(
194 FilterInput::Make(color_source_contents),
195 ColorFilterContents::AbsorbOpacity::kYes);
196 }
197
198 /// 5. Composite the color source with the blurred mask.
199
200 return ColorFilterContents::MakeBlend(
201 BlendMode::kSourceIn,
202 {FilterInput::Make(blurred_mask), FilterInput::Make(color_contents)});
203 }

References impeller::Paint::color_filter, impeller::Entity::kDecal, impeller::kSourceIn, impeller::ColorFilterContents::kYes, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::FilterContents::MakeGaussianBlur(), impeller::Geometry::MakeRect(), impeller::Paint::style, and impeller::Color::White().

## ◆ CreateMaskBlur() [3/3]

std::shared_ptr< FilterContents > impeller::Paint::MaskBlurDescriptor::CreateMaskBlur | ( | std::shared_ptr< TextureContents > | texture_contents | ) | const

Definition at line 127 of file paint.cc.

128 {
129 Scalar expand_amount = GaussianBlurFilterContents::CalculateBlurRadius(
130 GaussianBlurFilterContents::ScaleSigma(sigma.sigma));
131 texture_contents->SetSourceRect(
132 texture_contents->GetSourceRect().Expand(expand_amount, expand_amount));
133 auto mask = std::make_shared<SolidColorContents>();
134 mask->SetColor(Color::White());
135 std::optional<Rect> coverage = texture_contents->GetCoverage({});
136 std::shared_ptr<Geometry> geometry;
137 if (coverage) {
138 texture_contents->SetDestinationRect(
139 coverage.value().Expand(expand_amount, expand_amount));
140 geometry = Geometry::MakeRect(coverage.value());
141 }
142 mask->SetGeometry(geometry);
143 auto descriptor = texture_contents->GetSamplerDescriptor();
144 texture_contents->SetSamplerDescriptor(descriptor);
145 std::shared_ptr<FilterContents> blurred_mask =
146 FilterContents::MakeGaussianBlur(FilterInput::Make(mask), sigma, sigma,
147 Entity::TileMode::kDecal, style,
148 geometry);
149
150 return ColorFilterContents::MakeBlend(
151 BlendMode::kSourceIn,
152 {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
153 }

References impeller::GaussianBlurFilterContents::CalculateBlurRadius(), impeller::Entity::kDecal, impeller::kSourceIn, impeller::FilterInput::Make(), impeller::ColorFilterContents::MakeBlend(), impeller::FilterContents::MakeGaussianBlur(), impeller::Geometry::MakeRect(), impeller::GaussianBlurFilterContents::ScaleSigma(), impeller::Sigma::sigma, sigma, style, and impeller::Color::White().

## Member Data Documentation

## ◆ respect_ctm

bool impeller::Paint::MaskBlurDescriptor::respect_ctm = true

Text mask blurs need to not apply the CTM to the blur kernel. See: https://github.com/flutter/flutter/issues/115112

Definition at line 53 of file paint.h.

## ◆ sigma

Sigma impeller::Paint::MaskBlurDescriptor::sigma

Definition at line 50 of file paint.h.

Referenced by CreateMaskBlur().

## ◆ style

FilterContents::BlurStyle impeller::Paint::MaskBlurDescriptor::style

Definition at line 49 of file paint.h.

Referenced by CreateMaskBlur(), impeller::DlDispatcherBase::drawShadow(), impeller::testing::MaskBlurVariantTest(), and impeller::testing::TEST_P().

The documentation for this struct was generated from the following files:

- impeller/aiks/paint.h
- impeller/aiks/paint.cc

impeller::Sigma::sigma
Scalar sigma
Definition: sigma.h:33
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::Paint::MaskBlurDescriptor::sigma
Sigma sigma
Definition: paint.h:50
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:49
impeller::Vector2
Point Vector2
Definition: point.h:326
impeller::GaussianBlurFilterContents::CalculateBlurRadius
static Scalar CalculateBlurRadius(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:787
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:80
impeller::Color::White
static constexpr Color White()
Definition: color.h:266
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:769
impeller::FilterContents::MakeBorderMaskBlur
static std::shared_ptr< FilterContents > MakeBorderMaskBlur(FilterInput::Ref input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal)
Definition: filter_contents.cc:49
impeller::Geometry::MakeRect
static std::shared_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:89
impeller::BlendMode::kSourceIn
@ kSourceIn
impeller::Paint::MaskBlurDescriptor::respect_ctm
bool respect_ctm
Definition: paint.h:53
impeller::ColorFilterContents::AbsorbOpacity::kYes
@ kYes
impeller::ColorFilterContents::MakeBlend
static std::shared_ptr< ColorFilterContents > MakeBlend(BlendMode blend_mode, FilterInput::Vector inputs, std::optional< Color > foreground_color=std::nullopt)
the [inputs] are expected to be in the order of dst, src.
Definition: color_filter_contents.cc:17
impeller::GaussianBlurFilterContents::ScaleSigma
static Scalar ScaleSigma(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:807
impeller::FilterContents::MakeGaussianBlur
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, BlurStyle mask_blur_style=BlurStyle::kNormal, const std::shared_ptr< Geometry > &mask_geometry=nullptr)
Definition: filter_contents.cc:36