12 #include "flutter/display_list/geometry/dl_path_builder.h"
13 #include "flutter/display_list/testing/dl_test_snippets.h"
14 #include "fml/logging.h"
15 #include "gtest/gtest.h"
55 #include "impeller/renderer/testing/mocks.h"
57 #include "third_party/abseil-cpp/absl/status/status_matchers.h"
58 #include "third_party/imgui/imgui.h"
79 auto image = CreateTextureForFixture(
"boston.jpg");
85 auto actual = filter->GetCoverage({});
88 ASSERT_TRUE(actual.has_value());
95 filter->SetCoverageHint(expected);
96 auto actual = filter->GetCoverage({});
98 ASSERT_TRUE(actual.has_value());
123 auto contents = std::make_unique<SolidColorContents>();
125 std::unique_ptr<Geometry> geom =
127 contents->SetGeometry(geom.get());
130 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
134 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
146 auto contents = std::make_unique<TiledTextureContents>();
147 std::unique_ptr<Geometry> geom =
149 contents->SetGeometry(geom.get());
150 contents->SetTexture(bridge);
153 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
158 Point offset(100, 100);
189 auto contents = std::make_unique<SolidColorContents>();
190 std::unique_ptr<Geometry> geom =
192 contents->SetGeometry(geom.get());
196 return entity.
Render(context, pass);
198 ASSERT_TRUE(OpenPlaygroundHere(callback));
203 const Point margin(140, 180);
209 static Scalar miter_limit = 1.41421357;
212 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
214 ImGui::SliderFloat(
"Miter limit", &miter_limit, 0, 30);
215 ImGui::SliderFloat(
"Stroke width", &width, 0, 100);
216 if (ImGui::Button(
"Reset")) {
217 miter_limit = 1.41421357;
224 auto render_path = [width = width, &context, &pass, &world_matrix](
226 auto contents = std::make_unique<SolidColorContents>();
227 std::unique_ptr<Geometry> geom =
232 .miter_limit = miter_limit,
234 contents->SetGeometry(geom.get());
242 if (coverage.has_value()) {
243 auto bounds_contents = std::make_unique<SolidColorContents>();
246 flutter::DlPath::MakeRect(entity.
GetCoverage().value()));
248 bounds_contents->SetGeometry(geom.get());
249 bounds_contents->SetColor(
Color::Green().WithAlpha(0.5));
251 bounds_entity.
SetContents(std::move(bounds_contents));
252 bounds_entity.
Render(context, pass);
255 entity.
Render(context, pass);
258 const Point a_def(0, 0), b_def(0, 100), c_def(150, 0), d_def(150, -100),
270 render_path(flutter::DlPathBuilder{}
272 .CubicCurveTo(
b, d, c)
286 render_path(flutter::DlPathBuilder{}
288 .CubicCurveTo(
b, d, c)
302 render_path(flutter::DlPathBuilder{}
304 .CubicCurveTo(
b, d, c)
321 render_path(flutter::DlPathBuilder{}
339 render_path(flutter::DlPathBuilder{}
357 render_path(flutter::DlPathBuilder{}
368 ASSERT_TRUE(OpenPlaygroundHere(callback));
374 flutter::DlPathBuilder{}
375 .MoveTo({237.164, 125.003})
376 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
378 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
380 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
382 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
384 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
392 auto contents = std::make_shared<SolidColorContents>();
394 contents->SetGeometry(geom.get());
397 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
402 const char* input_axis[] = {
"X",
"Y",
"Z"};
403 static int rotation_axis_index = 0;
404 static float rotation = 0;
405 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
406 ImGui::SliderFloat(
"Rotation", &rotation, -
kPi,
kPi);
407 ImGui::Combo(
"Rotation Axis", &rotation_axis_index, input_axis,
408 sizeof(input_axis) /
sizeof(
char*));
410 switch (rotation_axis_index) {
421 rotation_matrix =
Matrix{};
425 if (ImGui::Button(
"Reset")) {
429 Matrix current_transform =
433 pass.GetRenderTargetSize().height / 2.0)));
434 Matrix result_transform = current_transform * rotation_matrix;
443 auto contents = std::make_shared<SolidColorContents>();
445 contents->SetGeometry(geom.get());
448 return entity.
Render(context, pass);
450 ASSERT_TRUE(OpenPlaygroundHere(callback));
456 flutter::DlPathBuilder{}
457 .MoveTo({359.934, 96.6335})
458 .CubicCurveTo({358.189, 96.7055}, {356.436, 96.7908},
460 .CubicCurveTo({354.571, 96.8953}, {354.469, 96.9016},
462 .CubicCurveTo({352.672, 97.0038}, {350.969, 97.113},
464 .CubicCurveTo({349.048, 97.2506}, {348.836, 97.2678},
466 .CubicCurveTo({347.019, 97.4014}, {345.407, 97.5299},
468 .CubicCurveTo({343.428, 97.704}, {343.065, 97.7402},
470 .CubicCurveTo({341.221, 97.9086}, {339.736, 98.0505},
472 .CubicCurveTo({337.702, 98.2642}, {337.156, 98.3292},
474 .CubicCurveTo({335.284, 98.5356}, {333.956, 98.6837},
476 .CubicCurveTo({332.495, 98.8635}, {332.366, 98.8818},
478 .
LineTo({332.237, 102.601})
479 .
LineTo({321.778, 102.601})
480 .
LineTo({321.778, 100.382})
481 .CubicCurveTo({321.572, 100.413}, {321.367, 100.442},
483 .CubicCurveTo({319.22, 100.79}, {317.277, 101.123},
485 .CubicCurveTo({315.322, 101.481}, {315.311, 101.482},
487 .
LineTo({310.017, 105.94})
488 .
LineTo({309.779, 105.427})
489 .
LineTo({314.403, 101.651})
490 .CubicCurveTo({314.391, 101.653}, {314.379, 101.656},
492 .CubicCurveTo({312.528, 102.001}, {310.687, 102.366},
494 .CubicCurveTo({307.85, 102.955}, {306.855, 103.182}, {305.859, 103.4})
495 .CubicCurveTo({305.048, 103.579}, {304.236, 103.75},
497 .
LineTo({299.105, 107.578})
498 .
LineTo({298.867, 107.065})
499 .
LineTo({302.394, 104.185})
500 .
LineTo({302.412, 104.171})
501 .CubicCurveTo({301.388, 104.409}, {300.366, 104.67},
503 .CubicCurveTo({298.618, 105.1}, {297.89, 105.269}, {297.165, 105.455})
504 .CubicCurveTo({295.262, 105.94}, {293.36, 106.445},
506 .CubicCurveTo({291.132, 107.072}, {290.802, 107.163},
508 .CubicCurveTo({289.463, 107.544}, {288.455, 107.839},
510 .CubicCurveTo({286.476, 108.431}, {285.506, 108.73},
512 .CubicCurveTo({283.674, 109.304}, {282.812, 109.579},
514 .CubicCurveTo({281.177, 110.112}, {280.406, 110.377},
516 .CubicCurveTo({278.458, 111.037}, {277.256, 111.449},
518 .CubicCurveTo({276.76, 111.622}, {276.716, 111.637},
520 .CubicCurveTo({275.017, 112.239}, {273.365, 112.836},
522 .
LineTo({271.717, 113.449})
523 .CubicCurveTo({271.496, 113.496}, {271.238, 113.559},
525 .CubicCurveTo({270.893, 113.645}, {270.822, 113.663},
527 .CubicCurveTo({270.468, 113.755}, {270.169, 113.834},
529 .CubicCurveTo({269.789, 113.94}, {269.732, 113.957},
531 .CubicCurveTo({269.391, 114.053}, {269.081, 114.143},
533 .CubicCurveTo({268.628, 114.276}, {268.5, 114.314},
535 .CubicCurveTo({268.172, 114.412}, {267.959, 114.478},
537 .CubicCurveTo({263.349, 115.964}, {258.058, 117.695},
539 .CubicCurveTo({253.556, 119.255}, {253.547, 119.258},
541 .CubicCurveTo({251.844, 119.849}, {250.056, 120.474},
543 .CubicCurveTo({248, 121.197}, {247.812, 121.264}, {247.621, 121.331})
544 .CubicCurveTo({247.079, 121.522}, {246.531, 121.715},
546 .CubicCurveTo({245.554, 122.06}, {245.126, 122.212},
548 .CubicCurveTo({244.071, 122.586}, {243.437, 122.811},
550 .CubicCurveTo({242.189, 123.255}, {241.58, 123.472},
552 .CubicCurveTo({240.659, 123.801}, {240.357, 123.909},
554 .CubicCurveTo({239.12, 124.351}, {238.18, 124.687}, {237.22, 125.032})
555 .
LineTo({237.164, 125.003})
556 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
558 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
560 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
562 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
564 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
569 .CubicCurveTo({359.978, 96.6317}, {359.956, 96.6326},
572 .MoveTo({337.336, 124.143})
573 .CubicCurveTo({337.274, 122.359}, {338.903, 121.511},
575 .CubicCurveTo({338.903, 121.511}, {338.96, 123.303},
578 .MoveTo({340.082, 121.849})
579 .CubicCurveTo({340.074, 121.917}, {340.062, 121.992},
581 .CubicCurveTo({340.039, 122.109}, {340.031, 122.142},
583 .CubicCurveTo({340.005, 122.26}, {339.98, 122.346},
585 .CubicCurveTo({339.941, 122.473}, {339.931, 122.507},
587 .CubicCurveTo({339.873, 122.672}, {339.819, 122.804},
589 .CubicCurveTo({339.747, 122.944}, {339.743, 122.949},
591 .CubicCurveTo({339.674, 123.08}, {339.593, 123.205},
593 .CubicCurveTo({339.473, 123.366}, {339.441, 123.401},
595 .CubicCurveTo({339.332, 123.534}, {339.243, 123.625},
597 .CubicCurveTo({339.105, 123.75}, {339.068, 123.786},
599 .CubicCurveTo({338.881, 123.937}, {338.724, 124.048},
601 .CubicCurveTo({338.532, 123.959}, {338.554, 123.79},
603 .CubicCurveTo({338.58, 123.625}, {338.58, 123.625}, {338.58, 123.625})
604 .CubicCurveTo({338.607, 123.455}, {338.65, 123.299},
606 .CubicCurveTo({338.708, 123.14}, {338.71, 123.127},
608 .CubicCurveTo({338.769, 122.971}, {338.833, 122.838},
610 .CubicCurveTo({338.911, 122.702}, {338.916, 122.69200000000001},
612 .CubicCurveTo({338.996, 122.557}, {339.072, 122.444},
614 .CubicCurveTo({339.161, 122.333}, {339.166, 122.326},
616 .CubicCurveTo({339.256, 122.215}, {339.339, 122.12},
618 .CubicCurveTo({339.428, 122.033}, {339.431, 122.03},
620 .CubicCurveTo({339.785, 121.687}, {340.106, 121.511},
622 .CubicCurveTo({340.106, 121.511}, {340.107, 121.645},
625 .MoveTo({340.678, 113.245})
626 .CubicCurveTo({340.594, 113.488}, {340.356, 113.655},
628 .CubicCurveTo({339.817, 113.948}, {339.465, 114.059},
630 .CubicCurveTo({338.251, 114.379}, {337.34, 114.516},
632 .CubicCurveTo({335.761, 114.516}, {335.072, 114.527},
634 .CubicCurveTo({334.125, 114.508}, {333.862, 114.462},
636 .CubicCurveTo({332.865, 114.318}, {332.096, 114.184},
638 .CubicCurveTo({330.979, 113.695}, {330.442, 113.34},
640 .CubicCurveTo({331.135, 111.755}, {333.219, 112.946},
642 .CubicCurveTo({334.54, 113.816}, {334.554, 113.8}, {334.569, 113.784})
643 .CubicCurveTo({333.38, 112.708}, {331.749, 110.985},
645 .CubicCurveTo({333.769, 109.82}, {334.713, 111.93},
647 .CubicCurveTo({334.915, 111.889}, {334.59, 109.636},
649 .CubicCurveTo({336.733, 109.636}, {336.408, 111.889},
651 .CubicCurveTo({336.609, 111.93}, {337.553, 109.82},
653 .CubicCurveTo({339.574, 110.984}, {337.942, 112.708},
655 .CubicCurveTo({336.768, 113.8}, {336.782, 113.816},
657 .CubicCurveTo({338.104, 112.946}, {340.187, 111.755},
659 .CubicCurveTo({340.71, 112.95}, {340.728, 113.102},
662 .MoveTo({346.357, 106.771})
663 .CubicCurveTo({346.295, 104.987}, {347.924, 104.139},
665 .CubicCurveTo({347.924, 104.139}, {347.982, 105.931},
668 .MoveTo({347.56, 106.771})
669 .CubicCurveTo({347.498, 104.987}, {349.127, 104.139},
671 .CubicCurveTo({349.127, 104.139}, {349.185, 105.931},
680 auto contents = std::make_shared<SolidColorContents>();
682 contents->SetGeometry(geom.get());
685 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
693 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kButt);
694 ASSERT_EQ(path_geometry->GetStrokeJoin(),
Join::kMiter);
716 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kRound);
724 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
734 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 8);
741 .miter_limit = -1.0f,
744 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
749 std::vector<const char*> blend_mode_names;
750 std::vector<BlendMode> blend_mode_values;
763 blend_mode_names.push_back(
"Clear");
766 blend_mode_names.push_back(
"Source");
769 blend_mode_names.push_back(
"Destination");
772 blend_mode_names.push_back(
"SourceOver");
775 blend_mode_names.push_back(
"DestinationOver");
778 blend_mode_names.push_back(
"SourceIn");
781 blend_mode_names.push_back(
"DestinationIn");
784 blend_mode_names.push_back(
"SourceOut");
787 blend_mode_names.push_back(
"DestinationOut");
790 blend_mode_names.push_back(
"SourceATop");
793 blend_mode_names.push_back(
"DestinationATop");
796 blend_mode_names.push_back(
"Xor");
799 blend_mode_names.push_back(
"Plus");
802 blend_mode_names.push_back(
"Modulate");
809 auto draw_rect = [&context, &pass, &world_matrix](
816 auto r = rect.GetLTRB();
827 pass.SetCommandLabel(
"Blended Rectangle");
829 options.blend_mode = blend_mode;
832 pass.SetVertexBuffer(
836 VS::FrameInfo frame_info;
837 frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
840 FS::FragInfo frag_info;
841 frag_info.color = color.Premultiply();
844 return pass.Draw().ok();
847 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
848 static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5);
849 ImGui::ColorEdit4(
"Color 1",
reinterpret_cast<float*
>(&color1));
850 ImGui::ColorEdit4(
"Color 2",
reinterpret_cast<float*
>(&color2));
851 static int current_blend_index = 3;
852 ImGui::ListBox(
"Blending mode", ¤t_blend_index,
853 blend_mode_names.data(), blend_mode_names.size());
856 BlendMode selected_mode = blend_mode_values[current_blend_index];
869 pass.GetRenderTargetSize().height),
877 ASSERT_TRUE(OpenPlaygroundHere(callback));
882 static float scale = 20;
884 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
885 ImGui::SliderFloat(
"Scale", &scale, 1, 100);
890 auto path = flutter::DlPathBuilder{}
891 .MoveTo({97.325, 34.818})
892 .CubicCurveTo({98.50862885295136, 34.81812293973836},
893 {99.46822048142015, 33.85863261475589},
894 {99.46822048142015, 32.67499810206613})
895 .CubicCurveTo({99.46822048142015, 31.491363589376355},
896 {98.50862885295136, 30.53187326439389},
897 {97.32499434685802, 30.531998226542708})
898 .CubicCurveTo({96.14153655073771, 30.532123170035373},
899 {95.18222070648729, 31.491540299350355},
900 {95.18222070648729, 32.67499810206613})
901 .CubicCurveTo({95.18222070648729, 33.85845590478189},
902 {96.14153655073771, 34.81787303409686},
903 {97.32499434685802, 34.81799797758954})
911 auto contents = std::make_shared<SolidColorContents>();
913 contents->SetGeometry(geom.get());
916 return entity.
Render(context, pass);
918 ASSERT_TRUE(OpenPlaygroundHere(callback));
922 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
923 auto boston = CreateTextureForFixture(
"boston.jpg");
924 auto kalimba = CreateTextureForFixture(
"kalimba.jpg");
925 ASSERT_TRUE(bridge && boston && kalimba);
943 entity.SetContents(blend1);
944 return entity.Render(context, pass);
946 ASSERT_TRUE(OpenPlaygroundHere(callback));
951 CreateTextureForFixture(
"boston.jpg",
true);
955 const char* input_type_names[] = {
"Texture",
"Solid Color"};
956 const char* blur_type_names[] = {
"Image blur",
"Mask blur"};
957 const char* pass_variation_names[] = {
"New"};
958 const char* blur_style_names[] = {
"Normal",
"Solid",
"Outer",
"Inner"};
959 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
968 static int selected_input_type = 0;
970 static int selected_blur_type = 0;
971 static int selected_pass_variation = 0;
972 static bool combined_sigma =
false;
973 static float blur_amount_coarse[2] = {0, 0};
974 static float blur_amount_fine[2] = {10, 10};
975 static int selected_blur_style = 0;
976 static int selected_tile_mode = 3;
977 static Color cover_color(1, 0, 0, 0.2);
978 static Color bounds_color(0, 1, 0, 0.1);
979 static float offset[2] = {500, 400};
980 static float rotation = 0;
981 static float scale[2] = {0.65, 0.65};
982 static float skew[2] = {0, 0};
983 static float path_rect[4] = {0, 0,
984 static_cast<float>(boston->GetSize().width),
985 static_cast<float>(boston->GetSize().height)};
987 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
989 ImGui::Combo(
"Input type", &selected_input_type, input_type_names,
990 sizeof(input_type_names) /
sizeof(
char*));
991 if (selected_input_type == 0) {
992 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
994 ImGui::ColorEdit4(
"Input color",
995 reinterpret_cast<float*
>(&input_color));
997 ImGui::Combo(
"Blur type", &selected_blur_type, blur_type_names,
998 sizeof(blur_type_names) /
sizeof(
char*));
999 if (selected_blur_type == 0) {
1000 ImGui::Combo(
"Pass variation", &selected_pass_variation,
1001 pass_variation_names,
1002 sizeof(pass_variation_names) /
sizeof(
char*));
1004 ImGui::Checkbox(
"Combined sigma", &combined_sigma);
1005 if (combined_sigma) {
1006 ImGui::SliderFloat(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
1007 ImGui::SliderFloat(
"Sigma (fine)", blur_amount_fine, 0, 10);
1008 blur_amount_coarse[1] = blur_amount_coarse[0];
1009 blur_amount_fine[1] = blur_amount_fine[0];
1011 ImGui::SliderFloat2(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
1012 ImGui::SliderFloat2(
"Sigma (fine)", blur_amount_fine, 0, 10);
1014 ImGui::Combo(
"Blur style", &selected_blur_style, blur_style_names,
1015 sizeof(blur_style_names) /
sizeof(
char*));
1016 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
1017 sizeof(tile_mode_names) /
sizeof(
char*));
1018 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1019 ImGui::ColorEdit4(
"Bounds color ",
1020 reinterpret_cast<float*
>(&bounds_color));
1021 ImGui::SliderFloat2(
"Translation", offset, 0,
1022 pass.GetRenderTargetSize().width);
1023 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1024 ImGui::SliderFloat2(
"Scale", scale, 0, 3);
1025 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1026 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1030 auto blur_sigma_x =
Sigma{blur_amount_coarse[0] + blur_amount_fine[0]};
1031 auto blur_sigma_y =
Sigma{blur_amount_coarse[1] + blur_amount_fine[1]};
1033 std::shared_ptr<Contents> input;
1037 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1039 std::unique_ptr<Geometry> solid_color_input;
1040 if (selected_input_type == 0) {
1041 auto texture = std::make_shared<TextureContents>();
1043 texture->SetDestinationRect(input_rect);
1044 texture->SetTexture(boston);
1045 texture->SetOpacity(input_color.
alpha);
1048 input_size = input_rect.GetSize();
1050 auto fill = std::make_shared<SolidColorContents>();
1051 fill->SetColor(input_color);
1055 fill->SetGeometry(solid_color_input.get());
1058 input_size = input_rect.GetSize();
1061 std::shared_ptr<FilterContents> blur;
1062 switch (selected_pass_variation) {
1064 blur = std::make_shared<GaussianBlurFilterContents>(
1065 blur_sigma_x.sigma, blur_sigma_y.sigma,
1066 tile_modes[selected_tile_mode], std::nullopt,
1067 blur_styles[selected_blur_style],
1074 tile_modes[selected_tile_mode],
1075 std::nullopt, blur_styles[selected_blur_style]);
1082 blur_styles[selected_blur_style]);
1091 auto target_contents = selected_blur_type == 0 ? blur : mask_blur;
1097 entity.
Render(context, pass);
1102 std::unique_ptr<Geometry> geom =
1104 auto contents = std::make_shared<SolidColorContents>();
1105 contents->SetColor(cover_color);
1106 contents->SetGeometry(geom.get());
1109 cover_entity.
Render(context, pass);
1113 std::optional<Rect> target_contents_coverage =
1115 if (target_contents_coverage.has_value()) {
1116 std::unique_ptr<Geometry> geom =
1118 target_contents->GetCoverage(entity).value()));
1119 auto contents = std::make_shared<SolidColorContents>();
1120 contents->SetColor(bounds_color);
1121 contents->SetGeometry(geom.get());
1125 bounds_entity.
Render(context, pass);
1130 ASSERT_TRUE(OpenPlaygroundHere(callback));
1134 auto boston = CreateTextureForFixture(
"boston.jpg");
1135 ASSERT_TRUE(boston);
1138 const char* morphology_type_names[] = {
"Dilate",
"Erode"};
1143 static int selected_morphology_type = 0;
1144 static float radius[2] = {20, 20};
1145 static Color cover_color(1, 0, 0, 0.2);
1146 static Color bounds_color(0, 1, 0, 0.1);
1147 static float offset[2] = {500, 400};
1148 static float rotation = 0;
1149 static float scale[2] = {0.65, 0.65};
1150 static float skew[2] = {0, 0};
1151 static float path_rect[4] = {0, 0,
1152 static_cast<float>(boston->GetSize().width),
1153 static_cast<float>(boston->GetSize().height)};
1154 static float effect_transform_scale = 1;
1156 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1158 ImGui::Combo(
"Morphology type", &selected_morphology_type,
1159 morphology_type_names,
1160 sizeof(morphology_type_names) /
sizeof(
char*));
1161 ImGui::SliderFloat2(
"Radius", radius, 0, 200);
1162 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
1163 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1164 ImGui::ColorEdit4(
"Bounds color ",
1165 reinterpret_cast<float*
>(&bounds_color));
1166 ImGui::SliderFloat2(
"Translation", offset, 0,
1167 pass.GetRenderTargetSize().width);
1168 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1169 ImGui::SliderFloat2(
"Scale", scale, 0, 3);
1170 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1171 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1172 ImGui::SliderFloat(
"Effect transform scale", &effect_transform_scale, 0,
1177 std::shared_ptr<Contents> input;
1181 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1182 auto texture = std::make_shared<TextureContents>();
1184 texture->SetDestinationRect(input_rect);
1185 texture->SetTexture(boston);
1186 texture->SetOpacity(input_color.
alpha);
1189 input_size = input_rect.GetSize();
1193 morphology_types[selected_morphology_type]);
1195 Vector2{effect_transform_scale, effect_transform_scale}));
1208 entity.
Render(context, pass);
1213 std::unique_ptr<Geometry> geom =
1215 auto cover_contents = std::make_shared<SolidColorContents>();
1216 cover_contents->SetColor(cover_color);
1217 cover_contents->SetGeometry(geom.get());
1220 cover_entity.
Render(context, pass);
1225 flutter::DlPath::MakeRect(contents->GetCoverage(entity).value()));
1226 auto bounds_contents = std::make_shared<SolidColorContents>();
1227 bounds_contents->SetColor(bounds_color);
1228 bounds_contents->SetGeometry(bounds_geom.get());
1229 bounds_entity.
SetContents(std::move(bounds_contents));
1232 bounds_entity.
Render(context, pass);
1236 ASSERT_TRUE(OpenPlaygroundHere(callback));
1248 entity.
SetContents(std::make_shared<SolidColorContents>());
1255 flutter::DlPath::MakeLine({0, 0}, {10, 10}),
1260 .miter_limit = 4.0f,
1264 auto contents = std::make_unique<SolidColorContents>();
1265 contents->SetGeometry(geometry.get());
1267 entity.SetContents(std::move(contents));
1268 auto actual = entity.GetCoverage();
1271 ASSERT_TRUE(actual.has_value());
1278 flutter::DlPath::MakeLine({0, 0}, {10, 10}),
1287 auto contents = std::make_unique<SolidColorContents>();
1288 contents->SetGeometry(geometry.get());
1290 entity.SetContents(std::move(contents));
1291 auto actual = entity.GetCoverage();
1295 ASSERT_TRUE(actual.has_value());
1302 flutter::DlPath::MakeLine({0, 0}, {10, 10}),
1307 .miter_limit = 2.0f,
1311 auto contents = std::make_unique<SolidColorContents>();
1312 contents->SetGeometry(geometry.get());
1314 entity.SetContents(std::move(contents));
1315 auto actual = entity.GetCoverage();
1318 ASSERT_TRUE(actual.has_value());
1324 auto fill = std::make_shared<SolidColorContents>();
1327 fill->SetGeometry(geom.get());
1335 auto actual = border_mask_blur->GetCoverage(e);
1337 ASSERT_TRUE(actual.has_value());
1344 auto actual = border_mask_blur->GetCoverage(e);
1345 auto expected =
Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
1346 ASSERT_TRUE(actual.has_value());
1354 auto fill = std::make_shared<SolidColorContents>();
1358 fill->SetGeometry(geom.get());
1360 auto coverage = fill->GetCoverage({});
1361 ASSERT_TRUE(coverage.has_value());
1367 auto fill = std::make_shared<SolidColorContents>();
1371 fill->SetGeometry(geom.get());
1379 ASSERT_TRUE(coverage.has_value());
1385 auto fill = std::make_shared<SolidColorContents>();
1389 fill->SetGeometry(geom.get());
1391 auto coverage = fill->GetCoverage({});
1392 ASSERT_FALSE(coverage.has_value());
1399 static float corner_radius = 100;
1401 static bool show_coverage =
false;
1407 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1408 ImGui::SliderFloat(
"Corner radius", &corner_radius, 0, 300);
1409 ImGui::SliderFloat(
"Blur radius", &
blur_radius, 0, 300);
1410 ImGui::ColorEdit4(
"Color",
reinterpret_cast<Scalar*
>(&color));
1411 ImGui::Checkbox(
"Show coverage", &show_coverage);
1412 if (show_coverage) {
1413 ImGui::ColorEdit4(
"Coverage color",
1414 reinterpret_cast<Scalar*
>(&coverage_color));
1418 auto [top_left, bottom_right] =
1421 Rect::MakeLTRB(top_left.x, top_left.y, bottom_right.x, bottom_right.y);
1423 auto contents = std::make_unique<SolidRRectBlurContents>();
1424 contents->SetShape(rect, corner_radius);
1425 contents->SetColor(color);
1431 entity.
Render(context, pass);
1434 if (show_coverage && coverage.has_value()) {
1435 auto bounds_contents = std::make_unique<SolidColorContents>();
1437 flutter::DlPath::MakeRect(entity.
GetCoverage().value()));
1438 bounds_contents->SetGeometry(geom.get());
1439 bounds_contents->SetColor(coverage_color.
Premultiply());
1441 bounds_entity.
SetContents(std::move(bounds_contents));
1442 bounds_entity.
Render(context, pass);
1447 ASSERT_TRUE(OpenPlaygroundHere(callback));
1452 auto fill = std::make_shared<SolidColorContents>();
1455 fill->SetGeometry(geom.get());
1473 auto actual = filter->GetCoverage(e);
1476 ASSERT_TRUE(actual.has_value());
1481 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
1482 ASSERT_TRUE(bay_bridge);
1492 static float offset[2] = {500, 400};
1493 static float rotation = 0;
1494 static float scale[2] = {0.65, 0.65};
1495 static float skew[2] = {0, 0};
1498 ImGui::Begin(
"Color Matrix",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1500 std::string label =
"##1";
1501 for (
int i = 0; i < 20; i += 5) {
1502 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
1503 &(color_matrix.
array[i]), 5,
nullptr,
nullptr,
1508 ImGui::SliderFloat2(
"Translation", &offset[0], 0,
1509 pass.GetRenderTargetSize().width);
1510 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1511 ImGui::SliderFloat2(
"Scale", &scale[0], 0, 3);
1512 ImGui::SliderFloat2(
"Skew", &skew[0], -3, 3);
1530 entity.
Render(context, pass);
1535 ASSERT_TRUE(OpenPlaygroundHere(callback));
1542 auto fill = std::make_shared<SolidColorContents>();
1543 fill->SetGeometry(geom.get());
1553 auto actual = filter->GetCoverage(e);
1556 ASSERT_TRUE(actual.has_value());
1561 auto image = CreateTextureForFixture(
"kalimba.jpg");
1584 return entity_left.
Render(context, pass) &&
1585 entity_right.
Render(context, pass);
1588 ASSERT_TRUE(OpenPlaygroundHere(callback));
1593 auto fill = std::make_shared<SolidColorContents>();
1596 fill->SetGeometry(geom.get());
1606 auto actual = filter->GetCoverage(e);
1609 ASSERT_TRUE(actual.has_value());
1614 auto image = CreateTextureForFixture(
"embarcadero.jpg");
1637 return entity_left.
Render(context, pass) &&
1638 entity_right.
Render(context, pass);
1641 ASSERT_TRUE(OpenPlaygroundHere(callback));
1646 switch (yuv_color_space) {
1648 yuv.
x = rgb.
x * 0.299 + rgb.
y * 0.587 + rgb.
z * 0.114;
1649 yuv.
y = rgb.
x * -0.169 + rgb.
y * -0.331 + rgb.
z * 0.5 + 0.5;
1650 yuv.
z = rgb.
x * 0.5 + rgb.
y * -0.419 + rgb.
z * -0.081 + 0.5;
1653 yuv.
x = rgb.
x * 0.257 + rgb.
y * 0.516 + rgb.
z * 0.100 + 0.063;
1654 yuv.
y = rgb.
x * -0.145 + rgb.
y * -0.291 + rgb.
z * 0.439 + 0.5;
1655 yuv.
z = rgb.
x * 0.429 + rgb.
y * -0.368 + rgb.
z * -0.071 + 0.5;
1664 Vector3 red = {244.0 / 255.0, 67.0 / 255.0, 54.0 / 255.0};
1665 Vector3 green = {76.0 / 255.0, 175.0 / 255.0, 80.0 / 255.0};
1666 Vector3 blue = {33.0 / 255.0, 150.0 / 255.0, 243.0 / 255.0};
1667 Vector3 white = {1.0, 1.0, 1.0};
1672 std::vector<Vector3> yuvs{red_yuv, green_yuv, blue_yuv, white_yuv};
1673 std::vector<uint8_t> y_data;
1674 std::vector<uint8_t> uv_data;
1675 for (
int i = 0; i < 4; i++) {
1677 uint8_t y = std::round(yuv.x * 255.0);
1678 uint8_t u = std::round(yuv.y * 255.0);
1679 uint8_t v = std::round(yuv.z * 255.0);
1680 for (
int j = 0; j < 16; j++) {
1681 y_data.push_back(y);
1683 for (
int j = 0; j < 8; j++) {
1684 uv_data.push_back(j % 2 == 0 ? u : v);
1688 auto blit_pass = cmd_buffer->CreateBlitPass();
1693 y_texture_descriptor.
size = {8, 8};
1696 auto y_mapping = std::make_shared<fml::DataMapping>(y_data);
1697 auto y_mapping_buffer =
1705 uv_texture_descriptor.
size = {4, 4};
1708 auto uv_mapping = std::make_shared<fml::DataMapping>(uv_data);
1709 auto uv_mapping_buffer =
1714 if (!blit_pass->EncodeCommands() ||
1716 FML_DLOG(ERROR) <<
"Could not copy contents into Y/UV texture.";
1719 return {y_texture, uv_texture};
1726 <<
"YUV to RGB filter is not supported on OpenGLES backend yet.";
1732 for (
int i = 0; i < 2; i++) {
1733 auto yuv_color_space = yuv_color_space_array[i];
1737 textures[0], textures[1], yuv_color_space);
1741 filter_contents->RenderToSnapshot(context, filter_entity, {});
1745 contents->SetTexture(snapshot->texture);
1746 contents->SetSourceRect(
Rect::MakeSize(snapshot->texture->GetSize()));
1750 entity.
Render(context, pass);
1754 ASSERT_TRUE(OpenPlaygroundHere(callback));
1758 auto runtime_stages_result =
1759 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1760 ABSL_ASSERT_OK(runtime_stages_result);
1761 std::shared_ptr<RuntimeStage> runtime_stage =
1762 runtime_stages_result
1764 ASSERT_TRUE(runtime_stage);
1765 ASSERT_TRUE(runtime_stage->IsDirty());
1767 bool expect_dirty =
true;
1773 EXPECT_EQ(runtime_stage->IsDirty(), expect_dirty);
1775 auto contents = std::make_shared<RuntimeEffectContents>();
1776 contents->SetGeometry(geom.get());
1777 contents->SetRuntimeStage(runtime_stage);
1779 struct FragUniforms {
1783 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1784 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1786 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1787 uniform_data->resize(
sizeof(FragUniforms));
1788 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1789 contents->SetUniformData(uniform_data);
1793 bool result = contents->Render(context, entity, pass);
1796 first_pipeline = pass.GetCommands().back().pipeline;
1798 EXPECT_EQ(pass.GetCommands().back().pipeline, first_pipeline);
1800 expect_dirty =
false;
1805 auto content_context = GetContentContext();
1808 content_context->GetRenderTargetCache()->CreateOffscreen(
1809 *content_context->GetContext(), {1, 1}, 1u);
1811 testing::MockRenderPass mock_pass(GetContext(), target);
1812 callback(*content_context, mock_pass);
1813 callback(*content_context, mock_pass);
1816 auto runtime_stages_result =
1817 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1818 ABSL_ASSERT_OK(runtime_stages_result);
1820 runtime_stages_result
1823 ASSERT_TRUE(runtime_stage->IsDirty());
1824 expect_dirty =
true;
1826 callback(*content_context, mock_pass);
1831 auto runtime_stages_result =
1832 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1833 ABSL_ASSERT_OK(runtime_stages_result);
1834 auto runtime_stage =
1835 runtime_stages_result
1837 ASSERT_TRUE(runtime_stage);
1838 ASSERT_TRUE(runtime_stage->IsDirty());
1840 auto contents = std::make_shared<RuntimeEffectContents>();
1842 contents->SetGeometry(geom.get());
1843 contents->SetRuntimeStage(runtime_stage);
1845 struct FragUniforms {
1849 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1850 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1852 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1853 uniform_data->resize(
sizeof(FragUniforms));
1854 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1855 contents->SetUniformData(uniform_data);
1863 GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
1864 *GetContext(), {GetWindowSize().width, GetWindowSize().height}, 1,
1865 "RuntimeEffect Texture");
1866 testing::MockRenderPass pass(GetContext(), target);
1868 ASSERT_TRUE(contents->Render(*GetContentContext(), entity, pass));
1869 ASSERT_EQ(pass.GetCommands().size(), 1u);
1870 const auto& command = pass.GetCommands()[0];
1871 ASSERT_TRUE(command.pipeline->GetDescriptor()
1872 .GetDepthStencilAttachmentDescriptor()
1874 ASSERT_TRUE(command.pipeline->GetDescriptor()
1875 .GetFrontStencilAttachmentDescriptor()
1880 auto runtime_stages_result =
1881 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1882 ABSL_ASSERT_OK(runtime_stages_result);
1883 std::shared_ptr<RuntimeStage> runtime_stage =
1884 runtime_stages_result
1886 ASSERT_TRUE(runtime_stage);
1887 ASSERT_TRUE(runtime_stage->IsDirty());
1889 auto contents = std::make_shared<RuntimeEffectContents>();
1890 contents->SetRuntimeStage(runtime_stage);
1892 EXPECT_TRUE(contents->BootstrapShader(*GetContentContext()));
1897 GTEST_SKIP() <<
"Test only applies to Vulkan";
1900 auto runtime_stages_result =
1901 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1902 ABSL_ASSERT_OK(runtime_stages_result);
1903 auto runtime_stage =
1904 runtime_stages_result
1906 ASSERT_TRUE(runtime_stage);
1907 ASSERT_TRUE(runtime_stage->IsDirty());
1909 auto contents = std::make_shared<RuntimeEffectContents>();
1911 contents->SetGeometry(geom.get());
1912 contents->SetRuntimeStage(runtime_stage);
1914 struct FragUniforms {
1918 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1919 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1921 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1922 uniform_data->resize(
sizeof(FragUniforms));
1923 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1926 uniform_data, GetContentContext()->GetTransientsDataBuffer(),
1927 runtime_stage->GetUniforms()[0],
1929 ->GetTransientsDataBuffer()
1930 .GetMinimumUniformAlignment());
1940 auto image = CreateTextureForFixture(
"boston.jpg");
1950 return entity.
Render(context, pass);
1952 ASSERT_TRUE(OpenPlaygroundHere(callback));
1956 auto image = CreateTextureForFixture(
"boston.jpg");
1966 return entity.
Render(context, pass);
1968 ASSERT_TRUE(OpenPlaygroundHere(callback));
1972 auto image = CreateTextureForFixture(
"boston.jpg");
1982 return entity.
Render(context, pass);
1984 ASSERT_TRUE(OpenPlaygroundHere(callback));
1988 auto image = CreateTextureForFixture(
"boston.jpg");
1998 return entity.
Render(context, pass);
2000 ASSERT_TRUE(OpenPlaygroundHere(callback));
2004 auto image = CreateTextureForFixture(
"boston.jpg");
2014 return entity.
Render(context, pass);
2016 ASSERT_TRUE(OpenPlaygroundHere(callback));
2020 auto arrow_head = flutter::DlPathBuilder{}
2030 .miter_limit = 4.0f,
2040 auto coverage = geometry->GetCoverage(
transform);
2051 EXPECT_TRUE(contents.
IsOpaque(matrix));
2053 EXPECT_FALSE(contents.
IsOpaque(matrix));
2061 EXPECT_FALSE(contents.
IsOpaque(matrix));
2071 EXPECT_FALSE(contents.
IsOpaque(matrix));
2073 EXPECT_FALSE(contents.
IsOpaque(matrix));
2077 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2082 EXPECT_FALSE(contents.
IsOpaque(matrix));
2092 EXPECT_TRUE(contents.
IsOpaque(matrix));
2094 EXPECT_FALSE(contents.
IsOpaque(matrix));
2097 EXPECT_FALSE(contents.
IsOpaque(matrix));
2101 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2106 EXPECT_FALSE(contents.
IsOpaque(matrix));
2116 EXPECT_TRUE(contents.
IsOpaque(matrix));
2118 EXPECT_FALSE(contents.
IsOpaque(matrix));
2121 EXPECT_FALSE(contents.
IsOpaque(matrix));
2125 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2130 EXPECT_FALSE(contents.
IsOpaque(matrix));
2140 EXPECT_TRUE(contents.
IsOpaque(matrix));
2142 EXPECT_FALSE(contents.
IsOpaque(matrix));
2145 EXPECT_FALSE(contents.
IsOpaque(matrix));
2149 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2154 EXPECT_FALSE(contents.
IsOpaque(matrix));
2159 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
2165 EXPECT_FALSE(contents.
IsOpaque(matrix));
2169 std::vector<Point>
points = {{10, 20}, {100, 200}};
2179 auto src_contents = std::make_shared<SolidColorContents>();
2181 src_contents->SetGeometry(src_geom.get());
2184 auto dst_contents = std::make_shared<SolidColorContents>();
2186 dst_contents->SetGeometry(dst_geom.get());
2193 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2205 auto content_context = GetContentContext();
2207 auto default_gyph = content_context->GetGlyphAtlasPipeline({
2209 .has_depth_stencil_attachments =
false,
2211 auto alt_gyph = content_context->GetGlyphAtlasPipeline(
2213 .has_depth_stencil_attachments =
true});
2215 EXPECT_NE(default_gyph, alt_gyph);
2216 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2217 alt_gyph->GetDescriptor().GetSpecializationConstants());
2219 auto use_a8 = GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
2222 std::vector<Scalar> expected_constants = {
static_cast<Scalar>(use_a8)};
2223 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2224 expected_constants);
2228 auto content_context = GetContentContext();
2229 auto default_color_burn = content_context->GetMorphologyFilterPipeline({
2233 auto decal_supported =
static_cast<Scalar>(
2234 GetContext()->GetCapabilities()->SupportsDecalSamplerAddressMode());
2235 std::vector<Scalar> expected_constants = {decal_supported};
2236 ASSERT_EQ(default_color_burn->GetDescriptor().GetSpecializationConstants(),
2237 expected_constants);
2245 auto hash_a = opts.
ToKey();
2248 auto hash_b = opts.
ToKey();
2251 auto hash_c = opts.
ToKey();
2254 auto hash_d = opts.
ToKey();
2256 EXPECT_NE(hash_a, hash_b);
2257 EXPECT_NE(hash_b, hash_c);
2258 EXPECT_NE(hash_c, hash_d);
2275 bool expected_layout =
false;
2277 FragmentShader::kDescriptorSetLayouts) {
2278 if (layout.binding == 64 &&
2280 expected_layout =
true;
2283 EXPECT_TRUE(expected_layout);
2289 testing::MockRenderPass mock_pass(GetContext(), target);
2294 return geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2300 get_result(flutter::DlPath::MakeRect(
Rect::MakeLTRB(0, 0, 100, 100)));
2320 testing::MockRenderPass mock_pass(GetContext(), target);
2327 for (
auto sweep = 0; sweep < 360; sweep += 12) {
2332 geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2335 <<
"start: " <<
start <<
" sweep: " << sweep;
2344 for (
auto sweep = 0; sweep < 360; sweep += 12) {
2349 geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2351 if (sweep < 348.6) {
2353 <<
"start: " <<
start <<
" sweep: " << sweep;
2356 <<
"start: " <<
start <<
" sweep: " << sweep;
2366 for (
auto sweep = 0; sweep < 360; sweep += 12) {
2371 geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2373 if (sweep < 300.0) {
2375 <<
"start: " <<
start <<
" sweep: " << sweep;
2378 <<
"start: " <<
start <<
" sweep: " << sweep;
2388 for (
auto sweep = 0; sweep < 360; sweep += 12) {
2393 geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2395 if (sweep < 347.4) {
2397 <<
"start: " <<
start <<
" sweep: " << sweep;
2400 <<
"start: " <<
start <<
" sweep: " << sweep;
2410 for (
auto sweep = 0; sweep < 360; sweep += 12) {
2415 geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2417 if (sweep < 270.1) {
2419 <<
"start: " <<
start <<
" sweep: " << sweep;
2422 <<
"start: " <<
start <<
" sweep: " << sweep;
2431 GTEST_SKIP() <<
"Validation is only fatal on Vulkan backend.";
2436 GetContentContext()->GetBlendColorBurnPipeline({
2438 .has_depth_stencil_attachments =
false,
2446 EXPECT_TRUE(path.GetBounds().IsEmpty());
2452 GetContentContext()->GetRenderTargetCache()->CreateOffscreen(
2453 *GetContext(), {1, 1}, 1u);
2454 testing::MockRenderPass render_pass(GetContext(), target);
2455 auto position_result =
2456 geom->GetPositionBuffer(*GetContentContext(), entity, render_pass);
2458 EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u);
2466 EXPECT_TRUE(path.GetBounds().IsEmpty());
2468 auto contents = std::make_shared<SolidColorContents>();
2470 contents->SetGeometry(geom.get());
2477 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2483 static float alpha = 10;
2484 static float beta = 10;
2485 static float radius = 40;
2486 static int degree = 4;
2489 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2490 ImGui::SliderFloat(
"Alpha", &alpha, 0, 100);
2491 ImGui::SliderFloat(
"Beta", &beta, 0, 100);
2492 ImGui::SliderInt(
"Degreee", °ree, 1, 20);
2493 ImGui::SliderFloat(
"Radius", &radius, 0, 400);
2494 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&color));
2497 auto contents = std::make_shared<SolidColorContents>();
2498 std::unique_ptr<SuperellipseGeometry> geom =
2499 std::make_unique<SuperellipseGeometry>(
Point{400, 400}, radius, degree,
2501 contents->SetColor(color);
2502 contents->SetGeometry(geom.get());
2507 return entity.
Render(context, pass);
2510 ASSERT_TRUE(OpenPlaygroundHere(callback));
2516 static int style_index = 0;
2517 static float center[2] = {830, 830};
2518 static float size[2] = {600, 600};
2519 static bool horizontal_symmetry =
true;
2520 static bool vertical_symmetry =
true;
2521 static bool corner_symmetry =
true;
2523 const char* style_options[] = {
"Fill",
"Stroke"};
2527 static std::array<float, 2> radius_tl = {200};
2528 static std::array<float, 2> radius_tr;
2529 static std::array<float, 2> radius_bl;
2530 static std::array<float, 2> radius_br;
2532 auto AddRadiusControl = [](std::array<float, 2>& radii,
const char* tb_name,
2533 const char* lr_name) {
2534 std::string name =
"Radius";
2535 if (!horizontal_symmetry || !vertical_symmetry) {
2538 if (!vertical_symmetry) {
2539 name = name +
" " + tb_name;
2541 if (!horizontal_symmetry) {
2542 name = name +
" " + lr_name;
2544 if (corner_symmetry) {
2545 ImGui::SliderFloat(name.c_str(), radii.data(), 0, 1000);
2547 ImGui::SliderFloat2(name.c_str(), radii.data(), 0, 1000);
2551 if (corner_symmetry) {
2552 radius_tl[1] = radius_tl[0];
2553 radius_tr[1] = radius_tr[0];
2554 radius_bl[1] = radius_bl[0];
2555 radius_br[1] = radius_br[0];
2558 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2560 ImGui::Combo(
"Style", &style_index, style_options,
2561 sizeof(style_options) /
sizeof(
char*));
2562 ImGui::SliderFloat2(
"Center", center, 0, 1000);
2563 ImGui::SliderFloat2(
"Size", size, 0, 1000);
2564 ImGui::Checkbox(
"Symmetry: Horizontal", &horizontal_symmetry);
2565 ImGui::Checkbox(
"Symmetry: Vertical", &vertical_symmetry);
2566 ImGui::Checkbox(
"Symmetry: Corners", &corner_symmetry);
2567 AddRadiusControl(radius_tl,
"Top",
"Left");
2568 if (!horizontal_symmetry) {
2569 AddRadiusControl(radius_tr,
"Top",
"Right");
2571 radius_tr = radius_tl;
2573 if (!vertical_symmetry) {
2574 AddRadiusControl(radius_bl,
"Bottom",
"Left");
2576 radius_bl = radius_tl;
2578 if (!horizontal_symmetry && !vertical_symmetry) {
2579 AddRadiusControl(radius_br,
"Bottom",
"Right");
2581 if (horizontal_symmetry) {
2582 radius_br = radius_bl;
2584 radius_br = radius_tr;
2592 .
top_left = {radius_tl[0], radius_tl[1]},
2593 .top_right = {radius_tr[0], radius_tr[1]},
2594 .bottom_left = {radius_bl[0], radius_bl[1]},
2595 .bottom_right = {radius_br[0], radius_br[1]},
2602 std::unique_ptr<Geometry> geom;
2603 if (style_index == 0) {
2604 geom = std::make_unique<RoundSuperellipseGeometry>(
2608 path = flutter::DlPath::MakeRoundSuperellipse(rse);
2612 auto contents = std::make_shared<SolidColorContents>();
2614 contents->SetGeometry(geom.get());
2619 return entity.
Render(context, pass);
2622 ASSERT_TRUE(OpenPlaygroundHere(callback));
2636 auto cmd_buffer = content_context.
GetContext()->CreateCommandBuffer();
2639 content_context.
GetContext()->GetResourceAllocator());
2642 *content_context.
GetContext(), {500, 500}, 1);
2643 auto pass = cmd_buffer->CreateRenderPass(render_target);
2646 geom->GetPositionBuffer(content_context, entity, *pass);
2649 Point* written_data =
reinterpret_cast<Point*
>(
2653 std::vector<Point> expected = {
Point(300.0, 200.0),
Point(300.0, 300.0),
2656 for (
size_t i = 0; i < expected.size(); i++) {
2657 const Point& point = written_data[i];
2658 EXPECT_NEAR(point.
x, expected[i].x, 0.1);
2659 EXPECT_NEAR(point.
y, expected[i].y, 0.1);
2674 auto cmd_buffer = content_context.
GetContext()->CreateCommandBuffer();
2677 content_context.
GetContext()->GetResourceAllocator());
2680 *content_context.
GetContext(), {500, 500}, 1);
2681 auto pass = cmd_buffer->CreateRenderPass(render_target);
2684 geom->GetPositionBuffer(content_context, entity, *pass);
2687 Point* written_data =
reinterpret_cast<Point*
>(
2691 std::vector<Point> expected_head = {
Point(250.0, 200.0),
Point(299.9, 200.0),
2694 for (
size_t i = 0; i < expected_head.size(); i++) {
2695 const Point& point = written_data[i];
2696 EXPECT_NEAR(point.
x, expected_head[i].x, 0.1);
2697 EXPECT_NEAR(point.
y, expected_head[i].y, 0.1);
2704 auto result = contents.ApplyColorFilter([](
const Color& color) {
2707 ASSERT_TRUE(result);
2709 Color(0.424452, 0.828743, 0.79105, 0.9375));
2712 #define APPLY_COLOR_FILTER_GRADIENT_TEST(name) \
2713 TEST_P(EntityTest, name##GradientApplyColorFilter) { \
2714 auto contents = name##GradientContents(); \
2715 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.75)}); \
2716 auto result = contents.ApplyColorFilter([](const Color& color) { \
2717 return color.Blend(Color::LimeGreen().WithAlpha(0.75), \
2718 BlendMode::kScreen); \
2720 ASSERT_TRUE(result); \
2722 std::vector<Color> expected = {Color(0.433247, 0.879523, 0.825324, 0.75)}; \
2723 ASSERT_COLORS_NEAR(contents.GetColors(), expected); \
2732 flutter::DlPathBuilder builder;
2733 for (
int i = 0; i < 10000; i++) {
2734 builder.LineTo(
Point(i, i));
2742 auto cmd_buffer = content_context.GetContext()->CreateCommandBuffer();
2745 content_context.GetContext()->GetResourceAllocator());
2748 *content_context.GetContext(), {10, 10}, 1);
2749 auto pass = cmd_buffer->CreateRenderPass(render_target);
2752 geom->GetPositionBuffer(content_context, entity, *pass);
2758 Point* written_data =
reinterpret_cast<Point*
>(
2762 std::vector<Point> expected = {
2763 Point(2043.46, 2050.54),
2764 Point(2050.54, 2043.46),
2765 Point(2044.46, 2051.54),
2766 Point(2051.54, 2044.46),
2767 Point(2045.46, 2052.54)
2771 EXPECT_NEAR(point.
x, expected[0].x, 0.1);
2772 EXPECT_NEAR(point.
y, expected[0].y, 0.1);
2775 EXPECT_NEAR(point.
x, expected[1].x, 0.1);
2776 EXPECT_NEAR(point.
y, expected[1].y, 0.1);
2779 EXPECT_NEAR(point.
x, expected[2].x, 0.1);
2780 EXPECT_NEAR(point.
y, expected[2].y, 0.1);
2783 EXPECT_NEAR(point.
x, expected[3].x, 0.1);
2784 EXPECT_NEAR(point.
y, expected[3].y, 0.1);
2787 EXPECT_NEAR(point.
x, expected[4].x, 0.1);
2788 EXPECT_NEAR(point.
y, expected[4].y, 0.1);
2796 bool SetLabel(std::string_view label)
override {
return true; }
2805 return const_cast<uint8_t*
>(storage_.data());
2808 void Flush(std::optional<Range> range)
const override {
2809 flush_called_ =
true;
2815 std::vector<uint8_t> storage_;
2816 mutable bool flush_called_ =
false;
2822 return ISize(1024, 1024);
2827 return std::make_shared<FlushTestDeviceBuffer>(desc);
2831 bool threadsafe)
override {
2839 const std::shared_ptr<Context>& context,
2840 const std::shared_ptr<TypographerContext>& typographer_context,
2841 const std::shared_ptr<Allocator>& allocator)
2844 allocator, context->GetIdleWaiter(),
2845 context->GetCapabilities()->GetMinimumUniformAlignment()));
2847 allocator, context->GetIdleWaiter(),
2848 context->GetCapabilities()->GetMinimumUniformAlignment()));
2854 testing::MockRenderPass mock_pass(GetContext(), target);
2856 auto content_context = std::make_shared<FlushTestContentContext>(
2857 GetContext(), GetTypographerContext(),
2858 std::make_shared<FlushTestAllocator>());
2861 auto result = geometry->GetPositionBuffer(*content_context, {}, mock_pass);
2864 result.vertex_buffer.vertex_buffer.GetBuffer());
2865 EXPECT_TRUE(device_buffer->flush_called());
An object that allocates device memory.
static std::shared_ptr< ColorFilterContents > MakeColorMatrix(FilterInput::Ref input, const ColorMatrix &color_matrix)
static std::shared_ptr< ColorFilterContents > MakeSrgbToLinearFilter(FilterInput::Ref input)
static std::shared_ptr< ColorFilterContents > MakeLinearToSrgbFilter(FilterInput::Ref input)
static std::shared_ptr< ColorFilterContents > MakeBlend(BlendMode blend_mode, FilterInput::Vector inputs, std::optional< Color > foreground_color=std::nullopt)
the [inputs] are expected to be in the order of dst, src.
void SetGeometry(const Geometry *geometry)
Set the geometry that this contents will use to render.
void SetColors(std::vector< Color > colors)
void SetTransientsDataBuffer(std::shared_ptr< HostBuffer > host_buffer)
PipelineRef GetSolidFillPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsIndexesBuffer() const
Retrieve the current host buffer for transient storage of indexes used for indexed draws.
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
void SetTransientsIndexesBuffer(std::shared_ptr< HostBuffer > host_buffer)
std::shared_ptr< Context > GetContext() const
virtual bool IsOpaque(const Matrix &transform) const
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
To do anything rendering related with Impeller, you need a context.
virtual std::shared_ptr< CommandBuffer > CreateCommandBuffer() const =0
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
virtual std::shared_ptr< CommandQueue > GetCommandQueue() const =0
Return the graphics queue for submitting command buffers.
virtual std::shared_ptr< Allocator > GetResourceAllocator() const =0
Returns the allocator used to create textures and buffers on the device.
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
virtual uint8_t * OnGetContents() const =0
void SetTransform(const Matrix &transform)
Set the global transform matrix for this Entity.
std::optional< Rect > GetCoverage() const
BlendMode GetBlendMode() const
void SetContents(std::shared_ptr< Contents > contents)
void SetBlendMode(BlendMode blend_mode)
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
static constexpr BlendMode kLastPipelineBlendMode
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, std::optional< Rect > bounds=std::nullopt, BlurStyle mask_blur_style=BlurStyle::kNormal, const Geometry *mask_geometry=nullptr)
@ kNormal
Blurred inside and outside.
@ kOuter
Nothing inside, blurred outside.
@ kInner
Blurred inside, nothing outside.
@ kSolid
Solid inside, blurred outside.
static std::shared_ptr< FilterContents > MakeMorphology(FilterInput::Ref input, Radius radius_x, Radius radius_y, MorphType morph_type)
static std::shared_ptr< FilterContents > MakeBorderMaskBlur(FilterInput::Ref input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal)
static std::shared_ptr< FilterContents > MakeYUVToRGBFilter(std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
static std::unique_ptr< Geometry > MakeFillPath(const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
static std::unique_ptr< Geometry > MakeRect(const Rect &rect)
static std::unique_ptr< Geometry > MakeStrokePath(const flutter::DlPath &path, const StrokeParameters &stroke={})
static std::unique_ptr< Geometry > MakeRoundSuperellipse(const Rect &rect, Scalar corner_radius)
static std::unique_ptr< Geometry > MakeCover()
static std::unique_ptr< Geometry > MakeStrokedArc(const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
void SetTileMode(Entity::TileMode tile_mode)
void SetColors(std::vector< Color > colors)
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
A geometry class specialized for Canvas::DrawPoints.
std::optional< Rect > GetCoverage(const Matrix &transform) const override
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
void SetTileMode(Entity::TileMode tile_mode)
void SetColors(std::vector< Color > colors)
Render passes encode render commands directed as one specific render target into an underlying comman...
VertexShader_ VertexShader
FragmentShader_ FragmentShader
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr, std::optional< PixelFormat > target_pixel_format=std::nullopt)
static BufferView EmplaceVulkanUniform(const std::shared_ptr< const std::vector< uint8_t >> &input_data, HostBuffer &host_buffer, const RuntimeUniformDescription &uniform, size_t minimum_uniform_alignment)
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
void SetColor(Color color)
A Geometry that produces fillable vertices representing the stroked outline of a |DlPath| object usin...
static Rational RoundScaledFontSize(Scalar scale)
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
void SetTexture(std::shared_ptr< Texture > texture)
VertexBuffer CreateVertexBuffer(HostBuffer &data_host_buffer, HostBuffer &indexes_host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc, bool threadsafe) override
std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc) override
ISize GetMaxTextureSizeSupported() const override
FlushTestContentContext(const std::shared_ptr< Context > &context, const std::shared_ptr< TypographerContext > &typographer_context, const std::shared_ptr< Allocator > &allocator)
bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)
void Flush(std::optional< Range > range) const override
bool SetLabel(std::string_view label, Range range) override
bool SetLabel(std::string_view label) override
uint8_t * OnGetContents() const override
FlushTestDeviceBuffer(const DeviceBufferDescriptor &desc)
bool flush_called() const
Vector2 blur_radius
Blur radius in source pixels based on scaled_sigma.
Vector2 padding
The halo padding in source space.
#define ASSERT_RECT_NEAR(a, b)
#define ASSERT_COLOR_NEAR(a, b)
EntityPlayground EntityTest
Rect RectMakeCenterSize(Point center, Size size)
TEST_P(AiksTest, DrawAtlasNoColor)
APPLY_COLOR_FILTER_GRADIENT_TEST(Linear)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
static Vector3 RGBToYUV(Vector3 rgb, YUVColorSpace yuv_color_space)
static std::vector< std::shared_ptr< Texture > > CreateTestYUVTextures(Context *context, YUVColorSpace yuv_color_space)
Join
An enum that describes ways to join two segments of a path.
@ kPoint
Draws a point at each input vertex.
Point DrawPlaygroundPoint(PlaygroundPoint &point)
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
constexpr float kEhCloseEnough
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
Cap
An enum that describes ways to decorate the end of a path contour.
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
static constexpr size_t kPointArenaSize
The size of the point arena buffer stored on the tessellator.
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
ContentContextOptions OptionsFromPass(const RenderPass &pass)
void Close(PathBuilder *builder)
const DeviceBuffer * GetBuffer() const
static constexpr Color LimeGreen()
static constexpr Color MintCream()
static constexpr Color DeepPink()
static constexpr Color Black()
static constexpr Color CornflowerBlue()
static constexpr Color White()
constexpr Color WithAlpha(Scalar new_alpha) const
static constexpr Color WhiteTransparent()
static constexpr Color Coral()
static constexpr Color Red()
constexpr Color Premultiply() const
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()
PrimitiveType primitive_type
bool has_depth_stencil_attachments
constexpr uint64_t ToKey() const
@ kNormal
The geometry has no overlapping triangles.
VertexBuffer vertex_buffer
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr bool IsIdentity() const
static Matrix MakeRotationY(Radians r)
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
static Matrix MakeRotationZ(Radians r)
static constexpr Matrix MakeScale(const Vector3 &s)
static Matrix MakeRotationX(Radians r)
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
A structure to store all of the parameters related to stroking a path or basic geometry object.
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
constexpr static TRect MakeSize(const TSize< U > &size)
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::vector< Point > points