Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
impeller::BorderMaskBlurFilterContents Class Referencefinal

#include <border_mask_blur_filter_contents.h>

Inheritance diagram for impeller::BorderMaskBlurFilterContents:
impeller::FilterContents impeller::Contents

Public Member Functions

 BorderMaskBlurFilterContents ()
 
 ~BorderMaskBlurFilterContents () override
 
void SetSigma (Sigma sigma_x, Sigma sigma_y)
 
void SetBlurStyle (BlurStyle blur_style)
 
std::optional< RectGetFilterCoverage (const FilterInput::Vector &inputs, const Entity &entity, const Matrix &effect_transform) const override
 Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter across the specified inputs, ignoring the coverage hint.
 
std::optional< RectGetFilterSourceCoverage (const Matrix &effect_transform, const Rect &output_limit) const override
 Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on the specified output coverage, ignoring the inputs which will be accommodated by the caller.
 
- Public Member Functions inherited from impeller::FilterContents
 FilterContents ()
 
 ~FilterContents () override
 
void SetInputs (FilterInput::Vector inputs)
 The input texture sources for this filter. Each input's emitted texture is expected to have premultiplied alpha colors.
 
void SetEffectTransform (const Matrix &effect_transform)
 Sets the transform which gets appended to the effect of this filter. Note that this is in addition to the entity's transform.
 
std::optional< EntityGetEntity (const ContentContext &renderer, const Entity &entity, const std::optional< Rect > &coverage_hint) const
 Create an Entity that renders this filter's output.
 
bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
std::optional< RectGetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered.
 
void PopulateGlyphAtlas (const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale) override
 Add any text data to the specified lazy atlas. The scale parameter must be used again later when drawing the text.
 
std::optional< SnapshotRenderToSnapshot (const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &label="Filter Snapshot") const override
 Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of GetCoverage(entity).
 
const FilterContentsAsFilter () const override
 Cast to a filter. Returns nullptr if this Contents is not a filter.
 
std::optional< RectGetSourceCoverage (const Matrix &effect_transform, const Rect &output_limit) const
 Determines the coverage of source pixels that will be needed to produce results for the specified |output_limit| under the specified |effect_transform|. This is essentially a reverse of the |GetCoverage| method computing a source coverage from an intended |output_limit| coverage.
 
virtual Matrix GetLocalTransform (const Matrix &parent_transform) const
 
Matrix GetTransform (const Matrix &parent_transform) const
 
virtual bool IsTranslationOnly () const
 Returns true if this filter graph doesn't perform any basis transforms to the filtered content. For example: Rotating, scaling, and skewing are all basis transforms, but translating is not.
 
bool IsLeaf () const
 Returns true if this filter does not have any FilterInput children.
 
void SetLeafInputs (const FilterInput::Vector &inputs)
 Replaces the set of all leaf FilterContents with a new set of FilterInputs.
 
virtual void SetRenderingMode (Entity::RenderingMode rendering_mode)
 Marks this filter chain as applying in a subpass scenario.
 
- Public Member Functions inherited from impeller::Contents
 Contents ()
 
virtual ~Contents ()
 
void SetCoverageHint (std::optional< Rect > coverage_hint)
 Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of GetCoverage().
 
const std::optional< Rect > & GetCoverageHint () const
 
virtual bool IsOpaque () const
 Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity.
 
virtual ClipCoverage GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
 Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer.
 
virtual bool ShouldRender (const Entity &entity, const std::optional< Rect > clip_coverage) const
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
void SetColorSourceSize (Size size)
 
virtual bool CanInheritOpacity (const Entity &entity) const
 Whether or not this contents can accept the opacity peephole optimization.
 
virtual void SetInheritedOpacity (Scalar opacity)
 Inherit the provided opacity.
 
virtual std::optional< ColorAsBackgroundColor (const Entity &entity, ISize target_size) const
 Returns a color if this Contents will flood the given target_size with a color. This output color is the "Source" color that will be used for the Entity's blend operation.
 
virtual bool ApplyColorFilter (const ColorFilterProc &color_filter_proc)
 If possible, applies a color filter to this contents inputs on the CPU.
 

Private Member Functions

std::optional< EntityRenderFilter (const FilterInput::Vector &input_textures, const ContentContext &renderer, const Entity &entity, const Matrix &effect_transform, const Rect &coverage, const std::optional< Rect > &coverage_hint) const override
 Converts zero or more filter inputs into a render instruction.
 

Additional Inherited Members

- Public Types inherited from impeller::FilterContents
enum class  BlurStyle { kNormal , kSolid , kOuter , kInner }
 
