| 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 flutter::DlColorFilter *color_filter, bool invert_colors, RectGeometry *rect_geom) const
std::shared_ptr< FilterContents > | CreateMaskBlur (std::shared_ptr< TextureContents > texture_contents, RectGeometry *rect_geom) 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 51 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 419 of file paint.cc.

422 {
423 Vector2 blur_sigma(sigma.sigma, sigma.sigma);
424 if (!respect_ctm) {
425 blur_sigma /=
426 Vector2(ctm.GetBasisX().GetLength(), ctm.GetBasisY().GetLength());
427 }
428 if (is_solid_color) {
429 return FilterContents::MakeGaussianBlur(input, Sigma(blur_sigma.x),
430 Sigma(blur_sigma.y),
431 Entity::TileMode::kDecal, style);
432 }
433 return FilterContents::MakeBorderMaskBlur(input, Sigma(blur_sigma.x),
434 Sigma(blur_sigma.y), style);
435 }
impeller::Entity::TileMode::kDecal
@ kDecal
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:51
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 Geometry *mask_geometry=nullptr)
Definition: filter_contents.cc:38
impeller::Vector2
Point Vector2
Definition: point.h:331
impeller::Paint::MaskBlurDescriptor::respect_ctm
bool respect_ctm
Definition: paint.h:56
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:52
impeller::Paint::MaskBlurDescriptor::sigma
Sigma sigma
Definition: paint.h:53
impeller::Sigma::sigma
Scalar sigma
Definition: sigma.h:33

References impeller::Matrix::GetBasisX(), impeller::Matrix::GetBasisY(), impeller::Vector3::GetLength(), 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 flutter::DlColorFilter * | color_filter,
|  | bool | invert_colors,
|  | RectGeometry * | rect_geom
| ) |  | 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 363 of file paint.cc.

367 {
368 // If it's a solid color then we can just get away with doing one Gaussian
369 // blur. The color filter will always be applied on the CPU.
370 if (color_source_contents->IsSolidColor()) {
371 return FilterContents::MakeGaussianBlur(
372 FilterInput::Make(color_source_contents), sigma, sigma,
373 Entity::TileMode::kDecal, style, color_source_contents->GetGeometry());
374 }
375
376 /// 1. Create an opaque white mask of the original geometry.
377
378 auto mask = std::make_shared<SolidColorContents>();
379 mask->SetColor(Color::White());
380 mask->SetGeometry(color_source_contents->GetGeometry());
381
382 /// 2. Blur the mask.
383
384 auto blurred_mask = FilterContents::MakeGaussianBlur(
385 FilterInput::Make(mask), sigma, sigma, Entity::TileMode::kDecal, style,
386 color_source_contents->GetGeometry());
387
388 /// 3. Replace the geometry of the original color source with a rectangle that
389 /// covers the full region of the blurred mask. Note that geometry is in
390 /// local bounds.
391
392 auto expanded_local_bounds = blurred_mask->GetCoverage({});
393 if (!expanded_local_bounds.has_value()) {
394 expanded_local_bounds = Rect();
395 }
396 *rect_geom = RectGeometry(expanded_local_bounds.value());
397 color_source_contents->SetGeometry(rect_geom);
398 std::shared_ptr<Contents> color_contents = color_source_contents;
399
400 /// 4. Apply the user set color filter on the GPU, if applicable.
401 if (color_filter) {
402 color_contents =
403 WrapWithGPUColorFilter(color_filter, FilterInput::Make(color_contents),
404 ColorFilterContents::AbsorbOpacity::kYes);
405 }
406 if (invert_colors) {
407 color_contents =
408 WrapWithInvertColors(FilterInput::Make(color_contents),
409 ColorFilterContents::AbsorbOpacity::kYes);
410 }
411
412 /// 5. Composite the color source with the blurred mask.
413
414 return ColorFilterContents::MakeBlend(
415 BlendMode::kSourceIn,
416 {FilterInput::Make(blurred_mask), FilterInput::Make(color_contents)});
417 }
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::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(const flutter::DlColorFilter *filter, const std::shared_ptr< FilterInput > &input, ColorFilterContents::AbsorbOpacity absorb_opacity)
Definition: color_filter.cc:24
impeller::WrapWithInvertColors
std::shared_ptr< ColorFilterContents > WrapWithInvertColors(const std::shared_ptr< FilterInput > &input, ColorFilterContents::AbsorbOpacity absorb_opacity)
Definition: color_filter.cc:16
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:792
impeller::BlendMode::kSourceIn
@ kSourceIn
impeller::Color::White
static constexpr Color White()
Definition: color.h:263
impeller::Paint::color_filter
const flutter::DlColorFilter * color_filter
Definition: paint.h:76
impeller::Paint::invert_colors
bool invert_colors
Definition: paint.h:85

References impeller::WrapWithGPUColorFilter(), and impeller::WrapWithInvertColors().

## ◆ CreateMaskBlur() [3/3]

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

Definition at line 333 of file paint.cc.

335 {
336 Scalar expand_amount = GaussianBlurFilterContents::CalculateBlurRadius(
337 GaussianBlurFilterContents::ScaleSigma(sigma.sigma));
338 texture_contents->SetSourceRect(
339 texture_contents->GetSourceRect().Expand(expand_amount, expand_amount));
340 auto mask = std::make_shared<SolidColorContents>();
341 mask->SetColor(Color::White());
342 std::optional<Rect> coverage = texture_contents->GetCoverage({});
343 Geometry* geometry = nullptr;
344 if (coverage) {
345 texture_contents->SetDestinationRect(
346 coverage.value().Expand(expand_amount, expand_amount));
347 *rect_geom = RectGeometry(coverage.value());
348 geometry = rect_geom;
349 }
350 mask->SetGeometry(geometry);
351 auto descriptor = texture_contents->GetSamplerDescriptor();
352 texture_contents->SetSamplerDescriptor(descriptor);
353 std::shared_ptr<FilterContents> blurred_mask =
354 FilterContents::MakeGaussianBlur(FilterInput::Make(mask), sigma, sigma,
355 Entity::TileMode::kDecal, style,
356 geometry);
357
358 return ColorFilterContents::MakeBlend(
359 BlendMode::kSourceIn,
360 {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
361 }
impeller::GaussianBlurFilterContents::CalculateBlurRadius
static Scalar CalculateBlurRadius(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:877
impeller::GaussianBlurFilterContents::ScaleSigma
static Scalar ScaleSigma(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:897
impeller::Scalar
float Scalar
Definition: scalar.h:18

## 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 56 of file paint.h.

## ◆ sigma

Sigma impeller::Paint::MaskBlurDescriptor::sigma

Definition at line 53 of file paint.h.

## ◆ style

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

Definition at line 52 of file paint.h.

Referenced by impeller::DlDispatcherBase::drawShadow().

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

- impeller/display_list/paint.h
- impeller/display_list/paint.cc