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

#include <morphology_filter_contents.h>

Inheritance diagram for impeller::DirectionalMorphologyFilterContents:
impeller::FilterContents impeller::Contents

Public Member Functions

 DirectionalMorphologyFilterContents ()
 
 ~DirectionalMorphologyFilterContents () override
 
void SetRadius (Radius radius)
 
void SetDirection (Vector2 direction)
 
void SetMorphType (MorphType morph_type)
 
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 morphology_filter_contents.h.

Constructor & Destructor Documentation

◆ DirectionalMorphologyFilterContents()

impeller::DirectionalMorphologyFilterContents::DirectionalMorphologyFilterContents ( )
default

◆ ~DirectionalMorphologyFilterContents()

impeller::DirectionalMorphologyFilterContents::~DirectionalMorphologyFilterContents ( )
overridedefault

Member Function Documentation

◆ GetFilterCoverage()

std::optional< Rect > impeller::DirectionalMorphologyFilterContents::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 167 of file morphology_filter_contents.cc.

170 {
171 if (inputs.empty()) {
172 return std::nullopt;
173 }
174
175 auto coverage = inputs[0]->GetCoverage(entity);
176 if (!coverage.has_value()) {
177 return std::nullopt;
178 }
179 auto transform = inputs[0]->GetTransform(entity) * effect_transform.Basis();
180 auto transformed_vector =
181 transform.TransformDirection(direction_ * radius_.radius).Abs();
182
183 auto origin = coverage->GetOrigin();
184 auto size = Vector2(coverage->GetSize());
185 switch (morph_type_) {
187 origin -= transformed_vector;
188 size += transformed_vector * 2;
189 break;
191 origin += transformed_vector;
192 size -= transformed_vector * 2;
193 break;
194 }
195 if (size.x < 0 || size.y < 0) {
196 return Rect::MakeSize(Size(0, 0));
197 }
198 return Rect::MakeOriginSize(origin, Size(size.x, size.y));
199}
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
Point Vector2
Definition point.h:320
TSize< Scalar > Size
Definition size.h:137
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
Scalar radius
Definition sigma.h:49
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition rect.h:140
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146

◆ GetFilterSourceCoverage()

std::optional< Rect > impeller::DirectionalMorphologyFilterContents::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 202 of file morphology_filter_contents.cc.

204 {
205 auto transformed_vector =
206 effect_transform.TransformDirection(direction_ * radius_.radius).Abs();
207 switch (morph_type_) {
209 return output_limit.Expand(-transformed_vector);
211 return output_limit.Expand(transformed_vector);
212 }
213}

◆ RenderFilter()

std::optional< Entity > impeller::DirectionalMorphologyFilterContents::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.

Render to texture.

Implements impeller::FilterContents.

Definition at line 38 of file morphology_filter_contents.cc.

