From e8416202dbd048599349d58cc57e67aa30b90d60 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 24 Sep 2024 15:54:45 -0700 Subject: [PATCH 1/4] Fixes blend + color filter --- engine.code-workspace | 92 ++++++++++++++++++- .../display_list/aiks_dl_blend_unittests.cc | 52 +++++++++++ tools/vscode_workspace/engine-workspace.yaml | 17 ++++ 3 files changed, 160 insertions(+), 1 deletion(-) diff --git a/engine.code-workspace b/engine.code-workspace index 96023ecbf0a43..908621fd25c48 100644 --- a/engine.code-workspace +++ b/engine.code-workspace @@ -232,6 +232,33 @@ "kind": "build" } }, + { + "type": "shell", + "command": "./flutter/bin/et", + "options": { + "cwd": "${workspaceFolder}/.." + }, + "problemMatcher": [ + "$gcc" + ], + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared", + "clear": true + }, + "group": { + "kind": "build", + "isDefault": true + }, + "label": "host_debug_unopt_arm64", + "args": [ + "build", + "-c", + "host_debug_unopt_arm64" + ] + }, { "type": "shell", "command": "./flutter/bin/et", @@ -285,6 +312,68 @@ "host_debug_unopt_arm64", "//flutter/impeller/golden_tests:impeller_golden_tests" ] + }, + { + "type": "shell", + "command": "./flutter/bin/et", + "options": { + "cwd": "${workspaceFolder}/.." + }, + "problemMatcher": [ + "$gcc" + ], + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared", + "clear": true + }, + "group": { + "kind": "build" + }, + "label": "ios_debug_unopt_arm64", + "args": [ + "build", + "-c", + "host_debug_unopt_arm64", + "&&", + "./flutter/bin/et", + "build", + "-c", + "ios_debug_unopt" + ] + }, + { + "type": "shell", + "command": "./flutter/bin/et", + "options": { + "cwd": "${workspaceFolder}/.." + }, + "problemMatcher": [ + "$gcc" + ], + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared", + "clear": true + }, + "group": { + "kind": "build" + }, + "label": "android_debug_unopt_arm64", + "args": [ + "build", + "-c", + "host_debug_unopt_arm64", + "&&", + "./flutter/bin/et", + "build", + "-c", + "android_debug_unopt_arm64" + ] } ] }, @@ -374,7 +463,8 @@ "name": "impeller_golden_tests_arm64", "program": "${workspaceFolder}/../out/host_debug_unopt_arm64/impeller_golden_tests", "args": [ - "--working_dir=~/Desktop" + "--working_dir=~/Desktop", + "--gtest_filter=*/Metal" ], "preLaunchTask": "impeller_golden_tests_arm64" } diff --git a/impeller/display_list/aiks_dl_blend_unittests.cc b/impeller/display_list/aiks_dl_blend_unittests.cc index cdddca598112c..0c9fcd51ae8a5 100644 --- a/impeller/display_list/aiks_dl_blend_unittests.cc +++ b/impeller/display_list/aiks_dl_blend_unittests.cc @@ -194,6 +194,58 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +// Compare results with https://api.flutter.dev/flutter/dart-ui/BlendMode.html +TEST_P(AiksTest, ImageFilterBlend) { + 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::kSrc, DlBlendMode::kSrcATop, DlBlendMode::kSrcOver, + DlBlendMode::kSrcIn, DlBlendMode::kSrcOut, DlBlendMode::kDst, + DlBlendMode::kDstATop, DlBlendMode::kDstOver, DlBlendMode::kDstIn, + DlBlendMode::kDstOut, DlBlendMode::kClear, DlBlendMode::kXor}; + + 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(), diff --git a/tools/vscode_workspace/engine-workspace.yaml b/tools/vscode_workspace/engine-workspace.yaml index d1f7cd698eb46..ed9f275d0f4b0 100644 --- a/tools/vscode_workspace/engine-workspace.yaml +++ b/tools/vscode_workspace/engine-workspace.yaml @@ -192,6 +192,12 @@ tasks: clear: true group: kind: build + - <<: *et-task + label: host_debug_unopt_arm64 + args: + - build + - -c + - host_debug_unopt_arm64 - <<: *et-task label: display_list_unittests_arm64 args: @@ -217,6 +223,17 @@ tasks: - build - -c - ios_debug_unopt + - <<: *et-task + label: android_debug_unopt_arm64 + args: + - build + - -c + - host_debug_unopt_arm64 + - "&&" + - *et-cmd + - build + - -c + - android_debug_unopt_arm64 extensions: recommendations: # C++ TestMate From 87258f4967178c9e0c9637fa95c4f1f5165c19cc Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2024 08:37:04 -0700 Subject: [PATCH 2/4] applied jasons fix --- .../contents/filters/blend_filter_contents.cc | 3 ++- tools/vscode_workspace/engine-workspace.yaml | 17 ----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index 9148e920a3751..59c21d2caf8ec 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -454,7 +454,7 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( BlendModeToString(blend_mode))); #endif // IMPELLER_DEBUG pass.SetVertexBuffer(std::move(vtx_buffer)); - auto options = OptionsFromPass(pass); + auto options = OptionsFromPassAndEntity(pass, entity); options.primitive_type = PrimitiveType::kTriangleStrip; pass.SetPipeline(renderer.GetPorterDuffBlendPipeline(options)); @@ -505,6 +505,7 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( Entity sub_entity; sub_entity.SetContents(std::move(contents)); + sub_entity.SetBlendMode(entity.GetBlendMode()); return sub_entity; } diff --git a/tools/vscode_workspace/engine-workspace.yaml b/tools/vscode_workspace/engine-workspace.yaml index ed9f275d0f4b0..d1f7cd698eb46 100644 --- a/tools/vscode_workspace/engine-workspace.yaml +++ b/tools/vscode_workspace/engine-workspace.yaml @@ -192,12 +192,6 @@ tasks: clear: true group: kind: build - - <<: *et-task - label: host_debug_unopt_arm64 - args: - - build - - -c - - host_debug_unopt_arm64 - <<: *et-task label: display_list_unittests_arm64 args: @@ -223,17 +217,6 @@ tasks: - build - -c - ios_debug_unopt - - <<: *et-task - label: android_debug_unopt_arm64 - args: - - build - - -c - - host_debug_unopt_arm64 - - "&&" - - *et-cmd - - build - - -c - - android_debug_unopt_arm64 extensions: recommendations: # C++ TestMate From bf1346f69f3a004ad9b99bb419db5bd9ede35068 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2024 08:38:30 -0700 Subject: [PATCH 3/4] oops --- engine.code-workspace | 92 +------------------------------------------ 1 file changed, 1 insertion(+), 91 deletions(-) diff --git a/engine.code-workspace b/engine.code-workspace index 908621fd25c48..96023ecbf0a43 100644 --- a/engine.code-workspace +++ b/engine.code-workspace @@ -232,33 +232,6 @@ "kind": "build" } }, - { - "type": "shell", - "command": "./flutter/bin/et", - "options": { - "cwd": "${workspaceFolder}/.." - }, - "problemMatcher": [ - "$gcc" - ], - "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, - "panel": "shared", - "clear": true - }, - "group": { - "kind": "build", - "isDefault": true - }, - "label": "host_debug_unopt_arm64", - "args": [ - "build", - "-c", - "host_debug_unopt_arm64" - ] - }, { "type": "shell", "command": "./flutter/bin/et", @@ -312,68 +285,6 @@ "host_debug_unopt_arm64", "//flutter/impeller/golden_tests:impeller_golden_tests" ] - }, - { - "type": "shell", - "command": "./flutter/bin/et", - "options": { - "cwd": "${workspaceFolder}/.." - }, - "problemMatcher": [ - "$gcc" - ], - "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, - "panel": "shared", - "clear": true - }, - "group": { - "kind": "build" - }, - "label": "ios_debug_unopt_arm64", - "args": [ - "build", - "-c", - "host_debug_unopt_arm64", - "&&", - "./flutter/bin/et", - "build", - "-c", - "ios_debug_unopt" - ] - }, - { - "type": "shell", - "command": "./flutter/bin/et", - "options": { - "cwd": "${workspaceFolder}/.." - }, - "problemMatcher": [ - "$gcc" - ], - "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, - "panel": "shared", - "clear": true - }, - "group": { - "kind": "build" - }, - "label": "android_debug_unopt_arm64", - "args": [ - "build", - "-c", - "host_debug_unopt_arm64", - "&&", - "./flutter/bin/et", - "build", - "-c", - "android_debug_unopt_arm64" - ] } ] }, @@ -463,8 +374,7 @@ "name": "impeller_golden_tests_arm64", "program": "${workspaceFolder}/../out/host_debug_unopt_arm64/impeller_golden_tests", "args": [ - "--working_dir=~/Desktop", - "--gtest_filter=*/Metal" + "--working_dir=~/Desktop" ], "preLaunchTask": "impeller_golden_tests_arm64" } From 141ff45cdc5e4f1ef0c1864eb62d1d19a2d0d91d Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2024 10:32:44 -0700 Subject: [PATCH 4/4] added golden golden --- 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 d219c257836a9..eb2565823f4f4 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -711,6 +711,9 @@ 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