Skip to content

Commit f5f3bbb

Browse files
committed
adds localtopass matrix
1 parent 8f3230d commit f5f3bbb

8 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎engine/src/flutter/impeller/display_list/canvas.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,8 @@ void Canvas::SaveLayer(const Paint& paint,
18851885
WrapInput(renderer_, backdrop_filter,
18861886
FilterInput::Make(std::move(input_texture)));
18871887
backdrop_filter_contents->SetEffectTransform(
1888+
transform_stack_.back().transform.Basis());
1889+
backdrop_filter_contents->SetLocalToPassTransform(
18881890
transform_stack_.back().transform);
18891891
backdrop_filter_contents->SetRenderingMode(
18901892
transform_stack_.back().transform.HasTranslation()

‎engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ void FilterContents::SetEffectTransform(const Matrix& effect_transform) {
146146
}
147147
}
148148

149+
void FilterContents::SetLocalToPassTransform(
150+
const Matrix& local_to_pass_transform) {
151+
local_to_pass_transform_ = local_to_pass_transform;
152+
153+
for (auto& input : inputs_) {
154+
input->SetLocalToPassTransform(local_to_pass_transform);
155+
}
156+
}
157+
149158
bool FilterContents::Render(const ContentContext& renderer,
150159
const Entity& entity,
151160
RenderPass& pass) const {

‎engine/src/flutter/impeller/entity/contents/filters/filter_contents.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ class FilterContents : public Contents {
106106
/// Entity being rendered.
107107
void SetEffectTransform(const Matrix& effect_transform);
108108

109+
/// @brief Sets the transform used for transforming local canvas geometry
110+
/// (such as `DlBlurImageFilter::bounds_`) into subpass coordinates.
111+
///
112+
/// In subpass and backdrop filter rendering scenarios, the effect
113+
/// itself (such as blur sigma or matrix filter transformations)
114+
/// operates on the screen-space backdrop and typically only requires
115+
/// the scale and rotation of the canvas CTM (via
116+
/// `SetEffectTransform`) to avoid shifting or double-translating the
117+
/// effect.
118+
///
119+
/// However, local geometry defined in widget/canvas space (such as a
120+
/// bounded blur rectangle) requires the full current transformation
121+
/// matrix including translation to be mapped accurately to the
122+
/// backdrop texture space (e.g. when rendering bounded blurs inside
123+
/// scrolling views).
124+
///
125+
/// @see `SetEffectTransform`
126+
void SetLocalToPassTransform(const Matrix& local_to_pass_transform);
127+
128+
const Matrix& GetLocalToPassTransform() const {
129+
return local_to_pass_transform_;
130+
}
131+
109132
/// @brief Create an Entity that renders this filter's output.
110133
std::optional<Entity> GetEntity(
111134
const ContentContext& renderer,
@@ -228,6 +251,7 @@ class FilterContents : public Contents {
228251

229252
FilterInput::Vector inputs_;
230253
Matrix effect_transform_ = Matrix();
254+
Matrix local_to_pass_transform_ = Matrix();
231255

232256
FilterContents(const FilterContents&) = delete;
233257

‎engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
847847

848848
std::optional<Quad> source_bounds;
849849
if (bounds_.has_value()) {
850-
Matrix transform = snapshot_entity.GetTransform() * effect_transform;
850+
Matrix transform =
851+
snapshot_entity.GetTransform() * GetLocalToPassTransform();
851852
source_bounds = bounds_->GetTransformedPoints(transform);
852853
}
853854

‎engine/src/flutter/impeller/entity/contents/filters/inputs/filter_contents_filter_input.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ void FilterContentsFilterInput::SetEffectTransform(const Matrix& matrix) {
5858
filter_->SetEffectTransform(matrix);
5959
}
6060

61+
void FilterContentsFilterInput::SetLocalToPassTransform(const Matrix& matrix) {
62+
filter_->SetLocalToPassTransform(matrix);
63+
}
64+
6165
void FilterContentsFilterInput::SetRenderingMode(
6266
Entity::RenderingMode rendering_mode) {
6367
filter_->SetRenderingMode(rendering_mode);

‎engine/src/flutter/impeller/entity/contents/filters/inputs/filter_contents_filter_input.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class FilterContentsFilterInput final : public FilterInput {
3737
// |FilterInput|
3838
virtual void SetEffectTransform(const Matrix& matrix) override;
3939

40+
// |FilterInput|
41+
virtual void SetLocalToPassTransform(const Matrix& matrix) override;
42+
4043
// |FilterInput|
4144
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode) override;
4245

‎engine/src/flutter/impeller/entity/contents/filters/inputs/filter_input.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ FilterInput::~FilterInput() = default;
8080

8181
void FilterInput::SetEffectTransform(const Matrix& matrix) {}
8282

83+
void FilterInput::SetLocalToPassTransform(const Matrix& matrix) {}
84+
8385
void FilterInput::SetRenderingMode(Entity::RenderingMode rendering_mode) {}
8486

8587
} // namespace impeller

‎engine/src/flutter/impeller/entity/contents/filters/inputs/filter_input.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class FilterInput {
9393
/// @brief Sets the effect transform of filter inputs.
9494
virtual void SetEffectTransform(const Matrix& matrix);
9595

96+
/// @brief Sets the local to pass transform of filter inputs.
97+
///
98+
/// @see `FilterContents::SetLocalToPassTransform`
99+
virtual void SetLocalToPassTransform(const Matrix& matrix);
100+
96101
/// @brief Turns on subpass mode for filter inputs.
97102
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode);
98103
};

0 commit comments

Comments
 (0)