From 122fa33d5422744b98c785151b0cc2a1416cdf30 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Tue, 16 Jul 2024 14:33:09 -0700 Subject: [PATCH 1/2] [Impeller] Use depth transform in framebuffer blend entities. --- .../display_list/aiks_dl_clip_unittests.cc | 25 +++++++++++++++++++ .../contents/filters/blend_filter_contents.cc | 6 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/impeller/display_list/aiks_dl_clip_unittests.cc b/impeller/display_list/aiks_dl_clip_unittests.cc index 5576f343f9945..543ee827487b9 100644 --- a/impeller/display_list/aiks_dl_clip_unittests.cc +++ b/impeller/display_list/aiks_dl_clip_unittests.cc @@ -117,5 +117,30 @@ TEST_P(AiksTest, ClipsUseCurrentTransform) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +/// If correct, this test should draw a green circle. If any red is visible, +/// there is a depth bug. +TEST_P(AiksTest, FramebufferBlendsRespectClips) { + DisplayListBuilder builder; + + // Clear the whole canvas with white. + DlPaint paint; + paint.setColor(DlColor::kWhite()); + builder.DrawPaint(paint); + + builder.ClipPath(SkPath::Circle(150, 150, 50), DlCanvas::ClipOp::kIntersect); + + // Draw a red rectangle that should not show through the circle clip. + paint.setColor(DlColor::kRed()); + paint.setBlendMode(DlBlendMode::kMultiply); + builder.DrawRect(SkRect::MakeXYWH(100, 100, 100, 100), paint); + + // Draw a green circle that shows through the clip. + paint.setColor(DlColor::kGreen()); + paint.setBlendMode(DlBlendMode::kSrcOver); + builder.DrawCircle(SkPoint::Make(150, 150), 50, paint); + + ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); +} + } // namespace testing } // namespace impeller diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index f7f3f2d94cd6a..2d5b61428d6db 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -365,7 +365,8 @@ std::optional BlendFilterContents::CreateForegroundAdvancedBlend( FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler); frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale(); - frame_info.mvp = pass.GetOrthographicTransform() * dst_snapshot->transform; + frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(), + pass, dst_snapshot->transform); blend_info.dst_input_alpha = absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes @@ -454,7 +455,8 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( FS::FragInfo frag_info; VS::FrameInfo frame_info; - frame_info.mvp = pass.GetOrthographicTransform() * dst_snapshot->transform; + frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(), + pass, dst_snapshot->transform); auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor; if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) { From 906ac11f8244c63fb4b3c77c26a17266d756ec96 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Tue, 16 Jul 2024 15:17:46 -0700 Subject: [PATCH 2/2] diff --- testing/impeller_golden_tests_output.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index 82812e676a43a..a7e803cc170f2 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -644,6 +644,9 @@ impeller_Play_AiksTest_ForegroundPipelineBlendAppliesTransformCorrectly_Vulkan.p impeller_Play_AiksTest_FramebufferAdvancedBlendCoverage_Metal.png impeller_Play_AiksTest_FramebufferAdvancedBlendCoverage_OpenGLES.png impeller_Play_AiksTest_FramebufferAdvancedBlendCoverage_Vulkan.png +impeller_Play_AiksTest_FramebufferBlendsRespectClips_Metal.png +impeller_Play_AiksTest_FramebufferBlendsRespectClips_OpenGLES.png +impeller_Play_AiksTest_FramebufferBlendsRespectClips_Vulkan.png impeller_Play_AiksTest_GaussianBlurAnimatedBackdrop_Metal.png impeller_Play_AiksTest_GaussianBlurAnimatedBackdrop_OpenGLES.png impeller_Play_AiksTest_GaussianBlurAnimatedBackdrop_Vulkan.png