12 #include "flutter/display_list/testing/dl_test_snippets.h"
13 #include "fml/logging.h"
14 #include "gtest/gtest.h"
55 #include "impeller/renderer/testing/mocks.h"
57 #include "third_party/imgui/imgui.h"
74 auto image = CreateTextureForFixture(
"boston.jpg");
80 auto actual = filter->GetCoverage({});
83 ASSERT_TRUE(actual.has_value());
90 filter->SetCoverageHint(expected);
91 auto actual = filter->GetCoverage({});
93 ASSERT_TRUE(actual.has_value());
118 auto contents = std::make_unique<SolidColorContents>();
121 contents->SetGeometry(geom.get());
124 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
128 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
140 auto contents = std::make_unique<TiledTextureContents>();
142 contents->SetGeometry(geom.get());
143 contents->SetTexture(bridge);
146 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
181 auto contents = std::make_unique<SolidColorContents>();
183 contents->SetGeometry(geom.get());
187 return entity.
Render(context, pass);
189 ASSERT_TRUE(OpenPlaygroundHere(callback));
194 const Point margin(140, 180);
200 static Scalar miter_limit = 1.41421357;
203 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
205 ImGui::SliderFloat(
"Miter limit", &miter_limit, 0, 30);
206 ImGui::SliderFloat(
"Stroke width", &width, 0, 100);
207 if (ImGui::Button(
"Reset")) {
208 miter_limit = 1.41421357;
215 auto render_path = [width = width, &context, &pass, &world_matrix](
217 auto contents = std::make_unique<SolidColorContents>();
218 std::unique_ptr<Geometry> geom =
220 contents->SetGeometry(geom.get());
228 if (coverage.has_value()) {
229 auto bounds_contents = std::make_unique<SolidColorContents>();
234 bounds_contents->SetGeometry(geom.get());
235 bounds_contents->SetColor(
Color::Green().WithAlpha(0.5));
237 bounds_entity.
SetContents(std::move(bounds_contents));
238 bounds_entity.
Render(context, pass);
241 entity.
Render(context, pass);
244 const Point a_def(0, 0), b_def(0, 100), c_def(150, 0), d_def(150, -100),
330 ASSERT_TRUE(OpenPlaygroundHere(callback));
337 .
MoveTo({237.164, 125.003})
338 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
340 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
342 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
344 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
346 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
354 auto contents = std::make_shared<SolidColorContents>();
356 contents->SetGeometry(geom.get());
359 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
364 const char* input_axis[] = {
"X",
"Y",
"Z"};
365 static int rotation_axis_index = 0;
366 static float rotation = 0;
367 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
368 ImGui::SliderFloat(
"Rotation", &rotation, -
kPi,
kPi);
369 ImGui::Combo(
"Rotation Axis", &rotation_axis_index, input_axis,
370 sizeof(input_axis) /
sizeof(
char*));
372 switch (rotation_axis_index) {
383 rotation_matrix =
Matrix{};
387 if (ImGui::Button(
"Reset")) {
391 Matrix current_transform =
395 pass.GetRenderTargetSize().height / 2.0)));
396 Matrix result_transform = current_transform * rotation_matrix;
405 auto contents = std::make_shared<SolidColorContents>();
407 contents->SetGeometry(geom.get());
410 return entity.
Render(context, pass);
412 ASSERT_TRUE(OpenPlaygroundHere(callback));
419 .
MoveTo({359.934, 96.6335})
420 .CubicCurveTo({358.189, 96.7055}, {356.436, 96.7908},
422 .CubicCurveTo({354.571, 96.8953}, {354.469, 96.9016},
424 .CubicCurveTo({352.672, 97.0038}, {350.969, 97.113},
426 .CubicCurveTo({349.048, 97.2506}, {348.836, 97.2678},
428 .CubicCurveTo({347.019, 97.4014}, {345.407, 97.5299},
430 .CubicCurveTo({343.428, 97.704}, {343.065, 97.7402},
432 .CubicCurveTo({341.221, 97.9086}, {339.736, 98.0505},
434 .CubicCurveTo({337.702, 98.2642}, {337.156, 98.3292},
436 .CubicCurveTo({335.284, 98.5356}, {333.956, 98.6837},
438 .CubicCurveTo({332.495, 98.8635}, {332.366, 98.8818},
440 .
LineTo({332.237, 102.601})
441 .
LineTo({321.778, 102.601})
442 .
LineTo({321.778, 100.382})
443 .CubicCurveTo({321.572, 100.413}, {321.367, 100.442},
445 .CubicCurveTo({319.22, 100.79}, {317.277, 101.123},
447 .CubicCurveTo({315.322, 101.481}, {315.311, 101.482},
449 .
LineTo({310.017, 105.94})
450 .
LineTo({309.779, 105.427})
451 .
LineTo({314.403, 101.651})
452 .CubicCurveTo({314.391, 101.653}, {314.379, 101.656},
454 .CubicCurveTo({312.528, 102.001}, {310.687, 102.366},
456 .CubicCurveTo({307.85, 102.955}, {306.855, 103.182}, {305.859, 103.4})
457 .CubicCurveTo({305.048, 103.579}, {304.236, 103.75},
459 .
LineTo({299.105, 107.578})
460 .
LineTo({298.867, 107.065})
461 .
LineTo({302.394, 104.185})
462 .
LineTo({302.412, 104.171})
463 .CubicCurveTo({301.388, 104.409}, {300.366, 104.67},
465 .CubicCurveTo({298.618, 105.1}, {297.89, 105.269}, {297.165, 105.455})
466 .CubicCurveTo({295.262, 105.94}, {293.36, 106.445},
468 .CubicCurveTo({291.132, 107.072}, {290.802, 107.163},
470 .CubicCurveTo({289.463, 107.544}, {288.455, 107.839},
472 .CubicCurveTo({286.476, 108.431}, {285.506, 108.73},
474 .CubicCurveTo({283.674, 109.304}, {282.812, 109.579},
476 .CubicCurveTo({281.177, 110.112}, {280.406, 110.377},
478 .CubicCurveTo({278.458, 111.037}, {277.256, 111.449},
480 .CubicCurveTo({276.76, 111.622}, {276.716, 111.637},
482 .CubicCurveTo({275.017, 112.239}, {273.365, 112.836},
484 .
LineTo({271.717, 113.449})
485 .CubicCurveTo({271.496, 113.496}, {271.238, 113.559},
487 .CubicCurveTo({270.893, 113.645}, {270.822, 113.663},
489 .CubicCurveTo({270.468, 113.755}, {270.169, 113.834},
491 .CubicCurveTo({269.789, 113.94}, {269.732, 113.957},
493 .CubicCurveTo({269.391, 114.053}, {269.081, 114.143},
495 .CubicCurveTo({268.628, 114.276}, {268.5, 114.314},
497 .CubicCurveTo({268.172, 114.412}, {267.959, 114.478},
499 .CubicCurveTo({263.349, 115.964}, {258.058, 117.695},
501 .CubicCurveTo({253.556, 119.255}, {253.547, 119.258},
503 .CubicCurveTo({251.844, 119.849}, {250.056, 120.474},
505 .CubicCurveTo({248, 121.197}, {247.812, 121.264}, {247.621, 121.331})
506 .CubicCurveTo({247.079, 121.522}, {246.531, 121.715},
508 .CubicCurveTo({245.554, 122.06}, {245.126, 122.212},
510 .CubicCurveTo({244.071, 122.586}, {243.437, 122.811},
512 .CubicCurveTo({242.189, 123.255}, {241.58, 123.472},
514 .CubicCurveTo({240.659, 123.801}, {240.357, 123.909},
516 .CubicCurveTo({239.12, 124.351}, {238.18, 124.687}, {237.22, 125.032})
517 .
LineTo({237.164, 125.003})
518 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
520 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
522 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
524 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
526 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
531 .CubicCurveTo({359.978, 96.6317}, {359.956, 96.6326},
534 .MoveTo({337.336, 124.143})
535 .CubicCurveTo({337.274, 122.359}, {338.903, 121.511},
537 .CubicCurveTo({338.903, 121.511}, {338.96, 123.303},
540 .MoveTo({340.082, 121.849})
541 .CubicCurveTo({340.074, 121.917}, {340.062, 121.992},
543 .CubicCurveTo({340.039, 122.109}, {340.031, 122.142},
545 .CubicCurveTo({340.005, 122.26}, {339.98, 122.346},
547 .CubicCurveTo({339.941, 122.473}, {339.931, 122.507},
549 .CubicCurveTo({339.873, 122.672}, {339.819, 122.804},
551 .CubicCurveTo({339.747, 122.944}, {339.743, 122.949},
553 .CubicCurveTo({339.674, 123.08}, {339.593, 123.205},
555 .CubicCurveTo({339.473, 123.366}, {339.441, 123.401},
557 .CubicCurveTo({339.332, 123.534}, {339.243, 123.625},
559 .CubicCurveTo({339.105, 123.75}, {339.068, 123.786},
561 .CubicCurveTo({338.881, 123.937}, {338.724, 124.048},
563 .CubicCurveTo({338.532, 123.959}, {338.554, 123.79},
565 .CubicCurveTo({338.58, 123.625}, {338.58, 123.625}, {338.58, 123.625})
566 .CubicCurveTo({338.607, 123.455}, {338.65, 123.299},
568 .CubicCurveTo({338.708, 123.14}, {338.71, 123.127},
570 .CubicCurveTo({338.769, 122.971}, {338.833, 122.838},
572 .CubicCurveTo({338.911, 122.702}, {338.916, 122.69200000000001},
574 .CubicCurveTo({338.996, 122.557}, {339.072, 122.444},
576 .CubicCurveTo({339.161, 122.333}, {339.166, 122.326},
578 .CubicCurveTo({339.256, 122.215}, {339.339, 122.12},
580 .CubicCurveTo({339.428, 122.033}, {339.431, 122.03},
582 .CubicCurveTo({339.785, 121.687}, {340.106, 121.511},
584 .CubicCurveTo({340.106, 121.511}, {340.107, 121.645},
587 .MoveTo({340.678, 113.245})
588 .CubicCurveTo({340.594, 113.488}, {340.356, 113.655},
590 .CubicCurveTo({339.817, 113.948}, {339.465, 114.059},
592 .CubicCurveTo({338.251, 114.379}, {337.34, 114.516},
594 .CubicCurveTo({335.761, 114.516}, {335.072, 114.527},
596 .CubicCurveTo({334.125, 114.508}, {333.862, 114.462},
598 .CubicCurveTo({332.865, 114.318}, {332.096, 114.184},
600 .CubicCurveTo({330.979, 113.695}, {330.442, 113.34},
602 .CubicCurveTo({331.135, 111.755}, {333.219, 112.946},
604 .CubicCurveTo({334.54, 113.816}, {334.554, 113.8}, {334.569, 113.784})
605 .CubicCurveTo({333.38, 112.708}, {331.749, 110.985},
607 .CubicCurveTo({333.769, 109.82}, {334.713, 111.93},
609 .CubicCurveTo({334.915, 111.889}, {334.59, 109.636},
611 .CubicCurveTo({336.733, 109.636}, {336.408, 111.889},
613 .CubicCurveTo({336.609, 111.93}, {337.553, 109.82},
615 .CubicCurveTo({339.574, 110.984}, {337.942, 112.708},
617 .CubicCurveTo({336.768, 113.8}, {336.782, 113.816},
619 .CubicCurveTo({338.104, 112.946}, {340.187, 111.755},
621 .CubicCurveTo({340.71, 112.95}, {340.728, 113.102},
624 .MoveTo({346.357, 106.771})
625 .CubicCurveTo({346.295, 104.987}, {347.924, 104.139},
627 .CubicCurveTo({347.924, 104.139}, {347.982, 105.931},
630 .MoveTo({347.56, 106.771})
631 .CubicCurveTo({347.498, 104.987}, {349.127, 104.139},
633 .CubicCurveTo({349.127, 104.139}, {349.185, 105.931},
642 auto contents = std::make_shared<SolidColorContents>();
644 contents->SetGeometry(geom.get());
647 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
655 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kButt);
656 ASSERT_EQ(path_geometry->GetStrokeJoin(),
Join::kMiter);
668 ASSERT_EQ(path_geometry->GetStrokeCap(),
Cap::kRound);
676 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
683 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 8);
690 ASSERT_FLOAT_EQ(path_geometry->GetMiterLimit(), 4);
695 std::vector<const char*> blend_mode_names;
696 std::vector<BlendMode> blend_mode_values;
709 blend_mode_names.push_back(
"Clear");
712 blend_mode_names.push_back(
"Source");
715 blend_mode_names.push_back(
"Destination");
718 blend_mode_names.push_back(
"SourceOver");
721 blend_mode_names.push_back(
"DestinationOver");
724 blend_mode_names.push_back(
"SourceIn");
727 blend_mode_names.push_back(
"DestinationIn");
730 blend_mode_names.push_back(
"SourceOut");
733 blend_mode_names.push_back(
"DestinationOut");
736 blend_mode_names.push_back(
"SourceATop");
739 blend_mode_names.push_back(
"DestinationATop");
742 blend_mode_names.push_back(
"Xor");
745 blend_mode_names.push_back(
"Plus");
748 blend_mode_names.push_back(
"Modulate");
755 auto draw_rect = [&context, &pass, &world_matrix](
762 auto r = rect.GetLTRB();
773 pass.SetCommandLabel(
"Blended Rectangle");
775 options.blend_mode = blend_mode;
778 pass.SetVertexBuffer(
781 VS::FrameInfo frame_info;
782 frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
785 FS::FragInfo frag_info;
786 frag_info.color = color.Premultiply();
789 return pass.Draw().ok();
792 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
793 static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5);
794 ImGui::ColorEdit4(
"Color 1",
reinterpret_cast<float*
>(&color1));
795 ImGui::ColorEdit4(
"Color 2",
reinterpret_cast<float*
>(&color2));
796 static int current_blend_index = 3;
797 ImGui::ListBox(
"Blending mode", ¤t_blend_index,
798 blend_mode_names.data(), blend_mode_names.size());
801 BlendMode selected_mode = blend_mode_values[current_blend_index];
814 pass.GetRenderTargetSize().height),
822 ASSERT_TRUE(OpenPlaygroundHere(callback));
827 static float scale = 20;
829 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
830 ImGui::SliderFloat(
"Scale", &
scale, 1, 100);
837 .CubicCurveTo({98.50862885295136, 34.81812293973836},
838 {99.46822048142015, 33.85863261475589},
839 {99.46822048142015, 32.67499810206613})
840 .CubicCurveTo({99.46822048142015, 31.491363589376355},
841 {98.50862885295136, 30.53187326439389},
842 {97.32499434685802, 30.531998226542708})
843 .CubicCurveTo({96.14153655073771, 30.532123170035373},
844 {95.18222070648729, 31.491540299350355},
845 {95.18222070648729, 32.67499810206613})
846 .CubicCurveTo({95.18222070648729, 33.85845590478189},
847 {96.14153655073771, 34.81787303409686},
848 {97.32499434685802, 34.81799797758954})
856 auto contents = std::make_shared<SolidColorContents>();
858 contents->SetGeometry(geom.get());
861 return entity.
Render(context, pass);
863 ASSERT_TRUE(OpenPlaygroundHere(callback));
867 auto bridge = CreateTextureForFixture(
"bay_bridge.jpg");
868 auto boston = CreateTextureForFixture(
"boston.jpg");
869 auto kalimba = CreateTextureForFixture(
"kalimba.jpg");
870 ASSERT_TRUE(bridge && boston && kalimba);
888 entity.SetContents(blend1);
889 return entity.Render(context, pass);
891 ASSERT_TRUE(OpenPlaygroundHere(callback));
896 CreateTextureForFixture(
"boston.jpg",
true);
900 const char* input_type_names[] = {
"Texture",
"Solid Color"};
901 const char* blur_type_names[] = {
"Image blur",
"Mask blur"};
902 const char* pass_variation_names[] = {
"New"};
903 const char* blur_style_names[] = {
"Normal",
"Solid",
"Outer",
"Inner"};
904 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
913 static int selected_input_type = 0;
915 static int selected_blur_type = 0;
916 static int selected_pass_variation = 0;
917 static bool combined_sigma =
false;
918 static float blur_amount_coarse[2] = {0, 0};
919 static float blur_amount_fine[2] = {10, 10};
920 static int selected_blur_style = 0;
921 static int selected_tile_mode = 3;
922 static Color cover_color(1, 0, 0, 0.2);
923 static Color bounds_color(0, 1, 0, 0.1);
924 static float offset[2] = {500, 400};
925 static float rotation = 0;
926 static float scale[2] = {0.65, 0.65};
927 static float skew[2] = {0, 0};
928 static float path_rect[4] = {0, 0,
929 static_cast<float>(boston->GetSize().width),
930 static_cast<float>(boston->GetSize().height)};
932 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
934 ImGui::Combo(
"Input type", &selected_input_type, input_type_names,
935 sizeof(input_type_names) /
sizeof(
char*));
936 if (selected_input_type == 0) {
937 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
939 ImGui::ColorEdit4(
"Input color",
940 reinterpret_cast<float*
>(&input_color));
942 ImGui::Combo(
"Blur type", &selected_blur_type, blur_type_names,
943 sizeof(blur_type_names) /
sizeof(
char*));
944 if (selected_blur_type == 0) {
945 ImGui::Combo(
"Pass variation", &selected_pass_variation,
946 pass_variation_names,
947 sizeof(pass_variation_names) /
sizeof(
char*));
949 ImGui::Checkbox(
"Combined sigma", &combined_sigma);
950 if (combined_sigma) {
951 ImGui::SliderFloat(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
952 ImGui::SliderFloat(
"Sigma (fine)", blur_amount_fine, 0, 10);
953 blur_amount_coarse[1] = blur_amount_coarse[0];
954 blur_amount_fine[1] = blur_amount_fine[0];
956 ImGui::SliderFloat2(
"Sigma (coarse)", blur_amount_coarse, 0, 1000);
957 ImGui::SliderFloat2(
"Sigma (fine)", blur_amount_fine, 0, 10);
959 ImGui::Combo(
"Blur style", &selected_blur_style, blur_style_names,
960 sizeof(blur_style_names) /
sizeof(
char*));
961 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
962 sizeof(tile_mode_names) /
sizeof(
char*));
963 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
964 ImGui::ColorEdit4(
"Bounds color ",
965 reinterpret_cast<float*
>(&bounds_color));
966 ImGui::SliderFloat2(
"Translation",
offset, 0,
967 pass.GetRenderTargetSize().width);
968 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
969 ImGui::SliderFloat2(
"Scale",
scale, 0, 3);
970 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
971 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
975 auto blur_sigma_x =
Sigma{blur_amount_coarse[0] + blur_amount_fine[0]};
976 auto blur_sigma_y =
Sigma{blur_amount_coarse[1] + blur_amount_fine[1]};
978 std::shared_ptr<Contents> input;
982 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
984 std::unique_ptr<Geometry> solid_color_input;
985 if (selected_input_type == 0) {
986 auto texture = std::make_shared<TextureContents>();
988 texture->SetDestinationRect(input_rect);
989 texture->SetTexture(boston);
990 texture->SetOpacity(input_color.
alpha);
993 input_size = input_rect.GetSize();
995 auto fill = std::make_shared<SolidColorContents>();
996 fill->SetColor(input_color);
1000 fill->SetGeometry(solid_color_input.get());
1003 input_size = input_rect.GetSize();
1006 std::shared_ptr<FilterContents> blur;
1007 switch (selected_pass_variation) {
1009 blur = std::make_shared<GaussianBlurFilterContents>(
1010 blur_sigma_x.sigma, blur_sigma_y.sigma,
1011 tile_modes[selected_tile_mode], blur_styles[selected_blur_style],
1018 tile_modes[selected_tile_mode], blur_styles[selected_blur_style]);
1025 blur_styles[selected_blur_style]);
1034 auto target_contents = selected_blur_type == 0 ? blur : mask_blur;
1040 entity.
Render(context, pass);
1045 std::unique_ptr<Geometry> geom =
1047 auto contents = std::make_shared<SolidColorContents>();
1048 contents->SetColor(cover_color);
1049 contents->SetGeometry(geom.get());
1052 cover_entity.
Render(context, pass);
1056 std::optional<Rect> target_contents_coverage =
1058 if (target_contents_coverage.has_value()) {
1061 .
AddRect(target_contents->GetCoverage(entity).value())
1063 auto contents = std::make_shared<SolidColorContents>();
1064 contents->SetColor(bounds_color);
1065 contents->SetGeometry(geom.get());
1069 bounds_entity.
Render(context, pass);
1074 ASSERT_TRUE(OpenPlaygroundHere(callback));
1078 auto boston = CreateTextureForFixture(
"boston.jpg");
1079 ASSERT_TRUE(boston);
1082 const char* morphology_type_names[] = {
"Dilate",
"Erode"};
1087 static int selected_morphology_type = 0;
1088 static float radius[2] = {20, 20};
1089 static Color cover_color(1, 0, 0, 0.2);
1090 static Color bounds_color(0, 1, 0, 0.1);
1091 static float offset[2] = {500, 400};
1092 static float rotation = 0;
1093 static float scale[2] = {0.65, 0.65};
1094 static float skew[2] = {0, 0};
1095 static float path_rect[4] = {0, 0,
1096 static_cast<float>(boston->GetSize().width),
1097 static_cast<float>(boston->GetSize().height)};
1098 static float effect_transform_scale = 1;
1100 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1102 ImGui::Combo(
"Morphology type", &selected_morphology_type,
1103 morphology_type_names,
1104 sizeof(morphology_type_names) /
sizeof(
char*));
1105 ImGui::SliderFloat2(
"Radius", radius, 0, 200);
1106 ImGui::SliderFloat(
"Input opacity", &input_color.
alpha, 0, 1);
1107 ImGui::ColorEdit4(
"Cover color",
reinterpret_cast<float*
>(&cover_color));
1108 ImGui::ColorEdit4(
"Bounds color ",
1109 reinterpret_cast<float*
>(&bounds_color));
1110 ImGui::SliderFloat2(
"Translation",
offset, 0,
1111 pass.GetRenderTargetSize().width);
1112 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1113 ImGui::SliderFloat2(
"Scale",
scale, 0, 3);
1114 ImGui::SliderFloat2(
"Skew", skew, -3, 3);
1115 ImGui::SliderFloat4(
"Path XYWH", path_rect, -1000, 1000);
1116 ImGui::SliderFloat(
"Effect transform scale", &effect_transform_scale, 0,
1121 std::shared_ptr<Contents> input;
1125 Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]);
1126 auto texture = std::make_shared<TextureContents>();
1128 texture->SetDestinationRect(input_rect);
1129 texture->SetTexture(boston);
1130 texture->SetOpacity(input_color.
alpha);
1133 input_size = input_rect.GetSize();
1137 morphology_types[selected_morphology_type]);
1139 Vector2{effect_transform_scale, effect_transform_scale}));
1152 entity.
Render(context, pass);
1157 std::unique_ptr<Geometry> geom =
1159 auto cover_contents = std::make_shared<SolidColorContents>();
1160 cover_contents->SetColor(cover_color);
1161 cover_contents->SetGeometry(geom.get());
1164 cover_entity.
Render(context, pass);
1170 .
AddRect(contents->GetCoverage(entity).value())
1172 auto bounds_contents = std::make_shared<SolidColorContents>();
1173 bounds_contents->SetColor(bounds_color);
1174 bounds_contents->SetGeometry(bounds_geom.get());
1175 bounds_entity.
SetContents(std::move(bounds_contents));
1178 bounds_entity.
Render(context, pass);
1182 ASSERT_TRUE(OpenPlaygroundHere(callback));
1194 entity.
SetContents(std::make_shared<SolidColorContents>());
1205 auto contents = std::make_unique<SolidColorContents>();
1206 contents->SetGeometry(geometry.get());
1212 ASSERT_TRUE(actual.has_value());
1223 auto contents = std::make_unique<SolidColorContents>();
1224 contents->SetGeometry(geometry.get());
1231 ASSERT_TRUE(actual.has_value());
1242 auto contents = std::make_unique<SolidColorContents>();
1243 contents->SetGeometry(geometry.get());
1249 ASSERT_TRUE(actual.has_value());
1255 auto fill = std::make_shared<SolidColorContents>();
1258 fill->SetGeometry(geom.get());
1266 auto actual = border_mask_blur->GetCoverage(e);
1268 ASSERT_TRUE(actual.has_value());
1275 auto actual = border_mask_blur->GetCoverage(e);
1276 auto expected =
Rect::MakeXYWH(-287.792, -4.94975, 504.874, 504.874);
1277 ASSERT_TRUE(actual.has_value());
1285 auto fill = std::make_shared<SolidColorContents>();
1290 fill->SetGeometry(geom.get());
1292 auto coverage = fill->GetCoverage({});
1293 ASSERT_TRUE(coverage.has_value());
1299 auto fill = std::make_shared<SolidColorContents>();
1303 fill->SetGeometry(geom.get());
1311 ASSERT_TRUE(coverage.has_value());
1317 auto fill = std::make_shared<SolidColorContents>();
1321 fill->SetGeometry(geom.get());
1323 auto coverage = fill->GetCoverage({});
1324 ASSERT_FALSE(coverage.has_value());
1331 static float corner_radius = 100;
1333 static bool show_coverage =
false;
1336 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1337 ImGui::SliderFloat(
"Corner radius", &corner_radius, 0, 300);
1338 ImGui::SliderFloat(
"Blur radius", &
blur_radius, 0, 300);
1339 ImGui::ColorEdit4(
"Color",
reinterpret_cast<Scalar*
>(&color));
1340 ImGui::Checkbox(
"Show coverage", &show_coverage);
1341 if (show_coverage) {
1342 ImGui::ColorEdit4(
"Coverage color",
1343 reinterpret_cast<Scalar*
>(&coverage_color));
1349 auto [top_left, bottom_right] =
1352 Rect::MakeLTRB(top_left.x, top_left.y, bottom_right.x, bottom_right.y);
1354 auto contents = std::make_unique<SolidRRectBlurContents>();
1355 contents->SetRRect(rect, {corner_radius, corner_radius});
1356 contents->SetColor(color);
1362 entity.
Render(context, pass);
1365 if (show_coverage && coverage.has_value()) {
1366 auto bounds_contents = std::make_unique<SolidColorContents>();
1369 bounds_contents->SetGeometry(geom.get());
1370 bounds_contents->SetColor(coverage_color.
Premultiply());
1372 bounds_entity.
SetContents(std::move(bounds_contents));
1373 bounds_entity.
Render(context, pass);
1378 ASSERT_TRUE(OpenPlaygroundHere(callback));
1383 auto fill = std::make_shared<SolidColorContents>();
1386 fill->SetGeometry(geom.get());
1404 auto actual = filter->GetCoverage(e);
1407 ASSERT_TRUE(actual.has_value());
1412 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
1413 ASSERT_TRUE(bay_bridge);
1423 static float offset[2] = {500, 400};
1424 static float rotation = 0;
1425 static float scale[2] = {0.65, 0.65};
1426 static float skew[2] = {0, 0};
1429 ImGui::Begin(
"Color Matrix",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1431 std::string label =
"##1";
1432 for (
int i = 0; i < 20; i += 5) {
1433 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
1434 &(color_matrix.
array[i]), 5,
nullptr,
nullptr,
1439 ImGui::SliderFloat2(
"Translation", &
offset[0], 0,
1440 pass.GetRenderTargetSize().width);
1441 ImGui::SliderFloat(
"Rotation", &rotation, 0,
kPi * 2);
1442 ImGui::SliderFloat2(
"Scale", &
scale[0], 0, 3);
1443 ImGui::SliderFloat2(
"Skew", &skew[0], -3, 3);
1461 entity.
Render(context, pass);
1466 ASSERT_TRUE(OpenPlaygroundHere(callback));
1473 auto fill = std::make_shared<SolidColorContents>();
1474 fill->SetGeometry(geom.get());
1484 auto actual = filter->GetCoverage(e);
1487 ASSERT_TRUE(actual.has_value());
1492 auto image = CreateTextureForFixture(
"kalimba.jpg");
1515 return entity_left.
Render(context, pass) &&
1516 entity_right.
Render(context, pass);
1519 ASSERT_TRUE(OpenPlaygroundHere(callback));
1524 auto fill = std::make_shared<SolidColorContents>();
1527 fill->SetGeometry(geom.get());
1537 auto actual = filter->GetCoverage(e);
1540 ASSERT_TRUE(actual.has_value());
1545 auto image = CreateTextureForFixture(
"embarcadero.jpg");
1568 return entity_left.
Render(context, pass) &&
1569 entity_right.
Render(context, pass);
1572 ASSERT_TRUE(OpenPlaygroundHere(callback));
1577 switch (yuv_color_space) {
1579 yuv.
x = rgb.
x * 0.299 + rgb.
y * 0.587 + rgb.
z * 0.114;
1580 yuv.
y = rgb.
x * -0.169 + rgb.
y * -0.331 + rgb.
z * 0.5 + 0.5;
1581 yuv.
z = rgb.
x * 0.5 + rgb.
y * -0.419 + rgb.
z * -0.081 + 0.5;
1584 yuv.
x = rgb.
x * 0.257 + rgb.
y * 0.516 + rgb.
z * 0.100 + 0.063;
1585 yuv.
y = rgb.
x * -0.145 + rgb.
y * -0.291 + rgb.
z * 0.439 + 0.5;
1586 yuv.
z = rgb.
x * 0.429 + rgb.
y * -0.368 + rgb.
z * -0.071 + 0.5;
1595 Vector3 red = {244.0 / 255.0, 67.0 / 255.0, 54.0 / 255.0};
1596 Vector3 green = {76.0 / 255.0, 175.0 / 255.0, 80.0 / 255.0};
1597 Vector3 blue = {33.0 / 255.0, 150.0 / 255.0, 243.0 / 255.0};
1598 Vector3 white = {1.0, 1.0, 1.0};
1603 std::vector<Vector3> yuvs{red_yuv, green_yuv, blue_yuv, white_yuv};
1604 std::vector<uint8_t> y_data;
1605 std::vector<uint8_t> uv_data;
1606 for (
int i = 0; i < 4; i++) {
1608 uint8_t y = std::round(yuv.x * 255.0);
1609 uint8_t u = std::round(yuv.y * 255.0);
1610 uint8_t v = std::round(yuv.z * 255.0);
1611 for (
int j = 0; j < 16; j++) {
1612 y_data.push_back(y);
1614 for (
int j = 0; j < 8; j++) {
1615 uv_data.push_back(j % 2 == 0 ? u : v);
1619 auto blit_pass = cmd_buffer->CreateBlitPass();
1624 y_texture_descriptor.
size = {8, 8};
1627 auto y_mapping = std::make_shared<fml::DataMapping>(y_data);
1628 auto y_mapping_buffer =
1636 uv_texture_descriptor.
size = {4, 4};
1639 auto uv_mapping = std::make_shared<fml::DataMapping>(uv_data);
1640 auto uv_mapping_buffer =
1645 if (!blit_pass->EncodeCommands() ||
1647 FML_DLOG(ERROR) <<
"Could not copy contents into Y/UV texture.";
1650 return {y_texture, uv_texture};
1657 <<
"YUV to RGB filter is not supported on OpenGLES backend yet.";
1663 for (
int i = 0; i < 2; i++) {
1664 auto yuv_color_space = yuv_color_space_array[i];
1668 textures[0], textures[1], yuv_color_space);
1671 auto snapshot = filter_contents->RenderToSnapshot(context, filter_entity);
1675 contents->SetTexture(snapshot->texture);
1676 contents->SetSourceRect(
Rect::MakeSize(snapshot->texture->GetSize()));
1680 entity.
Render(context, pass);
1684 ASSERT_TRUE(OpenPlaygroundHere(callback));
1688 auto runtime_stages =
1689 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1690 auto runtime_stage =
1692 ASSERT_TRUE(runtime_stage);
1693 ASSERT_TRUE(runtime_stage->IsDirty());
1695 bool expect_dirty =
true;
1701 EXPECT_EQ(runtime_stage->IsDirty(), expect_dirty);
1703 auto contents = std::make_shared<RuntimeEffectContents>();
1704 contents->SetGeometry(geom.get());
1705 contents->SetRuntimeStage(runtime_stage);
1707 struct FragUniforms {
1711 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1712 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1714 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1715 uniform_data->resize(
sizeof(FragUniforms));
1716 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1717 contents->SetUniformData(uniform_data);
1721 bool result = contents->Render(context, entity, pass);
1724 first_pipeline = pass.GetCommands().back().pipeline;
1726 EXPECT_EQ(pass.GetCommands().back().pipeline, first_pipeline);
1728 expect_dirty =
false;
1733 auto content_context = GetContentContext();
1736 content_context->GetRenderTargetCache()->CreateOffscreen(
1737 *content_context->GetContext(), {1, 1}, 1u);
1739 testing::MockRenderPass mock_pass(GetContext(), target);
1740 callback(*content_context, mock_pass);
1741 callback(*content_context, mock_pass);
1744 runtime_stages = OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1748 ASSERT_TRUE(runtime_stage->IsDirty());
1749 expect_dirty =
true;
1751 callback(*content_context, mock_pass);
1756 auto runtime_stages =
1757 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1758 auto runtime_stage =
1760 ASSERT_TRUE(runtime_stage);
1761 ASSERT_TRUE(runtime_stage->IsDirty());
1763 auto contents = std::make_shared<RuntimeEffectContents>();
1765 contents->SetGeometry(geom.get());
1766 contents->SetRuntimeStage(runtime_stage);
1768 struct FragUniforms {
1772 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1773 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1775 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1776 uniform_data->resize(
sizeof(FragUniforms));
1777 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1778 contents->SetUniformData(uniform_data);
1786 GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
1787 *GetContext(), {GetWindowSize().width, GetWindowSize().height}, 1,
1788 "RuntimeEffect Texture");
1789 testing::MockRenderPass pass(GetContext(), target);
1791 ASSERT_TRUE(contents->Render(*GetContentContext(), entity, pass));
1792 ASSERT_EQ(pass.GetCommands().size(), 1u);
1793 const auto& command = pass.GetCommands()[0];
1794 ASSERT_TRUE(command.pipeline->GetDescriptor()
1795 .GetDepthStencilAttachmentDescriptor()
1797 ASSERT_TRUE(command.pipeline->GetDescriptor()
1798 .GetFrontStencilAttachmentDescriptor()
1803 auto runtime_stages =
1804 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1805 auto runtime_stage =
1807 ASSERT_TRUE(runtime_stage);
1808 ASSERT_TRUE(runtime_stage->IsDirty());
1810 auto contents = std::make_shared<RuntimeEffectContents>();
1811 contents->SetRuntimeStage(runtime_stage);
1813 EXPECT_TRUE(contents->BootstrapShader(*GetContentContext()));
1818 GTEST_SKIP() <<
"Test only applies to Vulkan";
1821 auto runtime_stages =
1822 OpenAssetAsRuntimeStage(
"runtime_stage_example.frag.iplr");
1823 auto runtime_stage =
1825 ASSERT_TRUE(runtime_stage);
1826 ASSERT_TRUE(runtime_stage->IsDirty());
1828 auto contents = std::make_shared<RuntimeEffectContents>();
1830 contents->SetGeometry(geom.get());
1831 contents->SetRuntimeStage(runtime_stage);
1833 struct FragUniforms {
1837 .iResolution =
Vector2(GetWindowSize().width, GetWindowSize().height),
1838 .iTime =
static_cast<Scalar>(GetSecondsElapsed()),
1840 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
1841 uniform_data->resize(
sizeof(FragUniforms));
1842 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
1845 uniform_data, GetContentContext()->GetTransientsBuffer(),
1846 runtime_stage->GetUniforms()[0]);
1856 auto image = CreateTextureForFixture(
"boston.jpg");
1866 return entity.
Render(context, pass);
1868 ASSERT_TRUE(OpenPlaygroundHere(callback));
1872 auto image = CreateTextureForFixture(
"boston.jpg");
1882 return entity.
Render(context, pass);
1884 ASSERT_TRUE(OpenPlaygroundHere(callback));
1888 auto image = CreateTextureForFixture(
"boston.jpg");
1898 return entity.
Render(context, pass);
1900 ASSERT_TRUE(OpenPlaygroundHere(callback));
1904 auto image = CreateTextureForFixture(
"boston.jpg");
1914 return entity.
Render(context, pass);
1916 ASSERT_TRUE(OpenPlaygroundHere(callback));
1920 auto image = CreateTextureForFixture(
"boston.jpg");
1930 return entity.
Render(context, pass);
1932 ASSERT_TRUE(OpenPlaygroundHere(callback));
1951 auto coverage = geometry->GetCoverage(
transform);
1962 EXPECT_TRUE(contents.
IsOpaque(matrix));
1964 EXPECT_FALSE(contents.
IsOpaque(matrix));
1973 EXPECT_FALSE(contents.
IsOpaque(matrix));
1983 EXPECT_FALSE(contents.
IsOpaque(matrix));
1985 EXPECT_FALSE(contents.
IsOpaque(matrix));
1994 EXPECT_FALSE(contents.
IsOpaque(matrix));
2004 EXPECT_TRUE(contents.
IsOpaque(matrix));
2006 EXPECT_FALSE(contents.
IsOpaque(matrix));
2009 EXPECT_FALSE(contents.
IsOpaque(matrix));
2018 EXPECT_FALSE(contents.
IsOpaque(matrix));
2028 EXPECT_TRUE(contents.
IsOpaque(matrix));
2030 EXPECT_FALSE(contents.
IsOpaque(matrix));
2033 EXPECT_FALSE(contents.
IsOpaque(matrix));
2042 EXPECT_FALSE(contents.
IsOpaque(matrix));
2052 EXPECT_TRUE(contents.
IsOpaque(matrix));
2054 EXPECT_FALSE(contents.
IsOpaque(matrix));
2057 EXPECT_FALSE(contents.
IsOpaque(matrix));
2066 EXPECT_FALSE(contents.
IsOpaque(matrix));
2071 auto bay_bridge = CreateTextureForFixture(
"bay_bridge.jpg");
2077 EXPECT_FALSE(contents.
IsOpaque(matrix));
2081 std::vector<Point> points = {{10, 20}, {100, 200}};
2091 auto src_contents = std::make_shared<SolidColorContents>();
2093 src_contents->SetGeometry(src_geom.get());
2096 auto dst_contents = std::make_shared<SolidColorContents>();
2098 dst_contents->SetGeometry(dst_geom.get());
2105 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2117 auto content_context = GetContentContext();
2119 auto default_gyph = content_context->GetGlyphAtlasPipeline({
2121 .has_depth_stencil_attachments =
false,
2123 auto alt_gyph = content_context->GetGlyphAtlasPipeline(
2125 .has_depth_stencil_attachments =
true});
2127 EXPECT_NE(default_gyph, alt_gyph);
2128 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2129 alt_gyph->GetDescriptor().GetSpecializationConstants());
2131 auto use_a8 = GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() ==
2134 std::vector<Scalar> expected_constants = {
static_cast<Scalar>(use_a8)};
2135 EXPECT_EQ(default_gyph->GetDescriptor().GetSpecializationConstants(),
2136 expected_constants);
2140 auto content_context = GetContentContext();
2141 auto default_color_burn = content_context->GetMorphologyFilterPipeline({
2145 auto decal_supported =
static_cast<Scalar>(
2146 GetContext()->GetCapabilities()->SupportsDecalSamplerAddressMode());
2147 std::vector<Scalar> expected_constants = {decal_supported};
2148 ASSERT_EQ(default_color_burn->GetDescriptor().GetSpecializationConstants(),
2149 expected_constants);
2157 auto hash_a = opts.
ToKey();
2160 auto hash_b = opts.
ToKey();
2163 auto hash_c = opts.
ToKey();
2166 auto hash_d = opts.
ToKey();
2168 EXPECT_NE(hash_a, hash_b);
2169 EXPECT_NE(hash_b, hash_c);
2170 EXPECT_NE(hash_c, hash_d);
2187 bool expected_layout =
false;
2189 FragmentShader::kDescriptorSetLayouts) {
2190 if (layout.binding == 64 &&
2192 expected_layout =
true;
2195 EXPECT_TRUE(expected_layout);
2201 testing::MockRenderPass mock_pass(GetContext(), target);
2203 auto get_result = [
this, &mock_pass](
const Path& path) {
2206 return geometry->GetPositionBuffer(*GetContentContext(), {}, mock_pass);
2235 GTEST_SKIP() <<
"Validation is only fatal on Vulkan backend.";
2240 GetContentContext()->GetBlendColorBurnPipeline({
2242 .has_depth_stencil_attachments =
false,
2258 GetContentContext()->GetRenderTargetCache()->CreateOffscreen(
2259 *GetContext(), {1, 1}, 1u);
2260 testing::MockRenderPass render_pass(GetContext(), target);
2261 auto position_result =
2262 geom->GetPositionBuffer(*GetContentContext(), entity, render_pass);
2264 EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u);
2276 auto contents = std::make_shared<SolidColorContents>();
2278 contents->SetGeometry(geom.get());
2285 ASSERT_TRUE(OpenPlaygroundHere(std::move(entity)));
2291 static float alpha = 10;
2292 static float beta = 10;
2293 static float radius = 40;
2294 static int degree = 4;
2297 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2298 ImGui::SliderFloat(
"Alpha", &alpha, 0, 100);
2299 ImGui::SliderFloat(
"Beta", &beta, 0, 100);
2300 ImGui::SliderInt(
"Degreee", °ree, 1, 20);
2301 ImGui::SliderFloat(
"Radius", &radius, 0, 400);
2302 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&color));
2305 auto contents = std::make_shared<SolidColorContents>();
2306 std::unique_ptr<SuperellipseGeometry> geom =
2307 std::make_unique<SuperellipseGeometry>(
Point{400, 400}, radius, degree,
2309 contents->SetColor(color);
2310 contents->SetGeometry(geom.get());
2315 return entity.
Render(context, pass);
2318 ASSERT_TRUE(OpenPlaygroundHere(callback));
2324 static float center[2] = {830, 830};
2325 static float size[2] = {600, 600};
2326 static bool horizontal_symmetry =
true;
2327 static bool vertical_symmetry =
true;
2328 static bool corner_symmetry =
true;
2332 static std::array<float, 2> radius_tl = {200};
2333 static std::array<float, 2> radius_tr;
2334 static std::array<float, 2> radius_bl;
2335 static std::array<float, 2> radius_br;
2337 auto AddRadiusControl = [](std::array<float, 2>& radii,
const char* tb_name,
2338 const char* lr_name) {
2339 std::string name =
"Radius";
2340 if (!horizontal_symmetry || !vertical_symmetry) {
2343 if (!vertical_symmetry) {
2344 name = name +
" " + tb_name;
2346 if (!horizontal_symmetry) {
2347 name = name +
" " + lr_name;
2349 if (corner_symmetry) {
2350 ImGui::SliderFloat(name.c_str(), radii.data(), 0, 1000);
2352 ImGui::SliderFloat2(name.c_str(), radii.data(), 0, 1000);
2356 if (corner_symmetry) {
2357 radius_tl[1] = radius_tl[0];
2358 radius_tr[1] = radius_tr[0];
2359 radius_bl[1] = radius_bl[0];
2360 radius_br[1] = radius_br[0];
2363 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
2365 ImGui::SliderFloat2(
"Center", center, 0, 1000);
2366 ImGui::SliderFloat2(
"Size", size, 0, 1000);
2367 ImGui::Checkbox(
"Symmetry: Horizontal", &horizontal_symmetry);
2368 ImGui::Checkbox(
"Symmetry: Vertical", &vertical_symmetry);
2369 ImGui::Checkbox(
"Symmetry: Corners", &corner_symmetry);
2370 AddRadiusControl(radius_tl,
"Top",
"Left");
2371 if (!horizontal_symmetry) {
2372 AddRadiusControl(radius_tr,
"Top",
"Right");
2374 radius_tr = radius_tl;
2376 if (!vertical_symmetry) {
2377 AddRadiusControl(radius_bl,
"Bottom",
"Left");
2379 radius_bl = radius_tl;
2381 if (!horizontal_symmetry && !vertical_symmetry) {
2382 AddRadiusControl(radius_br,
"Bottom",
"Right");
2384 if (horizontal_symmetry) {
2385 radius_br = radius_bl;
2387 radius_br = radius_tr;
2395 .
top_left = {radius_tl[0], radius_tl[1]},
2396 .top_right = {radius_tr[0], radius_tr[1]},
2397 .bottom_left = {radius_bl[0], radius_bl[1]},
2398 .bottom_right = {radius_br[0], radius_br[1]},
2401 auto contents = std::make_shared<SolidColorContents>();
2402 std::unique_ptr<RoundSuperellipseGeometry> geom =
2403 std::make_unique<RoundSuperellipseGeometry>(
2407 contents->SetGeometry(geom.get());
2412 return entity.
Render(context, pass);
2415 ASSERT_TRUE(OpenPlaygroundHere(callback));
2421 auto result = contents.ApplyColorFilter([](
const Color& color) {
2424 ASSERT_TRUE(result);
2426 Color(0.424452, 0.828743, 0.79105, 0.9375));
2429 #define APPLY_COLOR_FILTER_GRADIENT_TEST(name) \
2430 TEST_P(EntityTest, name##GradientApplyColorFilter) { \
2431 auto contents = name##GradientContents(); \
2432 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.75)}); \
2433 auto result = contents.ApplyColorFilter([](const Color& color) { \
2434 return color.Blend(Color::LimeGreen().WithAlpha(0.75), \
2435 BlendMode::kScreen); \
2437 ASSERT_TRUE(result); \
2439 std::vector<Color> expected = {Color(0.433247, 0.879523, 0.825324, 0.75)}; \
2440 ASSERT_COLORS_NEAR(contents.GetColors(), expected); \
2450 for (
int i = 0; i < 10000; i++) {
2453 Path path = builder.TakePath();
2459 auto cmd_buffer = content_context.
GetContext()->CreateCommandBuffer();
2462 content_context.
GetContext()->GetResourceAllocator());
2466 auto pass = cmd_buffer->CreateRenderPass(render_target);
2469 geom->GetPositionBuffer(content_context, entity, *pass);
2475 Point* written_data =
reinterpret_cast<Point*
>(
2479 std::vector<Point> expected = {
2480 Point(1019.46, 1026.54),
2481 Point(1026.54, 1019.46),
2482 Point(1020.45, 1027.54),
2483 Point(1027.54, 1020.46),
2484 Point(1020.46, 1027.53)
2488 EXPECT_NEAR(point.
x, expected[0].x, 0.1);
2489 EXPECT_NEAR(point.
y, expected[0].y, 0.1);
2492 EXPECT_NEAR(point.
x, expected[1].x, 0.1);
2493 EXPECT_NEAR(point.
y, expected[1].y, 0.1);
2496 EXPECT_NEAR(point.
x, expected[2].x, 0.1);
2497 EXPECT_NEAR(point.
y, expected[2].y, 0.1);
2500 EXPECT_NEAR(point.
x, expected[3].x, 0.1);
2501 EXPECT_NEAR(point.
y, expected[3].y, 0.1);
2504 EXPECT_NEAR(point.
x, expected[4].x, 0.1);
2505 EXPECT_NEAR(point.
y, expected[4].y, 0.1);
2510 for (
int i = 0; i < 10000; i++) {
2513 Path path = builder.TakePath();
2519 GetContext()->GetIdleWaiter());
2522 auto vertex_buffer = tessellator.GenerateLineStrip(path, *host_buffer, 1.0);
2528 Point* written_data =
reinterpret_cast<Point*
>(
2529 (vertex_buffer.vertex_buffer.GetBuffer()->OnGetContents() +
2530 vertex_buffer.vertex_buffer.GetRange().offset));
2532 std::vector<Point> expected = {
2541 EXPECT_NEAR(point.
x, expected[0].x, 0.1);
2542 EXPECT_NEAR(point.
y, expected[0].y, 0.1);
2545 EXPECT_NEAR(point.
x, expected[1].x, 0.1);
2546 EXPECT_NEAR(point.
y, expected[1].y, 0.1);
2549 EXPECT_NEAR(point.
x, expected[2].x, 0.1);
2550 EXPECT_NEAR(point.
y, expected[2].y, 0.1);
2553 EXPECT_NEAR(point.
x, expected[3].x, 0.1);
2554 EXPECT_NEAR(point.
y, expected[3].y, 0.1);
2557 EXPECT_NEAR(point.
x, expected[4].x, 0.1);
2558 EXPECT_NEAR(point.
y, expected[4].y, 0.1);
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)
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
PipelineRef GetSolidFillPipeline(ContentContextOptions opts) const
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
@ 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 > MakeStrokePath(const Path &path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
static std::unique_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
static std::unique_ptr< Geometry > MakeRect(const Rect &rect)
static std::unique_ptr< Geometry > MakeCover()
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter)
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...
PathBuilder & AddRect(Rect rect)
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & LineTo(Point point, bool relative=false)
Insert a line from the current position to point.
PathBuilder & MoveTo(Point point, bool relative=false)
PathBuilder & AddLine(const Point &p1, const Point &p2)
Move to point p1, then insert a line from p1 to p2.
PathBuilder & AddCubicCurve(Point p1, Point cp1, Point cp2, Point p2)
Move to point p1, then insert a cubic curve from p1 to p2 with control points cp1 and cp2.
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
std::optional< Rect > GetBoundingBox() const
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)
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 is created from a stroked path object.
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
static Scalar RoundScaledFontSize(Scalar scale)
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
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 &host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
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
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)
@ 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)
GlyphAtlasPipeline::VertexShader VS
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
GlyphAtlasPipeline::FragmentShader FS
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...
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
constexpr static TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
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...