5 #include "display_list/dl_sampling_options.h"
6 #include "display_list/dl_tile_mode.h"
7 #include "display_list/effects/dl_color_source.h"
8 #include "display_list/effects/dl_mask_filter.h"
11 #include "flutter/display_list/dl_blend_mode.h"
12 #include "flutter/display_list/dl_builder.h"
13 #include "flutter/display_list/dl_color.h"
14 #include "flutter/display_list/dl_paint.h"
15 #include "flutter/display_list/effects/dl_color_filter.h"
16 #include "flutter/display_list/geometry/dl_path_builder.h"
17 #include "flutter/testing/testing.h"
28 DisplayListBuilder builder;
29 builder.Transform(DlMatrix::MakeTranslation(
DlPoint(300, 300)) *
30 DlMatrix::MakeRotationZ(DlDegrees(90)));
32 DlPathBuilder arrow_stem;
33 DlPathBuilder arrow_head;
36 arrow_head.MoveTo(
DlPoint(50, 120))
41 DlColorFilter::MakeBlend(DlColor::kAliceBlue(), DlBlendMode::kSrcIn);
44 paint.setStrokeWidth(15.0);
45 paint.setStrokeCap(DlStrokeCap::kRound);
46 paint.setStrokeJoin(DlStrokeJoin::kRound);
47 paint.setDrawStyle(DlDrawStyle::kStroke);
48 paint.setColorFilter(filter);
49 paint.setColor(DlColor::kBlack());
51 builder.DrawPath(arrow_stem.TakePath(), paint);
52 builder.DrawPath(arrow_head.TakePath(), paint);
54 auto dl = builder.Build();
55 ASSERT_TRUE(OpenPlaygroundHere(dl));
59 DisplayListBuilder builder;
61 paint.setColor(DlColor::kRed());
62 paint.setStrokeWidth(20);
63 paint.setDrawStyle(DlDrawStyle::kStroke);
65 builder.DrawPath(DlPath::MakeLine(
DlPoint(200, 100),
DlPoint(800, 100)),
68 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
72 DisplayListBuilder builder;
74 paint.setColor(DlColor::kRed());
75 paint.setStrokeWidth(25);
76 paint.setDrawStyle(DlDrawStyle::kStroke);
78 builder.DrawPath(DlPath::MakeCircle(
DlPoint(500, 500), 250), paint);
80 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
84 DisplayListBuilder builder;
86 paint.setColor(DlColor::kRed());
87 paint.setStrokeWidth(100);
88 paint.setDrawStyle(DlDrawStyle::kStroke);
90 builder.DrawPath(DlPath::MakeCircle(
DlPoint(100, 100), 50), paint);
92 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
96 DisplayListBuilder builder;
98 paint.setColor(DlColor::kRed());
99 paint.setStrokeWidth(0.01);
100 paint.setDrawStyle(DlDrawStyle::kStroke);
102 builder.DrawPath(DlPath::MakeCircle(
DlPoint(100, 100), 50), paint);
104 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
108 DisplayListBuilder builder;
110 paint.setColor(DlColor::kRed());
111 paint.setStrokeWidth(200);
112 paint.setDrawStyle(DlDrawStyle::kStroke);
114 DlPath path = DlPath::MakeArc(DlRect::MakeXYWH(100, 100, 200, 200),
115 DlDegrees(0), DlDegrees(90),
false);
117 builder.DrawPath(path, paint);
119 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
123 DisplayListBuilder builder;
126 paint.setColor(DlColor::kRed());
127 paint.setStrokeWidth(20);
128 paint.setDrawStyle(DlDrawStyle::kStroke);
130 DlPathBuilder path_builder;
131 path_builder.MoveTo(
DlPoint(0, 200));
135 builder.DrawPath(path_builder.TakePath(), paint);
136 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
140 DisplayListBuilder builder;
143 paint.setColor(DlColor::kRed());
144 paint.setStrokeWidth(50);
145 paint.setDrawStyle(DlDrawStyle::kStroke);
146 paint.setStrokeCap(DlStrokeCap::kRound);
150 DlPathBuilder path_builder;
151 path_builder.MoveTo(
DlPoint(250, 250));
152 path_builder.QuadraticCurveTo(
DlPoint(100, 100),
DlPoint(250, 250));
154 builder.DrawPath(path_builder.TakePath(), paint);
156 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
160 DisplayListBuilder builder;
161 builder.Scale(GetContentScale().
x, GetContentScale().y);
164 paint.setColor(DlColor::kRed());
165 paint.setDrawStyle(DlDrawStyle::kFill);
167 DlPaint reference_paint;
168 reference_paint.setColor(DlColor::kGreen());
169 reference_paint.setDrawStyle(DlDrawStyle::kFill);
171 DlPathBuilder path_builder;
172 DlPathBuilder reference_builder;
175 path_builder.MoveTo(
DlPoint(100, 100));
176 path_builder.ConicCurveTo(
DlPoint(150, 150),
DlPoint(200, 100), 1.0f);
177 reference_builder.MoveTo(
DlPoint(300, 100));
178 reference_builder.QuadraticCurveTo(
DlPoint(350, 150),
DlPoint(400, 100));
181 path_builder.MoveTo(
DlPoint(100, 200));
183 reference_builder.MoveTo(
DlPoint(300, 200));
184 auto magic = DlPathBuilder::kArcApproximationMagic;
185 reference_builder.CubicCurveTo(
DlPoint(300, 200) +
DlPoint(50, 50) * magic,
190 path_builder.MoveTo(
DlPoint(100, 300));
191 path_builder.ConicCurveTo(
DlPoint(150, 350),
DlPoint(200, 300), 0.01f);
192 reference_builder.MoveTo(
DlPoint(300, 300));
193 reference_builder.LineTo(
DlPoint(350, 300.5));
194 reference_builder.LineTo(
DlPoint(400, 300));
197 path_builder.MoveTo(
DlPoint(100, 400));
198 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 400), 100.0f);
199 reference_builder.MoveTo(
DlPoint(300, 400));
200 reference_builder.LineTo(
DlPoint(350, 450));
201 reference_builder.LineTo(
DlPoint(400, 400));
203 builder.DrawPath(path_builder.TakePath(), paint);
204 builder.DrawPath(reference_builder.TakePath(), reference_paint);
206 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
210 DisplayListBuilder builder;
211 builder.Scale(GetContentScale().
x, GetContentScale().y);
214 paint.setColor(DlColor::kRed());
215 paint.setStrokeWidth(10);
216 paint.setDrawStyle(DlDrawStyle::kStroke);
217 paint.setStrokeCap(DlStrokeCap::kRound);
218 paint.setStrokeJoin(DlStrokeJoin::kRound);
220 DlPaint reference_paint;
221 reference_paint.setColor(DlColor::kGreen());
222 reference_paint.setStrokeWidth(10);
223 reference_paint.setDrawStyle(DlDrawStyle::kStroke);
224 reference_paint.setStrokeCap(DlStrokeCap::kRound);
225 reference_paint.setStrokeJoin(DlStrokeJoin::kRound);
227 DlPathBuilder path_builder;
228 DlPathBuilder reference_builder;
231 path_builder.MoveTo(
DlPoint(100, 100));
232 path_builder.ConicCurveTo(
DlPoint(150, 150),
DlPoint(200, 100), 1.0f);
233 reference_builder.MoveTo(
DlPoint(300, 100));
234 reference_builder.QuadraticCurveTo(
DlPoint(350, 150),
DlPoint(400, 100));
237 path_builder.MoveTo(
DlPoint(100, 200));
239 reference_builder.MoveTo(
DlPoint(300, 200));
240 auto magic = DlPathBuilder::kArcApproximationMagic;
241 reference_builder.CubicCurveTo(
DlPoint(300, 200) +
DlPoint(50, 50) * magic,
246 path_builder.MoveTo(
DlPoint(100, 300));
247 path_builder.ConicCurveTo(
DlPoint(150, 350),
DlPoint(200, 300), 0.0f);
248 reference_builder.MoveTo(
DlPoint(300, 300));
249 reference_builder.LineTo(
DlPoint(400, 300));
252 path_builder.MoveTo(
DlPoint(100, 400));
253 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 400), 100.0f);
254 reference_builder.MoveTo(
DlPoint(300, 400));
255 reference_builder.LineTo(
DlPoint(350, 450));
256 reference_builder.LineTo(
DlPoint(400, 400));
258 builder.DrawPath(path_builder.TakePath(), paint);
259 builder.DrawPath(reference_builder.TakePath(), reference_paint);
261 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
269 auto callback = [&]() -> sk_sp<DisplayList> {
271 ImGuiWindowFlags_AlwaysAutoResize)) {
272 ImGui::SliderFloat(
"Scale", &scale, 0, 6);
273 ImGui::SliderFloat(
"Rotate", &rotation, 0, 90);
274 ImGui::SliderFloat(
"Offset", &offset, 0, 2);
275 ImGui::SliderFloat(
"Width", &width, 0, 2);
279 DisplayListBuilder builder;
280 builder.Scale(GetContentScale().
x, GetContentScale().y);
281 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
284 paint.setStrokeWidth(width);
285 paint.setColor(DlColor::kWhite());
286 paint.setStrokeCap(DlStrokeCap::kRound);
287 paint.setStrokeJoin(DlStrokeJoin::kRound);
288 paint.setDrawStyle(DlDrawStyle::kStroke);
290 builder.Translate(512, 384);
291 builder.Scale(scale, scale);
292 builder.Rotate(rotation);
293 builder.Translate(-512, -384 + offset);
295 for (
int i = 0; i < 5; ++i) {
296 Scalar yoffset = i * 25.25f + 300.f;
297 DlPathBuilder path_builder;
299 path_builder.MoveTo(
DlPoint(100, yoffset));
300 path_builder.LineTo(
DlPoint(924, yoffset));
301 builder.DrawPath(path_builder.TakePath(), paint);
304 return builder.Build();
307 ASSERT_TRUE(OpenPlaygroundHere(callback));
314 auto callback = [&]() -> sk_sp<DisplayList> {
316 ImGuiWindowFlags_AlwaysAutoResize)) {
317 ImGui::SliderFloat(
"Scale", &scale, 0, 6);
318 ImGui::SliderFloat(
"Rotate", &rotation, 0, 90);
319 ImGui::SliderFloat(
"Offset", &offset, 0, 2);
323 DisplayListBuilder builder;
324 builder.Scale(GetContentScale().
x, GetContentScale().y);
325 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
328 paint.setStrokeWidth(0.f);
329 paint.setColor(DlColor::kWhite());
331 builder.Translate(512, 384);
332 builder.Scale(scale, scale);
333 builder.Rotate(rotation);
334 builder.Translate(-512, -384 + offset);
336 for (
int i = 0; i < 5; ++i) {
337 Scalar yoffset = i * 25.25f + 300.f;
339 builder.DrawLine(
DlPoint(100, yoffset),
DlPoint(924, yoffset), paint);
342 return builder.Build();
345 ASSERT_TRUE(OpenPlaygroundHere(callback));
349 DisplayListBuilder builder;
350 builder.Scale(GetContentScale().
x, GetContentScale().y);
353 paint.setColor(DlColor::kRed());
354 paint.setDrawStyle(DlDrawStyle::kFill);
356 DlPaint reference_paint;
357 reference_paint.setColor(DlColor::kGreen());
358 reference_paint.setDrawStyle(DlDrawStyle::kFill);
360 DlPathBuilder path_builder;
362 path_builder.MoveTo(
DlPoint(100, 100));
363 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 100), 5.0f);
365 DlPathBuilder reference_builder;
370 reference_builder.MoveTo(component.p1);
371 constexpr
int N = 100;
372 for (
int i = 1; i < N; i++) {
373 reference_builder.LineTo(component.Solve(
static_cast<Scalar>(i) / N));
375 reference_builder.LineTo(component.p2);
378 line_paint.setColor(DlColor::kYellow());
379 line_paint.setDrawStyle(DlDrawStyle::kStroke);
380 line_paint.setStrokeWidth(1.0f);
384 builder.DrawLine(
DlPoint(145, 100),
DlPoint(145, 450), line_paint);
385 builder.DrawLine(
DlPoint(155, 100),
DlPoint(155, 450), line_paint);
386 builder.DrawLine(
DlPoint(345, 100),
DlPoint(345, 450), line_paint);
387 builder.DrawLine(
DlPoint(355, 100),
DlPoint(355, 450), line_paint);
388 builder.DrawLine(
DlPoint(100, 392.5f),
DlPoint(400, 392.5f), line_paint);
391 builder.DrawPath(path_builder.TakePath(), paint);
392 builder.DrawPath(reference_builder.TakePath(), reference_paint);
394 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
398 DisplayListBuilder builder;
401 paint.setColor(DlColor::kRed());
405 .top_right = {25, 50},
406 .bottom_left = {25, 50},
407 .bottom_right = {50, 25},
409 DlPathBuilder path_builder;
411 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 200, 200), radii);
414 path_builder.AddPath(DlPath::MakeRoundRect(rrect));
415 path_builder.AddPath(DlPath::MakeCircle(
DlPoint(200, 200), 50));
416 path_builder.SetFillType(DlPathFillType::kOdd);
417 DlPath path = path_builder.TakePath();
422 builder.DrawPath(path, paint);
424 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
431 DisplayListBuilder builder;
437 DlPathBuilder path_builder;
438 path_builder.MoveTo(
DlPoint(50, 50));
439 path_builder.LineTo(
DlPoint(50, 100));
440 path_builder.LineTo(
DlPoint(100, 100));
441 path_builder.LineTo(
DlPoint(100, 50));
444 paint.setColor(DlColor::kRed());
445 paint.setDrawStyle(DlDrawStyle::kStroke);
446 paint.setStrokeWidth(10);
448 builder.DrawPath(path_builder.TakePath(), paint);
450 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
454 DisplayListBuilder builder;
458 DlPathBuilder path_builder;
459 path_builder.MoveTo(
DlPoint(50, 50));
460 path_builder.LineTo(
DlPoint(520, 120));
461 path_builder.LineTo(
DlPoint(300, 310));
462 path_builder.LineTo(
DlPoint(100, 50));
463 path_builder.Close();
466 paint.setColor(DlColor::kRed());
467 paint.setDrawStyle(DlDrawStyle::kStroke);
468 paint.setStrokeWidth(10);
470 builder.DrawPath(path_builder.TakePath(), paint);
472 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
477 auto callback = [&]() -> sk_sp<DisplayList> {
479 static float scale = 3;
480 static bool add_circle_clip =
true;
483 ImGuiWindowFlags_AlwaysAutoResize)) {
484 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&color));
485 ImGui::SliderFloat(
"Scale", &scale, 0, 6);
486 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
490 DisplayListBuilder builder;
491 builder.Scale(GetContentScale().
x, GetContentScale().y);
494 paint.setColor(DlColor::kWhite());
495 builder.DrawPaint(paint);
499 paint.setDrawStyle(DlDrawStyle::kStroke);
500 paint.setStrokeWidth(10);
502 DlPathBuilder path_builder;
503 path_builder.MoveTo(
DlPoint(20, 20));
505 path_builder.Close();
506 path_builder.MoveTo(
DlPoint(60, 20));
508 DlPath path = path_builder.TakePath();
510 builder.Scale(scale, scale);
512 if (add_circle_clip) {
517 auto [handle_a, handle_b] =
520 Matrix screen_to_canvas = builder.GetMatrix();
524 screen_to_canvas = screen_to_canvas.
Invert();
526 Point point_a = screen_to_canvas * handle_a;
527 Point point_b = screen_to_canvas * handle_b;
529 Point middle = point_a + point_b;
530 middle *= GetContentScale().
x / 2;
534 builder.ClipPath(DlPath::MakeCircle(middle, radius));
538 {DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
539 paint.setStrokeJoin(join);
541 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
542 paint.setStrokeCap(cap);
543 builder.DrawPath(path, paint);
544 builder.Translate(80, 0);
546 builder.Translate(-240, 60);
549 return builder.Build();
552 ASSERT_TRUE(OpenPlaygroundHere(callback));
556 DisplayListBuilder builder;
557 builder.Scale(GetContentScale().
x, GetContentScale().y);
560 paint.setColor(DlColor::kBlue());
561 paint.setStrokeWidth(10);
563 auto draw = [&builder](DlPaint& paint) {
565 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
566 paint.setStrokeCap(cap);
569 for (
int d = 15; d < 90; d += 15) {
571 Point origin = {100, 100};
574 auto a = origin + m * p0;
575 auto b = origin + m *
p1;
577 builder.DrawLine(a,
b, paint);
580 builder.DrawCircle(origin, 35, paint);
584 builder.Translate(250, 0);
586 builder.Translate(-750, 250);
589 std::vector<DlColor> colors = {
590 DlColor::ARGB(1, 0x1f / 255.0, 0.0, 0x5c / 255.0),
591 DlColor::ARGB(1, 0x5b / 255.0, 0.0, 0x60 / 255.0),
592 DlColor::ARGB(1, 0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0),
593 DlColor::ARGB(1, 0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0),
594 DlColor::ARGB(1, 0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0),
595 DlColor::ARGB(1, 0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0),
596 DlColor::ARGB(1, 0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0)};
597 std::vector<Scalar> stops = {
608 CreateTextureForFixture(
"airplane.jpg",
613 paint.setColorSource(DlColorSource::MakeRadial({100, 100}, 200, stops.size(),
614 colors.data(), stops.data(),
615 DlTileMode::kMirror));
618 DlMatrix matrix = DlMatrix::MakeTranslation({-150, 75});
619 paint.setColorSource(DlColorSource::MakeImage(
620 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
621 DlImageSampling::kMipmapLinear, &matrix));
624 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
633 auto callback = [&]() -> sk_sp<DisplayList> {
635 ImGuiWindowFlags_AlwaysAutoResize)) {
636 ImGui::SliderFloat(
"Scale", &scale, 0.001, 5);
637 ImGui::SliderFloat(
"Width", &line_width, 1, 20);
641 DisplayListBuilder builder;
642 builder.Scale(GetContentScale().
x, GetContentScale().y);
644 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
648 paint.setColor(DlColor::kGreenYellow());
649 paint.setStrokeWidth(line_width);
655 builder.Translate(100, 300);
656 builder.Scale(scale, scale);
657 builder.Translate(-100, -300);
665 paint.setColor(DlColor::kGreenYellow());
666 paint.setStrokeWidth(2.0);
669 builder.Translate(100, 500);
670 builder.Scale(0.2, 0.2);
671 builder.Translate(-100, -500);
677 return builder.Build();
679 ASSERT_TRUE(OpenPlaygroundHere(callback));
684 float line_width = 10.f;
685 float rotation = 0.f;
687 auto callback = [&]() -> sk_sp<DisplayList> {
689 ImGuiWindowFlags_AlwaysAutoResize)) {
691 ImGui::SliderFloat(
"Scale", &scale, 0.001f, 5.0f);
692 ImGui::SliderFloat(
"Width", &line_width, 1.0f, 20.0f);
693 ImGui::SliderFloat(
"Rotation", &rotation, 0.0f, 180.0f);
697 DisplayListBuilder builder;
698 builder.Scale(
static_cast<float>(GetContentScale().
x),
699 static_cast<float>(GetContentScale().y));
701 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
707 hex_paint.setStrokeWidth(line_width);
713 float r_sin60 = r * std::sqrt(3.0f) / 2.0f;
714 float r_cos60 = r / 2.0f;
724 DlPoint(cx + r_cos60, cy + r_sin60);
727 builder.Translate(cx, cy);
728 builder.Scale(scale, scale);
729 builder.Rotate(rotation);
730 builder.Translate(-cx, -cy);
732 builder.DrawLine(v0, v1, hex_paint);
733 builder.DrawLine(v1, v2, hex_paint);
734 builder.DrawLine(v2, v3, hex_paint);
735 builder.DrawLine(v3, v4, hex_paint);
736 builder.DrawLine(v4, v5, hex_paint);
737 builder.DrawLine(v5, v0, hex_paint);
740 return builder.Build();
742 ASSERT_TRUE(OpenPlaygroundHere(callback));
746 DisplayListBuilder builder;
747 builder.Scale(GetContentScale().
x, GetContentScale().y);
749 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
752 paint.setColor(DlColor::kGreenYellow());
753 paint.setStrokeWidth(10);
755 auto draw = [&builder](DlPaint& paint) {
757 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
758 paint.setStrokeCap(cap);
761 for (
int d = 15; d < 90; d += 15) {
763 Point origin = {100, 100};
766 auto a = origin + m * p0;
767 auto b = origin + m *
p1;
769 builder.DrawLine(a,
b, paint);
772 builder.DrawCircle(origin, 35, paint);
776 builder.Translate(250, 0);
778 builder.Translate(-750, 250);
783 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
787 DisplayListBuilder builder;
789 paint.setColor(DlColor::kRed());
790 paint.setDrawStyle(DlDrawStyle::kStroke);
791 paint.setStrokeWidth(10);
793 builder.Translate(100, 100);
794 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
796 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
800 DisplayListBuilder builder;
802 paint.setColor(DlColor::kRed());
803 paint.setDrawStyle(DlDrawStyle::kStroke);
804 paint.setStrokeWidth(10);
805 paint.setStrokeJoin(DlStrokeJoin::kBevel);
807 builder.Translate(100, 100);
808 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
810 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
814 DlPathBuilder path_builder;
815 for (
auto i = 0; i < 10; i++) {
820 DlPath::MakeCircle(
DlPoint(100 + 50 * i, 100 + 50 * i), 100);
821 path_builder.AddPath(circle);
822 path_builder.Close();
824 path_builder.MoveTo(
DlPoint(100.f + 50.f * i - 100, 100.f + 50.f * i));
825 path_builder.LineTo(
DlPoint(100.f + 50.f * i, 100.f + 50.f * i - 100));
826 path_builder.LineTo(
DlPoint(100.f + 50.f * i - 100,
827 100.f + 50.f * i - 100));
828 path_builder.Close();
831 DlPath path = path_builder.TakePath();
833 DisplayListBuilder builder;
835 paint.setColor(DlColor::kRed().withAlpha(102));
836 builder.DrawPath(path, paint);
838 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
842 DisplayListBuilder builder;
843 builder.Scale(GetContentScale().
x, GetContentScale().y);
846 paint.setColor(DlColor::kRed());
848 std::vector<DlColor> colors = {DlColor::RGBA(1.0, 0.0, 0.0, 1.0),
849 DlColor::RGBA(0.0, 0.0, 0.0, 1.0)};
850 std::vector<Scalar> stops = {0.0, 1.0};
852 paint.setColorSource(
853 DlColorSource::MakeSweep({100, 100}, 45, 135, stops.size(), colors.data(),
854 stops.data(), DlTileMode::kMirror));
855 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
857 DlPathBuilder path_builder;
858 path_builder.AddArc(DlRect::MakeXYWH(10, 10, 100, 100),
859 DlDegrees(0), DlDegrees(0));
860 builder.DrawPath(path_builder.TakePath(), paint);
867 DisplayListBuilder builder;
869 paint.setColor(DlColor::kFuchsia());
871 builder.ClipPath(DlPath::MakeRect(DlRect::MakeXYWH(0, 0, 500, 500)));
872 builder.DrawPath(DlPath::MakeCircle(
DlPoint(500, 500), 250), paint);
874 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
882 auto callback = [&]() -> sk_sp<DisplayList> {
884 ImGuiWindowFlags_AlwaysAutoResize)) {
885 ImGui::SliderFloat(
"Stroke Width", &stroke_width, 1, 300);
886 ImGui::SliderFloat(
"Aspect", &aspect, 0.5, 2.0);
887 ImGui::SliderFloat(
"Start Angle", &start_angle, 0, 360);
888 ImGui::SliderFloat(
"End Angle", &end_angle, 0, 360);
892 DisplayListBuilder builder;
894 grey_paint.setColor(DlColor(0xff111111));
895 builder.DrawPaint(grey_paint);
898 white_paint.setColor(DlColor::kWhite());
899 white_paint.setStrokeWidth(stroke_width);
900 white_paint.setDrawStyle(DlDrawStyle::kStroke);
902 red_paint.setColor(DlColor::kRed());
905 builder.DrawRect(rect, red_paint);
906 builder.DrawArc(rect, start_angle, end_angle,
909 builder.DrawLine(
Point(frontier, 0),
Point(frontier, 150), red_paint);
911 return builder.Build();
913 ASSERT_TRUE(OpenPlaygroundHere(callback));
917 DisplayListBuilder builder;
920 paint.setColor(DlColor::kRed());
924 .top_right = DlSize(50, 50),
925 .bottom_left = DlSize(50, 50),
926 .bottom_right = DlSize(50, 50),
929 const Scalar kTriangleHeight = 100;
931 DlRect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f,
932 kTriangleHeight, kTriangleHeight),
937 DlPath rrect_path = DlPath::MakeRoundRect(rrect);
939 builder.Translate(200, 200);
943 DlPathBuilder path_builder;
944 path_builder.MoveTo(
DlPoint(0, kTriangleHeight));
945 path_builder.LineTo(
DlPoint(-kTriangleHeight / 2.0f, 0));
946 path_builder.LineTo(
DlPoint(kTriangleHeight / 2.0f, 0));
947 path_builder.Close();
948 path_builder.AddPath(rrect_path);
950 builder.DrawPath(path_builder.TakePath(), paint);
952 builder.Translate(100, 0);
955 DlPathBuilder path_builder;
956 path_builder.MoveTo(
DlPoint(0, kTriangleHeight));
957 path_builder.LineTo(
DlPoint(-kTriangleHeight / 2.0f, 0));
958 path_builder.LineTo(
DlPoint(0, -10));
959 path_builder.LineTo(
DlPoint(kTriangleHeight / 2.0f, 0));
960 path_builder.Close();
961 path_builder.AddPath(rrect_path);
963 builder.DrawPath(path_builder.TakePath(), paint);
966 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
970 DisplayListBuilder builder;
973 paint.setColor(DlColor::kRed());
974 paint.setDrawStyle(DlDrawStyle::kStroke);
975 paint.setStrokeWidth(15.0);
976 paint.setStrokeCap(DlStrokeCap::kRound);
978 DlPathBuilder path_builder;
979 path_builder.MoveTo(
DlPoint(100, 100));
980 path_builder.LineTo(
DlPoint(150, 150));
981 path_builder.MoveTo(
DlPoint(200, 200));
982 path_builder.LineTo(
DlPoint(200, 200));
984 builder.DrawPath(path_builder.TakePath(), paint);
986 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
990 DisplayListBuilder builder;
991 builder.Scale(GetContentScale().
x, GetContentScale().y);
993 builder.Translate(100, 0);
996 for (
auto cap : std::vector<DlStrokeCap>{
997 DlStrokeCap::kButt, DlStrokeCap::kRound, DlStrokeCap::kSquare}) {
998 DlPathBuilder path_builder;
999 path_builder.MoveTo({20, 50});
1000 path_builder.LineTo({50, 50});
1001 path_builder.MoveTo({120, 50});
1002 path_builder.LineTo({120, 80});
1003 path_builder.MoveTo({180, 50});
1004 path_builder.LineTo({180, 50});
1005 DlPath path = path_builder.TakePath();
1008 paint.setColor(DlColor::kRed());
1009 paint.setDrawStyle(DlDrawStyle::kStroke);
1010 paint.setStrokeWidth(20.0f);
1011 paint.setStrokeCap(cap);
1012 paint.setStrokeJoin(DlStrokeJoin::kBevel);
1014 builder.DrawPath(path, paint);
1016 paint.setColor(DlColor::kYellow());
1017 paint.setStrokeWidth(1.0f);
1018 paint.setStrokeCap(DlStrokeCap::kButt);
1020 builder.DrawPath(path, paint);
1022 builder.Translate(250, 0);
1026 builder.Translate(0, 100);
1029 for (
auto join : std::vector<DlStrokeJoin>{
1030 DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
1031 DlPathBuilder path_builder;
1032 path_builder.MoveTo({20, 50});
1033 path_builder.LineTo({50, 50});
1034 path_builder.LineTo({80, 50});
1035 path_builder.MoveTo({20, 150});
1036 path_builder.LineTo({50, 150});
1037 path_builder.LineTo({50, 180});
1038 path_builder.MoveTo({20, 250});
1039 path_builder.LineTo({50, 250});
1040 path_builder.LineTo({70, 270});
1041 path_builder.MoveTo({20, 350});
1042 path_builder.LineTo({50, 350});
1043 path_builder.LineTo({30, 370});
1044 path_builder.MoveTo({20, 450});
1045 path_builder.LineTo({50, 450});
1046 path_builder.LineTo({20, 450});
1047 path_builder.MoveTo({120, 80});
1048 path_builder.LineTo({150, 80});
1049 path_builder.LineTo({180, 80});
1050 path_builder.MoveTo({120, 180});
1051 path_builder.LineTo({150, 180});
1052 path_builder.LineTo({150, 150});
1053 path_builder.MoveTo({120, 280});
1054 path_builder.LineTo({150, 280});
1055 path_builder.LineTo({170, 260});
1056 path_builder.MoveTo({120, 380});
1057 path_builder.LineTo({150, 380});
1058 path_builder.LineTo({130, 360});
1059 path_builder.MoveTo({120, 480});
1060 path_builder.LineTo({150, 480});
1061 path_builder.LineTo({120, 480});
1062 DlPath path = path_builder.TakePath();
1066 paint.setColor(DlColor::kRed());
1067 paint.setDrawStyle(DlDrawStyle::kStroke);
1068 paint.setStrokeWidth(20.0f);
1069 paint.setStrokeCap(DlStrokeCap::kSquare);
1070 paint.setStrokeJoin(join);
1071 builder.DrawPath(path, paint);
1073 paint.setColor(DlColor::kYellow());
1074 paint.setStrokeWidth(1.0f);
1075 paint.setStrokeCap(DlStrokeCap::kButt);
1076 builder.DrawPath(path, paint);
1078 builder.Translate(250, 0);
1082 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1086 DisplayListBuilder builder;
1088 paint.setColor(DlColor::kGreen());
1089 paint.setDrawStyle(DlDrawStyle::kStroke);
1090 paint.setStrokeWidth(30);
1091 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5));
1093 builder.DrawCircle(
DlPoint(200, 200), 100, paint);
1095 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
TEST_P(AiksTest, DrawAtlasNoColor)
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
constexpr float kSqrt2Over2
flutter::DlRoundRect DlRoundRect
flutter::DlScalar DlScalar
static constexpr Color Black()
constexpr Color WithAlpha(Scalar new_alpha) const
static constexpr Color Red()
A 4x4 matrix using column-major storage.
bool IsInvertible() const
static Matrix MakeRotationZ(Radians r)
constexpr Type GetDistance(const TPoint &p) const
constexpr auto GetRight() const
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)