Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
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 Matrix &ctm) const
 

Public Attributes

FilterContents::BlurStyle style
 
Sigma sigma
 
bool respect_ctm = true
 

Detailed Description

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

208 {
209 Vector2 blur_sigma(sigma.sigma, sigma.sigma);
210 if (!respect_ctm) {
211 blur_sigma /= Vector2(ctm.GetBasisX().Length(), ctm.GetBasisY().Length());
212 }
213 if (is_solid_color) {
214 return FilterContents::MakeGaussianBlur(input, Sigma(blur_sigma.x),
215 Sigma(blur_sigma.y),
217 }
218 return FilterContents::MakeBorderMaskBlur(input, Sigma(blur_sigma.x),
219 Sigma(blur_sigma.y), style);
220}
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)
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:326
FilterContents::BlurStyle style
Definition: paint.h:49
Scalar sigma
Definition: sigma.h:33

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

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

◆ CreateMaskBlur() [3/3]

std::shared_ptr< FilterContents > impeller::Paint::MaskBlurDescriptor::CreateMaskBlur ( std::shared_ptr< TextureContents texture_contents) const

Definition at line 127 of file paint.cc.

128 {
131 texture_contents->SetSourceRect(
132 texture_contents->GetSourceRect().Expand(expand_amount, expand_amount));
133 auto mask = std::make_shared<SolidColorContents>();
134 mask->SetColor(Color::White());
135 std::optional<Rect> coverage = texture_contents->GetCoverage({});
136 std::shared_ptr<Geometry> geometry;
137 if (coverage) {
138 texture_contents->SetDestinationRect(
139 coverage.value().Expand(expand_amount, expand_amount));
140 geometry = Geometry::MakeRect(coverage.value());
141 }
142 mask->SetGeometry(geometry);
143 auto descriptor = texture_contents->GetSamplerDescriptor();
144 texture_contents->SetSamplerDescriptor(descriptor);
145 std::shared_ptr<FilterContents> blurred_mask =
148 geometry);
149
152 {FilterInput::Make(blurred_mask), FilterInput::Make(texture_contents)});
153}
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 53 of file paint.h.

◆ sigma

Sigma impeller::Paint::MaskBlurDescriptor::sigma

Definition at line 50 of file paint.h.

◆ style

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

Definition at line 49 of file paint.h.


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