From f9785c0498380820d31fef0bda61ab7b454aab47 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 20 Dec 2023 10:06:13 -0800 Subject: [PATCH] [Impeller] Add interactive Blur+Clip AiksTest. (flutter/engine#49283) I used this interactive toy to inspect the change in https://github.com/flutter/engine/pull/49206. Perhaps this can become our "kitchen sink" interactive toy for debugging blurs in Aiks (where we can easily form clips and add options for other paint state interactions as they become relevant). Video of `GaussianBlurRotatedAndClippedInteractive`: https://github.com/flutter/engine/assets/919017/e5be5f38-3644-43c4-a3d0-d08b03fcb7b0 Video of `GaussianBlurFilter` with the "Combined sigma" checkbox to make playing with the new blur easier: https://github.com/flutter/engine/assets/919017/65bd6567-83be-4337-8827-03e6a3dee9b1 --- .../flutter/impeller/aiks/aiks_unittests.cc | 46 +++++++++++++++++++ .../impeller/entity/entity_unittests.cc | 13 +++++- .../golden_playground_test_mac.cc | 18 ++++---- 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index 997d5ffe30..54d0b1de62 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -3909,6 +3909,52 @@ TEST_P(AiksTest, GaussianBlurRotatedAndClipped) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, GaussianBlurRotatedAndClippedInteractive) { + std::shared_ptr boston = CreateTextureForFixture("boston.jpg"); + + auto callback = [&](AiksContext& renderer) -> std::optional { + const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; + const Entity::TileMode tile_modes[] = { + Entity::TileMode::kClamp, Entity::TileMode::kRepeat, + Entity::TileMode::kMirror, Entity::TileMode::kDecal}; + + static float rotation = 0; + static int selected_tile_mode = 3; + + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + { + ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180); + ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names, + sizeof(tile_mode_names) / sizeof(char*)); + } + ImGui::End(); + + Canvas canvas; + Rect bounds = + Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height); + Vector2 image_center = Vector2(bounds.GetSize() / 2); + Paint paint = {.image_filter = + ImageFilter::MakeBlur(Sigma(20.0), Sigma(20.0), + FilterContents::BlurStyle::kNormal, + tile_modes[selected_tile_mode])}; + auto [handle_a, handle_b] = IMPELLER_PLAYGROUND_LINE( + Point(362, 309), Point(662, 459), 20, Color::Red(), Color::Red()); + Vector2 center = Vector2(1024, 768) / 2; + canvas.Scale(GetContentScale()); + canvas.ClipRect( + Rect::MakeLTRB(handle_a.x, handle_a.y, handle_b.x, handle_b.y)); + canvas.Translate({center.x, center.y, 0}); + canvas.Scale({0.6, 0.6, 1}); + canvas.Rotate(Degrees(rotation)); + + canvas.DrawImageRect(std::make_shared(boston), /*source=*/bounds, + /*dest=*/bounds.Shift(-image_center), paint); + return canvas.EndRecordingAsPicture(); + }; + + ASSERT_TRUE(OpenPlaygroundHere(callback)); +} + TEST_P(AiksTest, SubpassWithClearColorOptimization) { Canvas canvas; diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index 3a90efc787..b0f1c32501 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -1008,6 +1008,7 @@ TEST_P(EntityTest, GaussianBlurFilter) { static Color input_color = Color::Black(); static int selected_blur_type = 0; static int selected_pass_variation = 0; + static bool combined_sigma = false; static float blur_amount_coarse[2] = {0, 0}; static float blur_amount_fine[2] = {10, 10}; static int selected_blur_style = 0; @@ -1039,8 +1040,16 @@ TEST_P(EntityTest, GaussianBlurFilter) { pass_variation_names, sizeof(pass_variation_names) / sizeof(char*)); } - ImGui::SliderFloat2("Sigma (coarse)", blur_amount_coarse, 0, 1000); - ImGui::SliderFloat2("Sigma (fine)", blur_amount_fine, 0, 10); + ImGui::Checkbox("Combined sigma", &combined_sigma); + if (combined_sigma) { + ImGui::SliderFloat("Sigma (coarse)", blur_amount_coarse, 0, 1000); + ImGui::SliderFloat("Sigma (fine)", blur_amount_fine, 0, 10); + blur_amount_coarse[1] = blur_amount_coarse[0]; + blur_amount_fine[1] = blur_amount_fine[0]; + } else { + ImGui::SliderFloat2("Sigma (coarse)", blur_amount_coarse, 0, 1000); + ImGui::SliderFloat2("Sigma (fine)", blur_amount_fine, 0, 10); + } ImGui::Combo("Blur style", &selected_blur_style, blur_style_names, sizeof(blur_style_names) / sizeof(char*)); ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names, diff --git a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc index befe93b0a4..2bbea3d4db 100644 --- a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc +++ b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc @@ -33,20 +33,22 @@ static const std::vector kSkipTests = { "impeller_Play_AiksTest_ClippedBlurFilterRendersCorrectlyInteractive_Metal", "impeller_Play_AiksTest_ClippedBlurFilterRendersCorrectlyInteractive_" "Vulkan", - "impeller_Play_AiksTest_TextFrameSubpixelAlignment_Metal", - "impeller_Play_AiksTest_TextFrameSubpixelAlignment_Vulkan", - "impeller_Play_AiksTest_ColorWheel_Metal", - "impeller_Play_AiksTest_ColorWheel_Vulkan", - "impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Metal", - "impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Vulkan", - "impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Metal", - "impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan", "impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_" "Metal", "impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_" "Vulkan", + "impeller_Play_AiksTest_GaussianBlurRotatedAndClippedInteractive_Metal", + "impeller_Play_AiksTest_GaussianBlurRotatedAndClippedInteractive_Vulkan", + "impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Metal", + "impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan", + "impeller_Play_AiksTest_ColorWheel_Metal", + "impeller_Play_AiksTest_ColorWheel_Vulkan", "impeller_Play_AiksTest_SceneColorSource_Metal", "impeller_Play_AiksTest_SceneColorSource_Vulkan", + "impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Metal", + "impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Vulkan", + "impeller_Play_AiksTest_TextFrameSubpixelAlignment_Metal", + "impeller_Play_AiksTest_TextFrameSubpixelAlignment_Vulkan", // TextRotated is flakey and we can't seem to get it to stabilize on Skia // Gold. "impeller_Play_AiksTest_TextRotated_Metal",