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

Commit 585e3ed

Browse files
authored
[Impeller] cleaned up and removed golden test exceptions (#50572)
This starts generating golden image tests for most interactive tests instead of having to explicitly exempt them. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 42cdc73 commit 585e3ed

9 files changed

+113
-98
lines changed

impeller/aiks/aiks_blur_unittests.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
#include "flutter/impeller/aiks/aiks_unittests.h"
66

77
#include "impeller/aiks/canvas.h"
8-
#include "impeller/entity/contents/conical_gradient_contents.h"
9-
#include "impeller/entity/contents/filters/inputs/filter_input.h"
10-
#include "impeller/entity/contents/solid_color_contents.h"
118
#include "impeller/entity/render_target_cache.h"
12-
#include "impeller/geometry/geometry_asserts.h"
139
#include "impeller/geometry/path_builder.h"
1410
#include "impeller/playground/widgets.h"
1511
#include "impeller/renderer/testing/mocks.h"
@@ -452,14 +448,14 @@ TEST_P(AiksTest, GaussianBlurRotatedAndClippedInteractive) {
452448
static float scale = 0.6;
453449
static int selected_tile_mode = 3;
454450

455-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
456-
{
451+
if (AiksTest::ImGuiBegin("Controls", nullptr,
452+
ImGuiWindowFlags_AlwaysAutoResize)) {
457453
ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180);
458454
ImGui::SliderFloat("Scale", &scale, 0, 2.0);
459455
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
460456
sizeof(tile_mode_names) / sizeof(char*));
457+
ImGui::End();
461458
}
462-
ImGui::End();
463459

464460
Canvas canvas;
465461
Rect bounds =
@@ -556,13 +552,13 @@ TEST_P(AiksTest, GaussianBlurAnimatedBackdrop) {
556552
Scalar freq = 0.1;
557553
Scalar amp = 50.0;
558554
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
559-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
560-
{
555+
if (AiksTest::ImGuiBegin("Controls", nullptr,
556+
ImGuiWindowFlags_AlwaysAutoResize)) {
561557
ImGui::SliderFloat("Sigma", &sigma, 0, 200);
562558
ImGui::SliderFloat("Frequency", &freq, 0.01, 2.0);
563559
ImGui::SliderFloat("Amplitude", &amp, 1, 100);
560+
ImGui::End();
564561
}
565-
ImGui::End();
566562

567563
Canvas canvas;
568564
canvas.Scale(GetContentScale());

impeller/aiks/aiks_gradient_unittests.cc

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66

77
#include "impeller/aiks/canvas.h"
88
#include "impeller/entity/contents/conical_gradient_contents.h"
9-
#include "impeller/entity/contents/filters/inputs/filter_input.h"
109
#include "impeller/entity/contents/linear_gradient_contents.h"
1110
#include "impeller/entity/contents/radial_gradient_contents.h"
12-
#include "impeller/entity/contents/solid_color_contents.h"
1311
#include "impeller/entity/contents/sweep_gradient_contents.h"
1412
#include "impeller/geometry/geometry_asserts.h"
1513
#include "impeller/geometry/path_builder.h"
1614
#include "impeller/playground/widgets.h"
1715
#include "third_party/imgui/imgui.h"
18-
#include "txt/platform.h"
1916

2017
////////////////////////////////////////////////////////////////////////////////
2118
// This is for tests of Canvas that are interested the results of rendering
@@ -308,22 +305,24 @@ TEST_P(AiksTest, CanRenderLinearGradientManyColorsUnevenStops) {
308305
Entity::TileMode::kMirror, Entity::TileMode::kDecal};
309306

310307
static int selected_tile_mode = 0;
311-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
312-
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
313-
sizeof(tile_mode_names) / sizeof(char*));
314308
static Matrix matrix = {
315309
1, 0, 0, 0, //
316310
0, 1, 0, 0, //
317311
0, 0, 1, 0, //
318312
0, 0, 0, 1 //
319313
};
320-
std::string label = "##1";
321-
for (int i = 0; i < 4; i++) {
322-
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, &(matrix.vec[i]),
323-
4, NULL, NULL, "%.2f", 0);
324-
label[2]++;
314+
if (AiksTest::ImGuiBegin("Controls", nullptr,
315+
ImGuiWindowFlags_AlwaysAutoResize)) {
316+
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
317+
sizeof(tile_mode_names) / sizeof(char*));
318+
std::string label = "##1";
319+
for (int i = 0; i < 4; i++) {
320+
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
321+
&(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
322+
label[2]++;
323+
}
324+
ImGui::End();
325325
}
326-
ImGui::End();
327326

328327
Canvas canvas;
329328
Paint paint;
@@ -384,22 +383,24 @@ TEST_P(AiksTest, CanRenderRadialGradient) {
384383
Entity::TileMode::kMirror, Entity::TileMode::kDecal};
385384

386385
static int selected_tile_mode = 0;
387-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
388-
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
389-
sizeof(tile_mode_names) / sizeof(char*));
390386
static Matrix matrix = {
391387
1, 0, 0, 0, //
392388
0, 1, 0, 0, //
393389
0, 0, 1, 0, //
394390
0, 0, 0, 1 //
395391
};
396-
std::string label = "##1";
397-
for (int i = 0; i < 4; i++) {
398-
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, &(matrix.vec[i]),
399-
4, NULL, NULL, "%.2f", 0);
400-
label[2]++;
392+
if (AiksTest::ImGuiBegin("Controls", nullptr,
393+
ImGuiWindowFlags_AlwaysAutoResize)) {
394+
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
395+
sizeof(tile_mode_names) / sizeof(char*));
396+
std::string label = "##1";
397+
for (int i = 0; i < 4; i++) {
398+
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
399+
&(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
400+
label[2]++;
401+
}
402+
ImGui::End();
401403
}
402-
ImGui::End();
403404

404405
Canvas canvas;
405406
Paint paint;
@@ -427,22 +428,24 @@ TEST_P(AiksTest, CanRenderRadialGradientManyColors) {
427428
Entity::TileMode::kMirror, Entity::TileMode::kDecal};
428429

429430
static int selected_tile_mode = 0;
430-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
431-
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
432-
sizeof(tile_mode_names) / sizeof(char*));
433431
static Matrix matrix = {
434432
1, 0, 0, 0, //
435433
0, 1, 0, 0, //
436434
0, 0, 1, 0, //
437435
0, 0, 0, 1 //
438436
};
439-
std::string label = "##1";
440-
for (int i = 0; i < 4; i++) {
441-
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, &(matrix.vec[i]),
442-
4, NULL, NULL, "%.2f", 0);
443-
label[2]++;
437+
if (AiksTest::ImGuiBegin("Controls", nullptr,
438+
ImGuiWindowFlags_AlwaysAutoResize)) {
439+
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
440+
sizeof(tile_mode_names) / sizeof(char*));
441+
std::string label = "##1";
442+
for (int i = 0; i < 4; i++) {
443+
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
444+
&(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
445+
label[2]++;
446+
}
447+
ImGui::End();
444448
}
445-
ImGui::End();
446449

