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

[Impeller] cleaned up and removed golden test exceptions #50572

Merged
merged 12 commits into from
Feb 13, 2024
16 changes: 6 additions & 10 deletions impeller/aiks/aiks_blur_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
#include "flutter/impeller/aiks/aiks_unittests.h"

#include "impeller/aiks/canvas.h"
#include "impeller/entity/contents/conical_gradient_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/render_target_cache.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/playground/widgets.h"
#include "impeller/renderer/testing/mocks.h"
Expand Down Expand Up @@ -452,14 +448,14 @@ TEST_P(AiksTest, GaussianBlurRotatedAndClippedInteractive) {
static float scale = 0.6;
static int selected_tile_mode = 3;

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
{
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Rotation (degrees)", &rotation, -180, 180);
ImGui::SliderFloat("Scale", &scale, 0, 2.0);
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
ImGui::End();
}
ImGui::End();

Canvas canvas;
Rect bounds =
Expand Down Expand Up @@ -556,13 +552,13 @@ TEST_P(AiksTest, GaussianBlurAnimatedBackdrop) {
Scalar freq = 0.1;
Scalar amp = 50.0;
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
{
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Sigma", &sigma, 0, 200);
ImGui::SliderFloat("Frequency", &freq, 0.01, 2.0);
ImGui::SliderFloat("Amplitude", &amp, 1, 100);
ImGui::End();
}
ImGui::End();

Canvas canvas;
canvas.Scale(GetContentScale());
Expand Down
79 changes: 42 additions & 37 deletions impeller/aiks/aiks_gradient_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

#include "impeller/aiks/canvas.h"
#include "impeller/entity/contents/conical_gradient_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/linear_gradient_contents.h"
#include "impeller/entity/contents/radial_gradient_contents.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/playground/widgets.h"
#include "third_party/imgui/imgui.h"
#include "txt/platform.h"

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

static int selected_tile_mode = 0;
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
static Matrix matrix = {
1, 0, 0, 0, //
0, 1, 0, 0, //
0, 0, 1, 0, //
0, 0, 0, 1 //
};
std::string label = "##1";
for (int i = 0; i < 4; i++) {
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, &(matrix.vec[i]),
4, NULL, NULL, "%.2f", 0);
label[2]++;
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
std::string label = "##1";
for (int i = 0; i < 4; i++) {
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
&(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
label[2]++;
}
ImGui::End();
}
ImGui::End();

Canvas canvas;
Paint paint;
Expand Down Expand Up @@ -384,22 +383,24 @@ TEST_P(AiksTest, CanRenderRadialGradient) {
Entity::TileMode::kMirror, Entity::TileMode::kDecal};

static int selected_tile_mode = 0;
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
static Matrix matrix = {
1, 0, 0, 0, //
0, 1, 0, 0, //
0, 0, 1, 0, //
0, 0, 0, 1 //
};
std::string label = "##1";
for (int i = 0; i < 4; i++) {
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, &(matrix.vec[i]),
4, NULL, NULL, "%.2f", 0);
label[2]++;
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
std::string label = "##1";
for (int i = 0; i < 4; i++) {
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
&(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
label[2]++;
}
ImGui::End();
}
ImGui::End();

Canvas canvas;
Paint paint;
Expand Down Expand Up @@ -427,22 +428,24 @@ TEST_P(AiksTest, CanRenderRadialGradientManyColors) {
Entity::TileMode::kMirror, Entity::TileMode::kDecal};

static int selected_tile_mode = 0;
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
static Matrix matrix = {
1, 0, 0, 0, //
0, 1, 0, 0, //
0, 0, 1, 0, //
0, 0, 0, 1 //
};
std::string label = "##1";
for (int i = 0; i < 4; i++) {
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, &(matrix.vec[i]),
4, NULL, NULL, "%.2f", 0);
label[2]++;
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
std::string label = "##1";
for (int i = 0; i < 4; i++) {
ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
&(matrix.vec[i]), 4, NULL, NULL, "%.2f", 0);
label[2]++;
}
ImGui::End();
}
ImGui::End();

Canvas canvas;
Paint paint;
Expand Down Expand Up @@ -660,13 +663,15 @@ TEST_P(AiksTest, GradientStrokesRenderCorrectly) {
static int selected_tile_mode = 0;
static float alpha = 1;

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderFloat("Scale", &scale, 0, 6);
ImGui::Checkbox("Circle clip", &add_circle_clip);
ImGui::SliderFloat("Alpha", &alpha, 0, 1);
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
ImGui::End();
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Scale", &scale, 0, 6);
ImGui::Checkbox("Circle clip", &add_circle_clip);
ImGui::SliderFloat("Alpha", &alpha, 0, 1);
ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names,
sizeof(tile_mode_names) / sizeof(char*));
ImGui::End();
}

Canvas canvas;
canvas.Scale(GetContentScale());
Expand Down
12 changes: 7 additions & 5 deletions impeller/aiks/aiks_path_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
static float scale = 3;
static bool add_circle_clip = true;

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
ImGui::SliderFloat("Scale", &scale, 0, 6);
ImGui::Checkbox("Circle clip", &add_circle_clip);
ImGui::End();
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
ImGui::SliderFloat("Scale", &scale, 0, 6);
ImGui::Checkbox("Circle clip", &add_circle_clip);
ImGui::End();
}

Canvas canvas;
canvas.Scale(GetContentScale());
Expand Down
8 changes: 7 additions & 1 deletion impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "impeller/aiks/aiks_context.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "impeller/typographer/typographer_context.h"
#include "third_party/imgui/imgui.h"

