From a0e203c8b6324121c49c8d672380f70aab4add96 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2024 09:02:55 -0700 Subject: [PATCH 1/4] Fixes image filter + advanced blends --- .../display_list/aiks_dl_blend_unittests.cc | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/impeller/display_list/aiks_dl_blend_unittests.cc b/impeller/display_list/aiks_dl_blend_unittests.cc index 0c9fcd51ae8a5..fc66216cc8f76 100644 --- a/impeller/display_list/aiks_dl_blend_unittests.cc +++ b/impeller/display_list/aiks_dl_blend_unittests.cc @@ -246,6 +246,62 @@ TEST_P(AiksTest, ImageFilterBlend) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } +TEST_P(AiksTest, ImageFilterAdvancedBlend) { + bool has_color_filter = true; + auto callback = [&]() -> sk_sp { + if (AiksTest::ImGuiBegin("Controls", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::Checkbox("has color filter", &has_color_filter); + ImGui::End(); + } + + DisplayListBuilder builder; + builder.Scale(GetContentScale().x, GetContentScale().y); + + auto src_image = + DlImageImpeller::Make(CreateTextureForFixture("blend_mode_src.png")); + auto dst_image = + DlImageImpeller::Make(CreateTextureForFixture("blend_mode_dst.png")); + + std::vector blend_modes = { + DlBlendMode::kScreen, DlBlendMode::kOverlay, + DlBlendMode::kDarken, DlBlendMode::kLighten, + DlBlendMode::kColorDodge, DlBlendMode::kColorBurn, + DlBlendMode::kHardLight, DlBlendMode::kSoftLight, + DlBlendMode::kDifference, DlBlendMode::kExclusion, + DlBlendMode::kMultiply, DlBlendMode::kHue, + DlBlendMode::kSaturation, DlBlendMode::kColor, + DlBlendMode::kLuminosity, + }; + + for (uint32_t i = 0; i < blend_modes.size(); ++i) { + builder.Save(); + builder.Translate((i % 5) * 200, (i / 5) * 200); + builder.Scale(0.4, 0.4); + { + DlPaint dstPaint; + builder.DrawImage(dst_image, {0, 0}, DlImageSampling::kMipmapLinear, + &dstPaint); + } + { + DlPaint srcPaint; + srcPaint.setBlendMode(blend_modes[i]); + if (has_color_filter) { + std::shared_ptr color_filter = + DlBlendColorFilter::Make(DlColor::RGBA(0.9, 0.5, 0.0, 1.0), + DlBlendMode::kSrcIn); + srcPaint.setColorFilter(color_filter); + } + builder.DrawImage(src_image, {0, 0}, DlImageSampling::kMipmapLinear, + &srcPaint); + } + builder.Restore(); + } + return builder.Build(); + }; + ASSERT_TRUE(OpenPlaygroundHere(callback)); +} + // Bug: https://github.com/flutter/flutter/issues/142549 TEST_P(AiksTest, BlendModePlusAlphaWideGamut) { EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(), From a45417a2302c7f5c714aace08fa6713b66cafa00 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2024 15:42:11 -0700 Subject: [PATCH 2/4] actually fixed it and renamed tests --- impeller/display_list/aiks_dl_blend_unittests.cc | 4 ++-- impeller/entity/contents/filters/blend_filter_contents.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/impeller/display_list/aiks_dl_blend_unittests.cc b/impeller/display_list/aiks_dl_blend_unittests.cc index fc66216cc8f76..0de3f60e6a6d5 100644 --- a/impeller/display_list/aiks_dl_blend_unittests.cc +++ b/impeller/display_list/aiks_dl_blend_unittests.cc @@ -195,7 +195,7 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) { } // Compare results with https://api.flutter.dev/flutter/dart-ui/BlendMode.html -TEST_P(AiksTest, ImageFilterBlend) { +TEST_P(AiksTest, ColorFilterBlend) { bool has_color_filter = true; auto callback = [&]() -> sk_sp { if (AiksTest::ImGuiBegin("Controls", nullptr, @@ -246,7 +246,7 @@ TEST_P(AiksTest, ImageFilterBlend) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -TEST_P(AiksTest, ImageFilterAdvancedBlend) { +TEST_P(AiksTest, ColorFilterAdvancedBlend) { bool has_color_filter = true; auto callback = [&]() -> sk_sp { if (AiksTest::ImGuiBegin("Controls", nullptr, diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index 59c21d2caf8ec..a1120d3f9039f 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -461,8 +461,9 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( FS::FragInfo frag_info; VS::FrameInfo frame_info; - frame_info.mvp = Entity::GetShaderTransform(entity.GetShaderClipDepth(), - pass, dst_snapshot->transform); + frame_info.mvp = Entity::GetShaderTransform( + entity.GetShaderClipDepth(), pass, + entity.GetTransform() * dst_snapshot->transform); auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor; if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) { From 6bb4263ccf8d9f83197975f4fbab77cf011c2684 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2024 15:48:27 -0700 Subject: [PATCH 3/4] added comment --- impeller/display_list/aiks_dl_blend_unittests.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/impeller/display_list/aiks_dl_blend_unittests.cc b/impeller/display_list/aiks_dl_blend_unittests.cc index 0de3f60e6a6d5..965959f33952c 100644 --- a/impeller/display_list/aiks_dl_blend_unittests.cc +++ b/impeller/display_list/aiks_dl_blend_unittests.cc @@ -246,6 +246,7 @@ TEST_P(AiksTest, ColorFilterBlend) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } +// Verification for: https://github.com/flutter/flutter/issues/155691 TEST_P(AiksTest, ColorFilterAdvancedBlend) { bool has_color_filter = true; auto callback = [&]() -> sk_sp { From 468e921f66e167739eb98f2bac647290c7f67ba8 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 26 Sep 2024 08:32:42 -0700 Subject: [PATCH 4/4] golden golden --- testing/impeller_golden_tests_output.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index eb2565823f4f4..c1d2d87bb5e80 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -523,6 +523,12 @@ impeller_Play_AiksTest_CollapsedDrawPaintInSubpassBackdropFilter_Vulkan.png impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_Metal.png impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_OpenGLES.png impeller_Play_AiksTest_CollapsedDrawPaintInSubpass_Vulkan.png +impeller_Play_AiksTest_ColorFilterAdvancedBlend_Metal.png +impeller_Play_AiksTest_ColorFilterAdvancedBlend_OpenGLES.png +impeller_Play_AiksTest_ColorFilterAdvancedBlend_Vulkan.png +impeller_Play_AiksTest_ColorFilterBlend_Metal.png +impeller_Play_AiksTest_ColorFilterBlend_OpenGLES.png +impeller_Play_AiksTest_ColorFilterBlend_Vulkan.png impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_Metal.png impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_OpenGLES.png impeller_Play_AiksTest_ColorMatrixFilterSubpassCollapseOptimization_Vulkan.png @@ -711,9 +717,6 @@ impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan.png impeller_Play_AiksTest_ImageColorSourceEffectTransform_Metal.png impeller_Play_AiksTest_ImageColorSourceEffectTransform_OpenGLES.png impeller_Play_AiksTest_ImageColorSourceEffectTransform_Vulkan.png -impeller_Play_AiksTest_ImageFilterBlend_Metal.png -impeller_Play_AiksTest_ImageFilterBlend_OpenGLES.png -impeller_Play_AiksTest_ImageFilterBlend_Vulkan.png impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Metal.png impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_OpenGLES.png impeller_Play_AiksTest_ImageFilteredSaveLayerWithUnboundedContents_Vulkan.png