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/imgui/imgui.h"
78 auto image = CreateTextureForFixture(
"boston.jpg");
84 auto actual = filter->GetCoverage({});
87 ASSERT_TRUE(actual.has_value());
94 filter->SetCoverageHint(expected);
95 auto actual = filter->GetCoverage({});
97 ASSERT_TRUE(actual.has_value());
122 auto contents = std::make_unique<SolidColorContents>();
124 std::unique_ptr<Geometry> geom =
126 contents->SetGeometry(geom.get());
129 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
133 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
145 auto contents = std::make_unique<TiledTextureContents>();
146 std::unique_ptr<Geometry> geom =
148 contents->SetGeometry(geom.get());
149 contents->SetTexture(bridge);
152 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
157 Point offset(100, 100);
188 auto contents = std::make_unique<SolidColorContents>();
189 std::unique_ptr<Geometry> geom =
191 contents->SetGeometry(geom.get());
195 return entity.
Render(context, pass);
197 ASSERT_TRUE(OpenPlaygroundHere(callback));
202 const Point margin(140, 180);
208 static Scalar miter_limit = 1.41421357;
211 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
213 ImGui::SliderFloat(
"Miter limit", &miter_limit, 0, 30);
214 ImGui::SliderFloat(
"Stroke width", &width, 0, 100);
215 if (ImGui::Button(
"Reset")) {
216 miter_limit = 1.41421357;
223 auto render_path = [width = width, &context, &pass, &world_matrix](
225 auto contents = std::make_unique<SolidColorContents>();
226 std::unique_ptr<Geometry> geom =
231 .miter_limit = miter_limit,
233 contents->SetGeometry(geom.get());
241 if (coverage.has_value()) {
242 auto bounds_contents = std::make_unique<SolidColorContents>();
245 flutter::DlPath::MakeRect(entity.
GetCoverage().value()));
247 bounds_contents->SetGeometry(geom.get());
248 bounds_contents->SetColor(
Color::Green().WithAlpha(0.5));
250 bounds_entity.
SetContents(std::move(bounds_contents));
251 bounds_entity.
Render(context, pass);
254 entity.
Render(context, pass);
257 const Point a_def(0, 0), b_def(0, 100), c_def(150, 0), d_def(150, -100),
269 render_path(flutter::DlPathBuilder{}
271 .CubicCurveTo(
b, d, c)
285 render_path(flutter::DlPathBuilder{}
287 .CubicCurveTo(
b, d, c)
301 render_path(flutter::DlPathBuilder{}
303 .CubicCurveTo(
b, d, c)
320 render_path(flutter::DlPathBuilder{}
338 render_path(flutter::DlPathBuilder{}
356 render_path(flutter::DlPathBuilder{}
367 ASSERT_TRUE(OpenPlaygroundHere(callback));
373 flutter::DlPathBuilder{}
374 .MoveTo({237.164, 125.003})
375 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
377 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
379 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
381 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
383 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
391 auto contents = std::make_shared<SolidColorContents>();
393 contents->SetGeometry(geom.get());
396 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
401 const char* input_axis[] = {
"X",
"Y",
"Z"};
402 static int rotation_axis_index = 0;
403 static float rotation = 0;
404 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
405 ImGui::SliderFloat(
"Rotation", &rotation, -
kPi,
kPi);
406 ImGui::Combo(
"Rotation Axis", &rotation_axis_index, input_axis,
407 sizeof(input_axis) /
sizeof(
char*));
409 switch (rotation_axis_index) {
420 rotation_matrix =
Matrix{};
424 if (ImGui::Button(
"Reset")) {
428 Matrix current_transform =
432 pass.GetRenderTargetSize().height / 2.0)));
433 Matrix result_transform = current_transform * rotation_matrix;
442 auto contents = std::make_shared<SolidColorContents>();
444 contents->SetGeometry(geom.get());
447 return entity.
Render(context, pass);
449 ASSERT_TRUE(OpenPlaygroundHere(callback));
455 flutter::DlPathBuilder{}
456 .MoveTo({359.934, 96.6335})
457 .CubicCurveTo({358.189, 96.7055}, {356.436, 96.7908},
459 .CubicCurveTo({354.571, 96.8953}, {354.469, 96.9016},
461 .CubicCurveTo({352.672, 97.0038}, {350.969, 97.113},
463 .CubicCurveTo({349.048, 97.2506}, {348.836, 97.2678},
465 .CubicCurveTo({347.019, 97.4014}, {345.407, 97.5299},
467 .CubicCurveTo({343.428, 97.704}, {343.065, 97.7402},
469 .CubicCurveTo({341.221, 97.9086}, {339.736, 98.0505},
471 .CubicCurveTo({337.702, 98.2642}, {337.156, 98.3292},
473 .CubicCurveTo({335.284, 98.5356}, {333.956, 98.6837},
475 .CubicCurveTo({332.495, 98.8635}, {332.366, 98.8818},
477 .
LineTo({332.237, 102.601})
478 .
LineTo({321.778, 102.601})
479 .
LineTo({321.778, 100.382})
480 .CubicCurveTo({321.572, 100.413}, {321.367, 100.442},
482 .CubicCurveTo({319.22, 100.79}, {317.277, 101.123},
484 .CubicCurveTo({315.322, 101.481}, {315.311, 101.482},
486 .
LineTo({310.017, 105.94})
487 .
LineTo({309.779, 105.427})
488 .
LineTo({314.403, 101.651})
489 .CubicCurveTo({314.391, 101.653}, {314.379, 101.656},
491 .CubicCurveTo({312.528, 102.001}, {310.687, 102.366},
493 .CubicCurveTo({307.85, 102.955}, {306.855, 103.182}, {305.859, 103.4})
494 .CubicCurveTo({305.048, 103.579}, {304.236, 103.75},
496 .
LineTo({299.105, 107.578})
497 .
LineTo({298.867, 107.065})
498 .
LineTo({302.394, 104.185})
499 .
LineTo({302.412, 104.171})
500 .CubicCurveTo({301.388, 104.409}, {300.366, 104.67},
502 .CubicCurveTo({298.618, 105.1}, {297.89, 105.269}, {297.165, 105.455})
503 .CubicCurveTo({295.262, 105.94}, {293.36, 106.445},
505 .CubicCurveTo({291.132, 107.072}, {290.802, 107.163},
507 .CubicCurveTo({289.463, 107.544}, {288.455, 107.839},
509 .CubicCurveTo({286.476, 108.431}, {285.506, 108.73},
511 .CubicCurveTo({283.674, 109.304}, {282.812, 109.579},
513 .CubicCurveTo({281.177, 110.112}, {280.406, 110.377},
515 .CubicCurveTo({278.458, 111.037}, {277.256, 111.449},
517 .CubicCurveTo({276.76, 111.622}, {276.716, 111.637},
519 .CubicCurveTo({275.017, 112.239}, {273.365, 112.836},
521 .
LineTo({271.717, 113.449})
522 .CubicCurveTo({271.496, 113.496}, {271.238, 113.559},
524 .CubicCurveTo({270.893, 113.645}, {270.822, 113.663},
526 .CubicCurveTo({270.468, 113.755}, {270.169, 113.834},
528 .CubicCurveTo({269.789, 113.94}, {269.732, 113.957},
530 .CubicCurveTo({269.391, 114.053}, {269.081, 114.143},
532 .CubicCurveTo({268.628, 114.276}, {268.5, 114.314},
534 .CubicCurveTo({268.172, 114.412}, {267.959, 114.478},
536 .CubicCurveTo({263.349, 115.964}, {258.058, 117.695},
538 .CubicCurveTo({253.556, 119.255}, {253.547, 119.258},
540 .CubicCurveTo({251.844, 119.849}, {250.056, 120.474},
542 .CubicCurveTo({248, 121.197}, {247.812, 121.264}, {247.621, 121.331})
543 .CubicCurveTo({247.079, 121.522}, {246.531, 121.715},
545 .CubicCurveTo({245.554, 122.06}, {245.126, 122.212},
547 .CubicCurveTo({244.071, 122.586}, {243.437, 122.811},
549 .CubicCurveTo({242.189, 123.255}, {241.58, 123.472},
551 .CubicCurveTo({240.659, 123.801}, {240.357, 123.909},
553 .CubicCurveTo({239.12, 124.351}, {238.18, 124.687}, {237.22, 125.032})
554 .
LineTo({237.164, 125.003})
555 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
557 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
559 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
561 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
563 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
568 .CubicCurveTo({359.978, 96.6317}, {359.956, 96.6326},
571 .MoveTo({337.336, 124.143})
572 .CubicCurveTo({337.274, 122.359}, {338.903, 121.511},
574 .CubicCurveTo({338.903, 121.511}, {338.96, 123.303},
577 .MoveTo({340.082, 121.849})
578 .CubicCurveTo({340.074, 121.917}, {340.062, 121.992},
580 .CubicCurveTo({340.039, 122.109}, {340.031, 122.142},
582 .CubicCurveTo({340.005, 122.26}, {339.98, 122.346},
584 .CubicCurveTo({339.941, 122.473}, {339.931, 122.507},
586 .CubicCurveTo({339.873, 122.672}, {339.819, 122.804},
588 .CubicCurveTo({339.747, 122.944}, {339.743, 122.949},
590 .CubicCurveTo({339.674, 123.08}, {339.593, 123.205},
592 .CubicCurveTo({339.473, 123.366}, {339.441, 123.401},
594 .CubicCurveTo({339.332, 123.534}, {339.243, 123.625},
596 .CubicCurveTo({339.105, 123.75}, {339.068, 123.786},
598 .CubicCurveTo({338.881, 123.937}, {338.724, 124.048},
600 .CubicCurveTo({338.532, 123.959}, {338.554, 123.79},
602 .CubicCurveTo({338.58, 123.625}, {338.58, 123.625}, {338.58, 123.625})
603 .CubicCurveTo({338.607, 123.455}, {338.65, 123.299},
605 .CubicCurveTo({338.708, 123.14}, {338.71, 123.127},
607 .CubicCurveTo({338.769, 122.971}, {338.833, 122.838},
609 .CubicCurveTo({338.911, 122.702}, {338.916, 122.69200000000001},
611 .CubicCurveTo({338.996, 122.557}, {339.072, 122.444},
613 .CubicCurveTo({339.161, 122.333}, {339.166, 122.326},
615 .CubicCurveTo({339.256, 122.215}, {339.339, 122.12},
617 .CubicCurveTo({339.428, 122.033}, {339.431, 122.03},
619 .CubicCurveTo({339.785, 121.687}, {340.106, 121.511},
621 .CubicCurveTo({340.106, 121.511}, {340.107, 121.645},
624 .MoveTo({340.678, 113.245})
625 .CubicCurveTo({340.594, 113.488}, {340.356, 113.655},
627 .CubicCurveTo({339.817, 113.948}, {339.465, 114.059},
629 .CubicCurveTo({338.251, 114.379}, {337.34, 114.516},
631 .CubicCurveTo({335.761, 114.516}, {335.072, 114.527},
633 .CubicCurveTo({334.125, 114.508}, {333.862, 114.462},
635 .CubicCurveTo({332.865, 114.318}, {332.096, 114.184},
637 .CubicCurveTo({330.979, 113.695}, {330.442, 113.34},
639 .CubicCurveTo({331.135, 111.755}, {333.219, 112.946},
641 .CubicCurveTo({334.54, 113.816}, {334.554, 113.8}, {334.569, 113.784})
642 .CubicCurveTo({333.38, 112.708}, {331.749, 110.985},
644 .CubicCurveTo({333.769, 109.82}, {334.713, 111.93},
646 .CubicCurveTo({334.915, 111.889}, {334.59, 109.636},
648 .CubicCurveTo({336.733, 109.636}, {336.408, 111.889},
650 .CubicCurveTo({336.609, 111.93}, {337.553, 109.82},
652 .CubicCurveTo({339.574, 110.984}, {337.942, 112.708},
654 .CubicCurveTo({336.768, 113.8}, {336.782, 113.816},
656 .CubicCurveTo({338.104, 112.946}, {340.187, 111.755},
658 .CubicCurveTo({340.71, 112.95}, {340.728, 113.102},
661 .MoveTo({346.357, 106.771})
662 .CubicCurveTo({346.295, 104.987}, {347.924, 104.139},
664 .CubicCurveTo({347.924, 104.139}, {347.982, 105.931},
667 .MoveTo({347.56, 106.771})
668 .CubicCurveTo({347.498, 104.987}, {349.127, 104.139},
670 .CubicCurveTo({349.127, 104.139}, {349.185, 105.931},
679 auto contents = std::make_shared<SolidColorContents>();
681 contents->SetGeometry(geom.get());
684 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
692 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kButt);
693 ASSERT_EQ(path_geometry->GetStrokeJoin(),
Join::kMiter);
715 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kRound);
723 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
733 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 8);
740 .miter_limit = -1.0f,
743 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
748 std::vector<const char*> blend_mode_names;
749 std::vector<BlendMode> blend_mode_values;
762 blend_mode_names.push_back(
"Clear");
765 blend_mode_names.push_back(
"Source");
768 blend_mode_names.push_back(
"Destination");
771 blend_mode_names.push_back(
"SourceOver");
774 blend_mode_names.push_back(
"DestinationOver");
777 blend_mode_names.push_back(
"SourceIn");
780 blend_mode_names.push_back(
"DestinationIn");
783 blend_mode_names.push_back(
"SourceOut");
786 blend_mode_names.push_back(
"DestinationOut");
789 blend_mode_names.push_back(
"SourceATop");
792 blend_mode_names.push_back(
"DestinationATop");
795 blend_mode_names.push_back(
"Xor");
798 blend_mode_names.push_back(
"Plus");
801 blend_mode_names.push_back(
"Modulate");
808 auto draw_rect = [&context, &pass, &world_matrix](
815 auto r = rect.GetLTRB();
826 pass.SetCommandLabel(
"Blended Rectangle");
828 options.blend_mode = blend_mode;
831 pass.SetVertexBuffer(
835 VS::FrameInfo frame_info;
836 frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
839 FS::FragInfo frag_info;
840 frag_info.color = color.Premultiply();
843 return pass.Draw().ok();
846 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
847 static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5);
848 ImGui::ColorEdit4(
"Color 1",
reinterpret_cast<float*
>(&color1));
849 ImGui::ColorEdit4(
"Color 2",
reinterpret_cast<float*
>(&color2));
850 static int current_blend_index = 3;
851 ImGui::ListBox(
"Blending mode", ¤t_blend_index,
852 blend_mode_names.data(), blend_mode_names.size());
855 BlendMode selected_mode = blend_mode_values[current_blend_index];
868 pass.GetRenderTargetSize().height),
876 ASSERT_TRUE(OpenPlaygroundHere(callback));
881 static float scale = 20;
883 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
884 ImGui::SliderFloat(
"Scale", &scale, 1, 100);
889 auto path = flutter::DlPathBuilder{}
890 .MoveTo({97.325, 34.818})
891 .CubicCurveTo({98.50862885295136, 34.81812293973836},
892 {99.46822048142015, 33.85863261475589},
893 {99.46822048142015, 32.67499810206613})
894 .CubicCurveTo({99.46822048142015, 31.491363589376355},
895 {98.50862885295136, 30.53187326439389},
896 {97.32499434685802, 30.531998226542708})
897 .CubicCurveTo({96.14153655073771, 30.532123170035373},
898 {95.18222070648729, 31.491540299350355},
899 {95.18222070648729, 32.67499810206613})
900 .CubicCurveTo({95.18222070648729, 33.85845590478189},
901 {96.14153655073771, 34.81787303409686},
902 {97.32499434685802, 34.81799797758954})
910 auto contents = std::make_shared<SolidColorContents>();
912 contents->SetGeometry(geom.get());
915 return entity.
Render(context, pass);
917 ASSERT_TRUE(OpenPlaygroundHere(callback));
921 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
922 auto boston = CreateTextureForFixture(
"boston.jpg");
923 auto kalimba = CreateTextureForFixture(
"kalimba.jpg");
924 ASSERT_TRUE(bridge && boston && kalimba);
942 entity.SetContents(blend1);
943 return entity.Render(context, pass);
945 ASSERT_TRUE(OpenPlaygroundHere(callback));
950 CreateTextureForFixture(
"boston.jpg",
true);
954 const char* input_type_names[] = {
"Texture",
"Solid Color"};
955 const char* blur_type_names[] = {
"Image blur",
"Mask blur"};
956 const char* pass_variation_names[] = {
"New"};
957 const char* blur_style_names[] = {
"Normal",
"Solid",
"Outer",
"Inner"};
958 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
967 static int selected_input_type = 0;
969 static int selected_blur_type = 0;
970 static int selected_pass_variation = 0;
971 static bool combined_sigma =
false;
972 static float blur_amount_coarse[2] = {0, 0};
973 static float blur_amount_fine[2] = {10, 10};
974 static int selected_blur_style = 0;
975 static int selected_tile_mode = 3;
976 static Color cover_color(1, 0, 0, 0.2);
977 static Color bounds_color(0, 1, 0, 0.1);
978 static float offset[2] = {500, 400};
979 static float rotation = 0;
980 static float scale[2] = {0.65, 0.65};
981 static float skew[2] = {0, 0};
982 static float path_rect[4] = {0, 0,
983 static_cast<float>(boston->GetSize().width),
984 static_cast<float>(boston->GetSize().height)};
986 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
988 ImGui::Combo(
"Input type", &selected_input_type, input_type_names,
989 sizeof(input_type_names) /
sizeof(
char*));
990 if (selected_input_type == 0) {
991 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
993 ImGui::ColorEdit4(
"Input color",
994 reinterpret_cast<float*
>(&input_color));
996 ImGui::Combo(
"Blur type", &selected_blur_type, blur_type_names,
997 sizeof(blur_type_names) /
sizeof(
char*));
998 if (selected_blur_type == 0) {
999 ImGui::Combo(
"Pass variation", &selected_pass_variation,
1000 pass_variation_names,
1001 sizeof(pass_variation_names) /
sizeof(
char*));
1003 ImGui::Checkbox(
"Combined sigma", &combined_sigma);
1004 if (combined_sigma) {
1005 ImGui::SliderFloat(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
1006 ImGui::SliderFloat(
"Sigma (fine)", blur_amount_fine, 0, 10);
1007 blur_amount_coarse[1] = blur_amount_coarse[0];
1008 blur_amount_fine[1] = blur_amount_fine[0];
1010 ImGui::SliderFloat2(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
1011 ImGui::SliderFloat2(
"Sigma (fine)", blur_amount_fine, 0, 10);
1013 ImGui::Combo(
"Blur style", &selected_blur_style, blur_style_names,
1014 sizeof(blur_style_names) /
sizeof(
char*));
1015 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
1016 sizeof(tile_mode_names) /
sizeof(
char*));
1017 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1018 ImGui::ColorEdit4(
"Bounds color ",
1019 reinterpret_cast<float*
>(&bounds_color));
1020 ImGui::SliderFloat2(
"Translation", offset, 0,
1021 pass.GetRenderTargetSize().width);
1022 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1023 ImGui::SliderFloat2(
"Scale", scale, 0, 3);
1024 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1025 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1029 auto blur_sigma_x =
Sigma{blur_amount_coarse[0] + blur_amount_fine[0]};
1030 auto blur_sigma_y =
Sigma{blur_amount_coarse[1] + blur_amount_fine[1]};
1032 std::shared_ptr<Contents> input;
1036 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1038 std::unique_ptr<Geometry> solid_color_input;
1039 if (selected_input_type == 0) {
1040 auto texture = std::make_shared<TextureContents>();
1042 texture->SetDestinationRect(input_rect);
1043 texture->SetTexture(boston);
1044 texture->SetOpacity(input_color.
alpha);
1047 input_size = input_rect.GetSize();
1049 auto fill = std::make_shared<SolidColorContents>();
1050 fill->SetColor(input_color);
1054 fill->SetGeometry(solid_color_input.get());
1057 input_size = input_rect.GetSize();
1060 std::shared_ptr<FilterContents> blur;
1061 switch (selected_pass_variation) {
1063 blur = std::make_shared<GaussianBlurFilterContents>(
1064 blur_sigma_x.sigma, blur_sigma_y.sigma,
1065 tile_modes[selected_tile_mode], blur_styles[selected_blur_style],
1072 tile_modes[selected_tile_mode], blur_styles[selected_blur_style]);
1079 blur_styles[selected_blur_style]);
1088 auto target_contents = selected_blur_type == 0 ? blur : mask_blur;
1094 entity.
Render(context, pass);
1099 std::unique_ptr<Geometry> geom =
1101 auto contents = std::make_shared<SolidColorContents>();
1102 contents->SetColor(cover_color);
1103 contents->SetGeometry(geom.get());
1106 cover_entity.
Render(context, pass);
1110 std::optional<Rect> target_contents_coverage =
1112 if (target_contents_coverage.has_value()) {
1113 std::unique_ptr<Geometry> geom =
1115 target_contents->GetCoverage(entity).value()));
1116 auto contents = std::make_shared<SolidColorContents>();
1117 contents->SetColor(bounds_color);
1118 contents->SetGeometry(geom.get());
1122 bounds_entity.
Render(context, pass);
1127 ASSERT_TRUE(OpenPlaygroundHere(callback));
1131 auto boston = CreateTextureForFixture(
"boston.jpg");
1132 ASSERT_TRUE(boston);
1135 const char* morphology_type_names[] = {
"Dilate",
"Erode"};
1140 static int selected_morphology_type = 0;
1141 static float radius[2] = {20, 20};
1142 static Color cover_color(1, 0, 0, 0.2);
1143 static Color bounds_color(0, 1, 0, 0.1);
1144 static float offset[2] = {500, 400};
1145 static float rotation = 0;
1146 static float scale[2] = {0.65, 0.65};
1147 static float skew[2] = {0, 0};
1148 static float path_rect[4] = {0, 0,
1149 static_cast<float>(boston->GetSize().width),
1150 static_cast<float>(boston->GetSize().height)};
1151 static float effect_transform_scale = 1;
1153 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1155 ImGui::Combo(
"Morphology type", &selected_morphology_type,
1156 morphology_type_names,
1157 sizeof(morphology_type_names) /
sizeof(
char*));
1158 ImGui::SliderFloat2(
"Radius", radius, 0, 200);
1159 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
1160 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1161 ImGui::ColorEdit4(
"Bounds color ",
1162 reinterpret_cast<float*
>(&bounds_color));
1163 ImGui::SliderFloat2(
"Translation", offset, 0,
1164 pass.GetRenderTargetSize().width);
1165 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1166 ImGui::SliderFloat2(
"Scale", scale, 0, 3);
1167 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1168 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1169 ImGui::SliderFloat(
"Effect transform scale", &effect_transform_scale, 0,
1174 std::shared_ptr<Contents> input;
1178 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1179 auto texture = std::make_shared<TextureContents>();
1181 texture->SetDestinationRect(input_rect);
1182 texture->SetTexture(boston);
1183 texture->SetOpacity(input_color.
alpha);
1186 input_size = input_rect.GetSize();
1190 morphology_types[selected_morphology_type]);
1192 Vector2{effect_transform_scale, effect_transform_scale}));
1205 entity.
Render(context, pass);
1210 std::unique_ptr<Geometry> geom =
1212 auto cover_contents = std::make_shared<SolidColorContents>();
1213 cover_contents->SetColor(cover_color);
1214 cover_contents->SetGeometry(geom.get());
1217 cover_entity.
Render(context, pass);
1222 flutter::DlPath::MakeRect(contents->GetCoverage(entity).value()));
1223 auto bounds_contents = std::make_shared<SolidColorContents>();
1224 bounds_contents->SetColor(bounds_color);
1225 bounds_contents->SetGeometry(bounds_geom.get());
1226 bounds_entity.
SetContents(std::move(bounds_contents));
1229 bounds_entity.
Render(context, pass);
1233 ASSERT_TRUE(OpenPlaygroundHere(callback));
1245 entity.
SetContents(std::make_shared<SolidColorContents>());
1252 flutter::DlPath::MakeLine({0, 0}, {10, 10}),
1257 .miter_limit = 4.0f,
1261 auto contents = std::make_unique<SolidColorContents>();
1262 contents->SetGeometry(geometry.get());
1264 entity.SetContents(std::move(contents));
1265 auto actual = entity.GetCoverage();
1268 ASSERT_TRUE(actual.has_value());
1275 flutter::DlPath::MakeLine({0, 0}, {10, 10}),
1284 auto contents = std::make_unique<SolidColorContents>();
1285 contents->SetGeometry(geometry.get());
1287 entity.SetContents(std::move(contents));
1288 auto actual = entity.GetCoverage();
1292 ASSERT_TRUE(actual.has_value());
1299 flutter::DlPath::MakeLine({0, 0}, {10, 10}),
1304 .miter_limit = 2.0f,
1308 auto contents = std::make_unique<SolidColorContents>();
1309 contents->SetGeometry(geometry.get());
1311 entity.SetContents(std::move(contents));
1312 auto actual = entity.GetCoverage();
1315 ASSERT_TRUE(actual.has_value());
1321 auto fill = std::make_shared<SolidColorContents>();
1324 fill->SetGeometry(geom.get());
1332 auto actual = border_mask_blur->GetCoverage(e);
1334 ASSERT_TRUE(actual.has_value());
1341 auto actual = border_mask_blur->GetCoverage(e);
1342 auto expected =
Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
1343 ASSERT_TRUE(actual.has_value());
1351 auto fill = std::make_shared<SolidColorContents>();
1355 fill->SetGeometry(geom.get());
1357 auto coverage = fill->GetCoverage({});
1358 ASSERT_TRUE(coverage.has_value());
1364 auto fill = std::make_shared<SolidColorContents>();
1368 fill->SetGeometry(geom.get());
1376 ASSERT_TRUE(coverage.has_value());
1382 auto fill = std::make_shared<SolidColorContents>();
1386 fill->SetGeometry(geom.get());
1388 auto coverage = fill->GetCoverage({});
1389 ASSERT_FALSE(coverage.has_value());
1396 static float corner_radius = 100;
1398 static bool show_coverage =
false;
1404 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1405 ImGui::SliderFloat(
"Corner radius", &corner_radius, 0, 300);
1406 ImGui::SliderFloat(
"Blur radius", &
blur_radius, 0, 300);
1407 ImGui::ColorEdit4(
"Color",
reinterpret_cast<Scalar*
>(&color));
1408 ImGui::Checkbox(
"Show coverage", &show_coverage);
1409 if (show_coverage) {
1410 ImGui::ColorEdit4(
"Coverage color",
1411 reinterpret_cast<Scalar*
>(&coverage_color));
1415 auto [top_left, bottom_right] =
1418 Rect::MakeLTRB(top_left.x, top_left.y, bottom_right.x, bottom_right.y);
1420 auto contents = std::make_unique<SolidRRectBlurContents>();
1421 contents->SetShape(rect, corner_radius);
1422 contents->SetColor(color);
1428 entity.
Render(context, pass);
1431 if (show_coverage && coverage.has_value()) {
1432 auto bounds_contents = std::make_unique<SolidColorContents>();
1434 flutter::DlPath::MakeRect(entity.
GetCoverage().value()));
1435 bounds_contents->SetGeometry(geom.get());
1436 bounds_contents->SetColor(coverage_color.
Premultiply());
1438 bounds_entity.
SetContents(std::move(bounds_contents));
1439 bounds_entity.
Render(context, pass);
1444 ASSERT_TRUE(OpenPlaygroundHere(callback));
1449 auto fill = std::make_shared<SolidColorContents>();
1452 fill->SetGeometry(geom.get());
1470 auto actual = filter->GetCoverage(e);
1473 ASSERT_TRUE(actual.has_value());
1478 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
1479 ASSERT_TRUE(bay_bridge);
1489 static float offset[2] = {500, 400};
1490 static float rotation = 0;
1491 static float scale[2] = {0.65, 0.65};
1492 static float skew[2] = {0, 0};
1495 ImGui::Begin(
"Color Matrix",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1497 std::string label =
"##1";
1498 for (
int i = 0; i < 20; i += 5) {
1499 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
1500 &(color_matrix.
array[i]), 5,
nullptr,
nullptr,
1505 ImGui::SliderFloat2(
"Translation", &offset[0], 0,
1506 pass.GetRenderTargetSize().width);
1507 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1508 ImGui::SliderFloat2(
"Scale", &scale[0], 0, 3);
1509 ImGui::SliderFloat2(
"Skew", &skew[0], -3, 3);
1527 entity.
Render(context, pass);
1532 ASSERT_TRUE(OpenPlaygroundHere(callback));
1539 auto fill = std::make_shared<SolidColorContents>();
1540 fill->SetGeometry(geom.get());
1550 auto actual = filter->GetCoverage(e);
1553 ASSERT_TRUE(actual.has_value());
1558 auto image = CreateTextureForFixture(
"kalimba.jpg");
1581 return entity_left.
Render(context, pass) &&
1582 entity_right.
Render(context, pass);
1585 ASSERT_TRUE(OpenPlaygroundHere(callback));
1590 auto fill = std::make_shared<SolidColorContents>();
1593 fill->SetGeometry(geom.get());
1603 auto actual = filter->GetCoverage(e);
1606 ASSERT_TRUE(actual.has_value());
1611 auto image = CreateTextureForFixture(
"embarcadero.jpg");
1634 return entity_left.
Render(context, pass) &&
1635 entity_right.
Render(context, pass);
1638 ASSERT_TRUE(OpenPlaygroundHere(callback));
1643 switch (yuv_color_space) {
1645 yuv.
x = rgb.
x * 0.299 + rgb.
y * 0.587 + rgb.
z * 0.114;
1646 yuv.
y = rgb.
x * -0.169 + rgb.
y * -0.331 + rgb.
z * 0.5 + 0.5;
1647 yuv.
z = rgb.
x * 0.5 + rgb.
y * -0.419 + rgb.
z * -0.081 + 0.5;
1650 yuv.
x = rgb.
x * 0.257 + rgb.
y * 0.516 + rgb.
z * 0.100 + 0.063;
1651 yuv.
y = rgb.
x * -0.145 + rgb.
y * -0.291 + rgb.
z * 0.439 + 0.5;
1652 yuv.
z = rgb.
x * 0.429 + rgb.
y * -0.368 + rgb.
z * -0.071 + 0.5;
1661 Vector3 red = {244.0 / 255.0, 67.0 / 255.0, 54.0 / 255.0};
1662 Vector3 green = {76.0 / 255.0, 175.0 / 255.0, 80.0 / 255.0};
1663 Vector3 blue = {33.0 / 255.0, 150.0 / 255.0, 243.0 / 255.0};
1664 Vector3 white = {1.0, 1.0, 1.0};
1669 std::vector<Vector3> yuvs{red_yuv, green_yuv, blue_yuv, white_yuv};
1670 std::vector<uint8_t> y_data;
1671 std::vector<uint8_t> uv_data;
1672 for (
int i = 0; i < 4; i++) {
1674 uint8_t y = std::round(yuv.x * 255.0);
1675 uint8_t u = std::round(yuv.y * 255.0);
1676 uint8_t v = std::round(yuv.z * 255.0);
1677 for (
int j = 0; j < 16; j++) {
1678 y_data.push_back(y);
1680 for (
int j = 0; j < 8; j++) {
1681 uv_data.push_back(j % 2 == 0 ? u : v);
1685 auto blit_pass = cmd_buffer->CreateBlitPass();
1690 y_texture_descriptor.
size = {8, 8};
1693 auto y_mapping = std::make_shared<fml::DataMapping>(y_data);
1694 auto y_mapping_buffer =
1702 uv_texture_descriptor.
size = {4, 4};
1705 auto uv_mapping = std::make_shared<fml::DataMapping>(uv_data);
1706 auto uv_mapping_buffer =
1711 if (!blit_pass->EncodeCommands() ||
1713 FML_DLOG(ERROR) <<
"Could not copy contents into Y/UV texture.";
1716 return {y_texture, uv_texture};
1723 <<
"YUV to RGB filter is not supported on OpenGLES backend yet.";
1729 for (
int i = 0; i < 2; i++) {
1730 auto yuv_color_space = yuv_color_space_array[i];
1734 textures[0], textures[1], yuv_color_space);
1737 auto snapshot = filter_contents->RenderToSnapshot(context, filter_entity);
1741 contents->SetTexture(snapshot->texture);
1742 contents->SetSourceRect(
Rect::MakeSize(snapshot->texture->GetSize()));
1746 entity.
Render(context, pass);
1750 ASSERT_TRUE(OpenPlaygroundHere(callback));
1754 auto runtime_stages =
1755 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1756 auto runtime_stage =
1758 ASSERT_TRUE(runtime_stage);
1759 ASSERT_TRUE(runtime_stage->IsDirty());
1761 bool expect_dirty =
true;
1767 EXPECT_EQ(runtime_stage->IsDirty(), expect_dirty);
1769 auto contents = std::make_shared<RuntimeEffectContents>();
1770 contents->SetGeometry(geom.get());
1771 contents->SetRuntimeStage(runtime_stage);
1773 struct FragUniforms {
1777 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1778 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1780 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1781 uniform_data->resize(
sizeof(FragUniforms));
1782 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1783 contents->SetUniformData(uniform_data);
1787 bool result = contents->Render(context, entity, pass);
1790 first_pipeline = pass.GetCommands().back().pipeline;
1792 EXPECT_EQ(pass.GetCommands().back().pipeline, first_pipeline);
1794 expect_dirty =
false;
1799 auto content_context = GetContentContext();
1802 content_context->GetRenderTargetCache()->CreateOffscreen(
1803 *content_context->GetContext(), {1, 1}, 1u);
1805 testing::MockRenderPass mock_pass(GetContext(), target);
1806 callback(*content_context, mock_pass);
1807 callback(*content_context, mock_pass);
1810 runtime_stages = OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1814 ASSERT_TRUE(runtime_stage->IsDirty());
1815 expect_dirty =
true;
1817 callback(*content_context, mock_pass);
1822 auto runtime_stages =
1823 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1824 auto runtime_stage =
1826 ASSERT_TRUE(runtime_stage);
1827 ASSERT_TRUE(runtime_stage->IsDirty());
1829 auto contents = std::make_shared<RuntimeEffectContents>();
1831 contents->SetGeometry(geom.get());
1832 contents->SetRuntimeStage(runtime_stage);
1834 struct FragUniforms {
1838 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1839 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1841 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1842 uniform_data->resize(
sizeof(FragUniforms));
1843 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1844 contents->SetUniformData(uniform_data);
1852 GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
1853 *GetContext(), {GetWindowSize().width, GetWindowSize().height}, 1,
1854 "RuntimeEffect Texture");
1855 testing::MockRenderPass pass(GetContext(), target);
1857 ASSERT_TRUE(contents->Render(*GetContentContext(), entity, pass));
1858 ASSERT_EQ(pass.GetCommands().size(), 1u);
1859 const auto& command = pass.GetCommands()[0];
1860 ASSERT_TRUE(command.pipeline->GetDescriptor()
1861 .GetDepthStencilAttachmentDescriptor()
1863 ASSERT_TRUE(command.pipeline->GetDescriptor()
1864 .GetFrontStencilAttachmentDescriptor()
1869 auto runtime_stages =
1870 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1871 auto runtime_stage =
1873 ASSERT_TRUE(runtime_stage);
1874 ASSERT_TRUE(runtime_stage->IsDirty());
1876 auto contents = std::make_shared<RuntimeEffectContents>();
1877 contents->SetRuntimeStage(runtime_stage);
1879 EXPECT_TRUE(contents->BootstrapShader(*GetContentContext()));
1884 GTEST_SKIP() <<
"Test only applies to Vulkan";
1887 auto runtime_stages =
1888 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1889 auto runtime_stage =
1891 ASSERT_TRUE(runtime_stage);
1892 ASSERT_TRUE(runtime_stage->IsDirty());
1894 auto contents = std::make_shared<RuntimeEffectContents>();
1896 contents->SetGeometry(geom.get());
1897 contents->SetRuntimeStage(runtime_stage);
1899 struct FragUniforms {
1903 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1904 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1906 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1907 uniform_data->resize(
sizeof(FragUniforms));
1908 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1911 uniform_data, GetContentContext()->GetTransientsDataBuffer(),
1912 runtime_stage->GetUniforms()[0],
1914 ->GetTransientsDataBuffer()
1915 .GetMinimumUniformAlignment());
1925 auto image = CreateTextureForFixture(
"boston.jpg");
1935 return entity.
Render(context, pass);
1937 ASSERT_TRUE(OpenPlaygroundHere(callback));
1941 auto image = CreateTextureForFixture(
"boston.jpg");
1951 return entity.
Render(context, pass);
1953 ASSERT_TRUE(OpenPlaygroundHere(callback));
1957 auto image = CreateTextureForFixture(
"boston.jpg");
1967 return entity.
Render(context, pass);
1969 ASSERT_TRUE(OpenPlaygroundHere(callback));
1973 auto image = CreateTextureForFixture(
"boston.jpg");
1983 return entity.
Render(context, pass);
1985 ASSERT_TRUE(OpenPlaygroundHere(callback));
1989 auto image = CreateTextureForFixture(
"boston.jpg");
1999 return entity.
Render(context, pass);
2001 ASSERT_TRUE(OpenPlaygroundHere(callback));
2005 auto arrow_head = flutter::DlPathBuilder{}
2015 .miter_limit = 4.0f,
2025 auto coverage = geometry->GetCoverage(
transform);
2036 EXPECT_TRUE(contents.
IsOpaque(matrix));
2038 EXPECT_FALSE(contents.
IsOpaque(matrix));
2046 EXPECT_FALSE(contents.
IsOpaque(matrix));
2056 EXPECT_FALSE(contents.
IsOpaque(matrix));
2058 EXPECT_FALSE(contents.
IsOpaque(matrix));
2062 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2067 EXPECT_FALSE(contents.
IsOpaque(matrix));
2077 EXPECT_TRUE(contents.
IsOpaque(matrix));
2079 EXPECT_FALSE(contents.
IsOpaque(matrix));
2082 EXPECT_FALSE(contents.
IsOpaque(matrix));
2086 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2091 EXPECT_FALSE(contents.
IsOpaque(matrix));
2101 EXPECT_TRUE(contents.
IsOpaque(matrix));
2103 EXPECT_FALSE(contents.
IsOpaque(matrix));
2106 EXPECT_FALSE(contents.
IsOpaque(matrix));
2110 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2115 EXPECT_FALSE(contents.
IsOpaque(matrix));
2125 EXPECT_TRUE(contents.
IsOpaque(matrix));
2127 EXPECT_FALSE(contents.
IsOpaque(matrix));
2130 EXPECT_FALSE(contents.
IsOpaque(matrix));
2134 flutter::DlPathBuilder{}.MoveTo({0, 0}).
LineTo({100, 100}).TakePath(),
2139 EXPECT_FALSE(contents.
IsOpaque(matrix));
2144 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
2150 EXPECT_FALSE(contents.
IsOpaque(matrix));
2154 std::vector<Point>
points = {{10, 20}, {100, 200}};
2164 auto src_contents = std::make_shared<SolidColorContents>();
2166 src_contents->SetGeometry(src_geom.get());
2169 auto dst_contents = std::make_shared<SolidColorContents>();
2171 dst_contents->SetGeometry(dst_geom.get());
2178 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2190 auto content_context = GetContentContext();
2192 auto default_gyph = content_context->GetGlyphAtlasPipeline({
2194 .has_depth_stencil_attachments =
false,
2196 auto alt_gyph = content_context->GetGlyphAtlasPipeline(
2198 .has_depth_stencil_attachments =
true});
2200 EXPECT_NE(default_gyph, alt_gyph);
2201 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2202 alt_gyph->GetDescriptor().GetSpecializationConstants());
2204 auto use_a8 = GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
2207 std::vector<Scalar> expected_constants = {
static_cast<Scalar>(use_a8)};
2208 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2209 expected_constants);
2213 auto content_context = GetContentContext();
2214 auto default_color_burn = content_context->GetMorphologyFilterPipeline({
2218 auto decal_supported =
static_cast<Scalar>(
2219 GetContext()->GetCapabilities()->SupportsDecalSamplerAddressMode());
2220 std::vector<Scalar> expected_constants = {decal_supported};
2221 ASSERT_EQ(default_color_burn->GetDescriptor().GetSpecializationConstants(),
2222 expected_constants);
2230 auto hash_a = opts.
ToKey();
2233 auto hash_b = opts.
ToKey();
2236 auto hash_c = opts.
ToKey();
2239 auto hash_d = opts.
ToKey();
2241 EXPECT_NE(hash_a, hash_b);
2242 EXPECT_NE(hash_b, hash_c);
2243 EXPECT_NE(hash_c, hash_d);
2260 bool expected_layout =
false;
2262 FragmentShader::kDescriptorSetLayouts) {
2263 if (layout.binding == 64 &&
2265 expected_layout =
true;
2268 EXPECT_TRUE(expected_layout);
2274 testing::MockRenderPass mock_pass(GetContext(), target);
2279 return geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2285 get_result(flutter::DlPath::MakeRect(
Rect::MakeLTRB(0, 0, 100, 100)));
2305 GTEST_SKIP() <<
"Validation is only fatal on Vulkan backend.";
2310 GetContentContext()->GetBlendColorBurnPipeline({
2312 .has_depth_stencil_attachments =
false,
2320 EXPECT_TRUE(path.GetBounds().IsEmpty());
2326 GetContentContext()->GetRenderTargetCache()->CreateOffscreen(
2327 *GetContext(), {1, 1}, 1u);
2328 testing::MockRenderPass render_pass(GetContext(), target);
2329 auto position_result =
2330 geom->GetPositionBuffer(*GetContentContext(), entity, render_pass);
2332 EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u);
2340 EXPECT_TRUE(path.GetBounds().IsEmpty());
2342 auto contents = std::make_shared<SolidColorContents>();
2344 contents->SetGeometry(geom.get());
2351 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2357 static float alpha = 10;
2358 static float beta = 10;
2359 static float radius = 40;
2360 static int degree = 4;
2363 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2364 ImGui::SliderFloat(
"Alpha", &alpha, 0, 100);
2365 ImGui::SliderFloat(
"Beta", &beta, 0, 100);
2366 ImGui::SliderInt(
"Degreee", °ree, 1, 20);
2367 ImGui::SliderFloat(
"Radius", &radius, 0, 400);
2368 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&color));
2371 auto contents = std::make_shared<SolidColorContents>();
2372 std::unique_ptr<SuperellipseGeometry> geom =
2373 std::make_unique<SuperellipseGeometry>(
Point{400, 400}, radius, degree,
2375 contents->SetColor(color);
2376 contents->SetGeometry(geom.get());
2381 return entity.
Render(context, pass);
2384 ASSERT_TRUE(OpenPlaygroundHere(callback));
2390 static int style_index = 0;
2391 static float center[2] = {830, 830};
2392 static float size[2] = {600, 600};
2393 static bool horizontal_symmetry =
true;
2394 static bool vertical_symmetry =
true;
2395 static bool corner_symmetry =
true;
2397 const char* style_options[] = {
"Fill",
"Stroke"};
2401 static std::array<float, 2> radius_tl = {200};
2402 static std::array<float, 2> radius_tr;
2403 static std::array<float, 2> radius_bl;
2404 static std::array<float, 2> radius_br;
2406 auto AddRadiusControl = [](std::array<float, 2>& radii,
const char* tb_name,
2407 const char* lr_name) {
2408 std::string name =
"Radius";
2409 if (!horizontal_symmetry || !vertical_symmetry) {
2412 if (!vertical_symmetry) {
2413 name = name +
" " + tb_name;
2415 if (!horizontal_symmetry) {
2416 name = name +
" " + lr_name;
2418 if (corner_symmetry) {
2419 ImGui::SliderFloat(name.c_str(), radii.data(), 0, 1000);
2421 ImGui::SliderFloat2(name.c_str(), radii.data(), 0, 1000);
2425 if (corner_symmetry) {
2426 radius_tl[1] = radius_tl[0];
2427 radius_tr[1] = radius_tr[0];
2428 radius_bl[1] = radius_bl[0];
2429 radius_br[1] = radius_br[0];
2432 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2434 ImGui::Combo(
"Style", &style_index, style_options,
2435 sizeof(style_options) /
sizeof(
char*));
2436 ImGui::SliderFloat2(
"Center", center, 0, 1000);
2437 ImGui::SliderFloat2(
"Size", size, 0, 1000);
2438 ImGui::Checkbox(
"Symmetry: Horizontal", &horizontal_symmetry);
2439 ImGui::Checkbox(
"Symmetry: Vertical", &vertical_symmetry);
2440 ImGui::Checkbox(
"Symmetry: Corners", &corner_symmetry);
2441 AddRadiusControl(radius_tl,
"Top",
"Left");
2442 if (!horizontal_symmetry) {
2443 AddRadiusControl(radius_tr,
"Top",
"Right");
2445 radius_tr = radius_tl;
2447 if (!vertical_symmetry) {
2448 AddRadiusControl(radius_bl,
"Bottom",
"Left");
2450 radius_bl = radius_tl;
2452 if (!horizontal_symmetry && !vertical_symmetry) {
2453 AddRadiusControl(radius_br,
"Bottom",
"Right");
2455 if (horizontal_symmetry) {
2456 radius_br = radius_bl;
2458 radius_br = radius_tr;
2466 .
top_left = {radius_tl[0], radius_tl[1]},
2467 .top_right = {radius_tr[0], radius_tr[1]},
2468 .bottom_left = {radius_bl[0], radius_bl[1]},
2469 .bottom_right = {radius_br[0], radius_br[1]},
2476 std::unique_ptr<Geometry> geom;
2477 if (style_index == 0) {
2478 geom = std::make_unique<RoundSuperellipseGeometry>(
2482 path = flutter::DlPath::MakeRoundSuperellipse(rse);
2486 auto contents = std::make_shared<SolidColorContents>();
2488 contents->SetGeometry(geom.get());
2493 return entity.
Render(context, pass);
2496 ASSERT_TRUE(OpenPlaygroundHere(callback));
2502 auto result = contents.ApplyColorFilter([](
const Color& color) {
2505 ASSERT_TRUE(result);
2507 Color(0.424452, 0.828743, 0.79105, 0.9375));
2510 #define APPLY_COLOR_FILTER_GRADIENT_TEST(name) \
2511 TEST_P(EntityTest, name##GradientApplyColorFilter) { \
2512 auto contents = name##GradientContents(); \
2513 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.75)}); \
2514 auto result = contents.ApplyColorFilter([](const Color& color) { \
2515 return color.Blend(Color::LimeGreen().WithAlpha(0.75), \
2516 BlendMode::kScreen); \
2518 ASSERT_TRUE(result); \
2520 std::vector<Color> expected = {Color(0.433247, 0.879523, 0.825324, 0.75)}; \
2521 ASSERT_COLORS_NEAR(contents.GetColors(), expected); \
2530 flutter::DlPathBuilder builder;
2531 for (
int i = 0; i < 10000; i++) {
2532 builder.LineTo(
Point(i, i));
2540 auto cmd_buffer = content_context.GetContext()->CreateCommandBuffer();
2543 content_context.GetContext()->GetResourceAllocator());
2546 *content_context.GetContext(), {10, 10}, 1);
2547 auto pass = cmd_buffer->CreateRenderPass(render_target);
2550 geom->GetPositionBuffer(content_context, entity, *pass);
2556 Point* written_data =
reinterpret_cast<Point*
>(
2560 std::vector<Point> expected = {
2561 Point(2043.46, 2050.54),
2562 Point(2050.54, 2043.46),
2563 Point(2044.46, 2051.54),
2564 Point(2051.54, 2044.46),
2565 Point(2045.46, 2052.54)
2569 EXPECT_NEAR(point.
x, expected[0].x, 0.1);
2570 EXPECT_NEAR(point.
y, expected[0].y, 0.1);
2573 EXPECT_NEAR(point.
x, expected[1].x, 0.1);
2574 EXPECT_NEAR(point.
y, expected[1].y, 0.1);
2577 EXPECT_NEAR(point.
x, expected[2].x, 0.1);
2578 EXPECT_NEAR(point.
y, expected[2].y, 0.1);
2581 EXPECT_NEAR(point.
x, expected[3].x, 0.1);
2582 EXPECT_NEAR(point.
y, expected[3].y, 0.1);
2585 EXPECT_NEAR(point.
x, expected[4].x, 0.1);
2586 EXPECT_NEAR(point.
y, expected[4].y, 0.1);
2594 bool SetLabel(std::string_view label)
override {
return true; }
2603 return const_cast<uint8_t*
>(storage_.data());
2606 void Flush(std::optional<Range> range)
const override {
2607 flush_called_ =
true;
2613 std::vector<uint8_t> storage_;
2614 mutable bool flush_called_ =
false;
2620 return ISize(1024, 1024);
2625 return std::make_shared<FlushTestDeviceBuffer>(desc);
2629 bool threadsafe)
override {
2637 const std::shared_ptr<Context>& context,
2638 const std::shared_ptr<TypographerContext>& typographer_context,
2639 const std::shared_ptr<Allocator>& allocator)
2642 allocator, context->GetIdleWaiter(),
2643 context->GetCapabilities()->GetMinimumUniformAlignment()));
2645 allocator, context->GetIdleWaiter(),
2646 context->GetCapabilities()->GetMinimumUniformAlignment()));
2652 testing::MockRenderPass mock_pass(GetContext(), target);
2654 auto content_context = std::make_shared<FlushTestContentContext>(
2655 GetContext(), GetTypographerContext(),
2656 std::make_shared<FlushTestAllocator>());
2659 auto result = geometry->GetPositionBuffer(*content_context, {}, mock_pass);
2662 result.vertex_buffer.vertex_buffer.GetBuffer());
2663 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)
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
@ 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 > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, Entity::TileMode tile_mode=Entity::TileMode::kDecal, BlurStyle mask_blur_style=BlurStyle::kNormal, const Geometry *mask_geometry=nullptr)
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::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)
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 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...
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