Flutter Impeller
impeller::Paint::MaskBlurDescriptor Struct Reference

#include <paint.h>

Public Member Functions

std::shared_ptr< FilterContents > CreateMaskBlur (std::shared_ptr< TextureContents > texture_contents, FillRectGeometry *rect_geom) const
 
std::shared_ptr< FilterContents > CreateMaskBlur (const FilterInput::Ref &input, bool is_solid_color, const Matrix &ctm) const
 
std::shared_ptr< Contents > CreateMaskBlur (const Paint &paint, const ContentContext &renderer, const Geometry *geometry, std::shared_ptr< ColorSourceContents > contents, bool needs_color_filter, FillRectGeometry *out_geom) const
 

Public Attributes

FilterContents::BlurStyle style
 
Sigma sigma
 
bool respect_ctm = true
 

Detailed Description

Definition at line 54 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 462 of file paint.cc.

465  {
466  Vector2 blur_sigma(sigma.sigma, sigma.sigma);
467  if (!respect_ctm) {
468  blur_sigma /=
469  Vector2(ctm.GetBasisX().GetLength(), ctm.GetBasisY().GetLength());
470  }
471  if (is_solid_color) {
473  input, Sigma(blur_sigma.x), Sigma(blur_sigma.y),
474  Entity::TileMode::kDecal, /*bounds=*/std::nullopt, style);
475  }
476  return FilterContents::MakeBorderMaskBlur(input, Sigma(blur_sigma.x),
477  Sigma(blur_sigma.y), style);
478 }
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, std::optional< Rect > bounds=std::nullopt, BlurStyle mask_blur_style=BlurStyle::kNormal, const Geometry *mask_geometry=nullptr)
static std::shared_ptr< FilterContents > MakeBorderMaskBlur(FilterInput::Ref input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal)
Point Vector2
Definition: point.h:430
FilterContents::BlurStyle style
Definition: paint.h:55
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< Contents > impeller::Paint::MaskBlurDescriptor::CreateMaskBlur ( const Paint &  paint,
const ContentContext &  renderer,
const Geometry *  geometry,
std::shared_ptr< ColorSourceContents >  contents,
bool  needs_color_filter,
FillRectGeometry *  out_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 405 of file paint.cc.

411  {
412  // If it's a solid color then we can just get away with doing one Gaussian
413  // blur. The color filter will always be applied on the CPU.
414  if (contents->IsSolidColor()) {
417  /*bounds=*/std::nullopt, style, geometry);
418  }
419 
420  /// 1. Create an opaque white mask of the original geometry.
421  auto mask = std::make_shared<SolidColorContents>(geometry);
422  mask->SetColor(Color::White());
423 
424  /// 2. Blur the mask.
425  auto blurred_mask = FilterContents::MakeGaussianBlur(
427  /*bounds=*/std::nullopt, style, geometry);
428 
429  /// 3. Replace the geometry of the original color source with a rectangle that
430  /// covers the full region of the blurred mask. Note that geometry is in
431  /// local bounds.
432  std::optional<Rect> expanded_local_bounds = blurred_mask->GetCoverage({});
433  if (!expanded_local_bounds.has_value()) {
434  expanded_local_bounds = Rect();
435  }
436  *out_geom = FillRectGeometry(expanded_local_bounds.value());
437 
438  std::shared_ptr<ColorSourceContents> expanded_contents =
439  paint.CreateContents(renderer, out_geom);
440  std::shared_ptr<Contents> final_contents = expanded_contents;
441 
442  /// 4. Apply the user set color filter on the GPU, if applicable.
443  if (needs_color_filter) {
444  if (paint.color_filter) {
445  final_contents = WrapWithGPUColorFilter(
446  paint.color_filter, FilterInput::Make(std::move(final_contents)),
448  }
449  if (paint.invert_colors) {
450  final_contents =
451  WrapWithInvertColors(FilterInput::Make(std::move(final_contents)),
453  }
454  }
455 
456  /// 5. Composite the color source with the blurred mask.
459  {FilterInput::Make(blurred_mask), FilterInput::Make(final_contents)});
460 }
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:857
static constexpr Color White()
Definition: color.h:269

References impeller::Paint::color_filter, impeller::Paint::CreateContents(), impeller::Paint::invert_colors, impeller::WrapWithGPUColorFilter(), and impeller::WrapWithInvertColors().

◆ CreateMaskBlur() [3/3]

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

Definition at line 376 of file paint.cc.

378  {
381  texture_contents->SetSourceRect(
382  texture_contents->GetSourceRect().Expand(expand_amount, expand_amount));
383  std::optional<Rect> coverage = texture_contents->GetCoverage({});
384  Geometry* geometry = nullptr;
385  if (coverage) {
386  texture_contents->SetDestinationRect(
387  coverage.value().Expand(expand_amount, expand_amount));
388  *rect_geom = FillRectGeometry(coverage.value());
389  geometry = rect_geom;
390  }
391  auto mask = std::make_shared<SolidColorContents>(geometry);
392  mask->SetColor(Color::White());
393  auto descriptor = texture_contents->GetSamplerDescriptor();
394  texture_contents->SetSamplerDescriptor(descriptor);
395  std::shared_ptr<FilterContents> blurred_mask =
398  /*bounds=*/std::nullopt, style, geometry);
399 
402  {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
403 }
float Scalar
Definition: scalar.h:19

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

◆ sigma

Sigma impeller::Paint::MaskBlurDescriptor::sigma

Definition at line 56 of file paint.h.

Referenced by impeller::testing::TEST_P().

◆ style

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

Definition at line 55 of file paint.h.

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


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