From 30c20d813f73fd994245ca2e26225a307f729f07 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 20 Dec 2023 05:30:29 -0800 Subject: [PATCH] [Impeller] Add interactive Blur+Clip AiksTest. --- 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/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 997d5ffe30f76..54d0b1de62401 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/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/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 3a90efc78701e..b0f1c32501142 100644 --- a/impeller/entity/entity_unittests.cc +++ b/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/impeller/golden_tests/golden_playground_test_mac.cc b/impeller/golden_tests/golden_playground_test_mac.cc index befe93b0a4cec..2bbea3d4db051 100644 --- a/impeller/golden_tests/golden_playground_test_mac.cc +++ b/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",