Skip to content

Commit a4a5439

Browse files
authored
[Impeller] Only strip the translation from backdrop filter effect transforms. (flutter#44029)
Resolves flutter/flutter#131305.
1 parent df12fff commit a4a5439

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

impeller/aiks/aiks_unittests.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,38 @@ TEST_P(AiksTest, DrawPictureWithText) {
29302930
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
29312931
}
29322932

2933+
TEST_P(AiksTest, MatrixSaveLayerFilter) {
2934+
Canvas canvas;
2935+
canvas.DrawPaint({.color = Color::Black()});
2936+
canvas.SaveLayer({}, std::nullopt);
2937+
{
2938+
canvas.DrawCircle(Point(200, 200), 100,
2939+
{.color = Color::Green().WithAlpha(0.5),
2940+
.blend_mode = BlendMode::kPlus});
2941+
// Should render a second circle, centered on the bottom-right-most edge of
2942+
// the circle.
2943+
canvas.SaveLayer({.image_filter =
2944+
[](const FilterInput::Ref& input,
2945+
const Matrix& effect_transform, bool is_subpass) {
2946+
Matrix matrix =
2947+
Matrix::MakeTranslation(
2948+
Vector2(1, 1) * (100 + 100 * k1OverSqrt2)) *
2949+
Matrix::MakeScale(Vector2(1, 1) * 0.2) *
2950+
Matrix::MakeTranslation(Vector2(-100, -100));
2951+
return FilterContents::MakeMatrixFilter(
2952+
input, matrix, {}, Matrix(), true);
2953+
}},
2954+
std::nullopt);
2955+
canvas.DrawCircle(Point(200, 200), 100,
2956+
{.color = Color::Green().WithAlpha(0.5),
2957+
.blend_mode = BlendMode::kPlus});
2958+
canvas.Restore();
2959+
}
2960+
canvas.Restore();
2961+
2962+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2963+
}
2964+
29332965
TEST_P(AiksTest, MatrixBackdropFilter) {
29342966
Canvas canvas;
29352967
canvas.DrawPaint({.color = Color::Black()});

impeller/entity/contents/filters/matrix_filter_contents.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
4949
// mentioned above). And so we sneak the subpass's captured CTM in through the
5050
// effect transform.
5151

52-
auto transform = is_subpass_ ? effect_transform.Basis()
53-
: entity.GetTransformation().Basis();
52+
auto transform = is_subpass_ ? effect_transform : entity.GetTransformation();
5453
snapshot->transform = transform * //
5554
matrix_ * //
5655
transform.Invert() * //

impeller/entity/entity_pass.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
470470
auto texture = pass_context.GetTexture();
471471
// Render the backdrop texture before any of the pass elements.
472472
const auto& proc = subpass->backdrop_filter_proc_;
473-
subpass_backdrop_filter_contents =
474-
proc(FilterInput::Make(std::move(texture)), subpass->xformation_,
475-
/*is_subpass*/ true);
473+
subpass_backdrop_filter_contents = proc(
474+
FilterInput::Make(std::move(texture)), subpass->xformation_.Basis(),
475+
/*is_subpass*/ true);
476476

477477
// The subpass will need to read from the current pass texture when
478478
// rendering the backdrop, so if there's an active pass, end it prior to

0 commit comments

Comments
 (0)