44 {
47
48 //----------------------------------------------------------------------------
49 /// Handle inputs.
50 ///
51
52 if (inputs.empty()) {
53 return std::nullopt;
54 }
55
56 auto input_snapshot = inputs[0]->GetSnapshot("Morphology", renderer, entity);
57 if (!input_snapshot.has_value()) {
58 return std::nullopt;
59 }
60
61 if (radius_.radius < kEhCloseEnough) {
62 return Entity::FromSnapshot(input_snapshot.value(), entity.GetBlendMode());
63 }
64
65 auto maybe_input_uvs = input_snapshot->GetCoverageUVs(coverage);
66 if (!maybe_input_uvs.has_value()) {
67 return std::nullopt;
68 }
69 auto input_uvs = maybe_input_uvs.value();
70
71 //----------------------------------------------------------------------------
72 /// Render to texture.
73 ///
74
75 ContentContext::SubpassCallback callback = [&](const ContentContext& renderer,
76 RenderPass& pass) {
77 auto& host_buffer = renderer.GetTransientsBuffer();
78
79 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
80 vtx_builder.AddVertices({
81 {Point(0, 0), input_uvs[0]},
82 {Point(1, 0), input_uvs[1]},
83 {Point(0, 1), input_uvs[2]},
84 {Point(1, 1), input_uvs[3]},
85 });
86
87 VS::FrameInfo frame_info;
88 frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
89 frame_info.texture_sampler_y_coord_scale =
90 input_snapshot->texture->GetYCoordScale();
91
92 auto transform = entity.GetTransform() * effect_transform.Basis();
93 auto transformed_radius =
94 transform.TransformDirection(direction_ * radius_.radius);
95 auto transformed_texture_vertices =
96 Rect::MakeSize(input_snapshot->texture->GetSize())
97 .GetTransformedPoints(input_snapshot->transform);
98 auto transformed_texture_width =
99 transformed_texture_vertices[0].GetDistance(
100 transformed_texture_vertices[1]);
101 auto transformed_texture_height =
102 transformed_texture_vertices[0].GetDistance(
103 transformed_texture_vertices[2]);
104
105 FS::FragInfo frag_info;
106 frag_info.radius = std::round(transformed_radius.GetLength());
107 frag_info.morph_type = static_cast<Scalar>(morph_type_);
108 frag_info.uv_offset =
109 input_snapshot->transform.Invert()
110 .TransformDirection(transformed_radius)
111 .Normalize() /
112 Point(transformed_texture_width, transformed_texture_height);
113
114 pass.SetCommandLabel("Morphology Filter");
115 auto options = OptionsFromPass(pass);
116 options.primitive_type = PrimitiveType::kTriangleStrip;
117 options.blend_mode = BlendMode::kSource;
118 pass.SetPipeline(renderer.GetMorphologyFilterPipeline(options));
119 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
120
121 auto sampler_descriptor = input_snapshot->sampler_descriptor;
122 if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
123 sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
124 sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
125 }
126
127 FS::BindTextureSampler(
128 pass, input_snapshot->texture,
129 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
130 sampler_descriptor));
131 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
132 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
133
134 return pass.Draw().ok();
135 };
136 std::shared_ptr<CommandBuffer> command_buffer =
137 renderer.GetContext()->CreateCommandBuffer();
138 if (command_buffer == nullptr) {
139 return std::nullopt;
140 }
141
142 fml::StatusOr<RenderTarget> render_target =
143 renderer.MakeSubpass("Directional Morphology Filter",
144 ISize(coverage.GetSize()), command_buffer, callback);
145 if (!render_target.ok()) {
146 return std::nullopt;
147 }
148 if (!renderer.GetContext()
149 ->GetCommandQueue()
150 ->Submit(/*buffers=*/{std::move(command_buffer)})
151 .ok()) {
152 return std::nullopt;
153 }
154
155 SamplerDescriptor sampler_desc;
156 sampler_desc.min_filter = MinMagFilter::kLinear;
157 sampler_desc.mag_filter = MinMagFilter::kLinear;
158
160 Snapshot{.texture = render_target.value().GetRenderTargetTexture(),
162 .sampler_descriptor = sampler_desc,
163 .opacity = input_snapshot->opacity},
164 entity.GetBlendMode());
165}
const char * options
const T & value() const
Definition status_or.h:77
bool ok() const
Definition status_or.h:75
std::function< bool(const ContentContext &, RenderPass &)> SubpassCallback
static Entity FromSnapshot(const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSourceOver)
Create an entity that can be used to render a given snapshot.
Definition entity.cc:22
FragmentShader_ FragmentShader
Definition pipeline.h:106
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
float Scalar
Definition scalar.h:18
constexpr float kEhCloseEnough
Definition constants.h:56
SolidFillVertexShader VS
TPoint< Scalar > Point
Definition point.h:316
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
TSize< int64_t > ISize
Definition size.h:138
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition contents.cc:20
static constexpr Matrix MakeOrthographic(TSize< T > size)
Definition matrix.h:495
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition rect.h:394

◆ SetDirection()

void impeller::DirectionalMorphologyFilterContents::SetDirection ( Vector2  direction)

Definition at line 27 of file morphology_filter_contents.cc.

27 {
28 direction_ = direction.Normalize();
29 if (direction_.IsZero()) {
30 direction_ = Vector2(0, 1);
31 }
32}
constexpr TPoint Normalize() const
Definition point.h:208
constexpr bool IsZero() const
Definition point.h:234

◆ SetMorphType()

void impeller::DirectionalMorphologyFilterContents::SetMorphType ( MorphType  morph_type)

Definition at line 34 of file morphology_filter_contents.cc.

34 {
35 morph_type_ = morph_type;
36}

◆ SetRadius()

void impeller::DirectionalMorphologyFilterContents::SetRadius ( Radius  radius)

Definition at line 23 of file morphology_filter_contents.cc.

23 {
24 radius_ = radius;
25}

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