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

Commit 3ea260f

Browse files
author
Jonah Williams
authored
[CP][Impeller] Use depth transform in framebuffer blend entities. (#53951) (#54478)
\Without this the depth always ends up being a very large z depth of 0.5, which can cause clips to be ignored.
1 parent c4b0a37 commit 3ea260f

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

impeller/display_list/aiks_dl_clip_unittests.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,30 @@ TEST_P(AiksTest, ClipsUseCurrentTransform) {
117117
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
118118
}
119119

120+
/// If correct, this test should draw a green circle. If any red is visible,
121+
/// there is a depth bug.
122+
TEST_P(AiksTest, FramebufferBlendsRespectClips) {
123+
DisplayListBuilder builder;
124+
125+
// Clear the whole canvas with white.
126+
DlPaint paint;
127+
paint.setColor(DlColor::kWhite());
128+
builder.DrawPaint(paint);
129+
130+
builder.ClipPath(SkPath::Circle(150, 150, 50), DlCanvas::ClipOp::kIntersect);
131+
132+
// Draw a red rectangle that should not show through the circle clip.
133+
paint.setColor(DlColor::kRed());
134+
paint.setBlendMode(DlBlendMode::kMultiply);
135+
builder.DrawRect(SkRect::MakeXYWH(100, 100, 100, 100), paint);
136+
137+
// Draw a green circle that shows through the clip.
138+
paint.setColor(DlColor::kGreen());
139+
paint.setBlendMode(DlBlendMode::kSrcOver);
140+
builder.DrawCircle(SkPoint::Make(150, 150), 50, paint);
141+
142+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
143+
}
144+
120145
} // namespace testing
121146
} // namespace impeller

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
365365
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
366366
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
367367

368-
frame_info.mvp = pass.GetOrthographicTransform() * dst_snapshot->transform;
368+
frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(),
369+
pass, dst_snapshot->transform);
369370

370371
blend_info.dst_input_alpha =
371372
absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
@@ -454,7 +455,8 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
454455
FS::FragInfo frag_info;
455456
VS::FrameInfo frame_info;
456457

457-
frame_info.mvp = pass.GetOrthographicTransform() * dst_snapshot->transform;
458+
frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(),
459+
pass, dst_snapshot->transform);
458460

459461
auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor;
460462
if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {

testing/impeller_golden_tests_output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ impeller_Play_AiksTest_ForegroundPipelineBlendAppliesTransformCorrectly_Vulkan.p
641641
impeller_Play_AiksTest_FramebufferAdvancedBlendCoverage_Metal.png
642642
impeller_Play_AiksTest_FramebufferAdvancedBlendCoverage_OpenGLES.png
643643
impeller_Play_AiksTest_FramebufferAdvancedBlendCoverage_Vulkan.png
644+
impeller_Play_AiksTest_FramebufferBlendsRespectClips_Metal.png
645+
impeller_Play_AiksTest_FramebufferBlendsRespectClips_OpenGLES.png
646+
impeller_Play_AiksTest_FramebufferBlendsRespectClips_Vulkan.png
644647
impeller_Play_AiksTest_GaussianBlurAnimatedBackdrop_Metal.png
645648
impeller_Play_AiksTest_GaussianBlurAnimatedBackdrop_OpenGLES.png
646649
impeller_Play_AiksTest_GaussianBlurAnimatedBackdrop_Vulkan.png

0 commit comments

Comments
 (0)