enum class  MorphType { kDilate , kErode }
 
- Public Types inherited from impeller::Contents
using ColorFilterProc = std::function< Color(Color)>
 
using RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)>
 
using CoverageProc = std::function< std::optional< Rect >(const Entity &entity)>
 
- Static Public Member Functions inherited from impeller::FilterContents
static std::shared_ptr< FilterContentsMakeGaussianBlur (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< FilterContentsMakeBorderMaskBlur (FilterInput::Ref input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal)
 
static std::shared_ptr< FilterContentsMakeDirectionalMorphology (FilterInput::Ref input, Radius radius, Vector2 direction, MorphType morph_type)
 
static std::shared_ptr< FilterContentsMakeMorphology (FilterInput::Ref input, Radius radius_x, Radius radius_y, MorphType morph_type)
 
static std::shared_ptr< FilterContentsMakeMatrixFilter (FilterInput::Ref input, const Matrix &matrix, const SamplerDescriptor &desc)
 
static std::shared_ptr< FilterContentsMakeLocalMatrixFilter (FilterInput::Ref input, const Matrix &matrix)
 
static std::shared_ptr< FilterContentsMakeYUVToRGBFilter (std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
 
- Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 
- Static Public Attributes inherited from impeller::FilterContents
static const int32_t kBlurFilterRequiredMipCount
 

Detailed Description

Definition at line 15 of file border_mask_blur_filter_contents.h.

Constructor & Destructor Documentation

◆ BorderMaskBlurFilterContents()

impeller::BorderMaskBlurFilterContents::BorderMaskBlurFilterContents ( )
default

◆ ~BorderMaskBlurFilterContents()

impeller::BorderMaskBlurFilterContents::~BorderMaskBlurFilterContents ( )
overridedefault

Member Function Documentation

◆ GetFilterCoverage()

std::optional< Rect > impeller::BorderMaskBlurFilterContents::GetFilterCoverage ( const FilterInput::Vector inputs,
const Entity entity,
const Matrix effect_transform 
) const
overridevirtual

Internal utility method for |GetLocalCoverage| that computes the output coverage of this filter across the specified inputs, ignoring the coverage hint.

Reimplemented from impeller::FilterContents.

Definition at line 145 of file border_mask_blur_filter_contents.cc.

148 {
149 if (inputs.empty()) {
150 return std::nullopt;
151 }
152
153 auto coverage = inputs[0]->GetCoverage(entity);
154 if (!coverage.has_value()) {
155 return std::nullopt;
156 }
157 auto transform = inputs[0]->GetTransform(entity) * effect_transform;
158 auto transformed_blur_vector =
159 transform.TransformDirection(Vector2(Radius{sigma_x_}.radius, 0)).Abs() +
160 transform.TransformDirection(Vector2(0, Radius{sigma_y_}.radius)).Abs();
161 return coverage->Expand(transformed_blur_vector);
162}
Point Vector2
Definition point.h:320
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47

◆ GetFilterSourceCoverage()

std::optional< Rect > impeller::BorderMaskBlurFilterContents::GetFilterSourceCoverage ( const Matrix effect_transform,
const Rect output_limit 
) const
overridevirtual

Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on the specified output coverage, ignoring the inputs which will be accommodated by the caller.

Implements impeller::FilterContents.

Definition at line 164 of file border_mask_blur_filter_contents.cc.

166 {
167 auto transformed_blur_vector =
168 effect_transform.TransformDirection(Vector2(Radius{sigma_x_}.radius, 0))
169 .Abs() +
170 effect_transform.TransformDirection(Vector2(0, Radius{sigma_y_}.radius))
171 .Abs();
172 return output_limit.Expand(transformed_blur_vector);
173}

◆ RenderFilter()

std::optional< Entity > impeller::BorderMaskBlurFilterContents::RenderFilter ( const FilterInput::Vector inputs,
const ContentContext renderer,
const Entity entity,
const Matrix effect_transform,
const Rect coverage,
const std::optional< Rect > &  coverage_hint 
) const
overrideprivatevirtual

Converts zero or more filter inputs into a render instruction.

Handle inputs.

Create AnonymousContents for rendering.

Implements impeller::FilterContents.

Definition at line 51 of file border_mask_blur_filter_contents.cc.

57 {
60
61 //----------------------------------------------------------------------------
62 /// Handle inputs.
63 ///
64
65 if (inputs.empty()) {
66 return std::nullopt;
67 }
68
69 auto input_snapshot =
70 inputs[0]->GetSnapshot("BorderMaskBlur", renderer, entity);
71 if (!input_snapshot.has_value()) {
72 return std::nullopt;
73 }
74
75 auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage);
76 if (!maybe_input_uvs.has_value()) {
77 return std::nullopt;
78 }
79 auto input_uvs = maybe_input_uvs.value();
80
81 //----------------------------------------------------------------------------
82 /// Create AnonymousContents for rendering.
83 ///
84
85 auto sigma = effect_transform * Vector2(sigma_x_.sigma, sigma_y_.sigma);
86 RenderProc render_proc = [coverage, input_snapshot, input_uvs = input_uvs,
87 src_color_factor = src_color_factor_,
88 inner_blur_factor = inner_blur_factor_,
89 outer_blur_factor = outer_blur_factor_, sigma](
90 const ContentContext& renderer,
91 const Entity& entity, RenderPass& pass) -> bool {
92 auto& host_buffer = renderer.GetTransientsBuffer();
93
94 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
95 auto origin = coverage.GetOrigin();
96 auto size = coverage.GetSize();
97 vtx_builder.AddVertices({
98 {origin, input_uvs[0]},
99 {{origin.x + size.width, origin.y}, input_uvs[1]},
100 {{origin.x, origin.y + size.height}, input_uvs[2]},
101 {{origin.x + size.width, origin.y + size.height}, input_uvs[3]},
102 });
103
104 auto options = OptionsFromPassAndEntity(pass, entity);
105 options.primitive_type = PrimitiveType::kTriangleStrip;
106
107 VS::FrameInfo frame_info;
108 frame_info.mvp = entity.GetShaderTransform(pass);
109 frame_info.texture_sampler_y_coord_scale =
110 input_snapshot->texture->GetYCoordScale();
111
112 FS::FragInfo frag_info;
113 frag_info.sigma_uv = sigma.Abs() / input_snapshot->texture->GetSize();
114 frag_info.src_factor = src_color_factor;
115 frag_info.inner_blur_factor = inner_blur_factor;
116 frag_info.outer_blur_factor = outer_blur_factor;
117
118 pass.SetCommandLabel("Border Mask Blur Filter");
119 pass.SetPipeline(renderer.GetBorderMaskBlurPipeline(options));
120 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
121
122 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
123 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
124
125 const std::unique_ptr<const Sampler>& sampler =
126 renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
127 FS::BindTextureSampler(pass, input_snapshot->texture, sampler);
128
129 return pass.Draw().ok();
130 };
131
132 CoverageProc coverage_proc =
133 [coverage](const Entity& entity) -> std::optional<Rect> {
134 return coverage.TransformBounds(entity.GetTransform());
135 };
136
137 auto contents = AnonymousContents::Make(render_proc, coverage_proc);
138
139 Entity sub_entity;
140 sub_entity.SetContents(std::move(contents));
141 sub_entity.SetBlendMode(entity.GetBlendMode());
142 return sub_entity;
143}
const char * options
static std::shared_ptr< Contents > Make(RenderProc render_proc, CoverageProc coverage_proc)
std::function< std::optional< Rect >(const Entity &entity)> CoverageProc
Definition contents.h:50
std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)> RenderProc
Definition contents.h:49
FragmentShader_ FragmentShader
Definition pipeline.h:106
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
SolidFillVertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition contents.cc:35
Scalar sigma
Definition sigma.h:33