447450
Canvas canvas;
448451
Paint paint;
@@ -660,13 +663,15 @@ TEST_P(AiksTest, GradientStrokesRenderCorrectly) {
660663
static int selected_tile_mode = 0;
661664
static float alpha = 1;
662665

663-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
664-
ImGui::SliderFloat("Scale", &scale, 0, 6);
665-
ImGui::Checkbox("Circle clip", &add_circle_clip);
666-
ImGui::SliderFloat("Alpha", &alpha, 0, 1);
667-
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
668-
sizeof(tile_mode_names) / sizeof(char*));
669-
ImGui::End();
666+
if (AiksTest::ImGuiBegin("Controls", nullptr,
667+
ImGuiWindowFlags_AlwaysAutoResize)) {
668+
ImGui::SliderFloat("Scale", &scale, 0, 6);
669+
ImGui::Checkbox("Circle clip", &add_circle_clip);
670+
ImGui::SliderFloat("Alpha", &alpha, 0, 1);
671+
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
672+
sizeof(tile_mode_names) / sizeof(char*));
673+
ImGui::End();
674+
}
670675

671676
Canvas canvas;
672677
canvas.Scale(GetContentScale());

impeller/aiks/aiks_path_unittests.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
185185
static float scale = 3;
186186
static bool add_circle_clip = true;
187187

188-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
189-
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
190-
ImGui::SliderFloat("Scale", &scale, 0, 6);
191-
ImGui::Checkbox("Circle clip", &add_circle_clip);
192-
ImGui::End();
188+
if (AiksTest::ImGuiBegin("Controls", nullptr,
189+
ImGuiWindowFlags_AlwaysAutoResize)) {
190+
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
191+
ImGui::SliderFloat("Scale", &scale, 0, 6);
192+
ImGui::Checkbox("Circle clip", &add_circle_clip);
193+
ImGui::End();
194+
}
193195

