9 #include <unordered_map>
13 #include "flutter/testing/testing.h"
14 #include "fml/logging.h"
15 #include "fml/time/time_point.h"
16 #include "gtest/gtest.h"
57 #include "include/core/SkBlendMode.h"
58 #include "third_party/imgui/imgui.h"
59 #include "third_party/skia/include/core/SkTextBlob.h"
92 std::shared_ptr<Texture> target,
93 const Matrix& transform)
override {
100 const Matrix& effect_transform)
const override {
105 const std::optional<Rect> coverage_;
106 const bool collapse_;
110 std::optional<Rect> bounds_hint,
111 bool collapse =
false) {
112 auto subpass = std::make_unique<EntityPass>();
116 subpass->AddEntity(entity);
117 subpass->SetDelegate(std::make_unique<TestPassDelegate>(collapse));
118 subpass->SetBoundsLimit(bounds_hint);
130 auto subpass0_coverage =
132 ASSERT_TRUE(subpass0_coverage.has_value());
135 auto subpass1_coverage =
137 ASSERT_TRUE(subpass1_coverage.has_value());
145 ASSERT_TRUE(coverage.has_value());
160 auto contents = std::make_unique<SolidColorContents>();
167 ASSERT_TRUE(OpenPlaygroundHere(pass));
177 auto pass_coverage = pass->GetElementsCoverage(std::nullopt);
178 ASSERT_TRUE(pass_coverage.has_value());
187 ASSERT_FALSE(pass_coverage.has_value());
194 ASSERT_TRUE(pass_coverage.has_value());
201 auto image = CreateTextureForFixture(
"boston.jpg");
207 auto actual = filter->GetCoverage({});
210 ASSERT_TRUE(actual.has_value());
217 filter->SetCoverageHint(expected);
218 auto actual = filter->GetCoverage({});
220 ASSERT_TRUE(actual.has_value());
226 auto contents = std::make_shared<SolidColorContents>();
234 ASSERT_TRUE(OpenPlaygroundHere(entity));
238 auto contents = std::make_shared<SolidColorContents>();
250 ASSERT_TRUE(OpenPlaygroundHere(entity));
258 Rect(200, 200, 200, 200));
273 auto contents = std::make_unique<SolidColorContents>();
277 ASSERT_TRUE(OpenPlaygroundHere(entity));
281 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
293 auto contents = std::make_unique<TiledTextureContents>();
295 contents->SetTexture(bridge);
298 ASSERT_TRUE(OpenPlaygroundHere(entity));
303 Point offset(100, 100);
333 auto contents = std::make_unique<SolidColorContents>();
338 return entity.
Render(context, pass);
340 ASSERT_TRUE(OpenPlaygroundHere(callback));
344 const Point padding(300, 250);
345 const Point margin(140, 180);
351 static Scalar miter_limit = 1.41421357;
354 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
356 ImGui::SliderFloat(
"Miter limit", &miter_limit, 0, 30);
357 ImGui::SliderFloat(
"Stroke width", &width, 0, 100);
358 if (ImGui::Button(
"Reset")) {
359 miter_limit = 1.41421357;
366 auto render_path = [width = width, &context, &pass, &world_matrix](
368 auto contents = std::make_unique<SolidColorContents>();
369 contents->SetGeometry(
378 if (coverage.has_value()) {
379 auto bounds_contents = std::make_unique<SolidColorContents>();
382 bounds_contents->SetColor(
Color::Green().WithAlpha(0.5));
384 bounds_entity.
SetContents(std::move(bounds_contents));
385 bounds_entity.
Render(context, pass);
388 entity.
Render(context, pass);
391 const Point a_def(0, 0), b_def(0, 100), c_def(150, 0), d_def(150, -100),
462 ASSERT_TRUE(OpenPlaygroundHere(callback));
469 .
MoveTo({237.164, 125.003})
470 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
472 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
474 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
476 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
478 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
484 ASSERT_TRUE(OpenPlaygroundHere(entity));
489 const char* input_axis[] = {
"X",
"Y",
"Z"};
490 static int rotation_axis_index = 0;
491 static float rotation = 0;
492 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
493 ImGui::SliderFloat(
"Rotation", &rotation, -
kPi,
kPi);
494 ImGui::Combo(
"Rotation Axis", &rotation_axis_index, input_axis,
495 sizeof(input_axis) /
sizeof(
char*));
497 switch (rotation_axis_index) {
508 rotation_matrix =
Matrix{};
512 if (ImGui::Button(
"Reset")) {
516 Matrix current_transform =
520 pass.GetRenderTargetSize().height / 2.0)));
521 Matrix result_transform = current_transform * rotation_matrix;
528 return entity.
Render(context, pass);
530 ASSERT_TRUE(OpenPlaygroundHere(callback));
537 .
MoveTo({359.934, 96.6335})
538 .CubicCurveTo({358.189, 96.7055}, {356.436, 96.7908},
540 .CubicCurveTo({354.571, 96.8953}, {354.469, 96.9016},
542 .CubicCurveTo({352.672, 97.0038}, {350.969, 97.113},
544 .CubicCurveTo({349.048, 97.2506}, {348.836, 97.2678},
546 .CubicCurveTo({347.019, 97.4014}, {345.407, 97.5299},
548 .CubicCurveTo({343.428, 97.704}, {343.065, 97.7402},
550 .CubicCurveTo({341.221, 97.9086}, {339.736, 98.0505},
552 .CubicCurveTo({337.702, 98.2642}, {337.156, 98.3292},
554 .CubicCurveTo({335.284, 98.5356}, {333.956, 98.6837},
556 .CubicCurveTo({332.495, 98.8635}, {332.366, 98.8818},
558 .
LineTo({332.237, 102.601})
559 .
LineTo({321.778, 102.601})
560 .
LineTo({321.778, 100.382})
561 .CubicCurveTo({321.572, 100.413}, {321.367, 100.442},
563 .CubicCurveTo({319.22, 100.79}, {317.277, 101.123},
565 .CubicCurveTo({315.322, 101.481}, {315.311, 101.482},
567 .
LineTo({310.017, 105.94})
568 .
LineTo({309.779, 105.427})
569 .
LineTo({314.403, 101.651})
570 .CubicCurveTo({314.391, 101.653}, {314.379, 101.656},
572 .CubicCurveTo({312.528, 102.001}, {310.687, 102.366},
574 .CubicCurveTo({307.85, 102.955}, {306.855, 103.182}, {305.859, 103.4})
575 .CubicCurveTo({305.048, 103.579}, {304.236, 103.75},
577 .
LineTo({299.105, 107.578})
578 .
LineTo({298.867, 107.065})
579 .
LineTo({302.394, 104.185})
580 .
LineTo({302.412, 104.171})
581 .CubicCurveTo({301.388, 104.409}, {300.366, 104.67},
583 .CubicCurveTo({298.618, 105.1}, {297.89, 105.269}, {297.165, 105.455})
584 .CubicCurveTo({295.262, 105.94}, {293.36, 106.445},
586 .CubicCurveTo({291.132, 107.072}, {290.802, 107.163},
588 .CubicCurveTo({289.463, 107.544}, {288.455, 107.839},
590 .CubicCurveTo({286.476, 108.431}, {285.506, 108.73},
592 .CubicCurveTo({283.674, 109.304}, {282.812, 109.579},
594 .CubicCurveTo({281.177, 110.112}, {280.406, 110.377},
596 .CubicCurveTo({278.458, 111.037}, {277.256, 111.449},
598 .CubicCurveTo({276.76, 111.622}, {276.716, 111.637},
600 .CubicCurveTo({275.017, 112.239}, {273.365, 112.836},
602 .
LineTo({271.717, 113.449})
603 .CubicCurveTo({271.496, 113.496}, {271.238, 113.559},
605 .CubicCurveTo({270.893, 113.645}, {270.822, 113.663},
607 .CubicCurveTo({270.468, 113.755}, {270.169, 113.834},
609 .CubicCurveTo({269.789, 113.94}, {269.732, 113.957},
611 .CubicCurveTo({269.391, 114.053}, {269.081, 114.143},
613 .CubicCurveTo({268.628, 114.276}, {268.5, 114.314},
615 .CubicCurveTo({268.172, 114.412}, {267.959, 114.478},
617 .CubicCurveTo({263.349, 115.964}, {258.058, 117.695},
619 .CubicCurveTo({253.556, 119.255}, {253.547, 119.258},
621 .CubicCurveTo({251.844, 119.849}, {250.056, 120.474},
623 .CubicCurveTo({248, 121.197}, {247.812, 121.264}, {247.621, 121.331})
624 .CubicCurveTo({247.079, 121.522}, {246.531, 121.715},
626 .CubicCurveTo({245.554, 122.06}, {245.126, 122.212},
628 .CubicCurveTo({244.071, 122.586}, {243.437, 122.811},
630 .CubicCurveTo({242.189, 123.255}, {241.58, 123.472},
632 .CubicCurveTo({240.659, 123.801}, {240.357, 123.909},
634 .CubicCurveTo({239.12, 124.351}, {238.18, 124.687}, {237.22, 125.032})
635 .
LineTo({237.164, 125.003})
636 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
638 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
640 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
642 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
644 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
649 .CubicCurveTo({359.978, 96.6317}, {359.956, 96.6326},
652 .MoveTo({337.336, 124.143})
653 .CubicCurveTo({337.274, 122.359}, {338.903, 121.511},
655 .CubicCurveTo({338.903, 121.511}, {338.96, 123.303},
658 .MoveTo({340.082, 121.849})
659 .CubicCurveTo({340.074, 121.917}, {340.062, 121.992},
661 .CubicCurveTo({340.039, 122.109}, {340.031, 122.142},
663 .CubicCurveTo({340.005, 122.26}, {339.98, 122.346},
665 .CubicCurveTo({339.941, 122.473}, {339.931, 122.507},
667 .CubicCurveTo({339.873, 122.672}, {339.819, 122.804},
669 .CubicCurveTo({339.747, 122.944}, {339.743, 122.949},
671 .CubicCurveTo({339.674, 123.08}, {339.593, 123.205},
673 .CubicCurveTo({339.473, 123.366}, {339.441, 123.401},
675 .CubicCurveTo({339.332, 123.534}, {339.243, 123.625},
677 .CubicCurveTo({339.105, 123.75}, {339.068, 123.786},
679 .CubicCurveTo({338.881, 123.937}, {338.724, 124.048},
681 .CubicCurveTo({338.532, 123.959}, {338.554, 123.79},
683 .CubicCurveTo({338.58, 123.625}, {338.58, 123.625}, {338.58, 123.625})
684 .CubicCurveTo({338.607, 123.455}, {338.65, 123.299},
686 .CubicCurveTo({338.708, 123.14}, {338.71, 123.127},
688 .CubicCurveTo({338.769, 122.971}, {338.833, 122.838},
690 .CubicCurveTo({338.911, 122.702}, {338.916, 122.69200000000001},
692 .CubicCurveTo({338.996, 122.557}, {339.072, 122.444},
694 .CubicCurveTo({339.161, 122.333}, {339.166, 122.326},
696 .CubicCurveTo({339.256, 122.215}, {339.339, 122.12},
698 .CubicCurveTo({339.428, 122.033}, {339.431, 122.03},
700 .CubicCurveTo({339.785, 121.687}, {340.106, 121.511},
702 .CubicCurveTo({340.106, 121.511}, {340.107, 121.645},
705 .MoveTo({340.678, 113.245})
706 .CubicCurveTo({340.594, 113.488}, {340.356, 113.655},
708 .CubicCurveTo({339.817, 113.948}, {339.465, 114.059},
710 .CubicCurveTo({338.251, 114.379}, {337.34, 114.516},
712 .CubicCurveTo({335.761, 114.516}, {335.072, 114.527},
714 .CubicCurveTo({334.125, 114.508}, {333.862, 114.462},
716 .CubicCurveTo({332.865, 114.318}, {332.096, 114.184},
718 .CubicCurveTo({330.979, 113.695}, {330.442, 113.34},
720 .CubicCurveTo({331.135, 111.755}, {333.219, 112.946},
722 .CubicCurveTo({334.54, 113.816}, {334.554, 113.8}, {334.569, 113.784})
723 .CubicCurveTo({333.38, 112.708}, {331.749, 110.985},
725 .CubicCurveTo({333.769, 109.82}, {334.713, 111.93},
727 .CubicCurveTo({334.915, 111.889}, {334.59, 109.636},
729 .CubicCurveTo({336.733, 109.636}, {336.408, 111.889},
731 .CubicCurveTo({336.609, 111.93}, {337.553, 109.82},
733 .CubicCurveTo({339.574, 110.984}, {337.942, 112.708},
735 .CubicCurveTo({336.768, 113.8}, {336.782, 113.816},
737 .CubicCurveTo({338.104, 112.946}, {340.187, 111.755},
739 .CubicCurveTo({340.71, 112.95}, {340.728, 113.102},
742 .MoveTo({346.357, 106.771})
743 .CubicCurveTo({346.295, 104.987}, {347.924, 104.139},
745 .CubicCurveTo({347.924, 104.139}, {347.982, 105.931},
748 .MoveTo({347.56, 106.771})
749 .CubicCurveTo({347.498, 104.987}, {349.127, 104.139},
751 .CubicCurveTo({349.127, 104.139}, {349.185, 105.931},
758 ASSERT_TRUE(OpenPlaygroundHere(entity));
766 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kButt);
767 ASSERT_EQ(path_geometry->GetStrokeJoin(),
Join::kMiter);
779 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kRound);
787 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
793 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 8);
799 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
804 std::vector<const char*> blend_mode_names;
805 std::vector<BlendMode> blend_mode_values;
818 blend_mode_names.push_back(
"Clear");
821 blend_mode_names.push_back(
"Source");
824 blend_mode_names.push_back(
"Destination");
827 blend_mode_names.push_back(
"SourceOver");
830 blend_mode_names.push_back(
"DestinationOver");
833 blend_mode_names.push_back(
"SourceIn");
836 blend_mode_names.push_back(
"DestinationIn");
839 blend_mode_names.push_back(
"SourceOut");
842 blend_mode_names.push_back(
"DestinationOut");
845 blend_mode_names.push_back(
"SourceATop");
848 blend_mode_names.push_back(
"DestinationATop");
851 blend_mode_names.push_back(
"Xor");
854 blend_mode_names.push_back(
"Plus");
857 blend_mode_names.push_back(
"Modulate");
864 auto draw_rect = [&context, &pass, &world_matrix](
870 auto r = rect.GetLTRB();
884 options.blend_mode = blend_mode;
890 VS::FrameInfo frame_info;
893 frame_info.color = color.Premultiply();
894 VS::BindFrameInfo(cmd,
895 pass.GetTransientsBuffer().EmplaceUniform(frame_info));
897 return pass.AddCommand(std::move(cmd));
900 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
901 static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5);
902 ImGui::ColorEdit4(
"Color 1",
reinterpret_cast<float*
>(&color1));
903 ImGui::ColorEdit4(
"Color 2",
reinterpret_cast<float*
>(&color2));
904 static int current_blend_index = 3;
905 ImGui::ListBox(
"Blending mode", ¤t_blend_index,
906 blend_mode_names.data(), blend_mode_names.size());
909 BlendMode selected_mode = blend_mode_values[current_blend_index];
918 result = result && draw_rect(
Rect(0, 0, pass.GetRenderTargetSize().width,
919 pass.GetRenderTargetSize().height),
927 ASSERT_TRUE(OpenPlaygroundHere(callback));
932 static float scale = 20;
934 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
935 ImGui::SliderFloat(
"Scale", &scale, 1, 100);
942 .CubicCurveTo({98.50862885295136, 34.81812293973836},
943 {99.46822048142015, 33.85863261475589},
944 {99.46822048142015, 32.67499810206613})
945 .CubicCurveTo({99.46822048142015, 31.491363589376355},
946 {98.50862885295136, 30.53187326439389},
947 {97.32499434685802, 30.531998226542708})
948 .CubicCurveTo({96.14153655073771, 30.532123170035373},
949 {95.18222070648729, 31.491540299350355},
950 {95.18222070648729, 32.67499810206613})
951 .CubicCurveTo({95.18222070648729, 33.85845590478189},
952 {96.14153655073771, 34.81787303409686},
953 {97.32499434685802, 34.81799797758954})
959 return entity.
Render(context, pass);
961 ASSERT_TRUE(OpenPlaygroundHere(callback));
965 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
966 auto boston = CreateTextureForFixture(
"boston.jpg");
967 auto kalimba = CreateTextureForFixture(
"kalimba.jpg");
968 ASSERT_TRUE(bridge && boston && kalimba);
986 entity.SetContents(blend1);
987 return entity.Render(context, pass);
989 ASSERT_TRUE(OpenPlaygroundHere(callback));
993 auto boston = CreateTextureForFixture(
"boston.jpg");
997 const char* input_type_names[] = {
"Texture",
"Solid Color"};
998 const char* blur_type_names[] = {
"Image blur",
"Mask blur"};
999 const char* pass_variation_names[] = {
"Two pass",
"Directional"};
1000 const char* blur_style_names[] = {
"Normal",
"Solid",
"Outer",
"Inner"};
1001 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
1010 static int selected_input_type = 0;
1012 static int selected_blur_type = 0;
1013 static int selected_pass_variation = 0;
1014 static float blur_amount_coarse[2] = {0, 0};
1015 static float blur_amount_fine[2] = {10, 10};
1016 static int selected_blur_style = 0;
1017 static int selected_tile_mode = 3;
1018 static Color cover_color(1, 0, 0, 0.2);
1019 static Color bounds_color(0, 1, 0, 0.1);
1020 static float offset[2] = {500, 400};
1021 static float rotation = 0;
1022 static float scale[2] = {0.65, 0.65};
1023 static float skew[2] = {0, 0};
1024 static float path_rect[4] = {0, 0,
1025 static_cast<float>(boston->GetSize().width),
1026 static_cast<float>(boston->GetSize().height)};
1028 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1030 ImGui::Combo(
"Input type", &selected_input_type, input_type_names,
1031 sizeof(input_type_names) /
sizeof(
char*));
1032 if (selected_input_type == 0) {
1033 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
1035 ImGui::ColorEdit4(
"Input color",
1036 reinterpret_cast<float*
>(&input_color));
1038 ImGui::Combo(
"Blur type", &selected_blur_type, blur_type_names,
1039 sizeof(blur_type_names) /
sizeof(
char*));
1040 if (selected_blur_type == 0) {
1041 ImGui::Combo(
"Pass variation", &selected_pass_variation,
1042 pass_variation_names,
1043 sizeof(pass_variation_names) /
sizeof(
char*));
1045 ImGui::SliderFloat2(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
1046 ImGui::SliderFloat2(
"Sigma (fine)", blur_amount_fine, 0, 10);
1047 ImGui::Combo(
"Blur style", &selected_blur_style, blur_style_names,
1048 sizeof(blur_style_names) /
sizeof(
char*));
1049 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
1050 sizeof(tile_mode_names) /
sizeof(
char*));
1051 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1052 ImGui::ColorEdit4(
"Bounds color",
1053 reinterpret_cast<float*
>(&bounds_color));
1054 ImGui::SliderFloat2(
"Translation", offset, 0,
1055 pass.GetRenderTargetSize().width);
1056 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1057 ImGui::SliderFloat2(
"Scale", scale, 0, 3);
1058 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1059 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1063 auto blur_sigma_x =
Sigma{blur_amount_coarse[0] + blur_amount_fine[0]};
1064 auto blur_sigma_y =
Sigma{blur_amount_coarse[1] + blur_amount_fine[1]};
1066 std::shared_ptr<Contents> input;
1070 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1071 if (selected_input_type == 0) {
1072 auto texture = std::make_shared<TextureContents>();
1074 texture->SetDestinationRect(input_rect);
1075 texture->SetTexture(boston);
1076 texture->SetOpacity(input_color.
alpha);
1079 input_size = input_rect.size;
1081 auto fill = std::make_shared<SolidColorContents>();
1082 fill->SetColor(input_color);
1087 input_size = input_rect.size;
1090 std::shared_ptr<FilterContents> blur;
1091 if (selected_pass_variation == 0) {
1094 blur_styles[selected_blur_style], tile_modes[selected_tile_mode]);
1096 Vector2 blur_vector(blur_sigma_x.sigma, blur_sigma_y.sigma);
1104 blur_styles[selected_blur_style]);
1113 auto target_contents = selected_blur_type == 0 ? blur : mask_blur;
1119 entity.
Render(context, pass);
1128 cover_entity.
Render(context, pass);
1134 .
AddRect(target_contents->GetCoverage(entity).value())
1139 bounds_entity.
Render(context, pass);
1143 ASSERT_TRUE(OpenPlaygroundHere(callback));
1147 auto boston = CreateTextureForFixture(
"boston.jpg");
1148 ASSERT_TRUE(boston);
1151 const char* morphology_type_names[] = {
"Dilate",
"Erode"};
1156 static int selected_morphology_type = 0;
1157 static float radius[2] = {20, 20};
1158 static Color cover_color(1, 0, 0, 0.2);
1159 static Color bounds_color(0, 1, 0, 0.1);
1160 static float offset[2] = {500, 400};
1161 static float rotation = 0;
1162 static float scale[2] = {0.65, 0.65};
1163 static float skew[2] = {0, 0};
1164 static float path_rect[4] = {0, 0,
1165 static_cast<float>(boston->GetSize().width),
1166 static_cast<float>(boston->GetSize().height)};
1167 static float effect_transform_scale = 1;
1169 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1171 ImGui::Combo(
"Morphology type", &selected_morphology_type,
1172 morphology_type_names,
1173 sizeof(morphology_type_names) /
sizeof(
char*));
1174 ImGui::SliderFloat2(
"Radius", radius, 0, 200);
1175 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
1176 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1177 ImGui::ColorEdit4(
"Bounds color",
1178 reinterpret_cast<float*
>(&bounds_color));
1179 ImGui::SliderFloat2(
"Translation", offset, 0,
1180 pass.GetRenderTargetSize().width);
1181 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1182 ImGui::SliderFloat2(
"Scale", scale, 0, 3);
1183 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1184 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1185 ImGui::SliderFloat(
"Effect transform scale", &effect_transform_scale, 0,
1190 std::shared_ptr<Contents> input;
1194 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1195 auto texture = std::make_shared<TextureContents>();
1197 texture->SetDestinationRect(input_rect);
1198 texture->SetTexture(boston);
1199 texture->SetOpacity(input_color.
alpha);
1202 input_size = input_rect.size;
1206 morphology_types[selected_morphology_type]);
1208 Vector2{effect_transform_scale, effect_transform_scale}));
1221 entity.
Render(context, pass);
1230 cover_entity.
Render(context, pass);
1239 bounds_entity.
Render(context, pass);
1243 ASSERT_TRUE(OpenPlaygroundHere(callback));
1255 entity.
SetContents(std::make_shared<SolidColorContents>());
1266 auto contents = std::make_unique<SolidColorContents>();
1267 contents->SetGeometry(std::move(geometry));
1272 ASSERT_TRUE(actual.has_value());
1283 auto contents = std::make_unique<SolidColorContents>();
1284 contents->SetGeometry(std::move(geometry));
1290 ASSERT_TRUE(actual.has_value());
1301 auto contents = std::make_unique<SolidColorContents>();
1302 contents->SetGeometry(std::move(geometry));
1307 ASSERT_TRUE(actual.has_value());
1313 auto fill = std::make_shared<SolidColorContents>();
1323 auto actual = border_mask_blur->GetCoverage(e);
1325 ASSERT_TRUE(actual.has_value());
1332 auto actual = border_mask_blur->GetCoverage(e);
1333 auto expected =
Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
1334 ASSERT_TRUE(actual.has_value());
1341 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
1342 auto size = atlas->GetSize();
1344 Scalar half_width = size.width / 2;
1345 Scalar half_height = size.height / 2;
1346 std::vector<Rect> texture_coordinates = {
1350 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
1352 std::vector<Matrix> transforms = {
1357 std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
1359 contents->SetTransforms(std::move(transforms));
1360 contents->SetTextureCoordinates(std::move(texture_coordinates));
1361 contents->SetTexture(atlas);
1368 ASSERT_TRUE(OpenPlaygroundHere(e));
1373 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
1374 auto size = atlas->GetSize();
1376 Scalar half_width = size.width / 2;
1377 Scalar half_height = size.height / 2;
1378 std::vector<Rect> texture_coordinates = {
1382 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
1384 std::vector<Matrix> transforms = {
1391 std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
1393 contents->SetTransforms(std::move(transforms));
1394 contents->SetTextureCoordinates(std::move(texture_coordinates));
1395 contents->SetTexture(atlas);
1396 contents->SetColors(colors);
1403 ASSERT_TRUE(OpenPlaygroundHere(e));
1409 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
1410 auto size = atlas->GetSize();
1412 Scalar half_width = size.width / 2;
1413 Scalar half_height = size.height / 2;
1414 std::vector<Rect> texture_coordinates = {
1418 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
1420 std::vector<Matrix> transforms = {
1427 std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
1429 contents->SetTransforms(std::move(transforms));
1430 contents->SetTextureCoordinates(std::move(texture_coordinates));
1431 contents->SetTexture(atlas);
1432 contents->SetColors(colors);
1439 ASSERT_TRUE(OpenPlaygroundHere(e));
1443 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
1444 auto size = atlas->GetSize();
1446 Scalar half_width = size.width / 2;
1447 Scalar half_height = size.height / 2;
1448 std::vector<Rect> texture_coordinates = {
1452 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
1453 std::vector<Matrix> transforms = {
1459 std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
1461 contents->SetTransforms(std::move(transforms));
1462 contents->SetTextureCoordinates(std::move(texture_coordinates));
1463 contents->SetTexture(atlas);
1471 ASSERT_EQ(contents->GetCoverage(e).value(),
1476 ASSERT_EQ(contents->GetCoverage(e).value(),
1483 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
1484 auto size = atlas->GetSize();
1486 Scalar half_width = size.width / 2;
1487 Scalar half_height = size.height / 2;
1488 std::vector<Rect> texture_coordinates = {
1492 Rect::MakeLTRB(half_width, half_height, size.width, size.height)};
1494 std::vector<Matrix> transforms = {
1500 std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
1502 contents->SetTransforms(std::move(transforms));
1503 contents->SetTextureCoordinates(std::move(texture_coordinates));
1504 contents->SetTexture(atlas);
1506 contents->SetAlpha(0.5);
1512 ASSERT_TRUE(OpenPlaygroundHere(e));
1516 auto atlas = CreateTextureForFixture(
"bay_bridge.jpg");
1517 auto size = atlas->GetSize();
1518 std::vector<Rect> texture_coordinates = {
1521 std::shared_ptr<AtlasContents> contents = std::make_shared<AtlasContents>();
1523 contents->SetTransforms(std::move(transforms));
1524 contents->SetTextureCoordinates(std::move(texture_coordinates));
1525 contents->SetTexture(atlas);
1532 ASSERT_TRUE(OpenPlaygroundHere(e));
1538 auto fill = std::make_shared<SolidColorContents>();
1544 auto coverage = fill->GetCoverage({});
1545 ASSERT_TRUE(coverage.has_value());
1551 auto fill = std::make_shared<SolidColorContents>();
1562 ASSERT_TRUE(coverage.has_value());
1568 auto fill = std::make_shared<SolidColorContents>();
1573 auto coverage = fill->GetCoverage({});
1574 ASSERT_FALSE(coverage.has_value());
1581 auto fill = std::make_shared<SolidColorContents>();
1590 auto fill = std::make_shared<SolidColorContents>();
1601 auto fill = std::make_shared<SolidColorContents>();
1611 auto fill = std::make_shared<SolidColorContents>();
1629 auto clip = std::make_shared<ClipContents>();
1640 auto restore = std::make_shared<ClipRestoreContents>();
1651 auto clip = std::make_shared<ClipContents>();
1653 auto result = clip->GetStencilCoverage(
Entity{},
Rect{});
1655 ASSERT_FALSE(result.coverage.has_value());
1660 auto clip = std::make_shared<ClipContents>();
1664 auto result = clip->GetStencilCoverage(
Entity{},
Rect{});
1666 ASSERT_FALSE(result.coverage.has_value());
1671 auto clip = std::make_shared<ClipContents>();
1676 ASSERT_FALSE(result.coverage.has_value());
1681 auto clip = std::make_shared<ClipContents>();
1688 ASSERT_TRUE(result.coverage.has_value());
1695 auto clip = std::make_shared<ClipContents>();
1702 ASSERT_TRUE(result.coverage.has_value());
1711 static float corner_radius = 100;
1712 static float blur_radius = 100;
1713 static bool show_coverage =
false;
1716 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1717 ImGui::SliderFloat(
"Corner radius", &corner_radius, 0, 300);
1718 ImGui::SliderFloat(
"Blur radius", &blur_radius, 0, 300);
1719 ImGui::ColorEdit4(
"Color",
reinterpret_cast<Scalar*
>(&color));
1720 ImGui::Checkbox(
"Show coverage", &show_coverage);
1721 if (show_coverage) {
1722 ImGui::ColorEdit4(
"Coverage color",
1723 reinterpret_cast<Scalar*
>(&coverage_color));
1730 Rect::MakeLTRB(top_left.x, top_left.y, bottom_right.x, bottom_right.y);
1732 auto contents = std::make_unique<SolidRRectBlurContents>();
1733 contents->SetRRect(rect, corner_radius);
1734 contents->SetColor(color);
1735 contents->SetSigma(
Radius(blur_radius));
1740 entity.
Render(context, pass);
1743 if (show_coverage && coverage.has_value()) {
1744 auto bounds_contents = std::make_unique<SolidColorContents>();
1747 bounds_contents->SetColor(coverage_color.
Premultiply());
1749 bounds_entity.
SetContents(std::move(bounds_contents));
1750 bounds_entity.
Render(context, pass);
1755 ASSERT_TRUE(OpenPlaygroundHere(callback));
1760 auto fill = std::make_shared<SolidColorContents>();
1780 auto actual = filter->GetCoverage(e);
1783 ASSERT_TRUE(actual.has_value());
1788 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
1789 ASSERT_TRUE(bay_bridge);
1799 static float offset[2] = {500, 400};
1800 static float rotation = 0;
1801 static float scale[2] = {0.65, 0.65};
1802 static float skew[2] = {0, 0};
1805 ImGui::Begin(
"Color Matrix",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1807 std::string label =
"##1";
1808 for (
int i = 0; i < 20; i += 5) {
1809 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
1810 &(color_matrix.
array[i]), 5,
nullptr,
nullptr,
1815 ImGui::SliderFloat2(
"Translation", &offset[0], 0,
1816 pass.GetRenderTargetSize().width);
1817 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1818 ImGui::SliderFloat2(
"Scale", &scale[0], 0, 3);
1819 ImGui::SliderFloat2(
"Skew", &skew[0], -3, 3);
1837 entity.
Render(context, pass);
1842 ASSERT_TRUE(OpenPlaygroundHere(callback));
1847 auto fill = std::make_shared<SolidColorContents>();
1859 auto actual = filter->GetCoverage(e);
1862 ASSERT_TRUE(actual.has_value());
1867 auto image = CreateTextureForFixture(
"kalimba.jpg");
1890 return entity_left.
Render(context, pass) &&
1891 entity_right.
Render(context, pass);
1894 ASSERT_TRUE(OpenPlaygroundHere(callback));
1899 auto fill = std::make_shared<SolidColorContents>();
1911 auto actual = filter->GetCoverage(e);
1914 ASSERT_TRUE(actual.has_value());
1919 auto image = CreateTextureForFixture(
"embarcadero.jpg");
1942 return entity_left.
Render(context, pass) &&
1943 entity_right.
Render(context, pass);
1946 ASSERT_TRUE(OpenPlaygroundHere(callback));
1950 auto boston = CreateTextureForFixture(
"boston.jpg");
1953 auto contents = std::make_shared<AtlasContents>();
1955 contents->SetTexture(boston);
1956 contents->SetColors({
1961 contents->SetTextureCoordinates({
1966 contents->SetTransforms({
1974 auto subatlas = contents->GenerateSubAtlas();
1975 ASSERT_EQ(subatlas->sub_texture_coords.size(), 1u);
1979 auto contents = std::make_shared<AtlasContents>();
1981 contents->SetTexture(boston);
1982 contents->SetColors({
1987 contents->SetTextureCoordinates({
1992 contents->SetTransforms({
1999 auto subatlas = contents->GenerateSubAtlas();
2000 ASSERT_EQ(subatlas->sub_texture_coords.size(), 3u);
2004 ASSERT_EQ(subatlas->result_texture_coords[0],
Rect::MakeXYWH(0, 0, 10, 10));
2005 ASSERT_EQ(subatlas->result_texture_coords[1],
2007 ASSERT_EQ(subatlas->result_texture_coords[2],
2014 switch (yuv_color_space) {
2016 yuv.
x = rgb.
x * 0.299 + rgb.
y * 0.587 + rgb.
z * 0.114;
2017 yuv.
y = rgb.
x * -0.169 + rgb.
y * -0.331 + rgb.
z * 0.5 + 0.5;
2018 yuv.
z = rgb.
x * 0.5 + rgb.
y * -0.419 + rgb.
z * -0.081 + 0.5;
2021 yuv.
x = rgb.
x * 0.257 + rgb.
y * 0.516 + rgb.
z * 0.100 + 0.063;
2022 yuv.
y = rgb.
x * -0.145 + rgb.
y * -0.291 + rgb.
z * 0.439 + 0.5;
2023 yuv.
z = rgb.
x * 0.429 + rgb.
y * -0.368 + rgb.
z * -0.071 + 0.5;
2032 Vector3 red = {244.0 / 255.0, 67.0 / 255.0, 54.0 / 255.0};
2033 Vector3 green = {76.0 / 255.0, 175.0 / 255.0, 80.0 / 255.0};
2034 Vector3 blue = {33.0 / 255.0, 150.0 / 255.0, 243.0 / 255.0};
2035 Vector3 white = {1.0, 1.0, 1.0};
2040 std::vector<Vector3> yuvs{red_yuv, green_yuv, blue_yuv, white_yuv};
2041 std::vector<uint8_t> y_data;
2042 std::vector<uint8_t> uv_data;
2043 for (
int i = 0; i < 4; i++) {
2045 uint8_t y = std::round(yuv.x * 255.0);
2046 uint8_t u = std::round(yuv.y * 255.0);
2047 uint8_t v = std::round(yuv.z * 255.0);
2048 for (
int j = 0; j < 16; j++) {
2049 y_data.push_back(y);
2051 for (
int j = 0; j < 8; j++) {
2052 uv_data.push_back(j % 2 == 0 ? u : v);
2058 y_texture_descriptor.
size = {8, 8};
2061 auto y_mapping = std::make_shared<fml::DataMapping>(y_data);
2062 if (!y_texture->SetContents(y_mapping)) {
2063 FML_DLOG(ERROR) <<
"Could not copy contents into Y texture.";
2069 uv_texture_descriptor.
size = {4, 4};
2072 auto uv_mapping = std::make_shared<fml::DataMapping>(uv_data);
2073 if (!uv_texture->SetContents(uv_mapping)) {
2074 FML_DLOG(ERROR) <<
"Could not copy contents into UV texture.";
2077 return {y_texture, uv_texture};
2083 GTEST_SKIP_(
"YUV to RGB filter is not supported on OpenGLES backend yet.");
2089 for (
int i = 0; i < 2; i++) {
2090 auto yuv_color_space = yuv_color_space_array[i];
2094 textures[0], textures[1], yuv_color_space);
2097 auto snapshot = filter_contents->RenderToSnapshot(context, filter_entity);
2101 contents->SetTexture(snapshot->texture);
2102 contents->SetSourceRect(
Rect::MakeSize(snapshot->texture->GetSize()));
2106 entity.
Render(context, pass);
2110 ASSERT_TRUE(OpenPlaygroundHere(callback));
2115 GTEST_SKIP_(
"This backend doesn't support runtime effects.");
2118 auto runtime_stage =
2119 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
2120 ASSERT_TRUE(runtime_stage->IsDirty());
2122 bool first_frame =
true;
2125 first_frame =
false;
2127 assert(runtime_stage->IsDirty() ==
false);
2130 auto contents = std::make_shared<RuntimeEffectContents>();
2133 contents->SetRuntimeStage(runtime_stage);
2135 struct FragUniforms {
2139 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
2140 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
2142 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
2143 uniform_data->resize(
sizeof(FragUniforms));
2144 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
2145 contents->SetUniformData(uniform_data);
2149 return contents->Render(context, entity, pass);
2151 ASSERT_TRUE(OpenPlaygroundHere(callback));
2158 auto texture_contents = std::make_shared<TextureContents>();
2159 texture_contents->SetOpacity(0.5);
2160 ASSERT_TRUE(texture_contents->CanInheritOpacity(entity));
2162 texture_contents->SetInheritedOpacity(0.5);
2163 ASSERT_EQ(texture_contents->GetOpacity(), 0.25);
2164 texture_contents->SetInheritedOpacity(0.5);
2165 ASSERT_EQ(texture_contents->GetOpacity(), 0.25);
2169 auto solid_color = std::make_shared<SolidColorContents>();
2170 solid_color->SetGeometry(
2172 solid_color->SetColor(
Color::Blue().WithAlpha(0.5));
2174 ASSERT_TRUE(solid_color->CanInheritOpacity(entity));
2176 solid_color->SetInheritedOpacity(0.5);
2177 ASSERT_EQ(solid_color->GetColor().alpha, 0.25);
2178 solid_color->SetInheritedOpacity(0.5);
2179 ASSERT_EQ(solid_color->GetColor().alpha, 0.25);
2183 auto tiled_texture = std::make_shared<TiledTextureContents>();
2184 tiled_texture->SetGeometry(
2186 tiled_texture->SetOpacityFactor(0.5);
2188 ASSERT_TRUE(tiled_texture->CanInheritOpacity(entity));
2190 tiled_texture->SetInheritedOpacity(0.5);
2191 ASSERT_EQ(tiled_texture->GetOpacityFactor(), 0.25);
2192 tiled_texture->SetInheritedOpacity(0.5);
2193 ASSERT_EQ(tiled_texture->GetOpacityFactor(), 0.25);
2199 auto blob = SkTextBlob::MakeFromString(
"A", font);
2201 auto lazy_glyph_atlas =
2203 lazy_glyph_atlas->AddTextFrame(*frame, 1.0f);
2205 auto text_contents = std::make_shared<TextContents>();
2206 text_contents->SetTextFrame(frame);
2207 text_contents->SetColor(
Color::Blue().WithAlpha(0.5));
2209 ASSERT_TRUE(text_contents->CanInheritOpacity(entity));
2211 text_contents->SetInheritedOpacity(0.5);
2212 ASSERT_EQ(text_contents->GetColor().alpha, 0.25);
2213 text_contents->SetInheritedOpacity(0.5);
2214 ASSERT_EQ(text_contents->GetColor().alpha, 0.25);
2221 auto runtime_effect = std::make_shared<RuntimeEffectContents>();
2222 ASSERT_FALSE(runtime_effect->CanInheritOpacity(entity));
2226 auto image = CreateTextureForFixture(
"boston.jpg");
2236 return entity.
Render(context, pass);
2238 ASSERT_TRUE(OpenPlaygroundHere(callback));
2242 auto image = CreateTextureForFixture(
"boston.jpg");
2252 return entity.
Render(context, pass);
2254 ASSERT_TRUE(OpenPlaygroundHere(callback));
2258 auto image = CreateTextureForFixture(
"boston.jpg");
2268 return entity.
Render(context, pass);
2270 ASSERT_TRUE(OpenPlaygroundHere(callback));
2274 auto image = CreateTextureForFixture(
"boston.jpg");
2284 return entity.
Render(context, pass);
2286 ASSERT_TRUE(OpenPlaygroundHere(callback));
2290 auto image = CreateTextureForFixture(
"boston.jpg");
2300 return entity.
Render(context, pass);
2302 ASSERT_TRUE(OpenPlaygroundHere(callback));
2316 EXPECT_LT(transform.e[0][0], 0.f);
2317 auto coverage = geometry->GetCoverage(transform);
2371 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
2383 auto [pts, indices] =
2387 .CreatePolyline(1.0));
2389 std::vector<Point> expected = {
2390 {0, 0}, {10, 0}, {10, 10}, {0, 10},
2392 std::vector<uint16_t> expected_indices = {0, 1, 2, 0, 2, 3};
2393 ASSERT_EQ(pts, expected);
2394 ASSERT_EQ(indices, expected_indices);
2398 auto [pts, indices] =
2403 .CreatePolyline(1.0));
2405 std::vector<Point> expected = {
2406 {0, 0}, {10, 0}, {10, 10}, {0, 10},
2407 {20, 20}, {30, 20}, {30, 30}, {20, 30}
2409 std::vector<uint16_t> expected_indices = {0, 1, 2, 0, 2, 3,
2411 ASSERT_EQ(pts, expected);
2412 ASSERT_EQ(indices, expected_indices);
2435 std::vector<Point> points = {{10, 20}, {100, 200}};
2445 auto src_contents = std::make_shared<SolidColorContents>();
2446 src_contents->SetGeometry(
2450 auto dst_contents = std::make_shared<SolidColorContents>();
2451 dst_contents->SetGeometry(
2459 ASSERT_TRUE(OpenPlaygroundHere(entity));
2478 allocated_.push_back(desc);
2489 std::vector<TextureDescriptor> allocated_;
2493 if (GetContext()->GetCapabilities()->SupportsFramebufferFetch()) {
2494 GTEST_SKIP() <<
"Backends that support framebuffer fetch dont use coverage "
2495 "for advanced blends.";
2498 auto contents = std::make_shared<SolidColorContents>();
2508 EXPECT_TRUE(coverage.has_value());
2510 auto pass = std::make_unique<EntityPass>();
2511 auto test_allocator = std::make_shared<TestRenderTargetAllocator>(
2512 GetContext()->GetResourceAllocator());
2519 *GetContext(), *test_allocator,
ISize::MakeWH(1000, 1000),
"Offscreen",
2523 pass->AddEntity(entity);
2525 EXPECT_TRUE(pass->Render(content_context, rt));
2527 if (test_allocator->GetDescriptors().size() == 6u) {
2528 EXPECT_EQ(test_allocator->GetDescriptors()[0].size,
ISize(1000, 1000));
2529 EXPECT_EQ(test_allocator->GetDescriptors()[1].size,
ISize(1000, 1000));
2531 EXPECT_EQ(test_allocator->GetDescriptors()[2].size,
ISize(200, 200));
2532 EXPECT_EQ(test_allocator->GetDescriptors()[3].size,
ISize(200, 200));
2533 EXPECT_EQ(test_allocator->GetDescriptors()[4].size,
ISize(200, 200));
2534 EXPECT_EQ(test_allocator->GetDescriptors()[5].size,
ISize(200, 200));
2535 }
else if (test_allocator->GetDescriptors().size() == 9u) {
2537 EXPECT_EQ(test_allocator->GetDescriptors()[0].size,
ISize(1000, 1000));
2538 EXPECT_EQ(test_allocator->GetDescriptors()[1].size,
ISize(1000, 1000));
2539 EXPECT_EQ(test_allocator->GetDescriptors()[2].size,
ISize(1000, 1000));
2540 EXPECT_EQ(test_allocator->GetDescriptors()[3].size,
ISize(1000, 1000));
2541 EXPECT_EQ(test_allocator->GetDescriptors()[4].size,
ISize(1000, 1000));
2543 EXPECT_EQ(test_allocator->GetDescriptors()[5].size,
ISize(200, 200));
2544 EXPECT_EQ(test_allocator->GetDescriptors()[5].size,
ISize(200, 200));
2545 EXPECT_EQ(test_allocator->GetDescriptors()[6].size,
ISize(200, 200));
2546 EXPECT_EQ(test_allocator->GetDescriptors()[7].size,
ISize(200, 200));