◆ SetBlurStyle()

void impeller::BorderMaskBlurFilterContents::SetBlurStyle ( BlurStyle  blur_style)

Definition at line 24 of file border_mask_blur_filter_contents.cc.

24 {
25 blur_style_ = blur_style;
26
27 switch (blur_style) {
29 src_color_factor_ = false;
30 inner_blur_factor_ = true;
31 outer_blur_factor_ = true;
32 break;
34 src_color_factor_ = true;
35 inner_blur_factor_ = false;
36 outer_blur_factor_ = true;
37 break;
39 src_color_factor_ = false;
40 inner_blur_factor_ = false;
41 outer_blur_factor_ = true;
42 break;
44 src_color_factor_ = false;
45 inner_blur_factor_ = true;
46 outer_blur_factor_ = false;
47 break;
48 }
49}
@ kNormal
Blurred inside and outside.
@ kOuter
Nothing inside, blurred outside.
@ kInner
Blurred inside, nothing outside.
@ kSolid
Solid inside, blurred outside.

◆ SetSigma()

void impeller::BorderMaskBlurFilterContents::SetSigma ( Sigma  sigma_x,
Sigma  sigma_y 
)

Definition at line 19 of file border_mask_blur_filter_contents.cc.

19 {
20 sigma_x_ = sigma_x;
21 sigma_y_ = sigma_y;
22}

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