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/testing/testing.h"
26 DisplayListBuilder builder;
27 builder.Transform(DlMatrix::MakeTranslation(
DlPoint(300, 300)) *
28 DlMatrix::MakeRotationZ(DlDegrees(90)));
30 DlPathBuilder arrow_stem;
31 DlPathBuilder arrow_head;
34 arrow_head.MoveTo(
DlPoint(50, 120))
39 DlColorFilter::MakeBlend(DlColor::kAliceBlue(), DlBlendMode::kSrcIn);
42 paint.setStrokeWidth(15.0);
43 paint.setStrokeCap(DlStrokeCap::kRound);
44 paint.setStrokeJoin(DlStrokeJoin::kRound);
45 paint.setDrawStyle(DlDrawStyle::kStroke);
46 paint.setColorFilter(filter);
47 paint.setColor(DlColor::kBlack());
49 builder.DrawPath(
DlPath(arrow_stem), paint);
50 builder.DrawPath(
DlPath(arrow_head), paint);
52 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
56 DisplayListBuilder builder;
58 paint.setColor(DlColor::kRed());
59 paint.setStrokeWidth(20);
60 paint.setDrawStyle(DlDrawStyle::kStroke);
62 builder.DrawPath(DlPath::MakeLine(
DlPoint(200, 100),
DlPoint(800, 100)),
65 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
69 DisplayListBuilder builder;
71 paint.setColor(DlColor::kRed());
72 paint.setStrokeWidth(25);
73 paint.setDrawStyle(DlDrawStyle::kStroke);
75 builder.DrawPath(DlPath::MakeCircle(
DlPoint(500, 500), 250), paint);
77 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
81 DisplayListBuilder builder;
83 paint.setColor(DlColor::kRed());
84 paint.setStrokeWidth(100);
85 paint.setDrawStyle(DlDrawStyle::kStroke);
87 builder.DrawPath(DlPath::MakeCircle(
DlPoint(100, 100), 50), paint);
89 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
93 DisplayListBuilder builder;
95 paint.setColor(DlColor::kRed());
96 paint.setStrokeWidth(0.01);
97 paint.setDrawStyle(DlDrawStyle::kStroke);
99 builder.DrawPath(DlPath::MakeCircle(
DlPoint(100, 100), 50), paint);
101 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
105 DisplayListBuilder builder;
107 paint.setColor(DlColor::kRed());
108 paint.setStrokeWidth(200);
109 paint.setDrawStyle(DlDrawStyle::kStroke);
111 DlPath path = DlPath::MakeArc(DlRect::MakeXYWH(100, 100, 200, 200),
112 DlDegrees(0), DlDegrees(90),
false);
114 builder.DrawPath(path, paint);
116 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
120 DisplayListBuilder builder;
123 paint.setColor(DlColor::kRed());
124 paint.setStrokeWidth(20);
125 paint.setDrawStyle(DlDrawStyle::kStroke);
127 DlPathBuilder path_builder;
128 path_builder.MoveTo(
DlPoint(0, 200));
132 builder.DrawPath(
DlPath(path_builder), paint);
133 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
137 DisplayListBuilder builder;
140 paint.setColor(DlColor::kRed());
141 paint.setStrokeWidth(50);
142 paint.setDrawStyle(DlDrawStyle::kStroke);
143 paint.setStrokeCap(DlStrokeCap::kRound);
147 DlPathBuilder path_builder;
148 path_builder.MoveTo(
DlPoint(250, 250));
149 path_builder.QuadraticCurveTo(
DlPoint(100, 100),
DlPoint(250, 250));
151 builder.DrawPath(
DlPath(path_builder), paint);
153 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
157 DisplayListBuilder builder;
158 builder.Scale(GetContentScale().
x, GetContentScale().y);
161 paint.setColor(DlColor::kRed());
162 paint.setDrawStyle(DlDrawStyle::kFill);
164 DlPaint reference_paint;
165 reference_paint.setColor(DlColor::kGreen());
166 reference_paint.setDrawStyle(DlDrawStyle::kFill);
168 DlPathBuilder path_builder;
169 DlPathBuilder reference_builder;
172 path_builder.MoveTo(
DlPoint(100, 100));
173 path_builder.ConicCurveTo(
DlPoint(150, 150),
DlPoint(200, 100), 1.0f);
174 reference_builder.MoveTo(
DlPoint(300, 100));
175 reference_builder.QuadraticCurveTo(
DlPoint(350, 150),
DlPoint(400, 100));
178 path_builder.MoveTo(
DlPoint(100, 200));
180 reference_builder.MoveTo(
DlPoint(300, 200));
181 auto magic = DlPathBuilder::kArcApproximationMagic;
182 reference_builder.CubicCurveTo(
DlPoint(300, 200) +
DlPoint(50, 50) * magic,
187 path_builder.MoveTo(
DlPoint(100, 300));
188 path_builder.ConicCurveTo(
DlPoint(150, 350),
DlPoint(200, 300), 0.01f);
189 reference_builder.MoveTo(
DlPoint(300, 300));
190 reference_builder.LineTo(
DlPoint(350, 300.5));
191 reference_builder.LineTo(
DlPoint(400, 300));
194 path_builder.MoveTo(
DlPoint(100, 400));
195 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 400), 100.0f);
196 reference_builder.MoveTo(
DlPoint(300, 400));
197 reference_builder.LineTo(
DlPoint(350, 450));
198 reference_builder.LineTo(
DlPoint(400, 400));
200 builder.DrawPath(
DlPath(path_builder), paint);
201 builder.DrawPath(
DlPath(reference_builder), reference_paint);
203 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
207 DisplayListBuilder builder;
208 builder.Scale(GetContentScale().
x, GetContentScale().y);
211 paint.setColor(DlColor::kRed());
212 paint.setStrokeWidth(10);
213 paint.setDrawStyle(DlDrawStyle::kStroke);
214 paint.setStrokeCap(DlStrokeCap::kRound);
215 paint.setStrokeJoin(DlStrokeJoin::kRound);
217 DlPaint reference_paint;
218 reference_paint.setColor(DlColor::kGreen());
219 reference_paint.setStrokeWidth(10);
220 reference_paint.setDrawStyle(DlDrawStyle::kStroke);
221 reference_paint.setStrokeCap(DlStrokeCap::kRound);
222 reference_paint.setStrokeJoin(DlStrokeJoin::kRound);
224 DlPathBuilder path_builder;
225 DlPathBuilder reference_builder;
228 path_builder.MoveTo(
DlPoint(100, 100));
229 path_builder.ConicCurveTo(
DlPoint(150, 150),
DlPoint(200, 100), 1.0f);
230 reference_builder.MoveTo(
DlPoint(300, 100));
231 reference_builder.QuadraticCurveTo(
DlPoint(350, 150),
DlPoint(400, 100));
234 path_builder.MoveTo(
DlPoint(100, 200));
236 reference_builder.MoveTo(
DlPoint(300, 200));
237 auto magic = DlPathBuilder::kArcApproximationMagic;
238 reference_builder.CubicCurveTo(
DlPoint(300, 200) +
DlPoint(50, 50) * magic,
243 path_builder.MoveTo(
DlPoint(100, 300));
244 path_builder.ConicCurveTo(
DlPoint(150, 350),
DlPoint(200, 300), 0.0f);
245 reference_builder.MoveTo(
DlPoint(300, 300));
246 reference_builder.LineTo(
DlPoint(400, 300));
249 path_builder.MoveTo(
DlPoint(100, 400));
250 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 400), 100.0f);
251 reference_builder.MoveTo(
DlPoint(300, 400));
252 reference_builder.LineTo(
DlPoint(350, 450));
253 reference_builder.LineTo(
DlPoint(400, 400));
255 builder.DrawPath(
DlPath(path_builder), paint);
256 builder.DrawPath(
DlPath(reference_builder), reference_paint);
258 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
265 auto callback = [&]() -> sk_sp<DisplayList> {
267 ImGuiWindowFlags_AlwaysAutoResize)) {
268 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
269 ImGui::SliderFloat(
"Rotate", &rotation, 0, 90);
270 ImGui::SliderFloat(
"Offset", &
offset, 0, 2);
274 DisplayListBuilder builder;
275 builder.Scale(GetContentScale().
x, GetContentScale().y);
276 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
279 paint.setStrokeWidth(0.f);
280 paint.setColor(DlColor::kWhite());
281 paint.setStrokeCap(DlStrokeCap::kRound);
282 paint.setStrokeJoin(DlStrokeJoin::kRound);
283 paint.setDrawStyle(DlDrawStyle::kStroke);
285 builder.Translate(512, 384);
287 builder.Rotate(rotation);
288 builder.Translate(-512, -384 +
offset);
290 for (
int i = 0; i < 5; ++i) {
291 Scalar yoffset = i * 25.25f + 300.f;
292 DlPathBuilder path_builder;
294 path_builder.MoveTo(
DlPoint(100, yoffset));
295 path_builder.LineTo(
DlPoint(924, yoffset));
296 builder.DrawPath(
DlPath(path_builder), paint);
299 return builder.Build();
302 ASSERT_TRUE(OpenPlaygroundHere(callback));
309 auto callback = [&]() -> sk_sp<DisplayList> {
311 ImGuiWindowFlags_AlwaysAutoResize)) {
312 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
313 ImGui::SliderFloat(
"Rotate", &rotation, 0, 90);
314 ImGui::SliderFloat(
"Offset", &
offset, 0, 2);
318 DisplayListBuilder builder;
319 builder.Scale(GetContentScale().
x, GetContentScale().y);
320 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
323 paint.setStrokeWidth(0.f);
324 paint.setColor(DlColor::kWhite());
326 builder.Translate(512, 384);
328 builder.Rotate(rotation);
329 builder.Translate(-512, -384 +
offset);
331 for (
int i = 0; i < 5; ++i) {
332 Scalar yoffset = i * 25.25f + 300.f;
334 builder.DrawLine(
DlPoint(100, yoffset),
DlPoint(924, yoffset), paint);
337 return builder.Build();
340 ASSERT_TRUE(OpenPlaygroundHere(callback));
344 DisplayListBuilder builder;
345 builder.Scale(GetContentScale().
x, GetContentScale().y);
348 paint.setColor(DlColor::kRed());
349 paint.setDrawStyle(DlDrawStyle::kFill);
351 DlPaint reference_paint;
352 reference_paint.setColor(DlColor::kGreen());
353 reference_paint.setDrawStyle(DlDrawStyle::kFill);
355 DlPathBuilder path_builder;
357 path_builder.MoveTo(
DlPoint(100, 100));
358 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 100), 5.0f);
360 DlPathBuilder reference_builder;
365 reference_builder.MoveTo(component.
p1);
366 constexpr
int N = 100;
367 for (
int i = 1; i < N; i++) {
368 reference_builder.LineTo(component.
Solve(
static_cast<Scalar>(i) / N));
370 reference_builder.LineTo(component.
p2);
373 line_paint.setColor(DlColor::kYellow());
374 line_paint.setDrawStyle(DlDrawStyle::kStroke);
375 line_paint.setStrokeWidth(1.0f);
379 builder.DrawLine(
DlPoint(145, 100),
DlPoint(145, 450), line_paint);
380 builder.DrawLine(
DlPoint(155, 100),
DlPoint(155, 450), line_paint);
381 builder.DrawLine(
DlPoint(345, 100),
DlPoint(345, 450), line_paint);
382 builder.DrawLine(
DlPoint(355, 100),
DlPoint(355, 450), line_paint);
383 builder.DrawLine(
DlPoint(100, 392.5f),
DlPoint(400, 392.5f), line_paint);
386 builder.DrawPath(
DlPath(path_builder), paint);
387 builder.DrawPath(
DlPath(reference_builder), reference_paint);
389 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
393 DisplayListBuilder builder;
396 paint.setColor(DlColor::kRed());
400 .top_right = {25, 50},
401 .bottom_left = {25, 50},
402 .bottom_right = {50, 25},
406 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 200, 200), radii);
409 path_builder.
AddPath(DlPath::MakeRoundRect(rrect).GetPath());
410 path_builder.
AddPath(DlPath::MakeCircle(
DlPoint(200, 200), 50).GetPath());
411 DlPath path(path_builder, DlPathFillType::kOdd);
416 builder.DrawPath(path, paint);
418 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
425 DisplayListBuilder builder;
431 DlPathBuilder path_builder;
432 path_builder.MoveTo(
DlPoint(50, 50));
433 path_builder.LineTo(
DlPoint(50, 100));
434 path_builder.LineTo(
DlPoint(100, 100));
435 path_builder.LineTo(
DlPoint(100, 50));
438 paint.setColor(DlColor::kRed());
439 paint.setDrawStyle(DlDrawStyle::kStroke);
440 paint.setStrokeWidth(10);
442 builder.DrawPath(
DlPath(path_builder), paint);
444 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
448 DisplayListBuilder builder;
452 DlPathBuilder path_builder;
453 path_builder.MoveTo(
DlPoint(50, 50));
454 path_builder.LineTo(
DlPoint(520, 120));
455 path_builder.LineTo(
DlPoint(300, 310));
456 path_builder.LineTo(
DlPoint(100, 50));
457 path_builder.Close();
460 paint.setColor(DlColor::kRed());
461 paint.setDrawStyle(DlDrawStyle::kStroke);
462 paint.setStrokeWidth(10);
464 builder.DrawPath(
DlPath(path_builder), paint);
466 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
471 auto callback = [&]() -> sk_sp<DisplayList> {
473 static float scale = 3;
474 static bool add_circle_clip =
true;
477 ImGuiWindowFlags_AlwaysAutoResize)) {
478 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&color));
479 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
480 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
484 DisplayListBuilder builder;
485 builder.Scale(GetContentScale().
x, GetContentScale().y);
488 paint.setColor(DlColor::kWhite());
489 builder.DrawPaint(paint);
493 paint.setDrawStyle(DlDrawStyle::kStroke);
494 paint.setStrokeWidth(10);
496 DlPathBuilder path_builder;
497 path_builder.MoveTo(
DlPoint(20, 20));
499 path_builder.Close();
500 path_builder.MoveTo(
DlPoint(60, 20));
502 DlPath path(path_builder);
506 if (add_circle_clip) {
511 auto [handle_a, handle_b] =
514 Matrix screen_to_canvas = builder.GetMatrix();
518 screen_to_canvas = screen_to_canvas.
Invert();
520 Point point_a = screen_to_canvas * handle_a;
521 Point point_b = screen_to_canvas * handle_b;
523 Point middle = point_a + point_b;
524 middle *= GetContentScale().
x / 2;
528 builder.ClipPath(DlPath::MakeCircle(middle, radius));
532 {DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
533 paint.setStrokeJoin(join);
535 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
536 paint.setStrokeCap(cap);
537 builder.DrawPath(path, paint);
538 builder.Translate(80, 0);
540 builder.Translate(-240, 60);
543 return builder.Build();
546 ASSERT_TRUE(OpenPlaygroundHere(callback));
550 DisplayListBuilder builder;
551 builder.Scale(GetContentScale().
x, GetContentScale().y);
554 paint.setColor(DlColor::kBlue());
555 paint.setStrokeWidth(10);
557 auto draw = [&builder](DlPaint& paint) {
559 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
560 paint.setStrokeCap(cap);
563 for (
int d = 15; d < 90; d += 15) {
565 Point origin = {100, 100};
568 auto a = origin + m * p0;
569 auto b = origin + m * p1;
571 builder.DrawLine(a,
b, paint);
574 builder.DrawCircle(origin, 35, paint);
578 builder.Translate(250, 0);
580 builder.Translate(-750, 250);
583 std::vector<DlColor> colors = {
584 DlColor::ARGB(1, 0x1f / 255.0, 0.0, 0x5c / 255.0),
585 DlColor::ARGB(1, 0x5b / 255.0, 0.0, 0x60 / 255.0),
586 DlColor::ARGB(1, 0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0),
587 DlColor::ARGB(1, 0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0),
588 DlColor::ARGB(1, 0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0),
589 DlColor::ARGB(1, 0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0),
590 DlColor::ARGB(1, 0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0)};
591 std::vector<Scalar> stops = {
602 CreateTextureForFixture(
"airplane.jpg",
607 paint.setColorSource(DlColorSource::MakeRadial({100, 100}, 200, stops.size(),
608 colors.data(), stops.data(),
609 DlTileMode::kMirror));
612 DlMatrix matrix = DlMatrix::MakeTranslation({-150, 75});
613 paint.setColorSource(DlColorSource::MakeImage(
614 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
615 DlImageSampling::kMipmapLinear, &matrix));
618 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
627 auto callback = [&]() -> sk_sp<DisplayList> {
629 ImGuiWindowFlags_AlwaysAutoResize)) {
630 ImGui::SliderFloat(
"Scale", &
scale, 0.001, 5);
631 ImGui::SliderFloat(
"Width", &line_width, 1, 20);
635 DisplayListBuilder builder;
636 builder.Scale(GetContentScale().
x, GetContentScale().y);
638 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
642 paint.setColor(DlColor::kGreenYellow());
643 paint.setStrokeWidth(line_width);
649 builder.Translate(100, 300);
651 builder.Translate(-100, -300);
659 paint.setColor(DlColor::kGreenYellow());
660 paint.setStrokeWidth(2.0);
663 builder.Translate(100, 500);
664 builder.Scale(0.2, 0.2);
665 builder.Translate(-100, -500);
671 return builder.Build();
673 ASSERT_TRUE(OpenPlaygroundHere(callback));
678 float line_width = 10.f;
679 float rotation = 0.f;
681 auto callback = [&]() -> sk_sp<DisplayList> {
683 ImGuiWindowFlags_AlwaysAutoResize)) {
685 ImGui::SliderFloat(
"Scale", &
scale, 0.001f, 5.0f);
686 ImGui::SliderFloat(
"Width", &line_width, 1.0f, 20.0f);
687 ImGui::SliderFloat(
"Rotation", &rotation, 0.0f, 180.0f);
691 DisplayListBuilder builder;
692 builder.Scale(
static_cast<float>(GetContentScale().
x),
693 static_cast<float>(GetContentScale().y));
695 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
701 hex_paint.setStrokeWidth(line_width);
707 float r_sin60 = r * std::sqrt(3.0f) / 2.0f;
708 float r_cos60 = r / 2.0f;
718 DlPoint(cx + r_cos60, cy + r_sin60);
721 builder.Translate(cx, cy);
723 builder.Rotate(rotation);
724 builder.Translate(-cx, -cy);
726 builder.DrawLine(v0, v1, hex_paint);
727 builder.DrawLine(v1, v2, hex_paint);
728 builder.DrawLine(v2, v3, hex_paint);
729 builder.DrawLine(v3, v4, hex_paint);
730 builder.DrawLine(v4, v5, hex_paint);
731 builder.DrawLine(v5, v0, hex_paint);
734 return builder.Build();
736 ASSERT_TRUE(OpenPlaygroundHere(callback));
740 DisplayListBuilder builder;
741 builder.Scale(GetContentScale().
x, GetContentScale().y);
743 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
746 paint.setColor(DlColor::kGreenYellow());
747 paint.setStrokeWidth(10);
749 auto draw = [&builder](DlPaint& paint) {
751 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
752 paint.setStrokeCap(cap);
755 for (
int d = 15; d < 90; d += 15) {
757 Point origin = {100, 100};
760 auto a = origin + m * p0;
761 auto b = origin + m * p1;
763 builder.DrawLine(a,
b, paint);
766 builder.DrawCircle(origin, 35, paint);
770 builder.Translate(250, 0);
772 builder.Translate(-750, 250);
777 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
781 DisplayListBuilder builder;
783 paint.setColor(DlColor::kRed());
784 paint.setDrawStyle(DlDrawStyle::kStroke);
785 paint.setStrokeWidth(10);
787 builder.Translate(100, 100);
788 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
790 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
794 DisplayListBuilder builder;
796 paint.setColor(DlColor::kRed());
797 paint.setDrawStyle(DlDrawStyle::kStroke);
798 paint.setStrokeWidth(10);
799 paint.setStrokeJoin(DlStrokeJoin::kBevel);
801 builder.Translate(100, 100);
802 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
804 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
808 DlPathBuilder path_builder;
809 for (
auto i = 0; i < 10; i++) {
814 DlPath::MakeCircle(
DlPoint(100 + 50 * i, 100 + 50 * i), 100);
815 path_builder.AddPath(circle.GetPath());
816 path_builder.Close();
818 path_builder.MoveTo(
DlPoint(100.f + 50.f * i - 100, 100.f + 50.f * i));
819 path_builder.LineTo(
DlPoint(100.f + 50.f * i, 100.f + 50.f * i - 100));
820 path_builder.LineTo(
DlPoint(100.f + 50.f * i - 100,
821 100.f + 50.f * i - 100));
822 path_builder.Close();
825 DlPath path(path_builder);
827 DisplayListBuilder builder;
829 paint.setColor(DlColor::kRed().withAlpha(102));
830 builder.DrawPath(path, paint);
832 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
836 DisplayListBuilder builder;
837 builder.Scale(GetContentScale().
x, GetContentScale().y);
840 paint.setColor(DlColor::kRed());
842 std::vector<DlColor> colors = {DlColor::RGBA(1.0, 0.0, 0.0, 1.0),
843 DlColor::RGBA(0.0, 0.0, 0.0, 1.0)};
844 std::vector<Scalar> stops = {0.0, 1.0};
846 paint.setColorSource(
847 DlColorSource::MakeSweep({100, 100}, 45, 135, stops.size(), colors.data(),
848 stops.data(), DlTileMode::kMirror));
849 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
851 DlPathBuilder path_builder;
852 path_builder.AddArc(DlRect::MakeXYWH(10, 10, 100, 100),
853 DlDegrees(0), DlDegrees(0));
854 builder.DrawPath(
DlPath(path_builder), paint);
861 DisplayListBuilder builder;
863 paint.setColor(DlColor::kFuchsia());
865 builder.ClipPath(DlPath::MakeRect(DlRect::MakeXYWH(0, 0, 500, 500)));
866 builder.DrawPath(DlPath::MakeCircle(
DlPoint(500, 500), 250), paint);
868 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
876 auto callback = [&]() -> sk_sp<DisplayList> {
878 ImGuiWindowFlags_AlwaysAutoResize)) {
879 ImGui::SliderFloat(
"Stroke Width", &
stroke_width, 1, 300);
880 ImGui::SliderFloat(
"Aspect", &aspect, 0.5, 2.0);
881 ImGui::SliderFloat(
"Start Angle", &start_angle, 0, 360);
882 ImGui::SliderFloat(
"End Angle", &end_angle, 0, 360);
886 DisplayListBuilder builder;
888 grey_paint.setColor(DlColor(0xff111111));
889 builder.DrawPaint(grey_paint);
892 white_paint.setColor(DlColor::kWhite());
894 white_paint.setDrawStyle(DlDrawStyle::kStroke);
896 red_paint.setColor(DlColor::kRed());
899 builder.DrawRect(rect, red_paint);
900 builder.DrawArc(rect, start_angle, end_angle,
903 builder.DrawLine(
Point(frontier, 0),
Point(frontier, 150), red_paint);
905 return builder.Build();
907 ASSERT_TRUE(OpenPlaygroundHere(callback));
911 DisplayListBuilder builder;
914 paint.setColor(DlColor::kRed());
918 .top_right = DlSize(50, 50),
919 .bottom_left = DlSize(50, 50),
920 .bottom_right = DlSize(50, 50),
923 const Scalar kTriangleHeight = 100;
925 DlRect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f,
926 kTriangleHeight, kTriangleHeight),
931 DlPath rrect_path = DlPath::MakeRoundRect(rrect);
933 builder.Translate(200, 200);
937 DlPathBuilder path_builder;
938 path_builder.MoveTo(
DlPoint(0, kTriangleHeight));
939 path_builder.LineTo(
DlPoint(-kTriangleHeight / 2.0f, 0));
940 path_builder.LineTo(
DlPoint(kTriangleHeight / 2.0f, 0));
941 path_builder.Close();
942 path_builder.AddPath(rrect_path.GetPath());
944 builder.DrawPath(
DlPath(path_builder), paint);
946 builder.Translate(100, 0);
949 DlPathBuilder path_builder;
950 path_builder.MoveTo(
DlPoint(0, kTriangleHeight));
951 path_builder.LineTo(
DlPoint(-kTriangleHeight / 2.0f, 0));
952 path_builder.LineTo(
DlPoint(0, -10));
953 path_builder.LineTo(
DlPoint(kTriangleHeight / 2.0f, 0));
954 path_builder.Close();
955 path_builder.AddPath(rrect_path.GetPath());
957 builder.DrawPath(
DlPath(path_builder), paint);
960 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
964 DisplayListBuilder builder;
967 paint.setColor(DlColor::kRed());
968 paint.setDrawStyle(DlDrawStyle::kStroke);
969 paint.setStrokeWidth(15.0);
970 paint.setStrokeCap(DlStrokeCap::kRound);
972 DlPathBuilder path_builder;
973 path_builder.MoveTo(
DlPoint(100, 100));
974 path_builder.LineTo(
DlPoint(150, 150));
975 path_builder.MoveTo(
DlPoint(200, 200));
976 path_builder.LineTo(
DlPoint(200, 200));
978 builder.DrawPath(
DlPath(path_builder), paint);
980 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)
PathBuilder & AddPath(const Path &path)
TEST_P(AiksTest, DrawAtlasNoColor)
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
constexpr float kSqrt2Over2
flutter::DlRoundRect DlRoundRect
flutter::DlScalar DlScalar
const Scalar stroke_width
static constexpr Color Black()
constexpr Color WithAlpha(Scalar new_alpha) const
static constexpr Color Red()
Point Solve(Scalar time) const
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)