33// found in the LICENSE file.
44
55#include " impeller/entity/contents/filters/runtime_effect_filter_contents.h"
6+
67#include < cstring>
8+ #include < optional>
9+
710#include " impeller/base/validation.h"
811#include " impeller/entity/contents/anonymous_contents.h"
912#include " impeller/entity/contents/runtime_effect_contents.h"
1013#include " impeller/entity/geometry/geometry.h"
11- #include " impeller/geometry/point.h"
1214#include " impeller/geometry/size.h"
1315
1416namespace impeller {
1517
18+ void RuntimeEffectFilterContents::SetRuntimeStage (
19+ std::shared_ptr<RuntimeStage> runtime_stage) {
20+ runtime_stage_ = std::move (runtime_stage);
21+ }
22+
23+ void RuntimeEffectFilterContents::SetUniforms (
24+ std::shared_ptr<std::vector<uint8_t >> uniforms) {
25+ uniforms_ = std::move (uniforms);
26+ }
27+
28+ void RuntimeEffectFilterContents::SetTextureInputs (
29+ std::vector<RuntimeEffectContents::TextureInput> texture_inputs) {
30+ texture_inputs_ = std::move (texture_inputs);
31+ }
32+
1633// |FilterContents|
1734std::optional<Entity> RuntimeEffectFilterContents::RenderFilter (
1835 const FilterInput::Vector& inputs,
@@ -26,10 +43,15 @@ std::optional<Entity> RuntimeEffectFilterContents::RenderFilter(
2643 }
2744
2845 auto input_snapshot =
29- inputs[0 ]->GetSnapshot (" RuntimeEffectContents" , renderer, {} );
46+ inputs[0 ]->GetSnapshot (" RuntimeEffectContents" , renderer, entity );
3047 if (!input_snapshot.has_value ()) {
3148 return std::nullopt ;
3249 }
50+ std::optional<Rect> maybe_input_coverage = input_snapshot->GetCoverage ();
51+ if (!maybe_input_coverage.has_value ()) {
52+ return std::nullopt ;
53+ }
54+ Rect input_coverage = maybe_input_coverage.value ();
3355 // The shader is required to have at least one sampler, the first of
3456 // which is treated as the input and a vec2 size uniform to compute the
3557 // offsets. These are validated at the dart:ui layer, but to avoid crashes we
@@ -40,24 +62,29 @@ std::optional<Entity> RuntimeEffectFilterContents::RenderFilter(
4062 << " Shader must have at least one sampler and a vec2 size uniform." ;
4163 return std::nullopt ;
4264 }
43- texture_inputs_[0 ].texture = input_snapshot->texture ;
65+
66+ // Update uniform values.
67+ std::vector<RuntimeEffectContents::TextureInput> texture_input_copy =
68+ texture_inputs_;
69+ texture_input_copy[0 ].texture = input_snapshot->texture ;
70+
4471 Size size = Size (input_snapshot->texture ->GetSize ());
4572 memcpy (uniforms_->data (), &size, sizeof (Size));
4673
4774 // ----------------------------------------------------------------------------
4875 // / Create AnonymousContents for rendering.
4976 // /
50- RenderProc render_proc = [input_snapshot, runtime_stage = runtime_stage_,
51- uniforms = uniforms_,
52- texture_inputs = texture_inputs_](
53- const ContentContext& renderer ,
54- const Entity& entity, RenderPass& pass) -> bool {
77+ RenderProc render_proc =
78+ [input_snapshot, runtime_stage = runtime_stage_, uniforms = uniforms_,
79+ texture_inputs = texture_input_copy,
80+ input_coverage]( const ContentContext& renderer, const Entity& entity ,
81+ RenderPass& pass) -> bool {
5582 RuntimeEffectContents contents;
5683 contents.SetRuntimeStage (runtime_stage);
5784 contents.SetUniformData (uniforms);
5885 contents.SetTextureInputs (texture_inputs);
5986 contents.SetGeometry (
60- Geometry::MakeRect (input_snapshot-> GetCoverage (). value ( )));
87+ Geometry::MakeRect (Rect::MakeSize (input_coverage. GetSize () )));
6188 return contents.Render (renderer, entity, pass);
6289 };
6390
@@ -71,7 +98,7 @@ std::optional<Entity> RuntimeEffectFilterContents::RenderFilter(
7198 Entity sub_entity;
7299 sub_entity.SetContents (std::move (contents));
73100 sub_entity.SetBlendMode (entity.GetBlendMode ());
74- sub_entity.SetTransform (entity. GetTransform () );
101+ sub_entity.SetTransform (input_snapshot-> transform );
75102 return sub_entity;
76103}
77104
0 commit comments