[Impeller] More impeller goldens from aiks_unittests (flutter/engine#40901)

This brings over the last of the tests mentioned in
https://github.com/flutter/engine/pull/40804#issuecomment-1492516301

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or Hixie said the PR is test-exempt. See [testing the engine]
for instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
gaaclarke
2023-04-03 18:07:19 -07:00
committed by GitHub
parent 1f7f52ffac
commit 4806e7d6e1
2 changed files with 121 additions and 191 deletions

View File

@@ -350,57 +350,34 @@ TEST_P(AiksTest, CanRenderLinearGradientDecal) {
CanRenderLinearGradient(this, Entity::TileMode::kDecal);
}
TEST_P(AiksTest, CanRenderLinearGradientWithOverlappingStops) {
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
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};
namespace {
void CanRenderLinearGradientWithOverlappingStops(AiksTest* aiks_test,
Entity::TileMode tile_mode) {
Canvas canvas;
Paint paint;
canvas.Translate({100.0, 100.0, 0});
paint.color_source = [tile_mode]() {
std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0}, Color{0.9568, 0.2627, 0.2118, 1.0},
Color{0.1294, 0.5882, 0.9529, 1.0}, Color{0.1294, 0.5882, 0.9529, 1.0}};
std::vector<Scalar> stops = {0.0, 0.5, 0.5, 1.0};
static int selected_tile_mode = 0;
static float alpha = 1;
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderFloat("Alpha", &alpha, 0, 1);
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]++;
}
ImGui::End();
Canvas canvas;
Paint paint;
canvas.Translate({100.0, 100.0, 0});
auto tile_mode = tile_modes[selected_tile_mode];
paint.color_source = [tile_mode]() {
std::vector<Color> colors = {Color{0.9568, 0.2627, 0.2118, 1.0},
Color{0.9568, 0.2627, 0.2118, 1.0},
Color{0.1294, 0.5882, 0.9529, 1.0},
Color{0.1294, 0.5882, 0.9529, 1.0}};
std::vector<Scalar> stops = {0.0, 0.5, 0.5, 1.0};
auto contents = std::make_shared<LinearGradientContents>();
contents->SetEndPoints({0, 0}, {500, 500});
contents->SetColors(std::move(colors));
contents->SetStops(std::move(stops));
contents->SetTileMode(tile_mode);
contents->SetEffectTransform(matrix);
return contents;
};
paint.color = Color(1.0, 1.0, 1.0, alpha);
canvas.DrawRect({0, 0, 500, 500}, paint);
return renderer.Render(canvas.EndRecordingAsPicture(), render_target);
auto contents = std::make_shared<LinearGradientContents>();
contents->SetEndPoints({0, 0}, {500, 500});
contents->SetColors(std::move(colors));
contents->SetStops(std::move(stops));
contents->SetTileMode(tile_mode);
return contents;
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
paint.color = Color(1.0, 1.0, 1.0, 1.0);
canvas.DrawRect({0, 0, 500, 500}, paint);
ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
} // namespace
// Only clamp is necessary. All tile modes are the same output.
TEST_P(AiksTest, CanRenderLinearGradientWithOverlappingStopsClamp) {
CanRenderLinearGradientWithOverlappingStops(this, Entity::TileMode::kClamp);
}
namespace {
@@ -456,59 +433,39 @@ TEST_P(AiksTest, CanRenderLinearGradientManyColorsDecal) {
CanRenderLinearGradientManyColors(this, Entity::TileMode::kDecal);
}
TEST_P(AiksTest, CanRenderLinearGradientWayManyColors) {
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
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 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]++;
}
ImGui::End();
Canvas canvas;
Paint paint;
canvas.Translate({100.0, 100.0, 0});
auto tile_mode = tile_modes[selected_tile_mode];
auto color = Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0};
std::vector<Color> colors;
std::vector<Scalar> stops;
auto current_stop = 0.0;
for (int i = 0; i < 2000; i++) {
colors.push_back(color);
stops.push_back(current_stop);
current_stop += 1 / 2000.0;
}
stops[2000 - 1] = 1.0;
paint.color_source = [tile_mode, stops = std::move(stops),
colors = std::move(colors)]() {
auto contents = std::make_shared<LinearGradientContents>();
contents->SetEndPoints({0, 0}, {200, 200});
contents->SetColors(colors);
contents->SetStops(stops);
contents->SetTileMode(tile_mode);
contents->SetEffectTransform(matrix);
return contents;
};
canvas.DrawRect({0, 0, 600, 600}, paint);
return renderer.Render(canvas.EndRecordingAsPicture(), render_target);
namespace {
void CanRenderLinearGradientWayManyColors(AiksTest* aiks_test,
Entity::TileMode tile_mode) {
Canvas canvas;
Paint paint;
canvas.Translate({100.0, 100.0, 0});
auto color = Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0};
std::vector<Color> colors;
std::vector<Scalar> stops;
auto current_stop = 0.0;
for (int i = 0; i < 2000; i++) {
colors.push_back(color);
stops.push_back(current_stop);
current_stop += 1 / 2000.0;
}
stops[2000 - 1] = 1.0;
paint.color_source = [tile_mode, stops = std::move(stops),
colors = std::move(colors)]() {
auto contents = std::make_shared<LinearGradientContents>();
contents->SetEndPoints({0, 0}, {200, 200});
contents->SetColors(colors);
contents->SetStops(stops);
contents->SetTileMode(tile_mode);
return contents;
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
canvas.DrawRect({0, 0, 600, 600}, paint);
ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
} // namespace
// Only test clamp on purpose since they all look the same.
TEST_P(AiksTest, CanRenderLinearGradientWayManyColorsClamp) {
CanRenderLinearGradientWayManyColors(this, Entity::TileMode::kClamp);
}
TEST_P(AiksTest, CanRenderLinearGradientManyColorsUnevenStops) {
@@ -713,66 +670,54 @@ TEST_P(AiksTest, CanRenderSweepGradientDecal) {
CanRenderSweepGradient(this, Entity::TileMode::kDecal);
}
TEST_P(AiksTest, CanRenderSweepGradientManyColors) {
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
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 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 //
namespace {
void CanRenderSweepGradientManyColors(AiksTest* aiks_test,
Entity::TileMode tile_mode) {
Canvas canvas;
Paint paint;
canvas.Translate({100.0, 100.0, 0});
paint.color_source = [tile_mode]() {
auto contents = std::make_shared<SweepGradientContents>();
contents->SetCenterAndAngles({100, 100}, Degrees(45), Degrees(135));
std::vector<Color> colors = {
Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
std::vector<Scalar> stops = {
0.0,
(1.0 / 6.0) * 1,
(1.0 / 6.0) * 2,
(1.0 / 6.0) * 3,
(1.0 / 6.0) * 4,
(1.0 / 6.0) * 5,
1.0,
};
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();
Canvas canvas;
Paint paint;
canvas.Translate({100.0, 100.0, 0});
auto tile_mode = tile_modes[selected_tile_mode];
paint.color_source = [tile_mode]() {
auto contents = std::make_shared<SweepGradientContents>();
contents->SetCenterAndAngles({100, 100}, Degrees(45), Degrees(135));
std::vector<Color> colors = {
Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
std::vector<Scalar> stops = {
0.0,
(1.0 / 6.0) * 1,
(1.0 / 6.0) * 2,
(1.0 / 6.0) * 3,
(1.0 / 6.0) * 4,
(1.0 / 6.0) * 5,
1.0,
};
contents->SetStops(std::move(stops));
contents->SetColors(std::move(colors));
contents->SetTileMode(tile_mode);
contents->SetEffectTransform(matrix);
return contents;
};
canvas.DrawRect({0, 0, 600, 600}, paint);
return renderer.Render(canvas.EndRecordingAsPicture(), render_target);
contents->SetStops(std::move(stops));
contents->SetColors(std::move(colors));
contents->SetTileMode(tile_mode);
return contents;
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
canvas.DrawRect({0, 0, 600, 600}, paint);
ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
} // namespace
TEST_P(AiksTest, CanRenderSweepGradientManyColorsClamp) {
CanRenderSweepGradientManyColors(this, Entity::TileMode::kClamp);
}
TEST_P(AiksTest, CanRenderSweepGradientManyColorsRepeat) {
CanRenderSweepGradientManyColors(this, Entity::TileMode::kRepeat);
}
TEST_P(AiksTest, CanRenderSweepGradientManyColorsMirror) {
CanRenderSweepGradientManyColors(this, Entity::TileMode::kMirror);
}
TEST_P(AiksTest, CanRenderSweepGradientManyColorsDecal) {
CanRenderSweepGradientManyColors(this, Entity::TileMode::kDecal);
}
TEST_P(AiksTest, CanRenderDifferentShapesWithSameColorSource) {
@@ -805,33 +750,26 @@ TEST_P(AiksTest, CanRenderDifferentShapesWithSameColorSource) {
}
TEST_P(AiksTest, CanPictureConvertToImage) {
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
static int size[2] = {1000, 1000};
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::SliderInt2("Size", size, 0, 1000);
ImGui::End();
Canvas recorder_canvas;
Paint paint;
paint.color = Color{0.9568, 0.2627, 0.2118, 1.0};
recorder_canvas.DrawRect({100.0, 100.0, 600, 600}, paint);
paint.color = Color{0.1294, 0.5882, 0.9529, 1.0};
recorder_canvas.DrawRect({200.0, 200.0, 600, 600}, paint);
Canvas recorder_canvas;
Paint paint;
paint.color = Color{0.9568, 0.2627, 0.2118, 1.0};
recorder_canvas.DrawRect({100.0, 100.0, 600, 600}, paint);
paint.color = Color{0.1294, 0.5882, 0.9529, 1.0};
recorder_canvas.DrawRect({200.0, 200.0, 600, 600}, paint);
Canvas canvas;
AiksContext renderer(GetContext());
paint.color = Color::BlackTransparent();
canvas.DrawPaint(paint);
Picture picture = recorder_canvas.EndRecordingAsPicture();
auto image = picture.ToImage(renderer, ISize{1000, 1000});
if (image) {
canvas.DrawImage(image, Point(), Paint());
paint.color = Color{0.1, 0.1, 0.1, 0.2};
canvas.DrawRect(Rect::MakeSize(ISize{1000, 1000}), paint);
}
Canvas canvas;
paint.color = Color::BlackTransparent();
canvas.DrawPaint(paint);
Picture picture = recorder_canvas.EndRecordingAsPicture();
auto image = picture.ToImage(renderer, ISize{size[0], size[1]});
if (image) {
canvas.DrawImage(image, Point(), Paint());
paint.color = Color{0.1, 0.1, 0.1, 0.2};
canvas.DrawRect(Rect::MakeSize(ISize{size[0], size[1]}), paint);
}
return renderer.Render(canvas.EndRecordingAsPicture(), render_target);
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, BlendModeShouldCoverWholeScreen) {

View File

@@ -58,19 +58,11 @@ void GoldenPlaygroundTest::SetUp() {
std::string test_name = GetTestName();
if (test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientWithOverlappingStops_"
"Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientWayManyColors_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientManyColorsUnevenStops_"
"Metal" ||
test_name == "impeller_Play_AiksTest_CanRenderRadialGradient_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderRadialGradientManyColors_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderSweepGradientManyColors_Metal" ||
test_name == "impeller_Play_AiksTest_CanPictureConvertToImage_Metal" ||
test_name == "impeller_Play_AiksTest_TextFrameSubpixelAlignment_Metal" ||
test_name == "impeller_Play_AiksTest_ColorWheel_Metal" ||
test_name == "impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Metal" ||