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

Commit 27cd01a

Browse files
committed
[Impeller] Fix matrix filter ordering.
1 parent b314a29 commit 27cd01a

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

impeller/aiks/aiks_unittests.cc

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

29092909
TEST_P(AiksTest, MatrixBackdropFilter) {
29102910
Canvas canvas;
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});
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+
}
29202927
canvas.Restore();
29212928

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

impeller/entity/contents/filters/matrix_filter_contents.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
3535
}
3636

3737
auto& transform = is_subpass_ ? effect_transform : entity.GetTransformation();
38-
snapshot->transform = transform * //
39-
matrix_ * //
40-
transform.Invert() * //
41-
snapshot->transform;
38+
snapshot->transform = snapshot->transform * //
39+
transform * //
40+
matrix_ * //
41+
transform.Invert();
4242
snapshot->sampler_descriptor = sampler_descriptor_;
4343
return Entity::FromSnapshot(snapshot, entity.GetBlendMode(),
4444
entity.GetStencilDepth());

impeller/entity/entity_pass.cc

Lines changed: 18 additions & 16 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> backdrop_filter_contents = nullptr;
468+
std::shared_ptr<Contents> subpass_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-
backdrop_filter_contents =
473+
subpass_backdrop_filter_contents =
474474
proc(FilterInput::Make(std::move(texture)), subpass->xformation_,
475475
/*is_subpass*/ true);
476476

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

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

533534
// Stencil textures aren't shared between EntityPasses (as much of the
534535
// time they are transient).
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-
)) {
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+
)) {
546548
// Validation error messages are triggered for all `OnRender()` failure
547549
// cases.
548550
return EntityPass::EntityResult::Failure();

0 commit comments

Comments
 (0)