15 #include "flutter/testing/testing.h"
16 #include "gtest/gtest.h"
21 #include "impeller/aiks/testing/context_spy.h"
39 #include "third_party/imgui/imgui.h"
40 #include "third_party/skia/include/core/SkFontMgr.h"
41 #include "txt/platform.h"
60 ASSERT_EQ(canvas.
Restore(),
false);
87 auto image = std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
96 auto image = std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
100 paint.invert_colors =
true;
112 paint.invert_colors =
true;
124 paint.invert_colors =
true;
131 bool GenerateMipmap(
const std::shared_ptr<Context>& context,
132 std::shared_ptr<Texture> texture,
134 auto buffer = context->CreateCommandBuffer();
138 auto pass = buffer->CreateBlitPass();
142 pass->GenerateMipmap(std::move(texture), std::move(label));
144 pass->EncodeCommands(context->GetResourceAllocator());
145 return context->GetCommandQueue()->Submit({buffer}).ok();
148 void CanRenderTiledTexture(
AiksTest* aiks_test,
150 Matrix local_matrix = {}) {
151 auto context = aiks_test->GetContext();
152 ASSERT_TRUE(context);
153 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
155 GenerateMipmap(context, texture,
"table_mountain_nx");
157 canvas.Scale(aiks_test->GetContentScale());
158 canvas.Translate({100.0f, 100.0f, 0});
162 paint.color = Color(1, 1, 1, 1);
178 PathBuilder path_builder;
179 path_builder.AddCircle({150, 150}, 150);
180 path_builder.AddRoundedRect(
Rect::MakeLTRB(300, 300, 600, 600), 10);
182 canvas.DrawPath(path_builder.TakePath(),
paint);
187 PathBuilder path_builder;
188 path_builder.AddCircle({150, 450}, 150);
191 canvas.DrawPath(path_builder.TakePath(),
paint);
194 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
222 auto image = std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
223 Size image_half_size =
Size(image->GetSize()) * 0.5;
227 source_rect = source_rect.Shift(
Point(image_half_size));
236 canvas.
Scale(GetContentScale());
281 std::vector<Color> gradient_colors = {
282 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
283 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
284 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
285 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
286 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
287 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
288 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
289 std::vector<Scalar> stops = {
298 auto texture = CreateTextureForFixture(
"airplane.jpg",
302 {500, 600}, 75, std::move(gradient_colors), std::move(stops),
336 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
337 Color{0.1294, 0.5882, 0.9529, 1.0}};
338 std::vector<Scalar> stops = {
344 {0, 0}, {100, 100}, std::move(colors), std::move(stops),
362 paint.color =
Color{0.9568, 0.2627, 0.2118, 1.0};
364 paint.color =
Color{0.1294, 0.5882, 0.9529, 1.0};
372 auto image = picture.
ToImage(renderer,
ISize{1000, 1000});
394 auto image = picture.
ToImage(renderer,
ISize{1000, 1000});
411 std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
495 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
552 const std::string& text,
553 const std::string_view& font_fixture,
557 Rect::MakeXYWH(options.position.x - 50, options.position.y, 900, 10),
558 Paint{.color = Color::Aqua().WithAlpha(0.25)});
562 Paint{.color = Color::Red().WithAlpha(0.25)});
565 auto c_font_fixture = std::string(font_fixture);
566 auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
570 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
571 SkFont sk_font(font_mgr->makeFromData(mapping), options.font_size);
572 auto blob = SkTextBlob::MakeFromString(text.c_str(), sk_font);
581 text_paint.color = options.color;
582 text_paint.mask_blur_descriptor = options.mask_blur_descriptor;
583 text_paint.stroke_width = 1;
592 const std::string& text,
593 const std::string& font_fixture,
597 Rect::MakeXYWH(options.position.x - 50, options.position.y, 900, 10),
598 Paint{.color = Color::Aqua().WithAlpha(0.25)});
602 Paint{.color = Color::Red().WithAlpha(0.25)});
605 auto mapping = flutter::testing::OpenFixtureAsMapping(font_fixture.c_str());
609 auto typeface_stb = std::make_shared<TypefaceSTB>(std::move(mapping));
612 typeface_stb, Font::Metrics{.point_size = options.font_size}, text);
615 text_paint.color = options.color;
624 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
625 "Roboto-Regular.ttf"));
634 canvas.
Scale({-1, 1, 1});
636 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
637 "Roboto-Regular.ttf"));
645 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
646 "Roboto-Regular.ttf",
656 canvas.
Scale({0.5, 0.5, 1});
658 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
659 "Roboto-Regular.ttf"));
666 canvas.
Scale({2.625, 2.625, 1});
668 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
669 "Roboto-Regular.ttf"));
677 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
678 "Roboto-Regular.ttf"));
686 std::array<Scalar, 20> phase_offsets = {
687 7.82637e-06, 0.131538, 0.755605, 0.45865, 0.532767,
688 0.218959, 0.0470446, 0.678865, 0.679296, 0.934693,
689 0.383502, 0.519416, 0.830965, 0.0345721, 0.0534616,
690 0.5297, 0.671149, 0.00769819, 0.383416, 0.0668422};
691 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
693 static float phase_variation = 0.2;
694 static float speed = 0.5;
695 static float magnitude = 100;
697 ImGuiWindowFlags_AlwaysAutoResize)) {
698 ImGui::SliderFloat(
"Font size", &
font_size, 5, 50);
699 ImGui::SliderFloat(
"Phase variation", &phase_variation, 0, 1);
700 ImGui::SliderFloat(
"Oscillation speed", &speed, 0, 2);
701 ImGui::SliderFloat(
"Oscillation magnitude", &magnitude, 0, 300);
706 canvas.
Scale(GetContentScale());
708 for (
size_t i = 0; i < phase_offsets.size(); i++) {
710 Point(200 + magnitude *
711 std::sin((-phase_offsets[i] *
k2Pi * phase_variation +
712 GetSecondsElapsed() * speed)),
716 GetContext(), canvas,
717 "the quick brown fox jumped over "
719 "Roboto-Regular.ttf",
720 {.font_size =
font_size, .position = position})) {
727 ASSERT_TRUE(OpenPlaygroundHere(callback));
735 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
736 "HomemadeApple.ttf"));
742 "Apple Color Emoji.ttc";
744 "NotoColorEmoji.ttf";
752 GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture));
761 GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture,
765 .sigma =
Sigma(4)}}));
774 GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture,
789 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
790 "Roboto-Regular.ttf"));
795 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
796 "Roboto-Regular.ttf"));
806 auto mapping = flutter::testing::OpenFixtureAsSkData(
"wtf.otf");
807 ASSERT_NE(mapping,
nullptr);
810 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
811 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
819 } text[] = {{
Point(0, 0),
"0F0F0F0"},
820 {
Point(1, 2),
"789"},
821 {
Point(1, 3),
"456"},
822 {
Point(1, 4),
"123"},
823 {
Point(0, 6),
"0F0F0F0"}};
824 for (
auto& t : text) {
828 auto blob = SkTextBlob::MakeFromString(t.text, sk_font);
829 ASSERT_NE(blob,
nullptr);
841 canvas.
Scale(GetContentScale());
849 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
850 "Roboto-Regular.ttf"));
866 canvas.
DrawPaint({.color = Color::Color::OrangeRed().WithAlpha(0.5)});
872 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
878 GetContext()->GetCapabilities()->GetDefaultColorFormat();
925 canvas.
Scale(GetContentScale());
927 const int color_count = 3;
928 Color colors[color_count] = {
940 paint.color = colors[(c_index++) % color_count];
949 std::vector<Color> gradient_colors = {
950 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
951 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
952 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
953 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
954 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
955 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
956 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
957 std::vector<Scalar> stops = {
966 auto texture = CreateTextureForFixture(
"airplane.jpg",
970 {500, 600}, 75, std::move(gradient_colors), std::move(stops),
984 canvas.
Scale(GetContentScale());
986 const int color_count = 3;
987 Color colors[color_count] = {
1000 for (
int i = 0; i < n; i++) {
1001 paint.color = colors[(c_index++) % color_count];
1002 canvas.DrawCircle(center, r,
paint);
1008 paint.stroke_width = 1;
1009 draw(canvas, {10, 10}, 2, 2, 14);
1010 paint.stroke_width = 5;
1011 draw(canvas, {10, 10}, 35, 10, 56);
1013 std::vector<Color> gradient_colors = {
1014 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1015 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1016 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1017 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1018 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1019 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1020 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1021 std::vector<Scalar> stops = {
1030 auto texture = CreateTextureForFixture(
"airplane.jpg",
1034 {500, 600}, 75, std::move(gradient_colors), std::move(stops),
1036 draw(canvas, {500, 600}, 5, 10, 10);
1041 draw(canvas, {800, 300}, 5, 10, 10);
1043 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1048 canvas.
Scale(GetContentScale());
1050 const int color_count = 3;
1051 Color colors[color_count] = {
1061 int long_radius = 600;
1062 int short_radius = 600;
1063 while (long_radius > 0 && short_radius > 0) {
1064 paint.color = colors[(c_index++) % color_count];
1066 long_radius * 2, short_radius * 2),
1069 short_radius * 2, long_radius * 2),
1071 if (short_radius > 30) {
1080 std::vector<Color> gradient_colors = {
1081 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1082 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1083 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1084 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1085 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1086 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1087 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1088 std::vector<Scalar> stops = {
1097 auto texture = CreateTextureForFixture(
"airplane.jpg",
1103 {300, 650}, 75, std::move(gradient_colors), std::move(stops),
1119 canvas.
Scale(GetContentScale());
1121 const int color_count = 3;
1122 Color colors[color_count] = {
1132 for (
int i = 0; i < 4; i++) {
1133 for (
int j = 0; j < 4; j++) {
1134 paint.color = colors[(c_index++) % color_count];
1139 paint.color = colors[(c_index++) % color_count];
1141 paint.color = colors[(c_index++) % color_count];
1144 std::vector<Color> gradient_colors = {
1145 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1146 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1147 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1148 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1149 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1150 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1151 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1152 std::vector<Scalar> stops = {
1161 auto texture = CreateTextureForFixture(
"airplane.jpg",
1167 for (
int i = 1; i <= 10; i++) {
1170 550 + i * 20, 550 + j * 20),
1175 {200, 650}, 75, std::move(gradient_colors), std::move(stops),
1184 for (
int i = 1; i <= 10; i++) {
1187 720 + i * 20, 220 + j * 20),
1202 canvas.
Scale(GetContentScale());
1213 for (
int i = 0; i < 5; i++) {
1214 Scalar x = (i + 1) * 100;
1215 Scalar radius = x / 10.0f;
1217 radius, 60.0f - radius),
1223 for (
int i = 0; i < 5; i++) {
1224 Scalar x = (i + 1) * 100;
1225 Scalar radius = x / 10.0f;
1231 for (
int i = 0; i < 5; i++) {
1232 Scalar x = (i + 1) * 100;
1233 Scalar radius = x / 10.0f;
1235 radius, 60.0f - radius),
1241 for (
int i = 0; i < 5; i++) {
1242 Scalar x = (i + 1) * 100;
1243 Scalar radius = x / 20.0f;
1251 for (
int i = 0; i < 5; i++) {
1252 Scalar x = (i + 1) * 100;
1253 Scalar radius = x / 20.0f;
1255 {radius, 5.0f},
paint);
1263 canvas.
Scale(GetContentScale());
1273 for (
int i = 0; i < 5; i++) {
1275 Scalar y_radius = i * 15;
1276 for (
int j = 0; j < 5; j++) {
1278 Scalar x_radius = j * 15;
1280 {x_radius, y_radius},
paint);
1289 canvas.
Scale(GetContentScale());
1291 const int color_count = 3;
1292 Color colors[color_count] = {
1301 auto draw_rrect_as_path = [&canvas](
const Rect& rect,
const Size& radii,
1309 for (
int i = 0; i < 4; i++) {
1310 for (
int j = 0; j < 4; j++) {
1311 paint.color = colors[(c_index++) % color_count];
1312 draw_rrect_as_path(
Rect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1316 paint.color = colors[(c_index++) % color_count];
1318 paint.color = colors[(c_index++) % color_count];
1321 std::vector<Color> gradient_colors = {
1322 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1323 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1324 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1325 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1326 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1327 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1328 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1329 std::vector<Scalar> stops = {
1338 auto texture = CreateTextureForFixture(
"airplane.jpg",
1344 for (
int i = 1; i <= 10; i++) {
1347 550 + i * 20, 550 + j * 20),
1352 {200, 650}, 75, std::move(gradient_colors), std::move(stops),
1361 for (
int i = 1; i <= 10; i++) {
1364 720 + i * 20, 220 + j * 20),
1378 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
1380 canvas.
Scale(GetContentScale());
1385 auto current =
Point{25, 25};
1387 const auto size =
Size(100, 100);
1395 .stroke_width = 5.0f,
1412 ASSERT_TRUE(OpenPlaygroundHere(callback));
1498 canvas.
Scale(GetContentScale());
1501 auto texture = std::make_shared<Image>(CreateTextureForFixture(
"boston.jpg"));
1502 auto draw_image_layer = [&canvas, &texture](
const Paint&
paint) {
1513 draw_image_layer(effect_paint);
1517 draw_image_layer(effect_paint);
1522 #if IMPELLER_ENABLE_3D
1526 flutter::testing::OpenFixtureAsMapping(
"flutter_logo_baked.glb.ipscene");
1527 ASSERT_NE(mapping,
nullptr);
1530 *mapping, *GetContext()->GetResourceAllocator());
1531 ASSERT_NE(gltf_scene,
nullptr);
1533 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
1540 ImGuiWindowFlags_AlwaysAutoResize)) {
1541 ImGui::SliderFloat(
"Distance", &
distance, 0, 4);
1542 ImGui::SliderFloat(
"Y", &y_pos, -3, 3);
1543 ImGui::SliderFloat(
"FOV", &fov, 1, 180);
1547 Scalar angle = GetSecondsElapsed();
1548 auto camera_position =
1551 paint.color_source = ColorSource::MakeScene(
1558 canvas.Scale(GetContentScale());
1559 canvas.DrawPaint(
paint);
1560 return canvas.EndRecordingAsPicture();
1563 ASSERT_TRUE(OpenPlaygroundHere(callback));
1565 #endif // IMPELLER_ENABLE_3D
1572 ASSERT_FALSE(
paint.HasColorFilter());
1574 paint.color_filter =
1577 ASSERT_TRUE(
paint.HasColorFilter());
1583 ASSERT_TRUE(
paint.HasColorFilter());
1585 paint.mask_blur_descriptor = {};
1587 ASSERT_TRUE(
paint.HasColorFilter());
1589 paint.color_filter =
nullptr;
1591 ASSERT_FALSE(
paint.HasColorFilter());
1603 ASSERT_EQ(picture.
pass->GetClearColor(), expected);
1605 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1606 std::shared_ptr<Context> real_context = GetContext();
1607 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1609 std::shared_ptr<Image> image = picture.
ToImage(renderer, {300, 300});
1611 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1612 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1613 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
1619 ParentSaveLayerCreatesRenderPassWhenChildBackdropFilterIsPresent) {
1629 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1630 std::shared_ptr<Context> real_context = GetContext();
1631 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1633 std::shared_ptr<Image> image = picture.
ToImage(renderer, {300, 300});
1635 ASSERT_EQ(spy->render_passes_.size(),
1637 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1638 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
1649 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1651 std::shared_ptr<Context> real_context = GetContext();
1652 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1654 std::shared_ptr<Image> image = picture.
ToImage(renderer, {300, 300});
1656 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1657 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1658 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
1669 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1671 std::shared_ptr<Context> real_context = GetContext();
1672 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1674 std::shared_ptr<Image> image = picture.
ToImage(renderer, {300, 300});
1676 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1677 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1678 ASSERT_EQ(render_pass->GetCommands().size(), 2llu);
1689 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1691 std::shared_ptr<Context> real_context = GetContext();
1692 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1694 std::shared_ptr<Image> image = picture.
ToImage(renderer, {300, 300});
1696 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1697 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1698 ASSERT_EQ(render_pass->GetCommands().size(), 1llu);
1709 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1711 std::shared_ptr<Context> real_context = GetContext();
1712 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1714 std::shared_ptr<Image> image = picture.
ToImage(renderer, {301, 301});
1716 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1717 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1718 ASSERT_EQ(render_pass->GetCommands().size(), 2llu);
1732 ASSERT_EQ(picture.
pass->GetClearColor(), expected);
1734 std::shared_ptr<ContextSpy> spy = ContextSpy::Make();
1735 std::shared_ptr<Context> real_context = GetContext();
1736 std::shared_ptr<ContextMock> mock_context = spy->MakeContext(real_context);
1738 std::shared_ptr<Image> image = picture.
ToImage(renderer, {300, 300});
1740 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1741 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1742 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
1758 std::optional<Color> actual_color;
1759 bool found_subpass =
false;
1761 if (
auto subpass = std::get_if<std::unique_ptr<EntityPass>>(&element)) {
1762 actual_color = subpass->get()->GetClearColor();
1763 found_subpass =
true;
1769 EXPECT_TRUE(found_subpass);
1770 EXPECT_FALSE(actual_color.has_value());
1809 1.0, 1.0, 1.0, 1.0, 0
1912 canvas.
Scale(GetContentScale());
1914 auto test = [&canvas](
const std::shared_ptr<ImageFilter>& filter) {
1915 auto DrawLine = [&canvas](
const Point& p0,
const Point& p1,
1931 canvas.
SaveLayer({.image_filter = filter},
1958 auto rotate_filter =
1963 test(rotate_filter);
1974 test(rgb_swap_filter);
2001 canvas.
Scale(GetContentScale());
2007 canvas.
SaveLayer({.image_filter = blur_filter}, std::nullopt);
2024 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2025 canvas.
DrawImage(image, {100, 100}, {});
2028 canvas.
DrawImage(image, {100, 500}, {});
2037 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2038 canvas.
DrawImage(image, {100, 100}, {});
2050 canvas.
DrawImage(image, {100, 500}, {});
2059 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2060 canvas.
DrawImage(image, {100, 100}, {});
2073 canvas.
DrawImage(image, {100, 500}, {});
2080 TranslucentSaveLayerWithColorFilterAndImageFilterDrawsCorrectly) {
2083 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2084 canvas.
DrawImage(image, {100, 100}, {});
2099 canvas.
DrawImage(image, {100, 500}, {});
2149 std::vector<Entity> entity;
2150 std::shared_ptr<SolidColorContents> contents;
2151 picture.
pass->IterateAllEntities([e = &entity, &contents](
Entity& entity) {
2154 std::static_pointer_cast<SolidColorContents>(entity.
GetContents());
2155 e->emplace_back(entity.
Clone());
2161 ASSERT_TRUE(entity.size() >= 1);
2162 ASSERT_TRUE(contents->IsOpaque());
2182 auto runtime_stages =
2183 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
2185 auto runtime_stage =
2187 ASSERT_TRUE(runtime_stage);
2188 ASSERT_TRUE(runtime_stage->IsDirty());
2190 struct FragUniforms {
2193 } frag_uniforms = {.iResolution =
Vector2(400, 400), .iTime = 100.0};
2194 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
2195 uniform_data->resize(
sizeof(FragUniforms));
2196 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
2198 std::vector<RuntimeEffectContents::TextureInput> texture_inputs;
2202 runtime_stage, uniform_data, texture_inputs);
2215 auto runtime_stages = OpenAssetAsRuntimeStage(
"gradient.frag.iplr");
2216 auto runtime_stage =
2218 ASSERT_TRUE(runtime_stage);
2219 ASSERT_TRUE(runtime_stage->IsDirty());
2221 struct FragUniforms {
2224 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
2225 uniform_data->resize(
sizeof(FragUniforms));
2226 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
2228 std::vector<RuntimeEffectContents::TextureInput> texture_inputs;
2232 runtime_stage, uniform_data, texture_inputs);
2236 canvas.
Scale(GetContentScale());
2244 std::vector<Point> points = {
2253 std::vector<PointStyle> caps = {
2274 auto texture = CreateTextureForFixture(
"table_mountain_nx.png",
2277 std::vector<Point> points = {
2286 std::vector<PointStyle> caps = {
2297 canvas.Translate({150, 0});
2300 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2307 auto mapping = flutter::testing::OpenFixtureAsSkData(
"Roboto-Regular.ttf");
2308 ASSERT_NE(mapping,
nullptr);
2311 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
2312 SkFont sk_font(font_mgr->makeFromData(mapping),
font_size);
2317 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
2318 Color{0.1294, 0.5882, 0.9529, 1.0}};
2319 std::vector<Scalar> stops = {
2324 {0, 0}, {100, 100}, std::move(colors), std::move(stops),
2331 auto blob = SkTextBlob::MakeFromString(
"Hello", sk_font);
2332 ASSERT_NE(blob,
nullptr);
2334 canvas.DrawTextFrame(frame,
Point(), text_paint);
2336 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2393 auto result = contents.ApplyColorFilter([](
const Color&
color) {
2396 ASSERT_TRUE(result);
2398 Color(0.424452, 0.828743, 0.79105, 0.9375));
2405 0.0, 0.0, 1.0, 0.01,
2406 0.0, 0.0, 0.0, 1.0) *
2410 "Roboto-Regular.ttf"));
2421 0.0, 0.0, 1.0, 0.01,
2422 0.0, 0.0, 0.0, 1.0) *
2426 "Roboto-Regular.ttf"));
2455 auto context = MakeContext();
2456 std::weak_ptr<Texture> weak_texture;
2459 auto texture = CreateTextureForFixture(
"table_mountain_nx.png");
2462 canvas.
Scale(GetContentScale());
2478 context->Shutdown();
2481 ASSERT_TRUE(weak_texture.expired()) <<
"When the texture is no longer in use "
2482 "by the backend, it should be "
2488 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
2490 ImGuiWindowFlags_AlwaysAutoResize)) {
2491 ImGui::SliderFloat(
"Scale", &
scale, 1, 2);
2495 canvas.
Scale(GetContentScale());
2497 std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2500 .image_filter = std::make_shared<MatrixImageFilter>(
2509 ASSERT_TRUE(OpenPlaygroundHere(callback));
2515 canvas.
Scale(GetContentScale());
2520 .image_filter = std::make_shared<MatrixImageFilter>(
2531 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
2533 canvas.
Scale(GetContentScale());
2538 .image_filter = std::make_shared<MatrixImageFilter>(
2550 SetWindowSize({400, 400});
2552 canvas.
Scale(GetContentScale());
2555 .image_filter = std::make_shared<MatrixImageFilter>(
2565 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2570 canvas.
Scale(GetContentScale());
2580 canvas.
Scale(GetContentScale());
2581 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2615 auto texture = CreateTextureForFixture(
"monkey.png");
2675 std::vector<uint32_t> expected = {
2687 std::vector<uint32_t> actual;
2690 if (
auto* subpass = std::get_if<std::unique_ptr<EntityPass>>(&element)) {
2691 actual.push_back(subpass->get()->GetClipDepth());
2693 if (
Entity* entity = std::get_if<Entity>(&element)) {
2694 actual.push_back(entity->GetClipDepth());
2699 ASSERT_EQ(actual.size(), expected.size());
2700 for (
size_t i = 0; i < expected.size(); i++) {
2701 EXPECT_EQ(expected[i], actual[i]) <<
"Index: " << i;
2708 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
2734 Matrix(1.0, 0.0, 0.0, 0.0,
2736 0.0, 0.0, 1.0, 0.003,
2737 0.0, 0.0, 0.0, 1.0) *
2740 std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2752 ASSERT_TRUE(OpenPlaygroundHere(callback));
2759 canvas.
Scale(GetContentScale());
2762 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
2763 Color{0.1294, 0.5882, 0.9529, 1.0}};
2764 std::vector<Scalar> stops = {
2769 {0, 0}, {100, 100}, std::move(colors), std::move(stops),
2787 texture_descriptor.
size =
ISize{1024, 1024};
2792 std::vector<uint8_t> bytes(4194304);
2793 bool alternate =
false;
2794 for (
auto i = 0u; i < 4194304; i += 4) {
2806 alternate = !alternate;
2810 auto mapping = std::make_shared<fml::NonOwnedMapping>(
2815 GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor);
2817 auto device_buffer =
2818 GetContext()->GetResourceAllocator()->CreateBufferWithCopy(*mapping);
2819 auto command_buffer = GetContext()->CreateCommandBuffer();
2820 auto blit_pass = command_buffer->CreateBlitPass();
2824 blit_pass->GenerateMipmap(texture);
2825 EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()));
2826 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({command_buffer}).ok());
2828 auto image = std::make_shared<Image>(texture);
2874 "Roboto-Regular.ttf"));
2879 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
2882 std::vector<uint8_t> bytes(100 * 100 * 4);
2883 for (
auto i = 0u; i < bytes.size(); i += 4) {
2890 std::make_shared<fml::NonOwnedMapping>(bytes.data(), bytes.size());
2891 auto device_buffer =
2892 GetContext()->GetResourceAllocator()->CreateBufferWithCopy(*mapping);
2893 auto cmd_buffer = GetContext()->CreateCommandBuffer();
2894 auto blit_pass = cmd_buffer->CreateBlitPass();
2899 blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()) &&
2900 GetContext()->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok();
2901 ASSERT_TRUE(did_submit);
2903 auto image = std::make_shared<Image>(bridge);