Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cda52b0

Browse files
author
jonahwilliams
committed
fixups for entity transform.
1 parent c786ea8 commit cda52b0

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

impeller/entity/contents/filters/runtime_effect_filter_contents.cc

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@
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

1416
namespace 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|
1734
std::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

impeller/entity/contents/filters/runtime_effect_filter_contents.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,24 @@
99

1010
namespace impeller {
1111

12+
/// A filter that applies a runtime effect shader
1213
class RuntimeEffectFilterContents final : public FilterContents {
1314
public:
1415
RuntimeEffectFilterContents() {}
1516

16-
~RuntimeEffectFilterContents() {}
17+
~RuntimeEffectFilterContents() = default;
1718

18-
void SetRuntimeStage(std::shared_ptr<RuntimeStage> runtime_stage) {
19-
runtime_stage_ = std::move(runtime_stage);
20-
}
19+
void SetRuntimeStage(std::shared_ptr<RuntimeStage> runtime_stage);
2120

22-
void SetUniforms(std::shared_ptr<std::vector<uint8_t>> uniforms) {
23-
uniforms_ = std::move(uniforms);
24-
}
21+
void SetUniforms(std::shared_ptr<std::vector<uint8_t>> uniforms);
2522

2623
void SetTextureInputs(
27-
std::vector<RuntimeEffectContents::TextureInput> texture_inputs) {
28-
texture_inputs_ = std::move(texture_inputs);
29-
}
24+
std::vector<RuntimeEffectContents::TextureInput> texture_inputs);
3025

3126
private:
3227
std::shared_ptr<RuntimeStage> runtime_stage_;
33-
mutable std::shared_ptr<std::vector<uint8_t>> uniforms_;
34-
mutable std::vector<RuntimeEffectContents::TextureInput> texture_inputs_;
28+
std::shared_ptr<std::vector<uint8_t>> uniforms_;
29+
std::vector<RuntimeEffectContents::TextureInput> texture_inputs_;
3530

3631
// |FilterContents|
3732
std::optional<Entity> RenderFilter(

0 commit comments

Comments
 (0)