12 #include "impeller/renderer/testing/mocks.h"
13 #include "third_party/imgui/imgui.h"
29 .sigma =
Sigma(99999),
46 .mask_blur_descriptor =
67 .mask_blur_descriptor =
79 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
99 ASSERT_TRUE(OpenPlaygroundHere(callback));
147 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
162 canvas.
DrawPath(builder.TakePath(), paint);
165 ASSERT_TRUE(OpenPlaygroundHere(callback));
179 canvas.
DrawPath(builder.TakePath(), paint);
203 canvas.
Scale(GetContentScale());
207 .mask_blur_descriptor =
210 .sigma =
Sigma(47.6),
219 canvas.
Scale(GetContentScale());
222 auto draw_line = [&canvas, &paint](
Point a,
Point b) {
225 paint.stroke_width = 5;
227 draw_line(
Point(dx + 100, dy + 100),
Point(dx + 200, dy + 200));
228 draw_line(
Point(dx + 100, dy + 200),
Point(dx + 200, dy + 100));
229 draw_line(
Point(dx + 150, dy + 100),
Point(dx + 200, dy + 150));
230 draw_line(
Point(dx + 100, dy + 150),
Point(dx + 150, dy + 200));
235 for (
int x = 0; x < 5; ++x) {
236 for (
int y = 0; y < 5; ++y) {
240 recorder_canvas.
DrawRect(rect, paint);
244 std::shared_ptr<Texture> texture =
245 picture.
ToImage(renderer,
ISize{100, 100})->GetTexture();
262 paint_lines(300, 300,
272 .mask_blur_descriptor =
314 const Scalar radius = 20.0f;
315 const Scalar y_spacing = 100.0f;
320 radius, 60.0f - radius),
325 canvas.
DrawCircle({x + 25, y + 25}, radius, paint);
330 radius, 60.0f - radius),
342 {radius, 5.0f}, paint);
370 {
"NormalTranslucentZeroSigma",
375 {
"NormalTranslucent",
388 {
"SolidTranslucentWithFilters",
396 .invert_colors =
true}},
398 {
"SolidTranslucentExclusionBlend",
409 {
"InnerTranslucentWithBlurImageFilter",
423 {
"OuterOpaqueWithBlurImageFilter",
432 #define MASK_BLUR_VARIANT_TEST(config) \
433 TEST_P(AiksTest, MaskBlurVariantTest##config) { \
434 ASSERT_TRUE(OpenPlaygroundHere( \
435 MaskBlurVariantTest(*this, kPaintVariations.at(#config)))); \
449 #undef MASK_BLUR_VARIANT_TEST
454 canvas.
Scale(GetContentScale());
472 canvas.
Scale(GetContentScale());
473 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
475 std::make_shared<Image>(boston),
476 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
489 #define FLT_FORWARD(mock, real, method) \
490 EXPECT_CALL(*mock, method()) \
491 .WillRepeatedly(::testing::Return(real->method()));
496 "This backend doesn't yet support setting device capabilities.");
498 if (!WillRenderSomething()) {
502 GTEST_SKIP_(
"This test requires playgrounds.");
505 std::shared_ptr<const Capabilities> old_capabilities =
506 GetContext()->GetCapabilities();
507 auto mock_capabilities = std::make_shared<MockCapabilities>();
508 EXPECT_CALL(*mock_capabilities, SupportsDecalSamplerAddressMode())
509 .Times(::testing::AtLeast(1))
510 .WillRepeatedly(::testing::Return(
false));
511 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultColorFormat);
512 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultStencilFormat);
514 GetDefaultDepthStencilFormat);
515 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsOffscreenMSAA);
517 SupportsImplicitResolvingMSAA);
518 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsReadFromResolve);
519 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsFramebufferFetch);
520 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsSSBO);
521 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsCompute);
523 SupportsTextureToTextureBlits);
524 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultGlyphAtlasFormat);
525 ASSERT_TRUE(SetCapabilities(mock_capabilities).ok());
527 auto texture = std::make_shared<Image>(CreateTextureForFixture(
"boston.jpg"));
529 canvas.
Scale(GetContentScale() * 0.5);
532 texture,
Point(200, 200),
544 canvas.
Scale(GetContentScale());
545 canvas.
Scale({0.5, 0.5, 1.0});
546 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
562 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
564 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
572 canvas.
Scale(GetContentScale());
576 canvas.
Scale({0.6, 0.6, 1});
579 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
580 bounds.
Shift(-image_center), paint);
587 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
589 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
597 canvas.
Scale(GetContentScale());
601 canvas.
Scale({0.6, 0.6, 1});
603 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
604 bounds.
Shift(-image_center), paint);
610 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
612 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
613 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
618 static float rotation = 0;
619 static float scale = 0.6;
620 static int selected_tile_mode = 3;
623 ImGuiWindowFlags_AlwaysAutoResize)) {
624 ImGui::SliderFloat(
"Rotation (degrees)", &rotation, -180, 180);
625 ImGui::SliderFloat(
"Scale", &
scale, 0, 2.0);
626 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
627 sizeof(tile_mode_names) /
sizeof(
char*));
633 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
638 tile_modes[selected_tile_mode])};
643 canvas.
Scale(GetContentScale());
650 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
651 bounds.
Shift(-image_center), paint);
655 ASSERT_TRUE(OpenPlaygroundHere(callback));
662 for (int32_t i = 1; i < 5; ++i) {
668 .
LineTo({100.f + fi, 100.f + fi})
676 std::shared_ptr<RenderTargetCache> cache =
677 std::make_shared<RenderTargetCache>(
678 GetContext()->GetResourceAllocator());
679 AiksContext aiks_context(GetContext(),
nullptr, cache);
680 std::shared_ptr<Image> image = picture.
ToImage(aiks_context, {1024, 768});
681 EXPECT_TRUE(image) <<
" length " << i;
689 for (int32_t i = 0; i < 5; ++i) {
705 std::shared_ptr<RenderTargetCache> cache =
706 std::make_shared<RenderTargetCache>(
707 GetContext()->GetResourceAllocator());
708 AiksContext aiks_context(GetContext(),
nullptr, cache);
709 std::shared_ptr<Image> image = picture.
ToImage(aiks_context, {1024, 768});
710 EXPECT_TRUE(image) <<
" clip rect " << i;
719 auto boston = std::make_shared<Image>(
720 CreateTextureForFixture(
"boston.jpg",
true));
726 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
728 ImGuiWindowFlags_AlwaysAutoResize)) {
729 ImGui::SliderFloat(
"Sigma", &sigma, 0, 200);
730 ImGui::SliderFloat(
"Frequency", &freq, 0.01, 2.0);
731 ImGui::SliderFloat(
"Amplitude", &, 1, 100);
736 canvas.
Scale(GetContentScale());
737 Scalar y = amp * sin(freq * 2.0 * M_PI * count / 60);
739 Point(1024 / 2 - boston->GetSize().width / 2,
740 (768 / 2 - boston->GetSize().height / 2) + y),
755 ASSERT_TRUE(OpenPlaygroundHere(callback));
760 canvas.
Scale(GetContentScale());
764 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
765 Color{0.7568, 0.2627, 0.2118, 1.0}};
766 std::vector<Scalar> stops = {0.0, 1.0};
770 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
793 canvas.
Scale(GetContentScale());
797 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
798 Color{0.7568, 0.2627, 0.2118, 1.0}};
799 std::vector<Scalar> stops = {0.0, 1.0};
803 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
826 canvas.
Scale(GetContentScale());
830 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
831 Color{0.7568, 0.2627, 0.2118, 1.0}};
832 std::vector<Scalar> stops = {0.0, 1.0};
836 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
859 canvas.
Scale(GetContentScale());
887 canvas.
Scale(GetContentScale());
915 canvas.
Scale(GetContentScale());
943 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
945 ImGuiWindowFlags_AlwaysAutoResize)) {
946 ImGui::SliderFloat(
"Sigma", &sigma, 0, 500);
950 canvas.
Scale(GetContentScale());
955 .sigma =
Sigma(sigma),
957 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
958 canvas.
DrawImage(std::make_shared<Image>(boston), {200, 200}, paint);
964 ASSERT_TRUE(OpenPlaygroundHere(callback));
976 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
992 ASSERT_TRUE(OpenPlaygroundHere(callback));
1005 EXPECT_EQ(4, picture.
pass->GetRequiredMipCount());
1009 size_t blur_required_mip_count =
1021 std::shared_ptr<RenderTargetCache> cache =
1022 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1023 AiksContext aiks_context(GetContext(),
nullptr, cache);
1024 picture.
ToImage(aiks_context, {100, 100});
1026 size_t max_mip_count = 0;
1027 for (
auto it = cache->GetRenderTargetDataBegin();
1028 it != cache->GetRenderTargetDataEnd(); ++it) {
1029 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1031 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1035 fml::testing::LogCapture log_capture;
1036 size_t blur_required_mip_count =
1050 std::shared_ptr<RenderTargetCache> cache =
1051 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1052 AiksContext aiks_context(GetContext(),
nullptr, cache);
1053 picture.
ToImage(aiks_context, {100, 100});
1055 size_t max_mip_count = 0;
1056 for (
auto it = cache->GetRenderTargetDataBegin();
1057 it != cache->GetRenderTargetDataEnd(); ++it) {
1058 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1060 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1074 size_t blur_required_mip_count =
1076 fml::testing::LogCapture log_capture;
1085 std::shared_ptr<RenderTargetCache> cache =
1086 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1087 AiksContext aiks_context(GetContext(),
nullptr, cache);
1088 picture.
ToImage(aiks_context, {1024, 768});
1090 size_t max_mip_count = 0;
1091 for (
auto it = cache->GetRenderTargetDataBegin();
1092 it != cache->GetRenderTargetDataEnd(); ++it) {
1093 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1095 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1109 size_t blur_required_mip_count =
1111 fml::testing::LogCapture log_capture;
1126 std::shared_ptr<RenderTargetCache> cache =
1127 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1128 AiksContext aiks_context(GetContext(),
nullptr, cache);
1129 picture.
ToImage(aiks_context, {1024, 768});
1131 size_t max_mip_count = 0;
1132 for (
auto it = cache->GetRenderTargetDataBegin();
1133 it != cache->GetRenderTargetDataEnd(); ++it) {
1134 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1136 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1151 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
1153 ImGuiWindowFlags_AlwaysAutoResize)) {
1154 ImGui::SliderFloat(
"Sigma", &sigma, 0, 500);
1158 canvas.
Scale(GetContentScale());
1161 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
1169 .mask_blur_descriptor =
1172 .sigma =
Sigma(sigma),
1176 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
1181 ASSERT_TRUE(OpenPlaygroundHere(callback));