35 morph_type_ = morph_type;
38std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
42 const Matrix& effect_transform,
44 const std::optional<Rect>& coverage_hint)
const {
56 auto input_snapshot =
inputs[0]->GetSnapshot(
"Morphology",
renderer, entity);
57 if (!input_snapshot.has_value()) {
65 auto maybe_input_uvs = input_snapshot->GetCoverageUVs(
coverage);
66 if (!maybe_input_uvs.has_value()) {
69 auto input_uvs = maybe_input_uvs.value();
77 auto& host_buffer =
renderer.GetTransientsBuffer();
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]},
87 VS::FrameInfo frame_info;
89 frame_info.texture_sampler_y_coord_scale =
90 input_snapshot->texture->GetYCoordScale();
93 auto transformed_radius =
95 auto transformed_texture_vertices =
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]);
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)
112 Point(transformed_texture_width, transformed_texture_height);
114 pass.SetCommandLabel(
"Morphology Filter");
119 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
121 auto sampler_descriptor = input_snapshot->sampler_descriptor;
122 if (
renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
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));
134 return pass.Draw().ok();
136 std::shared_ptr<CommandBuffer> command_buffer =
137 renderer.GetContext()->CreateCommandBuffer();
138 if (command_buffer ==
nullptr) {
143 renderer.MakeSubpass(
"Directional Morphology Filter",
145 if (!render_target.
ok()) {
150 ->Submit({std::move(command_buffer)})
155 SamplerDescriptor sampler_desc;
160 Snapshot{.texture = render_target.
value().GetRenderTargetTexture(),
162 .sampler_descriptor = sampler_desc,
163 .opacity = input_snapshot->opacity},
170 const Matrix& effect_transform)
const {
180 auto transformed_vector =
183 auto origin =
coverage->GetOrigin();
185 switch (morph_type_) {
187 origin -= transformed_vector;
188 size += transformed_vector * 2;
191 origin += transformed_vector;
192 size -= transformed_vector * 2;
203 const Matrix& effect_transform,
204 const Rect& output_limit)
const {
205 auto transformed_vector =
207 switch (morph_type_) {
209 return output_limit.
Expand(-transformed_vector);
211 return output_limit.
Expand(transformed_vector);
static void round(SkPoint *p)
std::function< bool(const ContentContext &, RenderPass &)> SubpassCallback
DirectionalMorphologyFilterContents()
void SetRadius(Radius radius)
std::optional< Rect > GetFilterCoverage(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 acros...
void SetMorphType(MorphType morph_type)
std::optional< Rect > GetFilterSourceCoverage(const Matrix &effect_transform, const Rect &output_limit) const override
Internal utility method for |GetSourceCoverage| that computes the inverse effect of this transform on...
~DirectionalMorphologyFilterContents() override
void SetDirection(Vector2 direction)
static Entity FromSnapshot(const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSourceOver)
Create an entity that can be used to render a given snapshot.
BlendMode GetBlendMode() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
VertexShader_ VertexShader
FragmentShader_ FragmentShader
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
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
constexpr float kEhCloseEnough
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
ContentContextOptions OptionsFromPass(const RenderPass &pass)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeOrthographic(TSize< T > size)
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
constexpr Vector4 TransformDirection(const Vector4 &v) const
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
constexpr TPoint Normalize() const
constexpr bool IsZero() const
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
static constexpr TRect MakeSize(const TSize< U > &size)
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.