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

Commit c7df4df

Browse files
authored
[Impeller] Add interactive Blur+Clip AiksTest. (#49283)
I used this interactive toy to inspect the change in #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
1 parent 3c9cc06 commit c7df4df

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,6 +3909,52 @@ TEST_P(AiksTest, GaussianBlurRotatedAndClipped) {
39093909
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
39103910
}
39113911

3912+
TEST_P(AiksTest, GaussianBlurRotatedAndClippedInteractive) {
3913+
std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
3914+
3915+
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
3916+
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
3917+
const Entity::TileMode tile_modes[] = {
3918+
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
3919+
Entity::TileMode::kMirror, Entity::TileMode::kDecal};
3920+
3921+
static float rotation = 0;
3922+
static int selected_tile_mode = 3;
3923+
3924+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
3925+
{
3926+
ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180);
3927+
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
3928+
sizeof(tile_mode_names) / sizeof(char*));
3929+
}
3930+
ImGui::End();
3931+
3932+
Canvas canvas;
3933+
Rect bounds =
3934+
Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
3935+
Vector2 image_center = Vector2(bounds.GetSize() / 2);
3936+
Paint paint = {.image_filter =
3937+
ImageFilter::MakeBlur(Sigma(20.0), Sigma(20.0),
3938+
FilterContents::BlurStyle::kNormal,
3939+
tile_modes[selected_tile_mode])};
3940+
auto [handle_a, handle_b] = IMPELLER_PLAYGROUND_LINE(
3941+
Point(362, 309), Point(662, 459), 20, Color::Red(), Color::Red());
3942+
Vector2 center = Vector2(1024, 768) / 2;
3943+
canvas.Scale(GetContentScale());
3944+
canvas.ClipRect(
3945+
Rect::MakeLTRB(handle_a.x, handle_a.y, handle_b.x, handle_b.y));
3946+
canvas.Translate({center.x, center.y, 0});
3947+
canvas.Scale({0.6, 0.6, 1});
3948+
canvas.Rotate(Degrees(rotation));
3949+
3950+
canvas.DrawImageRect(std::make_shared<Image>(boston), /*source=*/bounds,
3951+
/*dest=*/bounds.Shift(-image_center), paint);
3952+
return canvas.EndRecordingAsPicture();
3953+
};
3954+
3955+
ASSERT_TRUE(OpenPlaygroundHere(callback));
3956+
}
3957+
39123958
TEST_P(AiksTest, SubpassWithClearColorOptimization) {
39133959
Canvas canvas;
39143960

impeller/entity/entity_unittests.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ TEST_P(EntityTest, GaussianBlurFilter) {
10081008
static Color input_color = Color::Black();
10091009
static int selected_blur_type = 0;
10101010
static int selected_pass_variation = 0;
1011+
static bool combined_sigma = false;
10111012
static float blur_amount_coarse[2] = {0, 0};
10121013
static float blur_amount_fine[2] = {10, 10};
10131014
static int selected_blur_style = 0;
@@ -1039,8 +1040,16 @@ TEST_P(EntityTest, GaussianBlurFilter) {
10391040
pass_variation_names,
10401041
sizeof(pass_variation_names) / sizeof(char*));
10411042
}
1042-
ImGui::SliderFloat2("Sigma (coarse)", blur_amount_coarse, 0, 1000);
1043-
ImGui::SliderFloat2("Sigma (fine)", blur_amount_fine, 0, 10);
1043+
ImGui::Checkbox("Combined sigma", &combined_sigma);
1044+
if (combined_sigma) {
1045+
ImGui::SliderFloat("Sigma (coarse)", blur_amount_coarse, 0, 1000);
1046+
ImGui::SliderFloat("Sigma (fine)", blur_amount_fine, 0, 10);
1047+
blur_amount_coarse[1] = blur_amount_coarse[0];
1048+
blur_amount_fine[1] = blur_amount_fine[0];
1049+
} else {
1050+
ImGui::SliderFloat2("Sigma (coarse)", blur_amount_coarse, 0, 1000);
1051+
ImGui::SliderFloat2("Sigma (fine)", blur_amount_fine, 0, 10);
1052+
}
10441053
ImGui::Combo("Blur style", &selected_blur_style, blur_style_names,
10451054
sizeof(blur_style_names) / sizeof(char*));
10461055
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,

impeller/golden_tests/golden_playground_test_mac.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ static const std::vector<std::string> kSkipTests = {
3333
"impeller_Play_AiksTest_ClippedBlurFilterRendersCorrectlyInteractive_Metal",
3434
"impeller_Play_AiksTest_ClippedBlurFilterRendersCorrectlyInteractive_"
3535
"Vulkan",
36-
"impeller_Play_AiksTest_TextFrameSubpixelAlignment_Metal",
37-
"impeller_Play_AiksTest_TextFrameSubpixelAlignment_Vulkan",
38-
"impeller_Play_AiksTest_ColorWheel_Metal",
39-
"impeller_Play_AiksTest_ColorWheel_Vulkan",
40-
"impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Metal",
41-
"impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Vulkan",
42-
"impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Metal",
43-
"impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan",
4436
"impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_"
4537
"Metal",
4638
"impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_"
4739
"Vulkan",
40+
"impeller_Play_AiksTest_GaussianBlurRotatedAndClippedInteractive_Metal",
41+
"impeller_Play_AiksTest_GaussianBlurRotatedAndClippedInteractive_Vulkan",
42+
"impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Metal",
43+
"impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Vulkan",
44+
"impeller_Play_AiksTest_ColorWheel_Metal",
45+
"impeller_Play_AiksTest_ColorWheel_Vulkan",
4846
"impeller_Play_AiksTest_SceneColorSource_Metal",
4947
"impeller_Play_AiksTest_SceneColorSource_Vulkan",
48+
"impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Metal",
49+
"impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Vulkan",
50+
"impeller_Play_AiksTest_TextFrameSubpixelAlignment_Metal",
51+
"impeller_Play_AiksTest_TextFrameSubpixelAlignment_Vulkan",
5052
// TextRotated is flakey and we can't seem to get it to stabilize on Skia
5153
// Gold.
5254
"impeller_Play_AiksTest_TextRotated_Metal",

0 commit comments

Comments
 (0)