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> {
165 ASSERT_TRUE(OpenPlaygroundHere(callback));
203 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
205 ImGuiWindowFlags_AlwaysAutoResize)) {
206 ImGui::SliderFloat(
"Sigma", &sigma, 0, 50);
210 canvas.
Scale(GetContentScale());
214 .mask_blur_descriptor =
217 .sigma =
Sigma(sigma),
224 ASSERT_TRUE(OpenPlaygroundHere(callback));
229 canvas.
Scale(GetContentScale());
235 paint.stroke_width = 5;
237 draw_line(
Point(dx + 100, dy + 100),
Point(dx + 200, dy + 200));
238 draw_line(
Point(dx + 100, dy + 200),
Point(dx + 200, dy + 100));
239 draw_line(
Point(dx + 150, dy + 100),
Point(dx + 200, dy + 150));
240 draw_line(
Point(dx + 100, dy + 150),
Point(dx + 150, dy + 200));
245 for (
int x = 0; x < 5; ++x) {
246 for (
int y = 0; y < 5; ++y) {
254 std::shared_ptr<Texture> texture =
255 picture.
ToImage(renderer,
ISize{100, 100})->GetTexture();
272 paint_lines(300, 300,
282 .mask_blur_descriptor =
317 paint.mask_blur_descriptor->style = config.
style;
324 const Scalar radius = 20.0f;
325 const Scalar y_spacing = 100.0f;
330 radius, 60.0f - radius),
340 radius, 60.0f - radius),
352 {radius, 5.0f},
paint);
380 {
"NormalTranslucentZeroSigma",
385 {
"NormalTranslucent",
398 {
"SolidTranslucentWithFilters",
406 .invert_colors =
true}},
408 {
"SolidTranslucentExclusionBlend",
419 {
"InnerTranslucentWithBlurImageFilter",
433 {
"OuterOpaqueWithBlurImageFilter",
442 #define MASK_BLUR_VARIANT_TEST(config) \
443 TEST_P(AiksTest, MaskBlurVariantTest##config) { \
444 ASSERT_TRUE(OpenPlaygroundHere( \
445 MaskBlurVariantTest(*this, kPaintVariations.at(#config)))); \
459 #undef MASK_BLUR_VARIANT_TEST
464 canvas.
Scale(GetContentScale());
482 canvas.
Scale(GetContentScale());
483 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
485 std::make_shared<Image>(boston),
486 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
499 #define FLT_FORWARD(mock, real, method) \
500 EXPECT_CALL(*mock, method()) \
501 .WillRepeatedly(::testing::Return(real->method()));
506 "This backend doesn't yet support setting device capabilities.");
508 if (!WillRenderSomething()) {
512 GTEST_SKIP_(
"This test requires playgrounds.");
515 std::shared_ptr<const Capabilities> old_capabilities =
516 GetContext()->GetCapabilities();
517 auto mock_capabilities = std::make_shared<MockCapabilities>();
518 EXPECT_CALL(*mock_capabilities, SupportsDecalSamplerAddressMode())
519 .Times(::testing::AtLeast(1))
520 .WillRepeatedly(::testing::Return(
false));
521 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultColorFormat);
522 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultStencilFormat);
524 GetDefaultDepthStencilFormat);
525 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsOffscreenMSAA);
527 SupportsImplicitResolvingMSAA);
528 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsReadFromResolve);
529 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsFramebufferFetch);
530 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsSSBO);
531 FLT_FORWARD(mock_capabilities, old_capabilities, SupportsCompute);
533 SupportsTextureToTextureBlits);
534 FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultGlyphAtlasFormat);
535 ASSERT_TRUE(SetCapabilities(mock_capabilities).ok());
537 auto texture = std::make_shared<Image>(CreateTextureForFixture(
"boston.jpg"));
539 canvas.
Scale(GetContentScale() * 0.5);
542 texture,
Point(200, 200),
554 canvas.
Scale(GetContentScale());
555 canvas.
Scale({0.5, 0.5, 1.0});
556 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
572 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
574 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
582 canvas.
Scale(GetContentScale());
586 canvas.
Scale({0.6, 0.6, 1});
589 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
597 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
599 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
607 canvas.
Scale(GetContentScale());
611 canvas.
Scale({0.6, 0.6, 1});
613 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
620 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
622 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
623 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
628 static float rotation = 0;
629 static float scale = 0.6;
630 static int selected_tile_mode = 3;
633 ImGuiWindowFlags_AlwaysAutoResize)) {
634 ImGui::SliderFloat(
"Rotation (degrees)", &rotation, -180, 180);
635 ImGui::SliderFloat(
"Scale", &
scale, 0, 2.0);
636 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
637 sizeof(tile_mode_names) /
sizeof(
char*));
643 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height);
648 tile_modes[selected_tile_mode])};
653 canvas.
Scale(GetContentScale());
660 canvas.
DrawImageRect(std::make_shared<Image>(boston), bounds,
665 ASSERT_TRUE(OpenPlaygroundHere(callback));
669 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
670 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
675 static float rotation = 45;
676 static float scale = 0.6;
677 static int selected_tile_mode = 3;
680 ImGuiWindowFlags_AlwaysAutoResize)) {
681 ImGui::SliderFloat(
"Rotation (degrees)", &rotation, -180, 180);
682 ImGui::SliderFloat(
"Scale", &
scale, 0, 2.0);
683 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
684 sizeof(tile_mode_names) /
sizeof(
char*));
693 tile_modes[selected_tile_mode])};
695 canvas.
Scale(GetContentScale());
704 ASSERT_TRUE(OpenPlaygroundHere(callback));
711 for (int32_t i = 1; i < 5; ++i) {
717 .
LineTo({100.f + fi, 100.f + fi})
725 std::shared_ptr<RenderTargetCache> cache =
726 std::make_shared<RenderTargetCache>(
727 GetContext()->GetResourceAllocator());
728 AiksContext aiks_context(GetContext(),
nullptr, cache);
729 std::shared_ptr<Image> image = picture.
ToImage(aiks_context, {1024, 768});
730 EXPECT_TRUE(image) <<
" length " << i;
738 for (int32_t i = 0; i < 5; ++i) {
754 std::shared_ptr<RenderTargetCache> cache =
755 std::make_shared<RenderTargetCache>(
756 GetContext()->GetResourceAllocator());
757 AiksContext aiks_context(GetContext(),
nullptr, cache);
758 std::shared_ptr<Image> image = picture.
ToImage(aiks_context, {1024, 768});
759 EXPECT_TRUE(image) <<
" clip rect " << i;
768 auto boston = std::make_shared<Image>(
769 CreateTextureForFixture(
"boston.jpg",
true));
775 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
777 ImGuiWindowFlags_AlwaysAutoResize)) {
778 ImGui::SliderFloat(
"Sigma", &sigma, 0, 200);
779 ImGui::SliderFloat(
"Frequency", &freq, 0.01, 2.0);
780 ImGui::SliderFloat(
"Amplitude", &, 1, 100);
785 canvas.
Scale(GetContentScale());
786 Scalar y = amp * sin(freq * 2.0 * M_PI * count / 60);
788 Point(1024 / 2 - boston->GetSize().width / 2,
789 (768 / 2 - boston->GetSize().height / 2) + y),
804 ASSERT_TRUE(OpenPlaygroundHere(callback));
809 canvas.
Scale(GetContentScale());
813 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
814 Color{0.7568, 0.2627, 0.2118, 1.0}};
815 std::vector<Scalar> stops = {0.0, 1.0};
819 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
842 canvas.
Scale(GetContentScale());
846 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
847 Color{0.7568, 0.2627, 0.2118, 1.0}};
848 std::vector<Scalar> stops = {0.0, 1.0};
852 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
875 canvas.
Scale(GetContentScale());
879 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
880 Color{0.7568, 0.2627, 0.2118, 1.0}};
881 std::vector<Scalar> stops = {0.0, 1.0};
885 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
908 canvas.
Scale(GetContentScale());
936 canvas.
Scale(GetContentScale());
964 canvas.
Scale(GetContentScale());
992 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
994 ImGuiWindowFlags_AlwaysAutoResize)) {
995 ImGui::SliderFloat(
"Sigma", &sigma, 0, 500);
999 canvas.
Scale(GetContentScale());
1004 .sigma =
Sigma(sigma),
1006 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
1007 canvas.
DrawImage(std::make_shared<Image>(boston), {200, 200},
paint);
1013 ASSERT_TRUE(OpenPlaygroundHere(callback));
1025 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
1041 ASSERT_TRUE(OpenPlaygroundHere(callback));
1054 EXPECT_EQ(4, picture.
pass->GetRequiredMipCount());
1058 size_t blur_required_mip_count =
1070 std::shared_ptr<RenderTargetCache> cache =
1071 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1072 AiksContext aiks_context(GetContext(),
nullptr, cache);
1073 picture.
ToImage(aiks_context, {100, 100});
1075 size_t max_mip_count = 0;
1076 for (
auto it = cache->GetRenderTargetDataBegin();
1077 it != cache->GetRenderTargetDataEnd(); ++it) {
1078 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1080 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1084 fml::testing::LogCapture log_capture;
1085 size_t blur_required_mip_count =
1099 std::shared_ptr<RenderTargetCache> cache =
1100 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1101 AiksContext aiks_context(GetContext(),
nullptr, cache);
1102 picture.
ToImage(aiks_context, {100, 100});
1104 size_t max_mip_count = 0;
1105 for (
auto it = cache->GetRenderTargetDataBegin();
1106 it != cache->GetRenderTargetDataEnd(); ++it) {
1107 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1109 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1123 size_t blur_required_mip_count =
1125 fml::testing::LogCapture log_capture;
1134 std::shared_ptr<RenderTargetCache> cache =
1135 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1136 AiksContext aiks_context(GetContext(),
nullptr, cache);
1137 picture.
ToImage(aiks_context, {1024, 768});
1139 size_t max_mip_count = 0;
1140 for (
auto it = cache->GetRenderTargetDataBegin();
1141 it != cache->GetRenderTargetDataEnd(); ++it) {
1142 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1144 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1158 size_t blur_required_mip_count =
1160 fml::testing::LogCapture log_capture;
1175 std::shared_ptr<RenderTargetCache> cache =
1176 std::make_shared<RenderTargetCache>(GetContext()->GetResourceAllocator());
1177 AiksContext aiks_context(GetContext(),
nullptr, cache);
1178 picture.
ToImage(aiks_context, {1024, 768});
1180 size_t max_mip_count = 0;
1181 for (
auto it = cache->GetRenderTargetDataBegin();
1182 it != cache->GetRenderTargetDataEnd(); ++it) {
1183 max_mip_count = std::max(it->config.mip_count, max_mip_count);
1185 EXPECT_EQ(max_mip_count, blur_required_mip_count);
1200 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
1202 ImGuiWindowFlags_AlwaysAutoResize)) {
1203 ImGui::SliderFloat(
"Sigma", &sigma, 0, 500);
1207 canvas.
Scale(GetContentScale());
1210 std::shared_ptr<Texture> boston = CreateTextureForFixture(
"boston.jpg");
1217 .color_source = image_source,
1218 .mask_blur_descriptor =
1221 .sigma =
Sigma(sigma),
1225 Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
1230 ASSERT_TRUE(OpenPlaygroundHere(callback));