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

Commit 1d75700

Browse files
authored
Revert "[Impeller] Fix MatrixFilter multiplication ordering for subpasses. (#43943)"
This reverts commit 33a24ff.
1 parent 4fded78 commit 1d75700

File tree

3 files changed

+30
-73
lines changed

3 files changed

+30
-73
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,22 +2908,15 @@ TEST_P(AiksTest, DrawPictureWithText) {
29082908

29092909
TEST_P(AiksTest, MatrixBackdropFilter) {
29102910
Canvas canvas;
2911-
canvas.DrawPaint({.color = Color::Black()});
2912-
canvas.SaveLayer({}, std::nullopt);
2913-
{
2914-
canvas.DrawCircle(
2915-
Point(200, 200), 100,
2916-
{.color = Color::Green(), .blend_mode = BlendMode::kPlus});
2917-
// Should render a second intersecting circle, offset by 100, 100.
2918-
canvas.SaveLayer({}, std::nullopt,
2919-
[](const FilterInput::Ref& input,
2920-
const Matrix& effect_transform, bool is_subpass) {
2921-
return FilterContents::MakeMatrixFilter(
2922-
input, Matrix::MakeTranslation(Vector2(100, 100)),
2923-
{}, Matrix(), true);
2924-
});
2925-
canvas.Restore();
2926-
}
2911+
canvas.SaveLayer({}, std::nullopt,
2912+
[](const FilterInput::Ref& input,
2913+
const Matrix& effect_transform, bool is_subpass) {
2914+
return FilterContents::MakeMatrixFilter(
2915+
input, Matrix::MakeTranslation(Vector2(100, 100)), {},
2916+
Matrix(), true);
2917+
});
2918+
canvas.DrawCircle(Point(100, 100), 100,
2919+
{.color = Color::Green(), .blend_mode = BlendMode::kPlus});
29272920
canvas.Restore();
29282921

29292922
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));

impeller/entity/contents/filters/matrix_filter_contents.cc

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,11 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
3434
return std::nullopt;
3535
}
3636

37-
if (is_subpass_) {
38-
// There are two special quirks with how Matrix filters behave when used as
39-
// subpass backdrop filters:
40-
//
41-
// 1. For subpass backdrop filters, the snapshot transform is always just a
42-
// translation that positions the parent pass texture correctly relative
43-
// to the subpass texture. However, this translation always needs to be
44-
// applied in screen space.
45-
//
46-
// Since we know the snapshot transform will always have an identity
47-
// basis in this case, we safely reverse the order and apply the filter's
48-
// matrix within the snapshot transform space.
49-
//
50-
// 2. The filter's matrix needs to be applied within the space defined by
51-
// the scene's current transformation matrix (CTM). For example: If the
52-
// CTM is scaled up, then translations applied by the matrix should be
53-
// magnified accordingly.
54-
//
55-
// To accomplish this, we sandwitch the filter's matrix within the CTM in
56-
// both cases. But notice that for the subpass backdrop filter case, we
57-
// use the "effect transform" instead of the Entity's transform!
58-
//
59-
// That's because in the subpass backdrop filter case, the Entity's
60-
// transform isn't actually the captured CTM of the scene like it usually
61-
// is; instead, it's just a screen space translation that offsets the
62-
// backdrop texture (as mentioned above). And so we sneak the subpass's
63-
// captured CTM in through the effect transform.
64-
//
65-
66-
snapshot->transform = snapshot->transform * //
67-
effect_transform * //
68-
matrix_ * //
69-
effect_transform.Invert();
70-
} else {
71-
snapshot->transform = entity.GetTransformation() * //
72-
matrix_ * //
73-
entity.GetTransformation().Invert() * //
74-
snapshot->transform;
75-
}
37+
auto& transform = is_subpass_ ? effect_transform : entity.GetTransformation();
38+
snapshot->transform = transform * //
39+
matrix_ * //
40+
transform.Invert() * //
41+
snapshot->transform;
7642
snapshot->sampler_descriptor = sampler_descriptor_;
7743
return Entity::FromSnapshot(snapshot, entity.GetBlendMode(),
7844
entity.GetStencilDepth());

impeller/entity/entity_pass.cc

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,12 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
465465
return EntityPass::EntityResult::Skip();
466466
}
467467

468-
std::shared_ptr<Contents> subpass_backdrop_filter_contents = nullptr;
468+
std::shared_ptr<Contents> backdrop_filter_contents = nullptr;
469469
if (subpass->backdrop_filter_proc_) {
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 =
473+
backdrop_filter_contents =
474474
proc(FilterInput::Make(std::move(texture)), subpass->xformation_,
475475
/*is_subpass*/ true);
476476

@@ -507,10 +507,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
507507
return EntityPass::EntityResult::Skip();
508508
}
509509

510-
auto subpass_coverage =
511-
(subpass->flood_clip_ || subpass_backdrop_filter_contents)
512-
? coverage_limit
513-
: GetSubpassCoverage(*subpass, coverage_limit);
510+
auto subpass_coverage = (subpass->flood_clip_ || backdrop_filter_contents)
511+
? coverage_limit
512+
: GetSubpassCoverage(*subpass, coverage_limit);
514513
if (!subpass_coverage.has_value()) {
515514
return EntityPass::EntityResult::Skip();
516515
}
@@ -533,18 +532,17 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
533532

534533
// Stencil textures aren't shared between EntityPasses (as much of the
535534
// time they are transient).
536-
if (!subpass->OnRender(
537-
renderer, // renderer
538-
root_pass_size, // root_pass_size
539-
subpass_target, // pass_target
540-
subpass_coverage->origin, // global_pass_position
541-
subpass_coverage->origin -
542-
global_pass_position, // local_pass_position
543-
++pass_depth, // pass_depth
544-
stencil_coverage_stack, // stencil_coverage_stack
545-
subpass->stencil_depth_, // stencil_depth_floor
546-
subpass_backdrop_filter_contents // backdrop_filter_contents
547-
)) {
535+
if (!subpass->OnRender(renderer, // renderer
536+
root_pass_size, // root_pass_size
537+
subpass_target, // pass_target
538+
subpass_coverage->origin, // global_pass_position
539+
subpass_coverage->origin -
540+
global_pass_position, // local_pass_position
541+
++pass_depth, // pass_depth
542+
stencil_coverage_stack, // stencil_coverage_stack
543+
subpass->stencil_depth_, // stencil_depth_floor
544+
backdrop_filter_contents // backdrop_filter_contents
545+
)) {
548546
// Validation error messages are triggered for all `OnRender()` failure
549547
// cases.
550548
return EntityPass::EntityResult::Failure();

0 commit comments

Comments
 (0)