35 morph_type_ = morph_type;
38std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
42 const Matrix& effect_transform,
44 const std::optional<Rect>& coverage_hint)
const {
45 using VS = MorphologyFilterPipeline::VertexShader;
46 using FS = MorphologyFilterPipeline::FragmentShader;
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& data_host_buffer = renderer.GetTransientsDataBuffer();
79 std::array<VS::PerVertexData, 4> vertices = {
80 VS::PerVertexData{
Point(0, 0), input_uvs[0]},
81 VS::PerVertexData{
Point(1, 0), input_uvs[1]},
82 VS::PerVertexData{
Point(0, 1), input_uvs[2]},
83 VS::PerVertexData{
Point(1, 1), input_uvs[3]},
86 VS::FrameInfo frame_info;
90 auto transformed_radius =
92 auto transformed_texture_vertices =
95 auto transformed_texture_width =
96 transformed_texture_vertices[0].GetDistance(
97 transformed_texture_vertices[1]);
98 auto transformed_texture_height =
99 transformed_texture_vertices[0].GetDistance(
100 transformed_texture_vertices[2]);
102 FS::FragInfo frag_info;
103 frag_info.radius = std::round(transformed_radius.GetLength());
104 frag_info.morph_type =
static_cast<Scalar>(morph_type_);
105 frag_info.uv_offset =
106 input_snapshot->transform.Invert()
107 .TransformDirection(transformed_radius)
109 Point(transformed_texture_width, transformed_texture_height);
111 pass.SetCommandLabel(
"Morphology Filter");
115 pass.SetPipeline(renderer.GetMorphologyFilterPipeline(options));
118 auto sampler_descriptor = input_snapshot->sampler_descriptor;
119 if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
124 FS::BindTextureSampler(
125 pass, input_snapshot->texture,
126 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
127 sampler_descriptor));
128 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
129 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
131 return pass.Draw().ok();
134 renderer.GetContext()->CreateCommandBuffer();
140 renderer.MakeSubpass(
"Directional Morphology Filter",
147 if (!render_target.
ok()) {
151 if (!renderer.GetContext()->EnqueueCommandBuffer(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 {
171 if (inputs.empty()) {
175 auto coverage = inputs[0]->GetCoverage(entity);
176 if (!coverage.has_value()) {
179 auto transform = inputs[0]->GetTransform(entity) * effect_transform.
Basis();
180 auto transformed_vector =
185 switch (morph_type_) {
187 origin -= transformed_vector;
188 size += transformed_vector * 2;
191 origin += transformed_vector;
192 size -= transformed_vector * 2;
195 if (size.x < 0 || size.y < 0) {
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);
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)
BlendMode GetBlendMode() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
static Entity FromSnapshot(const Snapshot &snapshot, BlendMode blend_mode=BlendMode::kSrcOver)
Create an entity that can be used to render a given snapshot.
FlutterDesktopBinaryReply callback
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
constexpr float kEhCloseEnough
LinePipeline::FragmentShader FS
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &data_host_buffer)
Create an index-less vertex buffer from a fixed size array.
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPass(const RenderPass &pass)
std::shared_ptr< CommandBuffer > command_buffer
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
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
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.
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
constexpr TSize Ceil() const