194196
Canvas canvas;
195197
canvas.Scale(GetContentScale());

impeller/aiks/aiks_playground.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "impeller/aiks/aiks_context.h"
1010
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
1111
#include "impeller/typographer/typographer_context.h"
12-
#include "third_party/imgui/imgui.h"
1312

1413
namespace impeller {
1514

@@ -57,4 +56,11 @@ bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
5756
});
5857
}
5958

59+
bool AiksPlayground::ImGuiBegin(const char* name,
60+
bool* p_open,
61+
ImGuiWindowFlags flags) {
62+
ImGui::Begin(name, p_open, flags);
63+
return true;
64+
}
65+
6066
} // namespace impeller

impeller/aiks/aiks_playground.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "impeller/aiks/picture.h"
1212
#include "impeller/playground/playground_test.h"
1313
#include "impeller/typographer/typographer_context.h"
14+
#include "third_party/imgui/imgui.h"
1415

1516
namespace impeller {
1617

@@ -32,6 +33,10 @@ class AiksPlayground : public PlaygroundTest {
3233

3334
bool OpenPlaygroundHere(AiksPlaygroundCallback callback);
3435

36+
static bool ImGuiBegin(const char* name,
37+
bool* p_open,
38+
ImGuiWindowFlags flags);
39+
3540
private:
3641
std::shared_ptr<TypographerContext> typographer_context_;
3742
AiksInspector inspector_;

impeller/aiks/aiks_unittests.cc

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121
#include "impeller/aiks/paint_pass_delegate.h"
2222
#include "impeller/aiks/testing/context_spy.h"
2323
#include "impeller/core/capture.h"
24-
#include "impeller/entity/contents/conical_gradient_contents.h"
2524
#include "impeller/entity/contents/filters/gaussian_blur_filter_contents.h"
26-
#include "impeller/entity/contents/filters/inputs/filter_input.h"
27-
#include "impeller/entity/contents/linear_gradient_contents.h"
28-
#include "impeller/entity/contents/radial_gradient_contents.h"
2925
#include "impeller/entity/contents/solid_color_contents.h"
30-
#include "impeller/entity/contents/sweep_gradient_contents.h"
3126
#include "impeller/entity/render_target_cache.h"
3227
#include "impeller/geometry/color.h"
3328
#include "impeller/geometry/constants.h"
@@ -38,17 +33,13 @@
3833
#include "impeller/playground/widgets.h"
3934
#include "impeller/renderer/command_buffer.h"
4035
#include "impeller/renderer/snapshot.h"
41-
#include "impeller/renderer/testing/mocks.h"
42-
#include "impeller/scene/material.h"
43-
#include "impeller/scene/node.h"
4436
#include "impeller/typographer/backends/skia/text_frame_skia.h"
4537
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
4638
#include "impeller/typographer/backends/stb/text_frame_stb.h"
4739
#include "impeller/typographer/backends/stb/typeface_stb.h"
4840
#include "impeller/typographer/backends/stb/typographer_context_stb.h"
4941
#include "third_party/imgui/imgui.h"
5042
#include "third_party/skia/include/core/SkFontMgr.h"
51-
#include "third_party/skia/include/core/SkTypeface.h"
5243
#include "txt/platform.h"
5344

5445
namespace impeller {
@@ -818,12 +809,14 @@ TEST_P(AiksTest, TextFrameSubpixelAlignment) {
818809
static float phase_variation = 0.2;
819810
static float speed = 0.5;
820811
static float magnitude = 100;
821-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
822-
ImGui::SliderFloat("Font size", &font_size, 5, 50);
823-
ImGui::SliderFloat("Phase variation", &phase_variation, 0, 1);
824-
ImGui::SliderFloat("Oscillation speed", &speed, 0, 2);
825-
ImGui::SliderFloat("Oscillation magnitude", &magnitude, 0, 300);
826-
ImGui::End();
812+
if (AiksTest::ImGuiBegin("Controls", nullptr,
813+
ImGuiWindowFlags_AlwaysAutoResize)) {
814+
ImGui::SliderFloat("Font size", &font_size, 5, 50);
815+
ImGui::SliderFloat("Phase variation", &phase_variation, 0, 1);
816+
ImGui::SliderFloat("Oscillation speed", &speed, 0, 2);
817+
ImGui::SliderFloat("Oscillation magnitude", &magnitude, 0, 300);
818+
ImGui::End();
819+
}
827820

828821
Canvas canvas;
829822
canvas.Scale(GetContentScale());
@@ -1067,15 +1060,15 @@ TEST_P(AiksTest, CanDrawPaintMultipleTimesInteractive) {
10671060
static Color foreground = Color::Color::OrangeRed().WithAlpha(0.5);
10681061
static int current_blend_index = 3;
10691062

1070-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1071-
{
1063+
if (AiksTest::ImGuiBegin("Controls", nullptr,
1064+
ImGuiWindowFlags_AlwaysAutoResize)) {
10721065
ImGui::ColorEdit4("Background", reinterpret_cast<float*>(&background));
10731066
ImGui::ColorEdit4("Foreground", reinterpret_cast<float*>(&foreground));
10741067
ImGui::ListBox("Blend mode", &current_blend_index,
10751068
modes.blend_mode_names.data(),
10761069
modes.blend_mode_names.size());
1070+
ImGui::End();
10771071
}
1078-
ImGui::End();
10791072

10801073
Canvas canvas;
10811074
canvas.Scale(Vector2(0.2, 0.2));
@@ -1162,8 +1155,8 @@ TEST_P(AiksTest, ColorWheel) {
11621155
static Color color1 = Color::Green();
11631156
static Color color2 = Color::Blue();
11641157

1165-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1166-
{
1158+
if (AiksTest::ImGuiBegin("Controls", nullptr,
1159+
ImGuiWindowFlags_AlwaysAutoResize)) {
11671160
ImGui::Checkbox("Cache the wheel", &cache_the_wheel);
11681161
ImGui::ListBox("Blending mode", &current_blend_index,
11691162
blend_modes.blend_mode_names.data(),
@@ -1173,8 +1166,8 @@ TEST_P(AiksTest, ColorWheel) {
11731166
ImGui::ColorEdit4("Color B", reinterpret_cast<float*>(&color1));
11741167
ImGui::ColorEdit4("Color C", reinterpret_cast<float*>(&color2));
11751168
ImGui::SliderFloat("Destination alpha", &dst_alpha, 0, 1);
1169+
ImGui::End();
11761170
}
1177-
ImGui::End();
11781171

11791172
static Point content_scale;
11801173
Point new_content_scale = GetContentScale();
@@ -1868,14 +1861,16 @@ TEST_P(AiksTest, SceneColorSource) {
18681861
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
18691862
Paint paint;
18701863

1871-
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
18721864
static Scalar distance = 2;
1873-
ImGui::SliderFloat("Distance", &distance, 0, 4);
18741865
static Scalar y_pos = 0;
1875-
ImGui::SliderFloat("Y", &y_pos, -3, 3);
18761866
static Scalar fov = 45;
1877-
ImGui::SliderFloat("FOV", &fov, 1, 180);
1878-
ImGui::End();
1867+
if (AiksTest::ImGuiBegin("Controls", nullptr,
1868+
ImGuiWindowFlags_AlwaysAutoResize)) {
1869+
ImGui::SliderFloat("Distance", &distance, 0, 4);
1870+
ImGui::SliderFloat("Y", &y_pos, -3, 3);
1871+
ImGui::SliderFloat("FOV", &fov, 1, 180);
1872+
ImGui::End();
1873+
}
18791874

18801875
Scalar angle = GetSecondsElapsed();
18811876
auto camera_position =
@@ -3066,13 +3061,16 @@ TEST_P(AiksTest, CaptureContext) {
30663061
auto color = document.AddColor("Background color", Color::CornflowerBlue());
30673062
canvas.DrawPaint({.color = color});
30683063

3069-
ImGui::Begin("TestDocument", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
3070-
document.GetElement()->properties.Iterate([](CaptureProperty& property) {
3071-
property.Invoke({.color = [](CaptureColorProperty& p) {
3072-
ImGui::ColorEdit4(p.label.c_str(), reinterpret_cast<float*>(&p.value));
3073-
}});
3074-
});
3075-
ImGui::End();
3064+
if (AiksTest::ImGuiBegin("TestDocument", nullptr,
3065+
ImGuiWindowFlags_AlwaysAutoResize)) {
3066+
document.GetElement()->properties.Iterate([](CaptureProperty& property) {
3067+
property.Invoke({.color = [](CaptureColorProperty& p) {
3068+
ImGui::ColorEdit4(p.label.c_str(),
3069+
reinterpret_cast<float*>(&p.value));
3070+
}});
3071+
});
3072+
ImGui::End();
3073+
}
30763074

30773075
return canvas.EndRecordingAsPicture();
30783076
};

0 commit comments

Comments
 (0)