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 std::shared_ptr< ColorFilter > &color_filter) const
 
std::shared_ptr< FilterContentsCreateMaskBlur (std::shared_ptr< TextureContents > texture_contents) const
 
std::shared_ptr< FilterContentsCreateMaskBlur (const FilterInput::Ref &input, bool is_solid_color) const
 

Public Attributes

FilterContents::BlurStyle style
 
Sigma sigma
 

Detailed Description

Definition at line 39 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

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

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

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

126  {
129  texture_contents->SetSourceRect(
130  texture_contents->GetSourceRect().Expand(expand_amount, expand_amount));
131  auto mask = std::make_shared<SolidColorContents>();
132  mask->SetColor(Color::White());
133  std::optional<Rect> coverage = texture_contents->GetCoverage({});
134  std::shared_ptr<Geometry> geometry;
135  if (coverage) {
136  texture_contents->SetDestinationRect(
137  coverage.value().Expand(expand_amount, expand_amount));
138  geometry = Geometry::MakeRect(coverage.value());
139  }
140  mask->SetGeometry(geometry);
141  auto descriptor = texture_contents->GetSamplerDescriptor();
142  texture_contents->SetSamplerDescriptor(descriptor);
143  std::shared_ptr<FilterContents> blurred_mask =
146  geometry);
147 
150  {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
151 }

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

◆ sigma

Sigma impeller::Paint::MaskBlurDescriptor::sigma

Definition at line 41 of file paint.h.

Referenced by CreateMaskBlur().

◆ style


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:41
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::Paint::MaskBlurDescriptor::style
FilterContents::BlurStyle style
Definition: paint.h:40
impeller::GaussianBlurFilterContents::CalculateBlurRadius
static Scalar CalculateBlurRadius(Scalar sigma)
Definition: gaussian_blur_filter_contents.cc:556
impeller::Paint::color_filter
std::shared_ptr< ColorFilter > color_filter
Definition: paint.h:68
impeller::Color::White
static constexpr Color White()
Definition: color.h:256
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:661
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:204
impeller::BlendMode::kSourceIn
@ kSourceIn
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:576
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