[Impeller] Only strip the translation from backdrop filter effect transforms. (flutter/engine#44029)

Resolves https://github.com/flutter/flutter/issues/131305.
This commit is contained in:
Brandon DeRosier
2023-07-25 22:17:08 -07:00
committed by GitHub
parent 1d2593d09f
commit 17530e0b22
3 changed files with 36 additions and 5 deletions

View File

@@ -2930,6 +2930,38 @@ TEST_P(AiksTest, DrawPictureWithText) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, MatrixSaveLayerFilter) {
Canvas canvas;
canvas.DrawPaint({.color = Color::Black()});
canvas.SaveLayer({}, std::nullopt);
{
canvas.DrawCircle(Point(200, 200), 100,
{.color = Color::Green().WithAlpha(0.5),
.blend_mode = BlendMode::kPlus});
// Should render a second circle, centered on the bottom-right-most edge of
// the circle.
canvas.SaveLayer({.image_filter =
[](const FilterInput::Ref& input,
const Matrix& effect_transform, bool is_subpass) {
Matrix matrix =
Matrix::MakeTranslation(
Vector2(1, 1) * (100 + 100 * k1OverSqrt2)) *
Matrix::MakeScale(Vector2(1, 1) * 0.2) *
Matrix::MakeTranslation(Vector2(-100, -100));
return FilterContents::MakeMatrixFilter(
input, matrix, {}, Matrix(), true);
}},
std::nullopt);
canvas.DrawCircle(Point(200, 200), 100,
{.color = Color::Green().WithAlpha(0.5),
.blend_mode = BlendMode::kPlus});
canvas.Restore();
}
canvas.Restore();
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, MatrixBackdropFilter) {
Canvas canvas;
canvas.DrawPaint({.color = Color::Black()});

View File

@@ -49,8 +49,7 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
// mentioned above). And so we sneak the subpass's captured CTM in through the
// effect transform.
auto transform = is_subpass_ ? effect_transform.Basis()
: entity.GetTransformation().Basis();
auto transform = is_subpass_ ? effect_transform : entity.GetTransformation();
snapshot->transform = transform * //
matrix_ * //
transform.Invert() * //

View File

@@ -470,9 +470,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
auto texture = pass_context.GetTexture();
// Render the backdrop texture before any of the pass elements.
const auto& proc = subpass->backdrop_filter_proc_;
subpass_backdrop_filter_contents =
proc(FilterInput::Make(std::move(texture)), subpass->xformation_,
/*is_subpass*/ true);
subpass_backdrop_filter_contents = proc(
FilterInput::Make(std::move(texture)), subpass->xformation_.Basis(),
/*is_subpass*/ true);
// The subpass will need to read from the current pass texture when
// rendering the backdrop, so if there's an active pass, end it prior to