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 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),
432  }
433  return FilterContents::MakeBorderMaskBlur(input, Sigma(blur_sigma.x),
434  Sigma(blur_sigma.y), style);
435 }
static std::shared_ptr< FilterContents > MakeBorderMaskBlur(FilterInput::Ref input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal)
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)
Point Vector2
Definition: point.h:331
FilterContents::BlurStyle style
Definition: paint.h:52
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()) {
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(
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 =
405  }
406  if (invert_colors) {
407  color_contents =
408  WrapWithInvertColors(FilterInput::Make(color_contents),
410  }
411 
412  /// 5. Composite the color source with the blurred mask.
413 
416  {FilterInput::Make(blurred_mask), FilterInput::Make(color_contents)});
417 }
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.
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(const flutter::DlColorFilter *filter, const std::shared_ptr< FilterInput > &input, ColorFilterContents::AbsorbOpacity absorb_opacity)
Definition: color_filter.cc:24
std::shared_ptr< ColorFilterContents > WrapWithInvertColors(const std::shared_ptr< FilterInput > &input, ColorFilterContents::AbsorbOpacity absorb_opacity)
Definition: color_filter.cc:16
TRect< Scalar > Rect
Definition: rect.h:792
static constexpr Color White()
Definition: color.h:263
const flutter::DlColorFilter * color_filter
Definition: paint.h:76
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  {
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 =
356  geometry);
357 
360  {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
361 }
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: