Flutter Impeller
impeller::Paint::MaskBlurDescriptor Struct Reference

#include <paint.h>

Public Member Functions

std::shared_ptr< FilterContentsCreateMaskBlur (std::shared_ptr< ColorSourceContents > color_source_contents, const flutter::DlColorFilter *color_filter, bool invert_colors, RectGeometry *rect_geom) const
 
std::shared_ptr< FilterContentsCreateMaskBlur (std::shared_ptr< TextureContents > texture_contents, RectGeometry *rect_geom) const
 
std::shared_ptr< FilterContentsCreateMaskBlur (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 429 of file paint.cc.

432  {
433  Vector2 blur_sigma(sigma.sigma, sigma.sigma);
434  if (!respect_ctm) {
435  blur_sigma /=
436  Vector2(ctm.GetBasisX().GetLength(), ctm.GetBasisY().GetLength());
437  }
438  if (is_solid_color) {
439  return FilterContents::MakeGaussianBlur(input, Sigma(blur_sigma.x),
440  Sigma(blur_sigma.y),
442  }
443  return FilterContents::MakeBorderMaskBlur(input, Sigma(blur_sigma.x),
444  Sigma(blur_sigma.y), style);
445 }

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 373 of file paint.cc.

377  {
378  // If it's a solid color then we can just get away with doing one Gaussian
379  // blur. The color filter will always be applied on the CPU.
380  if (color_source_contents->IsSolidColor()) {
382  FilterInput::Make(color_source_contents), sigma, sigma,
383  Entity::TileMode::kDecal, style, color_source_contents->GetGeometry());
384  }
385 
386  /// 1. Create an opaque white mask of the original geometry.
387 
388  auto mask = std::make_shared<SolidColorContents>();
389  mask->SetColor(Color::White());
390  mask->SetGeometry(color_source_contents->GetGeometry());
391 
392  /// 2. Blur the mask.
393 
394  auto blurred_mask = FilterContents::MakeGaussianBlur(
396  color_source_contents->GetGeometry());
397 
398  /// 3. Replace the geometry of the original color source with a rectangle that
399  /// covers the full region of the blurred mask. Note that geometry is in
400  /// local bounds.
401 
402  auto expanded_local_bounds = blurred_mask->GetCoverage({});
403  if (!expanded_local_bounds.has_value()) {
404  expanded_local_bounds = Rect();
405  }
406  *rect_geom = RectGeometry(expanded_local_bounds.value());
407  color_source_contents->SetGeometry(rect_geom);
408  std::shared_ptr<Contents> color_contents = color_source_contents;
409 
410  /// 4. Apply the user set color filter on the GPU, if applicable.
411  if (color_filter) {
412  color_contents =
415  }
416  if (invert_colors) {
417  color_contents =
418  WrapWithInvertColors(FilterInput::Make(color_contents),
420  }
421 
422  /// 5. Composite the color source with the blurred mask.
423 
426  {FilterInput::Make(blurred_mask), FilterInput::Make(color_contents)});
427 }

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 343 of file paint.cc.

345  {
348  texture_contents->SetSourceRect(
349  texture_contents->GetSourceRect().Expand(expand_amount, expand_amount));
350  auto mask = std::make_shared<SolidColorContents>();
351  mask->SetColor(Color::White());
352  std::optional<Rect> coverage = texture_contents->GetCoverage({});
353  Geometry* geometry = nullptr;
354  if (coverage) {
355  texture_contents->SetDestinationRect(
356  coverage.value().Expand(expand_amount, expand_amount));
357  *rect_geom = RectGeometry(coverage.value());
358  geometry = rect_geom;
359  }
360  mask->SetGeometry(geometry);
361  auto descriptor = texture_contents->GetSamplerDescriptor();
362  texture_contents->SetSamplerDescriptor(descriptor);
363  std::shared_ptr<FilterContents> blurred_mask =
366  geometry);
367 
370  {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
371 }

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::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:53
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::WrapWithInvertColors
std::shared_ptr< ColorFilterContents > WrapWithInvertColors(const std::shared_ptr< FilterInput > &input, ColorFilterContents::AbsorbOpacity absorb_opacity)
Definition: color_filter.cc:16
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:52
impeller::Vector2
Point Vector2
Definition: point.h:331
impeller::Paint::color_filter
const flutter::DlColorFilter * color_filter
Definition: paint.h:76
impeller::GaussianBlurFilterContents::CalculateBlurRadius
static Scalar CalculateBlurRadius(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:856
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::Color::White
static constexpr Color White()
Definition: color.h:263
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:776
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::Paint::invert_colors
bool invert_colors
Definition: paint.h:85
impeller::BlendMode::kSourceIn
@ kSourceIn
impeller::Paint::MaskBlurDescriptor::respect_ctm
bool respect_ctm
Definition: paint.h:56
impeller::ColorFilterContents::AbsorbOpacity::kYes
@ kYes
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:36
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:876