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()));
265 using DrawLinesCallback = std::function<void(DisplayListBuilder& builder,
266 const DlPaint& paint,
271 static void DrawLinesTest(
AiksTest* test,
const DrawLinesCallback& draw_fn) {
275 Scalar width_adjustment = 0.f;
276 bool invert_colors =
false;
278 auto callback = [=]()
mutable -> sk_sp<DisplayList> {
280 ImGuiWindowFlags_AlwaysAutoResize)) {
281 ImGui::SliderFloat(
"Scale", &scale, 0, 6);
282 ImGui::SliderFloat(
"Rotate", &rotation, 0, 90);
283 ImGui::SliderFloat(
"Offset", &offset, 0, 2);
284 ImGui::SliderFloat(
"Width Adjustment", &width_adjustment, -1, 2);
285 ImGui::Checkbox(
"Invert colors", &invert_colors);
289 DisplayListBuilder builder;
298 DlPaint(invert_colors ? DlColor(0xffeeeeee) : DlColor(0xff111111)));
301 paint.setColor(invert_colors ? DlColor::kBlack() : DlColor::kWhite());
303 std::vector<Scalar> widths = {0.0f, 0.3f, 1.0f};
304 std::vector<Scalar> angles = {0.0f, 3.0f, 45.0f, 87.0f, 90.0f};
306 const Scalar column_spacing = 1024.0f / widths.size();
307 const Scalar row_spacing = 768.0f / angles.size();
309 for (
size_t col = 0; col < widths.size(); ++col) {
310 Scalar col_x = (col + 0.5f) * column_spacing;
311 Scalar width = std::max(0.0f, widths[col] + width_adjustment);
312 for (
size_t row = 0; row < angles.size(); ++row) {
313 Scalar row_y = (row + 0.5f) * row_spacing;
315 builder.Translate(col_x, row_y);
316 builder.Scale(scale, scale);
317 builder.Rotate(angles[row] + rotation);
322 for (
int i = 0; i < 4; ++i) {
323 Scalar base_y = i * 8.0f - 12.0f;
324 Scalar subpixel_y = i * 0.25f;
325 Scalar line_y = base_y + subpixel_y + offset;
328 draw_fn(builder, paint, p0,
p1, width);
335 return builder.Build();
338 ASSERT_TRUE(test->OpenPlaygroundHere(callback));
343 DrawLinesTest(
this, [](DisplayListBuilder& builder,
const DlPaint& paint,
345 DlPaint stroke_paint = paint;
346 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
347 stroke_paint.setStrokeWidth(width);
348 DlPathBuilder path_builder;
349 path_builder.MoveTo(p0);
350 path_builder.LineTo(
p1);
351 builder.DrawPath(path_builder.TakePath(), stroke_paint);
356 DrawLinesTest(
this, [](DisplayListBuilder& builder,
const DlPaint& paint,
358 DlPaint stroke_paint = paint;
359 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
360 stroke_paint.setStrokeWidth(width);
361 builder.DrawLine(p0,
p1, stroke_paint);
366 DrawLinesTest(
this, [](DisplayListBuilder& builder,
const DlPaint& paint,
368 DlPaint fill_paint = paint;
369 fill_paint.setDrawStyle(DlDrawStyle::kFill);
371 Point center = {(p0.
x +
p1.x) * 0.5f, (p0.
y +
p1.y) * 0.5f};
373 DlRect::MakeEllipseBounds(center,
Size(length, width) * 0.5f),
379 DrawLinesTest(
this, [](DisplayListBuilder& builder,
const DlPaint& paint,
381 DlPaint fill_paint = paint;
382 fill_paint.setDrawStyle(DlDrawStyle::kFill);
384 Point center = {(p0.
x +
p1.x) * 0.5f, (p0.
y +
p1.y) * 0.5f};
385 builder.DrawRoundRect(
386 DlRoundRect::MakeRectRadius(
387 DlRect::MakeEllipseBounds(center,
Size(length, width) * 0.5f),
394 DisplayListBuilder builder;
395 builder.Scale(GetContentScale().
x, GetContentScale().y);
398 paint.setColor(DlColor::kRed());
399 paint.setDrawStyle(DlDrawStyle::kFill);
401 DlPaint reference_paint;
402 reference_paint.setColor(DlColor::kGreen());
403 reference_paint.setDrawStyle(DlDrawStyle::kFill);
405 DlPathBuilder path_builder;
407 path_builder.MoveTo(
DlPoint(100, 100));
408 path_builder.ConicCurveTo(
DlPoint(150, 450),
DlPoint(200, 100), 5.0f);
410 DlPathBuilder reference_builder;
415 reference_builder.MoveTo(component.p1);
416 constexpr
int N = 100;
417 for (
int i = 1; i < N; i++) {
418 reference_builder.LineTo(component.Solve(
static_cast<Scalar>(i) / N));
420 reference_builder.LineTo(component.p2);
423 line_paint.setColor(DlColor::kYellow());
424 line_paint.setDrawStyle(DlDrawStyle::kStroke);
425 line_paint.setStrokeWidth(1.0f);
429 builder.DrawLine(
DlPoint(145, 100),
DlPoint(145, 450), line_paint);
430 builder.DrawLine(
DlPoint(155, 100),
DlPoint(155, 450), line_paint);
431 builder.DrawLine(
DlPoint(345, 100),
DlPoint(345, 450), line_paint);
432 builder.DrawLine(
DlPoint(355, 100),
DlPoint(355, 450), line_paint);
433 builder.DrawLine(
DlPoint(100, 392.5f),
DlPoint(400, 392.5f), line_paint);
436 builder.DrawPath(path_builder.TakePath(), paint);
437 builder.DrawPath(reference_builder.TakePath(), reference_paint);
439 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
443 DisplayListBuilder builder;
446 paint.setColor(DlColor::kRed());
450 .top_right = {25, 50},
451 .bottom_left = {25, 50},
452 .bottom_right = {50, 25},
454 DlPathBuilder path_builder;
456 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 200, 200), radii);
459 path_builder.AddPath(DlPath::MakeRoundRect(rrect));
460 path_builder.AddPath(DlPath::MakeCircle(
DlPoint(200, 200), 50));
461 path_builder.SetFillType(DlPathFillType::kOdd);
462 DlPath path = path_builder.TakePath();
467 builder.DrawPath(path, paint);
469 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
476 DisplayListBuilder builder;
482 DlPathBuilder path_builder;
483 path_builder.MoveTo(
DlPoint(50, 50));
484 path_builder.LineTo(
DlPoint(50, 100));
485 path_builder.LineTo(
DlPoint(100, 100));
486 path_builder.LineTo(
DlPoint(100, 50));
489 paint.setColor(DlColor::kRed());
490 paint.setDrawStyle(DlDrawStyle::kStroke);
491 paint.setStrokeWidth(10);
493 builder.DrawPath(path_builder.TakePath(), paint);
495 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
499 DisplayListBuilder builder;
503 DlPathBuilder path_builder;
504 path_builder.MoveTo(
DlPoint(50, 50));
505 path_builder.LineTo(
DlPoint(520, 120));
506 path_builder.LineTo(
DlPoint(300, 310));
507 path_builder.LineTo(
DlPoint(100, 50));
508 path_builder.Close();
511 paint.setColor(DlColor::kRed());
512 paint.setDrawStyle(DlDrawStyle::kStroke);
513 paint.setStrokeWidth(10);
515 builder.DrawPath(path_builder.TakePath(), paint);
517 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
522 auto callback = [&]() -> sk_sp<DisplayList> {
524 static float scale = 3;
525 static bool add_circle_clip =
true;
528 ImGuiWindowFlags_AlwaysAutoResize)) {
529 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&color));
530 ImGui::SliderFloat(
"Scale", &scale, 0, 6);
531 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
535 DisplayListBuilder builder;
536 builder.Scale(GetContentScale().
x, GetContentScale().y);
539 paint.setColor(DlColor::kWhite());
540 builder.DrawPaint(paint);
544 paint.setDrawStyle(DlDrawStyle::kStroke);
545 paint.setStrokeWidth(10);
547 DlPathBuilder path_builder;
548 path_builder.MoveTo(
DlPoint(20, 20));
550 path_builder.Close();
551 path_builder.MoveTo(
DlPoint(60, 20));
553 DlPath path = path_builder.TakePath();
555 builder.Scale(scale, scale);
557 if (add_circle_clip) {
562 auto [handle_a, handle_b] =
565 Matrix screen_to_canvas = builder.GetMatrix();
569 screen_to_canvas = screen_to_canvas.
Invert();
571 Point point_a = screen_to_canvas * handle_a;
572 Point point_b = screen_to_canvas * handle_b;
574 Point middle = point_a + point_b;
575 middle *= GetContentScale().
x / 2;
579 builder.ClipPath(DlPath::MakeCircle(middle, radius));
583 {DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
584 paint.setStrokeJoin(join);
586 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
587 paint.setStrokeCap(cap);
588 builder.DrawPath(path, paint);
589 builder.Translate(80, 0);
591 builder.Translate(-240, 60);
594 return builder.Build();
597 ASSERT_TRUE(OpenPlaygroundHere(callback));
601 DisplayListBuilder builder;
602 builder.Scale(GetContentScale().
x, GetContentScale().y);
605 paint.setColor(DlColor::kBlue());
606 paint.setStrokeWidth(10);
608 auto draw = [&builder](DlPaint& paint) {
610 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
611 paint.setStrokeCap(cap);
614 for (
int d = 15; d < 90; d += 15) {
616 Point origin = {100, 100};
619 auto a = origin + m * p0;
620 auto b = origin + m *
p1;
622 builder.DrawLine(a,
b, paint);
625 builder.DrawCircle(origin, 35, paint);
629 builder.Translate(250, 0);
631 builder.Translate(-750, 250);
634 std::vector<DlColor> colors = {
635 DlColor::ARGB(1, 0x1f / 255.0, 0.0, 0x5c / 255.0),
636 DlColor::ARGB(1, 0x5b / 255.0, 0.0, 0x60 / 255.0),
637 DlColor::ARGB(1, 0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0),
638 DlColor::ARGB(1, 0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0),
639 DlColor::ARGB(1, 0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0),
640 DlColor::ARGB(1, 0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0),
641 DlColor::ARGB(1, 0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0)};
642 std::vector<Scalar> stops = {
653 CreateTextureForFixture(
"airplane.jpg",
658 paint.setColorSource(DlColorSource::MakeRadial({100, 100}, 200, stops.size(),
659 colors.data(), stops.data(),
660 DlTileMode::kMirror));
663 DlMatrix matrix = DlMatrix::MakeTranslation({-150, 75});
664 paint.setColorSource(DlColorSource::MakeImage(
665 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
666 DlImageSampling::kMipmapLinear, &matrix));
669 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
678 EnsureContextSupportsAntialiasLines();
682 auto callback = [&]() -> sk_sp<DisplayList> {
684 ImGuiWindowFlags_AlwaysAutoResize)) {
685 ImGui::SliderFloat(
"Scale", &scale, 0.001, 5);
686 ImGui::SliderFloat(
"Width", &line_width, 1, 20);
690 DisplayListBuilder builder;
691 builder.Scale(GetContentScale().
x, GetContentScale().y);
693 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
697 paint.setColor(DlColor::kGreenYellow());
698 paint.setStrokeWidth(line_width);
704 builder.Translate(100, 300);
705 builder.Scale(scale, scale);
706 builder.Translate(-100, -300);
714 paint.setColor(DlColor::kGreenYellow());
715 paint.setStrokeWidth(2.0);
718 builder.Translate(100, 500);
719 builder.Scale(0.2, 0.2);
720 builder.Translate(-100, -500);
726 return builder.Build();
728 ASSERT_TRUE(OpenPlaygroundHere(callback));
734 EnsureContextSupportsAntialiasLines();
737 float line_width = 10.f;
738 float rotation = 0.f;
740 auto callback = [&]() -> sk_sp<DisplayList> {
742 ImGuiWindowFlags_AlwaysAutoResize)) {
744 ImGui::SliderFloat(
"Scale", &scale, 0.001f, 5.0f);
745 ImGui::SliderFloat(
"Width", &line_width, 1.0f, 20.0f);
746 ImGui::SliderFloat(
"Rotation", &rotation, 0.0f, 180.0f);
750 DisplayListBuilder builder;
751 builder.Scale(
static_cast<float>(GetContentScale().
x),
752 static_cast<float>(GetContentScale().y));
754 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
760 hex_paint.setStrokeWidth(line_width);
766 float r_sin60 = r * std::sqrt(3.0f) / 2.0f;
767 float r_cos60 = r / 2.0f;
777 DlPoint(cx + r_cos60, cy + r_sin60);
780 builder.Translate(cx, cy);
781 builder.Scale(scale, scale);
782 builder.Rotate(rotation);
783 builder.Translate(-cx, -cy);
785 builder.DrawLine(v0, v1, hex_paint);
786 builder.DrawLine(v1, v2, hex_paint);
787 builder.DrawLine(v2, v3, hex_paint);
788 builder.DrawLine(v3, v4, hex_paint);
789 builder.DrawLine(v4, v5, hex_paint);
790 builder.DrawLine(v5, v0, hex_paint);
793 return builder.Build();
795 ASSERT_TRUE(OpenPlaygroundHere(callback));
801 EnsureContextSupportsAntialiasLines();
803 DisplayListBuilder builder;
804 builder.Scale(GetContentScale().
x, GetContentScale().y);
806 builder.DrawPaint(DlPaint(DlColor(0xff111111)));
809 paint.setColor(DlColor::kGreenYellow());
810 paint.setStrokeWidth(10);
812 auto draw = [&builder](DlPaint& paint) {
814 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
815 paint.setStrokeCap(cap);
818 for (
int d = 15; d < 90; d += 15) {
820 Point origin = {100, 100};
823 auto a = origin + m * p0;
824 auto b = origin + m *
p1;
826 builder.DrawLine(a,
b, paint);
829 builder.DrawCircle(origin, 35, paint);
833 builder.Translate(250, 0);
835 builder.Translate(-750, 250);
840 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
844 DisplayListBuilder builder;
846 paint.setColor(DlColor::kRed());
847 paint.setDrawStyle(DlDrawStyle::kStroke);
848 paint.setStrokeWidth(10);
850 builder.Translate(100, 100);
851 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
853 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
857 DisplayListBuilder builder;
859 paint.setColor(DlColor::kRed());
860 paint.setDrawStyle(DlDrawStyle::kStroke);
861 paint.setStrokeWidth(10);
862 paint.setStrokeJoin(DlStrokeJoin::kBevel);
864 builder.Translate(100, 100);
865 builder.DrawPath(DlPath::MakeRect(DlRect::MakeSize(DlSize(100, 100))), paint);
867 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
871 DlPathBuilder path_builder;
872 for (
auto i = 0; i < 10; i++) {
877 DlPath::MakeCircle(
DlPoint(100 + 50 * i, 100 + 50 * i), 100);
878 path_builder.AddPath(circle);
879 path_builder.Close();
881 path_builder.MoveTo(
DlPoint(100.f + 50.f * i - 100, 100.f + 50.f * i));
882 path_builder.LineTo(
DlPoint(100.f + 50.f * i, 100.f + 50.f * i - 100));
883 path_builder.LineTo(
DlPoint(100.f + 50.f * i - 100,
884 100.f + 50.f * i - 100));
885 path_builder.Close();
888 DlPath path = path_builder.TakePath();
890 DisplayListBuilder builder;
892 paint.setColor(DlColor::kRed().withAlpha(102));
893 builder.DrawPath(path, paint);
895 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
899 DisplayListBuilder builder;
900 builder.Scale(GetContentScale().
x, GetContentScale().y);
903 paint.setColor(DlColor::kRed());
905 std::vector<DlColor> colors = {DlColor::RGBA(1.0, 0.0, 0.0, 1.0),
906 DlColor::RGBA(0.0, 0.0, 0.0, 1.0)};
907 std::vector<Scalar> stops = {0.0, 1.0};
909 paint.setColorSource(
910 DlColorSource::MakeSweep({100, 100}, 45, 135, stops.size(), colors.data(),
911 stops.data(), DlTileMode::kMirror));
912 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
914 DlPathBuilder path_builder;
915 path_builder.AddArc(DlRect::MakeXYWH(10, 10, 100, 100),
916 DlDegrees(0), DlDegrees(0));
917 builder.DrawPath(path_builder.TakePath(), paint);
924 DisplayListBuilder builder;
926 paint.setColor(DlColor::kFuchsia());
928 builder.ClipPath(DlPath::MakeRect(DlRect::MakeXYWH(0, 0, 500, 500)));
929 builder.DrawPath(DlPath::MakeCircle(
DlPoint(500, 500), 250), paint);
931 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
939 auto callback = [&]() -> sk_sp<DisplayList> {
941 ImGuiWindowFlags_AlwaysAutoResize)) {
942 ImGui::SliderFloat(
"Stroke Width", &stroke_width, 1, 300);
943 ImGui::SliderFloat(
"Aspect", &aspect, 0.5, 2.0);
944 ImGui::SliderFloat(
"Start Angle", &start_angle, 0, 360);
945 ImGui::SliderFloat(
"End Angle", &end_angle, 0, 360);
949 DisplayListBuilder builder;
951 grey_paint.setColor(DlColor(0xff111111));
952 builder.DrawPaint(grey_paint);
955 white_paint.setColor(DlColor::kWhite());
956 white_paint.setStrokeWidth(stroke_width);
957 white_paint.setDrawStyle(DlDrawStyle::kStroke);
959 red_paint.setColor(DlColor::kRed());
962 builder.DrawRect(rect, red_paint);
963 builder.DrawArc(rect, start_angle, end_angle,
966 builder.DrawLine(
Point(frontier, 0),
Point(frontier, 150), red_paint);
968 return builder.Build();
970 ASSERT_TRUE(OpenPlaygroundHere(callback));
974 DisplayListBuilder builder;
977 paint.setColor(DlColor::kRed());
981 .top_right = DlSize(50, 50),
982 .bottom_left = DlSize(50, 50),
983 .bottom_right = DlSize(50, 50),
986 const Scalar kTriangleHeight = 100;
988 DlRect::MakeCircleBounds({0, 0}, kTriangleHeight * 0.5f), radii);
991 DlPath rrect_path = DlPath::MakeRoundRect(rrect);
993 builder.Translate(200, 200);
997 DlPathBuilder path_builder;
998 path_builder.MoveTo(
DlPoint(0, kTriangleHeight));
999 path_builder.LineTo(
DlPoint(-kTriangleHeight / 2.0f, 0));
1000 path_builder.LineTo(
DlPoint(kTriangleHeight / 2.0f, 0));
1001 path_builder.Close();
1002 path_builder.AddPath(rrect_path);
1004 builder.DrawPath(path_builder.TakePath(), paint);
1006 builder.Translate(100, 0);
1009 DlPathBuilder path_builder;
1010 path_builder.MoveTo(
DlPoint(0, kTriangleHeight));
1011 path_builder.LineTo(
DlPoint(-kTriangleHeight / 2.0f, 0));
1012 path_builder.LineTo(
DlPoint(0, -10));
1013 path_builder.LineTo(
DlPoint(kTriangleHeight / 2.0f, 0));
1014 path_builder.Close();
1015 path_builder.AddPath(rrect_path);
1017 builder.DrawPath(path_builder.TakePath(), paint);
1020 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1024 DisplayListBuilder builder;
1027 paint.setColor(DlColor::kRed());
1028 paint.setDrawStyle(DlDrawStyle::kStroke);
1029 paint.setStrokeWidth(15.0);
1030 paint.setStrokeCap(DlStrokeCap::kRound);
1032 DlPathBuilder path_builder;
1033 path_builder.MoveTo(
DlPoint(100, 100));
1034 path_builder.LineTo(
DlPoint(150, 150));
1035 path_builder.MoveTo(
DlPoint(200, 200));
1036 path_builder.LineTo(
DlPoint(200, 200));
1038 builder.DrawPath(path_builder.TakePath(), paint);
1040 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1044 DisplayListBuilder builder;
1047 paint.setColor(DlColor::kRed());
1048 paint.setDrawStyle(DlDrawStyle::kStroke);
1049 paint.setStrokeWidth(15.0);
1051 builder.Translate(100, 0);
1052 for (
auto join : std::vector<DlStrokeJoin>{
1053 DlStrokeJoin::kMiter, DlStrokeJoin::kRound, DlStrokeJoin::kBevel}) {
1054 builder.Translate(0, 100);
1055 paint.setStrokeJoin(join);
1057 DlPathBuilder path_builder;
1058 path_builder.MoveTo(
DlPoint(0, 0));
1059 path_builder.LineTo(
DlPoint(50, 50));
1060 path_builder.MoveTo(
DlPoint(50, 50));
1061 path_builder.LineTo(
DlPoint(100, 0));
1063 builder.DrawPath(path_builder.TakePath(), paint);
1066 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1070 DisplayListBuilder builder;
1071 builder.Scale(GetContentScale().
x, GetContentScale().y);
1073 builder.Translate(100, 0);
1076 for (
auto cap : std::vector<DlStrokeCap>{
1077 DlStrokeCap::kButt, DlStrokeCap::kRound, DlStrokeCap::kSquare}) {
1078 DlPathBuilder path_builder;
1079 path_builder.MoveTo({20, 50});
1080 path_builder.LineTo({50, 50});
1081 path_builder.MoveTo({120, 50});
1082 path_builder.LineTo({120, 80});
1083 path_builder.MoveTo({180, 50});
1084 path_builder.LineTo({180, 50});
1085 DlPath path = path_builder.TakePath();
1088 paint.setColor(DlColor::kRed());
1089 paint.setDrawStyle(DlDrawStyle::kStroke);
1090 paint.setStrokeWidth(20.0f);
1091 paint.setStrokeCap(cap);
1092 paint.setStrokeJoin(DlStrokeJoin::kBevel);
1094 builder.DrawPath(path, paint);
1096 paint.setColor(DlColor::kYellow());
1097 paint.setStrokeWidth(1.0f);
1098 paint.setStrokeCap(DlStrokeCap::kButt);
1100 builder.DrawPath(path, paint);
1102 builder.Translate(250, 0);
1106 builder.Translate(0, 100);
1109 for (
auto join : std::vector<DlStrokeJoin>{
1110 DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
1111 DlPathBuilder path_builder;
1112 path_builder.MoveTo({20, 50});
1113 path_builder.LineTo({50, 50});
1114 path_builder.LineTo({80, 50});
1115 path_builder.MoveTo({20, 150});
1116 path_builder.LineTo({50, 150});
1117 path_builder.LineTo({50, 180});
1118 path_builder.MoveTo({20, 250});
1119 path_builder.LineTo({50, 250});
1120 path_builder.LineTo({70, 270});
1121 path_builder.MoveTo({20, 350});
1122 path_builder.LineTo({50, 350});
1123 path_builder.LineTo({30, 370});
1124 path_builder.MoveTo({20, 450});
1125 path_builder.LineTo({50, 450});
1126 path_builder.LineTo({20, 450});
1127 path_builder.MoveTo({120, 80});
1128 path_builder.LineTo({150, 80});
1129 path_builder.LineTo({180, 80});
1130 path_builder.MoveTo({120, 180});
1131 path_builder.LineTo({150, 180});
1132 path_builder.LineTo({150, 150});
1133 path_builder.MoveTo({120, 280});
1134 path_builder.LineTo({150, 280});
1135 path_builder.LineTo({170, 260});
1136 path_builder.MoveTo({120, 380});
1137 path_builder.LineTo({150, 380});
1138 path_builder.LineTo({130, 360});
1139 path_builder.MoveTo({120, 480});
1140 path_builder.LineTo({150, 480});
1141 path_builder.LineTo({120, 480});
1142 DlPath path = path_builder.TakePath();
1146 paint.setColor(DlColor::kRed());
1147 paint.setDrawStyle(DlDrawStyle::kStroke);
1148 paint.setStrokeWidth(20.0f);
1149 paint.setStrokeCap(DlStrokeCap::kSquare);
1150 paint.setStrokeJoin(join);
1151 builder.DrawPath(path, paint);
1153 paint.setColor(DlColor::kYellow());
1154 paint.setStrokeWidth(1.0f);
1155 paint.setStrokeCap(DlStrokeCap::kButt);
1156 builder.DrawPath(path, paint);
1158 builder.Translate(250, 0);
1162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1166 DisplayListBuilder builder;
1168 paint.setColor(DlColor::kGreen());
1169 paint.setDrawStyle(DlDrawStyle::kStroke);
1170 paint.setStrokeWidth(30);
1171 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 5));
1173 builder.DrawCircle(
DlPoint(200, 200), 100, paint);
1175 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)