5#include "flutter/impeller/aiks/aiks_unittests.h"
16#include "flutter/testing/testing.h"
17#include "gtest/gtest.h"
43#include "third_party/imgui/imgui.h"
64 ASSERT_EQ(canvas.
Restore(),
false);
91 auto image = std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
100 auto image = std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
104 paint.invert_colors =
true;
116 paint.invert_colors =
true;
128 paint.invert_colors =
true;
135bool GenerateMipmap(
const std::shared_ptr<Context>& context,
136 std::shared_ptr<Texture>
texture,
138 auto buffer = context->CreateCommandBuffer();
142 auto pass =
buffer->CreateBlitPass();
146 pass->GenerateMipmap(std::move(
texture), std::move(label));
148 pass->EncodeCommands(context->GetResourceAllocator());
149 return context->GetCommandQueue()->Submit({
buffer}).
ok();
152void CanRenderTiledTexture(
AiksTest* aiks_test,
154 Matrix local_matrix = {}) {
155 auto context = aiks_test->GetContext();
156 ASSERT_TRUE(context);
157 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
159 GenerateMipmap(context,
texture,
"table_mountain_nx");
161 canvas.Scale(aiks_test->GetContentScale());
162 canvas.Translate({100.0f, 100.0f, 0});
166 paint.color = Color(1, 1, 1, 1);
182 PathBuilder path_builder;
183 path_builder.AddCircle({150, 150}, 150);
184 path_builder.AddRoundedRect(
Rect::MakeLTRB(300, 300, 600, 600), 10);
186 canvas.DrawPath(path_builder.TakePath(),
paint);
191 PathBuilder path_builder;
192 path_builder.AddCircle({150, 450}, 150);
195 canvas.DrawPath(path_builder.TakePath(),
paint);
198 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
226 auto image = std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
231 source_rect = source_rect.Shift(
Point(image_half_size));
240 canvas.
Scale(GetContentScale());
285 std::vector<Color> gradient_colors = {
286 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
287 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
288 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
289 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
290 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
291 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
292 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
293 std::vector<Scalar> stops = {
302 auto texture = CreateTextureForFixture(
"airplane.jpg",
306 {500, 600}, 75, std::move(gradient_colors), std::move(stops),
359 .HorizontalLineTo(-200)
361 .CubicCurveTo({0, -40}, {0, -80}, {200, -80})
399 for (
int i = 0; i < 15; i++) {
402 paint.color = colors[i % colors.size()];
431 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
432 Color{0.1294, 0.5882, 0.9529, 1.0}};
433 std::vector<Scalar> stops = {
439 {0, 0}, {100, 100}, std::move(colors), std::move(stops),
457 paint.color =
Color{0.9568, 0.2627, 0.2118, 1.0};
459 paint.color =
Color{0.1294, 0.5882, 0.9529, 1.0};
467 auto image = picture.ToImage(renderer,
ISize{1000, 1000});
489 auto image = picture.ToImage(renderer,
ISize{1000, 1000});
530 std::make_shared<Image>(CreateTextureForFixture(
"kalimba.jpg"));
614 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
670 const std::string&
text,
671 const std::string_view& font_fixture,
676 Paint{.color = Color::Aqua().WithAlpha(0.25)});
680 Paint{.color = Color::Red().WithAlpha(0.25)});
683 auto c_font_fixture = std::string(font_fixture);
689 SkFont sk_font(font_mgr->makeFromData(mapping),
options.font_size);
699 text_paint.color =
options.color;
700 text_paint.mask_blur_descriptor =
options.mask_blur_descriptor;
707 const std::string&
text,
708 const std::string& font_fixture,
713 Paint{.color = Color::Aqua().WithAlpha(0.25)});
717 Paint{.color = Color::Red().WithAlpha(0.25)});
724 auto typeface_stb = std::make_shared<TypefaceSTB>(std::move(mapping));
727 typeface_stb, Font::Metrics{.point_size =
options.font_size},
text);
730 text_paint.color =
options.color;
739 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
740 "Roboto-Regular.ttf"));
748 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
749 "Roboto-Regular.ttf"));
757 std::array<Scalar, 20> phase_offsets = {
758 7.82637e-06, 0.131538, 0.755605, 0.45865, 0.532767,
759 0.218959, 0.0470446, 0.678865, 0.679296, 0.934693,
760 0.383502, 0.519416, 0.830965, 0.0345721, 0.0534616,
761 0.5297, 0.671149, 0.00769819, 0.383416, 0.0668422};
763 static float font_size = 20;
764 static float phase_variation = 0.2;
765 static float speed = 0.5;
768 ImGuiWindowFlags_AlwaysAutoResize)) {
769 ImGui::SliderFloat(
"Font size", &font_size, 5, 50);
770 ImGui::SliderFloat(
"Phase variation", &phase_variation, 0, 1);
771 ImGui::SliderFloat(
"Oscillation speed", &speed, 0, 2);
772 ImGui::SliderFloat(
"Oscillation magnitude", &
magnitude, 0, 300);
777 canvas.
Scale(GetContentScale());
779 for (
size_t i = 0; i < phase_offsets.size(); i++) {
782 std::sin((-phase_offsets[i] *
k2Pi * phase_variation +
783 GetSecondsElapsed() * speed)),
784 200 + i * font_size * 1.1
787 GetContext(), canvas,
788 "the quick brown fox jumped over "
790 "Roboto-Regular.ttf",
791 {.font_size = font_size, .position = position})) {
798 ASSERT_TRUE(OpenPlaygroundHere(
callback));
806 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
807 "HomemadeApple.ttf"));
813 "Apple Color Emoji.ttc";
815 "NotoColorEmoji.ttf";
823 GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture));
832 GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture,
836 .sigma =
Sigma(4)}}));
845 GetContext(), canvas,
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊",
kFontFixture,
860 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
861 "Roboto-Regular.ttf"));
866 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
867 "Roboto-Regular.ttf"));
878 ASSERT_NE(mapping,
nullptr);
882 SkFont sk_font(font_mgr->makeFromData(mapping), font_size);
891 {
Point(1, 2),
"789"},
892 {
Point(1, 3),
"456"},
893 {
Point(1, 4),
"123"},
894 {
Point(0, 6),
"0F0F0F0"}};
895 for (
auto& t :
text) {
897 canvas.
Translate(t.position *
Point(font_size * 2, font_size * 1.1));
900 ASSERT_NE(blob,
nullptr);
912 canvas.
Scale(GetContentScale());
920 GetContext(), canvas,
"the quick brown fox jumped over the lazy dog!.?",
921 "Roboto-Regular.ttf"));
937 canvas.
DrawPaint({.color = Color::Color::OrangeRed().WithAlpha(0.5)});
943 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
949 GetContext()->GetCapabilities()->GetDefaultColorFormat();
996 canvas.
Scale(GetContentScale());
998 const int color_count = 3;
999 Color colors[color_count] = {
1010 while (radius > 0) {
1011 paint.color = colors[(c_index++) % color_count];
1020 std::vector<Color> gradient_colors = {
1021 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1022 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1023 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1024 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1025 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1026 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1027 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1028 std::vector<Scalar> stops = {
1037 auto texture = CreateTextureForFixture(
"airplane.jpg",
1041 {500, 600}, 75, std::move(gradient_colors), std::move(stops),
1055 canvas.
Scale(GetContentScale());
1057 const int color_count = 3;
1058 Color colors[color_count] = {
1071 for (
int i = 0; i < n; i++) {
1072 paint.color = colors[(c_index++) % color_count];
1079 paint.stroke_width = 1;
1080 draw(canvas, {10, 10}, 2, 2, 14);
1081 paint.stroke_width = 5;
1082 draw(canvas, {10, 10}, 35, 10, 56);
1084 std::vector<Color> gradient_colors = {
1085 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1086 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1087 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1088 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1089 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1090 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1091 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1092 std::vector<Scalar> stops = {
1101 auto texture = CreateTextureForFixture(
"airplane.jpg",
1105 {500, 600}, 75, std::move(gradient_colors), std::move(stops),
1107 draw(canvas, {500, 600}, 5, 10, 10);
1112 draw(canvas, {800, 300}, 5, 10, 10);
1119 canvas.
Scale(GetContentScale());
1121 const int color_count = 3;
1122 Color colors[color_count] = {
1132 int long_radius = 600;
1133 int short_radius = 600;
1134 while (long_radius > 0 && short_radius > 0) {
1135 paint.color = colors[(c_index++) % color_count];
1137 long_radius * 2, short_radius * 2),
1140 short_radius * 2, long_radius * 2),
1142 if (short_radius > 30) {
1151 std::vector<Color> gradient_colors = {
1152 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1153 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1154 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1155 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1156 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1157 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1158 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1159 std::vector<Scalar> stops = {
1168 auto texture = CreateTextureForFixture(
"airplane.jpg",
1174 {300, 650}, 75, std::move(gradient_colors), std::move(stops),
1190 canvas.
Scale(GetContentScale());
1192 const int color_count = 3;
1193 Color colors[color_count] = {
1203 for (
int i = 0; i < 4; i++) {
1204 for (
int j = 0; j < 4; j++) {
1205 paint.color = colors[(c_index++) % color_count];
1210 paint.color = colors[(c_index++) % color_count];
1212 paint.color = colors[(c_index++) % color_count];
1215 std::vector<Color> gradient_colors = {
1216 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1217 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1218 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1219 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1220 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1221 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1222 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1223 std::vector<Scalar> stops = {
1232 auto texture = CreateTextureForFixture(
"airplane.jpg",
1238 for (
int i = 1; i <= 10; i++) {
1241 550 + i * 20, 550 + j * 20),
1246 {200, 650}, 75, std::move(gradient_colors), std::move(stops),
1255 for (
int i = 1; i <= 10; i++) {
1258 720 + i * 20, 220 + j * 20),
1273 canvas.
Scale(GetContentScale());
1284 for (
int i = 0; i < 5; i++) {
1288 radius, 60.0f - radius),
1294 for (
int i = 0; i < 5; i++) {
1302 for (
int i = 0; i < 5; i++) {
1306 radius, 60.0f - radius),
1312 for (
int i = 0; i < 5; i++) {
1322 for (
int i = 0; i < 5; i++) {
1326 {radius, 5.0f},
paint);
1334 canvas.
Scale(GetContentScale());
1336 const int color_count = 3;
1337 Color colors[color_count] = {
1346 auto draw_rrect_as_path = [&canvas](
const Rect& rect,
const Size& radii,
1349 builder.AddRoundedRect(rect, radii);
1354 for (
int i = 0; i < 4; i++) {
1355 for (
int j = 0; j < 4; j++) {
1356 paint.color = colors[(c_index++) % color_count];
1357 draw_rrect_as_path(
Rect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1361 paint.color = colors[(c_index++) % color_count];
1363 paint.color = colors[(c_index++) % color_count];
1366 std::vector<Color> gradient_colors = {
1367 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
1368 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
1369 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
1370 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
1371 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
1372 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
1373 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
1374 std::vector<Scalar> stops = {
1383 auto texture = CreateTextureForFixture(
"airplane.jpg",
1389 for (
int i = 1; i <= 10; i++) {
1392 550 + i * 20, 550 + j * 20),
1397 {200, 650}, 75, std::move(gradient_colors), std::move(stops),
1406 for (
int i = 1; i <= 10; i++) {
1409 720 + i * 20, 220 + j * 20),
1425 canvas.
Scale(GetContentScale());
1430 auto current =
Point{25, 25};
1432 const auto size =
Size(100, 100);
1440 .stroke_width = 5.0f,
1457 ASSERT_TRUE(OpenPlaygroundHere(
callback));
1543 canvas.
Scale(GetContentScale());
1546 auto texture = std::make_shared<Image>(CreateTextureForFixture(
"boston.jpg"));
1558 draw_image_layer(effect_paint);
1562 draw_image_layer(effect_paint);
1567#if IMPELLER_ENABLE_3D
1572 ASSERT_NE(mapping,
nullptr);
1575 *mapping, *GetContext()->GetResourceAllocator());
1576 ASSERT_NE(gltf_scene,
nullptr);
1581 static Scalar distance = 2;
1585 ImGuiWindowFlags_AlwaysAutoResize)) {
1586 ImGui::SliderFloat(
"Distance", &distance, 0, 4);
1587 ImGui::SliderFloat(
"Y", &y_pos, -3, 3);
1588 ImGui::SliderFloat(
"FOV", &fov, 1, 180);
1592 Scalar angle = GetSecondsElapsed();
1593 auto camera_position =
1594 Vector3(distance * std::sin(angle), y_pos, -distance * std::cos(angle));
1596 paint.color_source = ColorSource::MakeScene(
1603 canvas.Scale(GetContentScale());
1604 canvas.DrawPaint(
paint);
1605 return canvas.EndRecordingAsPicture();
1608 ASSERT_TRUE(OpenPlaygroundHere(
callback));
1617 ASSERT_FALSE(
paint.HasColorFilter());
1619 paint.color_filter =
1622 ASSERT_TRUE(
paint.HasColorFilter());
1628 ASSERT_TRUE(
paint.HasColorFilter());
1630 paint.mask_blur_descriptor = {};
1632 ASSERT_TRUE(
paint.HasColorFilter());
1634 paint.color_filter =
nullptr;
1636 ASSERT_FALSE(
paint.HasColorFilter());
1640 auto entity_pass = std::make_shared<EntityPass>();
1644 paint.color_filter =
1648 auto delegate = std::make_shared<OpacityPeepholePassDelegate>(
paint);
1649 ASSERT_FALSE(delegate->CanCollapseIntoParentPass(entity_pass.get()));
1651 paint.color_filter =
nullptr;
1657 delegate = std::make_shared<OpacityPeepholePassDelegate>(
paint);
1658 ASSERT_FALSE(delegate->CanCollapseIntoParentPass(entity_pass.get()));
1660 paint.image_filter =
nullptr;
1664 delegate = std::make_shared<OpacityPeepholePassDelegate>(
paint);
1665 ASSERT_FALSE(delegate->CanCollapseIntoParentPass(entity_pass.get()));
1671 entity_pass->AddEntity(std::move(entity));
1674 delegate = std::make_shared<OpacityPeepholePassDelegate>(
paint);
1675 ASSERT_TRUE(delegate->CanCollapseIntoParentPass(entity_pass.get()));
1687 ASSERT_EQ(picture.pass->GetClearColor(), expected);
1690 std::shared_ptr<Context> real_context = GetContext();
1691 std::shared_ptr<ContextMock>
mock_context = spy->MakeContext(real_context);
1693 std::shared_ptr<Image>
image = picture.ToImage(renderer, {300, 300});
1695 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1696 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1697 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
1703 ParentSaveLayerCreatesRenderPassWhenChildBackdropFilterIsPresent) {
1714 std::shared_ptr<Context> real_context = GetContext();
1715 std::shared_ptr<ContextMock>
mock_context = spy->MakeContext(real_context);
1717 std::shared_ptr<Image>
image = picture.ToImage(renderer, {300, 300});
1719 ASSERT_EQ(spy->render_passes_.size(),
1721 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1722 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
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);
1755 std::shared_ptr<Context> real_context = GetContext();
1756 std::shared_ptr<ContextMock>
mock_context = spy->MakeContext(real_context);
1758 std::shared_ptr<Image>
image = picture.ToImage(renderer, {300, 300});
1760 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1761 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1762 ASSERT_EQ(render_pass->GetCommands().size(), 2llu);
1775 std::shared_ptr<Context> real_context = GetContext();
1776 std::shared_ptr<ContextMock>
mock_context = spy->MakeContext(real_context);
1778 std::shared_ptr<Image>
image = picture.ToImage(renderer, {300, 300});
1780 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1781 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1782 ASSERT_EQ(render_pass->GetCommands().size(), 1llu);
1795 std::shared_ptr<Context> real_context = GetContext();
1796 std::shared_ptr<ContextMock>
mock_context = spy->MakeContext(real_context);
1798 std::shared_ptr<Image>
image = picture.ToImage(renderer, {301, 301});
1800 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1801 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1802 ASSERT_EQ(render_pass->GetCommands().size(), 2llu);
1816 ASSERT_EQ(picture.pass->GetClearColor(), expected);
1819 std::shared_ptr<Context> real_context = GetContext();
1820 std::shared_ptr<ContextMock>
mock_context = spy->MakeContext(real_context);
1822 std::shared_ptr<Image>
image = picture.ToImage(renderer, {300, 300});
1824 ASSERT_EQ(spy->render_passes_.size(), 1llu);
1825 std::shared_ptr<RenderPass> render_pass = spy->render_passes_[0];
1826 ASSERT_EQ(render_pass->GetCommands().size(), 0llu);
1842 std::optional<Color> actual_color;
1843 bool found_subpass =
false;
1845 if (
auto subpass = std::get_if<std::unique_ptr<EntityPass>>(&element)) {
1846 actual_color = subpass->get()->GetClearColor();
1847 found_subpass =
true;
1854 EXPECT_FALSE(actual_color.has_value());
1893 1.0, 1.0, 1.0, 1.0, 0
1996 canvas.
Scale(GetContentScale());
1998 auto test = [&canvas](
const std::shared_ptr<ImageFilter>& filter) {
1999 auto DrawLine = [&canvas](
const Point& p0,
const Point& p1,
2015 canvas.
SaveLayer({.image_filter = filter},
2042 auto rotate_filter =
2047 test(rotate_filter);
2058 test(rgb_swap_filter);
2085 canvas.
Scale(GetContentScale());
2091 canvas.
SaveLayer({.image_filter = blur_filter}, std::nullopt);
2108 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2121 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2143 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2164 TranslucentSaveLayerWithColorFilterAndImageFilterDrawsCorrectly) {
2167 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2257 std::vector<Entity> entity;
2258 std::shared_ptr<SolidColorContents> contents;
2259 picture.pass->IterateAllEntities([e = &entity, &contents](
Entity& entity) {
2262 std::static_pointer_cast<SolidColorContents>(entity.GetContents());
2263 e->emplace_back(entity.Clone());
2269 ASSERT_TRUE(entity.size() >= 1);
2270 ASSERT_TRUE(contents->IsOpaque());
2290 auto runtime_stages =
2291 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
2293 auto runtime_stage =
2295 ASSERT_TRUE(runtime_stage);
2296 ASSERT_TRUE(runtime_stage->IsDirty());
2298 struct FragUniforms {
2301 } frag_uniforms = {.iResolution =
Vector2(400, 400), .iTime = 100.0};
2302 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
2303 uniform_data->resize(
sizeof(FragUniforms));
2304 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
2306 std::vector<RuntimeEffectContents::TextureInput> texture_inputs;
2310 runtime_stage, uniform_data, texture_inputs);
2323 auto runtime_stages = OpenAssetAsRuntimeStage(
"gradient.frag.iplr");
2324 auto runtime_stage =
2326 ASSERT_TRUE(runtime_stage);
2327 ASSERT_TRUE(runtime_stage->IsDirty());
2329 struct FragUniforms {
2332 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
2333 uniform_data->resize(
sizeof(FragUniforms));
2334 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
2336 std::vector<RuntimeEffectContents::TextureInput> texture_inputs;
2340 runtime_stage, uniform_data, texture_inputs);
2344 canvas.
Scale(GetContentScale());
2352 std::vector<Point>
points = {
2361 std::vector<PointStyle> caps = {
2384 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
2385 auto size = atlas->GetSize();
2386 auto image = std::make_shared<Image>(atlas);
2388 Scalar half_width = size.width / 2;
2389 Scalar half_height = size.height / 2;
2390 std::vector<Rect> texture_coordinates = {
2394 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
2396 std::vector<Matrix> transforms = {
2407 canvas.
Scale({0.25, 0.25, 1.0});
2417 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
2418 auto size = atlas->GetSize();
2419 auto image = std::make_shared<Image>(atlas);
2421 Scalar half_width = size.width / 2;
2422 Scalar half_height = size.height / 2;
2423 std::vector<Rect> texture_coordinates = {
2427 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
2429 std::vector<Matrix> transforms = {
2438 canvas.
Scale({0.25, 0.25, 1.0});
2446 auto texture = CreateTextureForFixture(
"table_mountain_nx.png",
2449 std::vector<Point>
points = {
2458 std::vector<PointStyle> caps = {
2469 canvas.Translate({150, 0});
2472 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2480 ASSERT_NE(mapping,
nullptr);
2484 SkFont sk_font(font_mgr->makeFromData(mapping), font_size);
2489 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
2490 Color{0.1294, 0.5882, 0.9529, 1.0}};
2491 std::vector<Scalar> stops = {
2496 {0, 0}, {100, 100}, std::move(colors), std::move(stops),
2504 ASSERT_NE(blob,
nullptr);
2506 canvas.DrawTextFrame(
frame,
Point(), text_paint);
2508 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2570 Color(0.424452, 0.828743, 0.79105, 0.9375));
2577 0.0, 0.0, 1.0, 0.01,
2578 0.0, 0.0, 0.0, 1.0) *
2582 "Roboto-Regular.ttf"));
2593 0.0, 0.0, 1.0, 0.01,
2594 0.0, 0.0, 0.0, 1.0) *
2598 "Roboto-Regular.ttf"));
2631 capture_context.Rewind();
2632 auto document = capture_context.GetDocument(
"TestDocument");
2638 ImGuiWindowFlags_AlwaysAutoResize)) {
2639 document.GetElement()->properties.Iterate([](
CaptureProperty& property) {
2640 property.Invoke({.color = [](CaptureColorProperty& p) {
2641 ImGui::ColorEdit4(p.label.c_str(),
2642 reinterpret_cast<float*
>(&p.value));
2654 ASSERT_FALSE(GetContext()->capture.IsActive());
2659 auto context = MakeContext();
2660 std::weak_ptr<Texture> weak_texture;
2663 auto texture = CreateTextureForFixture(
"table_mountain_nx.png");
2666 canvas.
Scale(GetContentScale());
2682 context->Shutdown();
2685 ASSERT_TRUE(weak_texture.expired()) <<
"When the texture is no longer in use "
2686 "by the backend, it should be "
2694 auto texture = CreateTextureForFixture(
"table_mountain_nx.png");
2701 std::vector<uint16_t> indices = {0u, 1u, 2u};
2702 std::vector<Point> texture_coordinates = {};
2703 std::vector<Color> vertex_colors = {};
2704 auto geometry = std::make_shared<VerticesGeometry>(
2705 vertices, indices, texture_coordinates, vertex_colors,
2716 auto texture = CreateTextureForFixture(
"table_mountain_nx.png");
2724 std::vector<uint16_t> indices = {0u, 1u, 2u};
2725 std::vector<Point> texture_coordinates = {};
2726 std::vector<Color> vertex_colors = {};
2727 auto geometry = std::make_shared<VerticesGeometry>(
2728 vertices, indices, texture_coordinates, vertex_colors,
2739 auto texture = CreateTextureForFixture(
"table_mountain_nx.png");
2741 paint.color_source =
2753 std::vector<uint16_t> indices = {};
2754 std::vector<Point> texture_coordinates = {};
2755 std::vector<Color> vertex_colors = {
2760 auto geometry = std::make_shared<VerticesGeometry>(
2761 vertices, indices, texture_coordinates, vertex_colors,
2771 auto texture = CreateTextureForFixture(
"table_mountain_nx.png");
2773 paint.color_source =
2785 std::vector<uint16_t> indices = {};
2786 std::vector<Point> texture_coordinates = {};
2787 std::vector<Color> vertex_colors = {
2792 auto geometry = std::make_shared<VerticesGeometry>(
2793 vertices, indices, texture_coordinates, vertex_colors,
2802 canvas.
Scale(GetContentScale());
2803 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2806 .image_filter = std::make_shared<MatrixImageFilter>(
2819 canvas.
Scale(GetContentScale());
2824 .image_filter = std::make_shared<MatrixImageFilter>(
2835 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
2837 canvas.
Scale(GetContentScale());
2842 .image_filter = std::make_shared<MatrixImageFilter>(
2854 SetWindowSize({400, 400});
2856 canvas.
Scale(GetContentScale());
2859 .image_filter = std::make_shared<MatrixImageFilter>(
2869 ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2874 canvas.
Scale(GetContentScale());
2884 canvas.
Scale(GetContentScale());
2885 auto image = std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
2919 auto texture = CreateTextureForFixture(
"monkey.png");
2979 std::vector<uint32_t> expected = {
2991 std::vector<uint32_t> actual;
2994 if (
auto* subpass = std::get_if<std::unique_ptr<EntityPass>>(&element)) {
2995 actual.push_back(subpass->get()->GetClipDepth());
2997 if (
Entity* entity = std::get_if<Entity>(&element)) {
2998 actual.push_back(entity->GetClipDepth());
3003 ASSERT_EQ(actual.size(), expected.size());
3004 for (
size_t i = 0; i < expected.size(); i++) {
3005 EXPECT_EQ(expected[i], actual[i]) <<
"Index: " << i;
3038 Matrix(1.0, 0.0, 0.0, 0.0,
3040 0.0, 0.0, 1.0, 0.003,
3041 0.0, 0.0, 0.0, 1.0) *
3044 std::make_shared<Image>(CreateTextureForFixture(
"airplane.jpg"));
3056 ASSERT_TRUE(OpenPlaygroundHere(
callback));
3063 canvas.
Scale(GetContentScale());
3066 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
3067 Color{0.1294, 0.5882, 0.9529, 1.0}};
3068 std::vector<Scalar> stops = {
3073 {0, 0}, {100, 100}, std::move(colors), std::move(stops),
3091 texture_descriptor.
size =
ISize{1024, 1024};
3096 std::vector<uint8_t> bytes(4194304);
3097 bool alternate =
false;
3098 for (
auto i = 0u; i < 4194304; i += 4) {
3110 alternate = !alternate;
3114 auto mapping = std::make_shared<fml::NonOwnedMapping>(
3119 GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor);
3122 ASSERT_TRUE(
texture->SetContents(mapping));
3124 auto command_buffer = GetContext()->CreateCommandBuffer();
3125 auto blit_pass = command_buffer->CreateBlitPass();
3127 blit_pass->GenerateMipmap(
texture);
3128 EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()));
3129 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({command_buffer}).
ok());
3141 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
3146 std::make_shared<Image>(CreateTextureForFixture(
"bay_bridge.jpg"));
3147 auto size = atlas->GetSize();
3149 Scalar half_width = size.width / 2;
3150 Scalar half_height = size.height / 2;
3151 std::vector<Rect> texture_coordinates = {
3155 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
3157 std::vector<Matrix> transforms = {
3166 canvas.
DrawAtlas(atlas, transforms, texture_coordinates, colors,
static const int points[]
static double magnitude(double a)
static bool ok(int result)
static SkBlendMode GetBlendMode(SkSVGFeBlend::Mode mode)
static SkScalar center(float pos0, float pos1)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
const Matrix & GetCurrentTransform() const
void DrawImageRect(const std::shared_ptr< Image > &image, Rect source, Rect dest, const Paint &paint, SamplerDescriptor sampler={}, SourceRectConstraint src_rect_constraint=SourceRectConstraint::kFast)
void DrawVertices(const std::shared_ptr< VerticesGeometry > &vertices, BlendMode blend_mode, const Paint &paint)
virtual void SaveLayer(const Paint &paint, std::optional< Rect > bounds=std::nullopt, const std::shared_ptr< ImageFilter > &backdrop_filter=nullptr, ContentBoundsPromise bounds_promise=ContentBoundsPromise::kUnknown, uint32_t total_content_depth=kMaxDepth)
void DrawOval(const Rect &rect, const Paint &paint)
void ClipPath(const Path &path, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
void ClipRRect(const Rect &rect, const Size &corner_radii, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
size_t GetSaveCount() const
void Transform(const Matrix &transform)
void DrawImage(const std::shared_ptr< Image > &image, Point offset, const Paint &paint, SamplerDescriptor sampler={})
void Rotate(Radians radians)
virtual void DrawTextFrame(const std::shared_ptr< TextFrame > &text_frame, Point position, const Paint &paint)
void DrawPaint(const Paint &paint)
void ClipRect(const Rect &rect, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
void Skew(Scalar sx, Scalar sy)
void Scale(const Vector2 &scale)
Picture EndRecordingAsPicture()
void DrawPath(const Path &path, const Paint &paint)
virtual void Save(uint32_t total_content_depth=kMaxDepth)
void DrawPoints(std::vector< Point > points, Scalar radius, const Paint &paint, PointStyle point_style)
void ClipOval(const Rect &bounds, Entity::ClipOperation clip_op=Entity::ClipOperation::kIntersect)
void DrawRect(const Rect &rect, const Paint &paint)
void DrawRRect(const Rect &rect, const Size &corner_radii, const Paint &paint)
void DrawAtlas(const std::shared_ptr< Image > &atlas, std::vector< Matrix > transforms, std::vector< Rect > texture_coordinates, std::vector< Color > colors, BlendMode blend_mode, SamplerDescriptor sampler, std::optional< Rect > cull_rect, const Paint &paint)
void Translate(const Vector3 &offset)
void DrawCircle(const Point ¢er, Scalar radius, const Paint &paint)
struct impeller::Canvas::DebugOptions debug_options
static CaptureContext MakeAllowlist(std::initializer_list< std::string > allowlist)
static std::shared_ptr< ColorFilter > MakeMatrix(ColorMatrix color_matrix)
static std::shared_ptr< ColorFilter > MakeBlend(BlendMode blend_mode, Color color)
static std::shared_ptr< ColorFilter > MakeLinearToSrgb()
static std::shared_ptr< ColorFilter > MakeSrgbToLinear()
static ColorSource MakeLinearGradient(Point start_point, Point end_point, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource MakeRadialGradient(Point center, Scalar radius, std::vector< Color > colors, std::vector< Scalar > stops, Entity::TileMode tile_mode, Matrix effect_transform)
static ColorSource MakeImage(std::shared_ptr< Texture > texture, Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode, SamplerDescriptor sampler_descriptor, Matrix effect_transform)
static ColorSource MakeRuntimeEffect(std::shared_ptr< RuntimeStage > runtime_stage, std::shared_ptr< std::vector< uint8_t > > uniform_data, std::vector< RuntimeEffectContents::TextureInput > texture_inputs)
std::variant< Entity, std::unique_ptr< EntityPass > > Element
void SetContents(std::shared_ptr< Contents > contents)
@ kNormal
Blurred inside and outside.
static std::shared_ptr< ImageFilter > MakeMatrix(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
static std::shared_ptr< ImageFilter > MakeLocalMatrix(const Matrix &matrix, const ImageFilter &internal_filter)
static std::shared_ptr< ImageFilter > MakeErode(Radius radius_x, Radius radius_y)
static std::shared_ptr< ImageFilter > MakeBlur(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
static std::shared_ptr< ImageFilter > MakeDilate(Radius radius_x, Radius radius_y)
static std::shared_ptr< ImageFilter > MakeFromColorFilter(const ColorFilter &color_filter)
static std::shared_ptr< ImageFilter > MakeCompose(const ImageFilter &inner, const ImageFilter &outer)
PathBuilder & AddRect(Rect rect)
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & MoveTo(Point point, bool relative=false)
PathBuilder & AddCircle(const Point ¢er, Scalar radius)
PathBuilder & AddLine(const Point &p1, const Point &p2)
Move to point p1, then insert a line from p1 to p2.
PathBuilder & AddRoundedRect(Rect rect, RoundingRadii radii)
PathBuilder & AddQuadraticCurve(Point p1, Point cp, Point p2)
Move to point p1, then insert a quadradic curve from p1 to p2 with the control point cp.
PathBuilder & SetConvexity(Convexity value)
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
static std::unique_ptr< SolidColorContents > Make(const Path &path, Color color)
static std::unique_ptr< TypographerContext > Make()
static std::shared_ptr< Node > MakeFromFlatbuffer(const fml::Mapping &ipscene_mapping, Allocator &allocator)
static std::shared_ptr< ContextSpy > Make()
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static const uint8_t buffer[]
#define ASSERT_MATRIX_NEAR(a, b)
#define ASSERT_COLOR_NEAR(a, b)
static MockContext mock_context
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
bool RenderTextInCanvasSTB(const std::shared_ptr< Context > &context, Canvas &canvas, const std::string &text, const std::string &font_fixture, TextRenderOptions options={})
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
static constexpr std::string_view kFontFixture
bool RenderTextInCanvasSkia(const std::shared_ptr< Context > &context, Canvas &canvas, const std::string &text, const std::string_view &font_fixture, TextRenderOptions options={})
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
std::shared_ptr< TextFrame > MakeTextFrameSTB(const std::shared_ptr< TypefaceSTB > &typeface_stb, Font::Metrics metrics, const std::string &text)
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
@ kRound
Points are drawn as squares.
@ kSquare
Points are drawn as circles.
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
constexpr float k1OverSqrt2
void Close(PathBuilder *builder)
constexpr const char * PixelFormatToString(PixelFormat format)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
const Scalar stroke_width
bool offscreen_texture_checkerboard
A capturable property type.
static constexpr Color Crimson()
static constexpr Color LimeGreen()
static constexpr Color BlackTransparent()
static constexpr Color Fuchsia()
static constexpr Color Black()
static constexpr Color DarkBlue()
static constexpr Color CornflowerBlue()
static constexpr Color MediumTurquoise()
static constexpr Color White()
static constexpr Color LightCoral()
constexpr Color WithAlpha(Scalar new_alpha) const
static constexpr Color SkyBlue()
static constexpr Color Maroon()
static constexpr Color Orange()
static constexpr Color Purple()
static constexpr Color Red()
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
static constexpr Color AntiqueWhite()
static constexpr Color Yellow()
Color Blend(Color source, BlendMode blend_mode) const
Blends an unpremultiplied destination color into a given unpremultiplied source color to form a new u...
static constexpr Color Blue()
static constexpr Color Green()
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakePerspective(Radians fov_y, Scalar aspect_ratio, Scalar z_near, Scalar z_far)
static Matrix MakeRotationY(Radians r)
static constexpr Matrix MakeLookAt(Vector3 position, Vector3 target, Vector3 up)
static Matrix MakeRotationZ(Radians r)
static constexpr Matrix MakeScale(const Vector3 &s)
FilterContents::BlurStyle style
std::optional< MaskBlurDescriptor > mask_blur_descriptor
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
static constexpr TPoint< Type > MakeXY(Type x, Type y)
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeSize(const TSize< U > &size)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
constexpr size_t MipCount() const
static constexpr TSize MakeWH(Type width, Type height)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
constexpr size_t GetByteSizeOfBaseMipLevel() const
std::optional< Paint::MaskBlurDescriptor > mask_blur_descriptor
#define EXPECT_TRUE(handle)