namespace impeller {

Expand Down Expand Up @@ -57,4 +56,11 @@ bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
});
}

bool AiksPlayground::ImGuiBegin(const char* name,
bool* p_open,
ImGuiWindowFlags flags) {
ImGui::Begin(name, p_open, flags);
return true;
}

} // namespace impeller
5 changes: 5 additions & 0 deletions impeller/aiks/aiks_playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/aiks/picture.h"
#include "impeller/playground/playground_test.h"
#include "impeller/typographer/typographer_context.h"
#include "third_party/imgui/imgui.h"

namespace impeller {

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

bool OpenPlaygroundHere(AiksPlaygroundCallback callback);

static bool ImGuiBegin(const char* name,
bool* p_open,
ImGuiWindowFlags flags);

private:
std::shared_ptr<TypographerContext> typographer_context_;
AiksInspector inspector_;
Expand Down
64 changes: 31 additions & 33 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
#include "impeller/aiks/paint_pass_delegate.h"
#include "impeller/aiks/testing/context_spy.h"
#include "impeller/core/capture.h"
#include "impeller/entity/contents/conical_gradient_contents.h"
#include "impeller/entity/contents/filters/gaussian_blur_filter_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/linear_gradient_contents.h"
#include "impeller/entity/contents/radial_gradient_contents.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/entity/render_target_cache.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/constants.h"
Expand All @@ -38,17 +33,13 @@
#include "impeller/playground/widgets.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/snapshot.h"
#include "impeller/renderer/testing/mocks.h"
#include "impeller/scene/material.h"
#include "impeller/scene/node.h"
#include "impeller/typographer/backends/skia/text_frame_skia.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "impeller/typographer/backends/stb/text_frame_stb.h"
#include "impeller/typographer/backends/stb/typeface_stb.h"
#include "impeller/typographer/backends/stb/typographer_context_stb.h"
#include "third_party/imgui/imgui.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "txt/platform.h"

namespace impeller {
Expand Down Expand Up @@ -818,12 +809,14 @@ TEST_P(AiksTest, TextFrameSubpixelAlignment) {
static float phase_variation = 0.2;
static float speed = 0.5;
static float magnitude = 100;
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderFloat("Font size", &font_size, 5, 50);
ImGui::SliderFloat("Phase variation", &phase_variation, 0, 1);
ImGui::SliderFloat("Oscillation speed", &speed, 0, 2);
ImGui::SliderFloat("Oscillation magnitude", &magnitude, 0, 300);
ImGui::End();
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Font size", &font_size, 5, 50);
ImGui::SliderFloat("Phase variation", &phase_variation, 0, 1);
ImGui::SliderFloat("Oscillation speed", &speed, 0, 2);
ImGui::SliderFloat("Oscillation magnitude", &magnitude, 0, 300);
ImGui::End();
}

Canvas canvas;
canvas.Scale(GetContentScale());
Expand Down Expand Up @@ -1067,15 +1060,15 @@ TEST_P(AiksTest, CanDrawPaintMultipleTimesInteractive) {
static Color foreground = Color::Color::OrangeRed().WithAlpha(0.5);
static int current_blend_index = 3;

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
{
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::ColorEdit4("Background", reinterpret_cast<float*>(&background));
ImGui::ColorEdit4("Foreground", reinterpret_cast<float*>(&foreground));
ImGui::ListBox("Blend mode", &current_blend_index,
modes.blend_mode_names.data(),
modes.blend_mode_names.size());
ImGui::End();
}
ImGui::End();

Canvas canvas;
canvas.Scale(Vector2(0.2, 0.2));
Expand Down Expand Up @@ -1162,8 +1155,8 @@ TEST_P(AiksTest, ColorWheel) {
static Color color1 = Color::Green();
static Color color2 = Color::Blue();

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
{
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Checkbox("Cache the wheel", &cache_the_wheel);
ImGui::ListBox("Blending mode", &current_blend_index,
blend_modes.blend_mode_names.data(),
Expand All @@ -1173,8 +1166,8 @@ TEST_P(AiksTest, ColorWheel) {
ImGui::ColorEdit4("Color B", reinterpret_cast<float*>(&color1));
ImGui::ColorEdit4("Color C", reinterpret_cast<float*>(&color2));
ImGui::SliderFloat("Destination alpha", &dst_alpha, 0, 1);
ImGui::End();
}
ImGui::End();

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

ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
static Scalar distance = 2;
ImGui::SliderFloat("Distance", &distance, 0, 4);
static Scalar y_pos = 0;
ImGui::SliderFloat("Y", &y_pos, -3, 3);
static Scalar fov = 45;
ImGui::SliderFloat("FOV", &fov, 1, 180);
ImGui::End();
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Distance", &distance, 0, 4);
ImGui::SliderFloat("Y", &y_pos, -3, 3);
ImGui::SliderFloat("FOV", &fov, 1, 180);
ImGui::End();
}

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

ImGui::Begin("TestDocument", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
document.GetElement()->properties.Iterate([](CaptureProperty& property) {
property.Invoke({.color = [](CaptureColorProperty& p) {
ImGui::ColorEdit4(p.label.c_str(), reinterpret_cast<float*>(&p.value));
}});
});
ImGui::End();
if (AiksTest::ImGuiBegin("TestDocument", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
document.GetElement()->properties.Iterate([](CaptureProperty& property) {
property.Invoke({.color = [](CaptureColorProperty& p) {
ImGui::ColorEdit4(p.label.c_str(),
reinterpret_cast<float*>(&p.value));
}});
});
ImGui::End();
}

return canvas.EndRecordingAsPicture();
};
Expand Down
Loading