diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index f8db238978..8af28dcf5d 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -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 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 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 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 stops = {0.0, 0.5, 0.5, 1.0}; - - auto contents = std::make_shared(); - 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(); + 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 colors; - std::vector 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(); - 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 colors; + std::vector 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(); + 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(); + contents->SetCenterAndAngles({100, 100}, Degrees(45), Degrees(135)); + std::vector 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 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(); - contents->SetCenterAndAngles({100, 100}, Degrees(45), Degrees(135)); - std::vector 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 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) { diff --git a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc index 5ff897c5c9..a4bfa29ab1 100644 --- a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc +++ b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc @@ -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" ||