5 #include "display_list/display_list.h"
6 #include "display_list/dl_sampling_options.h"
7 #include "display_list/dl_tile_mode.h"
8 #include "display_list/effects/dl_color_filter.h"
9 #include "display_list/effects/dl_color_source.h"
10 #include "display_list/effects/dl_image_filter.h"
11 #include "display_list/effects/dl_mask_filter.h"
14 #include "flutter/display_list/dl_blend_mode.h"
15 #include "flutter/display_list/dl_builder.h"
16 #include "flutter/display_list/dl_color.h"
17 #include "flutter/display_list/dl_paint.h"
18 #include "flutter/display_list/geometry/dl_path_builder.h"
21 #include "flutter/testing/display_list_testing.h"
22 #include "flutter/testing/testing.h"
31 DisplayListBuilder builder;
33 paint.setColor(DlColor::kBlue());
34 builder.DrawPath(DlPath::MakeRectXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
35 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
40 std::function<void(DisplayListBuilder&,
const DlRect&,
const DlPaint&)>;
42 sk_sp<DisplayList> MakeWideStrokedRects(
Point scale,
43 const DrawRectProc& draw_rect) {
44 DisplayListBuilder builder;
45 builder.Scale(scale.
x, scale.
y);
46 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
49 paint.setColor(DlColor::kBlue().withAlphaF(0.5));
50 paint.setDrawStyle(DlDrawStyle::kStroke);
51 paint.setStrokeWidth(30.0f);
57 paint.setStrokeJoin(DlStrokeJoin::kBevel);
58 draw_rect(builder, DlRect::MakeXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
59 draw_rect(builder, DlRect::MakeXYWH(250.0f, 100.0f, 10.0f, 100.0f), paint);
60 draw_rect(builder, DlRect::MakeXYWH(100.0f, 250.0f, 100.0f, 10.0f), paint);
62 paint.setStrokeJoin(DlStrokeJoin::kRound);
63 draw_rect(builder, DlRect::MakeXYWH(350.0f, 100.0f, 100.0f, 100.0f), paint);
64 draw_rect(builder, DlRect::MakeXYWH(500.0f, 100.0f, 10.0f, 100.0f), paint);
65 draw_rect(builder, DlRect::MakeXYWH(350.0f, 250.0f, 100.0f, 10.0f), paint);
67 paint.setStrokeJoin(DlStrokeJoin::kMiter);
68 draw_rect(builder, DlRect::MakeXYWH(600.0f, 100.0f, 100.0f, 100.0f), paint);
69 draw_rect(builder, DlRect::MakeXYWH(750.0f, 100.0f, 10.0f, 100.0f), paint);
70 draw_rect(builder, DlRect::MakeXYWH(600.0f, 250.0f, 100.0f, 10.0f), paint);
74 paint.setStrokeWidth(110.0f);
76 paint.setStrokeJoin(DlStrokeJoin::kBevel);
77 draw_rect(builder, DlRect::MakeXYWH(100.0f, 400.0f, 100.0f, 100.0f), paint);
79 paint.setStrokeJoin(DlStrokeJoin::kRound);
80 draw_rect(builder, DlRect::MakeXYWH(350.0f, 400.0f, 100.0f, 100.0f), paint);
82 paint.setStrokeJoin(DlStrokeJoin::kMiter);
83 draw_rect(builder, DlRect::MakeXYWH(600.0f, 400.0f, 100.0f, 100.0f), paint);
85 return builder.Build();
90 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
91 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
92 const DlPaint& paint) {
94 builder.DrawRect(rect, paint);
99 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
100 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
101 const DlPaint& paint) {
103 builder.DrawPath(DlPath::MakeRect(rect), paint);
108 DisplayListBuilder builder;
110 paint.setColor(DlColor::kRed());
112 builder.DrawImage(image,
DlPoint(100.0, 100.0),
113 DlImageSampling::kNearestNeighbor, &paint);
114 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
118 DisplayListBuilder builder;
120 paint.setColor(DlColor::kRed());
121 paint.setColorFilter(
122 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
123 paint.setInvertColors(
true);
126 builder.DrawImage(image,
DlPoint(100.0, 100.0),
127 DlImageSampling::kNearestNeighbor, &paint);
128 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
132 DisplayListBuilder builder;
134 paint.setColor(DlColor::kRed());
135 paint.setColorFilter(
136 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
137 paint.setInvertColors(
true);
139 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
140 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
144 DisplayListBuilder builder;
146 paint.setColor(DlColor::kRed());
147 paint.setColorFilter(
148 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
149 paint.setInvertColors(
true);
151 builder.DrawPaint(paint);
152 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
156 bool GenerateMipmap(
const std::shared_ptr<Context>& context,
157 std::shared_ptr<Texture> texture,
158 std::string_view label) {
159 auto buffer = context->CreateCommandBuffer();
163 auto pass = buffer->CreateBlitPass();
167 pass->GenerateMipmap(std::move(texture), label);
169 pass->EncodeCommands();
170 return context->GetCommandQueue()->Submit({buffer}).ok();
173 void CanRenderTiledTexture(
AiksTest* aiks_test,
174 DlTileMode tile_mode,
175 Matrix local_matrix = {}) {
176 auto context = aiks_test->GetContext();
177 ASSERT_TRUE(context);
178 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
180 GenerateMipmap(context, texture,
"table_mountain_nx");
182 auto color_source = DlColorSource::MakeImage(
183 image, tile_mode, tile_mode, DlImageSampling::kNearestNeighbor,
186 DisplayListBuilder builder;
188 paint.setColor(DlColor::kWhite());
189 paint.setColorSource(color_source);
191 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
192 builder.Translate(100.0f, 100.0f);
193 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
196 constexpr
auto stroke_width = 64;
197 paint.setDrawStyle(DlDrawStyle::kStroke);
198 paint.setStrokeWidth(stroke_width);
199 if (tile_mode == DlTileMode::kDecal) {
200 builder.DrawRect(DlRect::MakeXYWH(stroke_width, stroke_width, 600, 600),
203 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
208 DlPathBuilder path_builder;
209 path_builder.AddCircle(
DlPoint(150, 150), 150);
210 path_builder.AddRoundRect(
212 DlPath path = path_builder.TakePath();
215 EXPECT_FALSE(path.IsRect(
nullptr));
216 EXPECT_FALSE(path.IsOval(
nullptr));
217 EXPECT_FALSE(path.IsRoundRect(
nullptr));
220 EXPECT_FALSE(path.IsConvex());
222 paint.setDrawStyle(DlDrawStyle::kFill);
223 builder.DrawPath(path, paint);
230 constexpr
float kConicWeight = 0.707106781f;
231 const DlPath path = DlPathBuilder()
233 .ConicCurveTo({300, 300}, {300, 450}, kConicWeight)
234 .ConicCurveTo({300, 600}, {150, 600}, kConicWeight)
235 .ConicCurveTo({0, 600}, {0, 450}, kConicWeight)
236 .ConicCurveTo({0, 300}, {150, 300}, kConicWeight)
241 EXPECT_FALSE(path.IsRect(
nullptr));
242 EXPECT_FALSE(path.IsOval(
nullptr));
243 EXPECT_FALSE(path.IsRoundRect(
nullptr));
246 EXPECT_TRUE(path.IsConvex());
248 paint.setDrawStyle(DlDrawStyle::kFill);
249 builder.DrawPath(path, paint);
252 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
257 CanRenderTiledTexture(
this, DlTileMode::kClamp);
261 CanRenderTiledTexture(
this, DlTileMode::kRepeat);
265 CanRenderTiledTexture(
this, DlTileMode::kMirror);
269 CanRenderTiledTexture(
this, DlTileMode::kDecal);
273 CanRenderTiledTexture(
this, DlTileMode::kClamp,
278 DisplayListBuilder builder;
281 DlISize image_half_size =
282 DlISize(image->GetSize().width * 0.5f, image->GetSize().height * 0.5f);
285 auto source_rect = DlRect::MakeSize(image_half_size);
287 source_rect.Shift(image_half_size.width, image_half_size.height);
289 builder.DrawImageRect(image, source_rect,
290 DlRect::MakeXYWH(100, 100, 600, 600),
291 DlImageSampling::kNearestNeighbor);
292 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
296 DisplayListBuilder builder;
300 auto source_rect = DlRect::MakeXYWH(
301 image->GetSize().width * 0.25f, image->GetSize().height * 0.4f,
302 image->GetSize().width, image->GetSize().height);
304 auto dest_rect = DlRect::MakeXYWH(100, 100, 600, 600);
307 paint.setColor(DlColor::kMidGrey());
308 builder.DrawRect(dest_rect, paint);
310 builder.DrawImageRect(image, source_rect, dest_rect,
311 DlImageSampling::kNearestNeighbor);
312 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
316 DisplayListBuilder builder;
317 builder.Scale(GetContentScale().
x, GetContentScale().y);
320 paint.setColor(DlColor::kWhite());
321 builder.DrawPaint(paint);
323 auto draw = [&builder](
const DlPaint& paint,
Scalar x,
Scalar y) {
325 builder.Translate(
x, y);
328 builder.ClipRect(DlRect::MakeLTRB(50, 50, 150, 150));
329 builder.DrawPaint(paint);
334 builder.ClipOval(DlRect::MakeLTRB(200, 50, 300, 150));
335 builder.DrawPaint(paint);
340 builder.ClipRoundRect(
341 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(50, 200, 150, 300), 20, 20));
342 builder.DrawPaint(paint);
347 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
348 DlRect::MakeLTRB(200, 230, 300, 270), 20, 20));
349 builder.DrawPaint(paint);
354 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
355 DlRect::MakeLTRB(230, 200, 270, 300), 20, 20));
356 builder.DrawPaint(paint);
362 paint.setColor(DlColor::kBlue());
365 DlColor gradient_colors[7] = {
366 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
367 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
368 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
369 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
370 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
371 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
372 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
383 auto texture = CreateTextureForFixture(
"airplane.jpg",
387 paint.setColorSource(DlColorSource::MakeRadial(
388 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
391 paint.setColorSource(
392 DlColorSource::MakeImage(image, DlTileMode::kRepeat, DlTileMode::kRepeat,
393 DlImageSampling::kNearestNeighbor));
396 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
400 DisplayListBuilder builder;
403 red.setColor(DlColor::kRed());
406 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
408 builder.SaveLayer(std::nullopt, &alpha);
410 builder.DrawCircle(
DlPoint(125, 125), 125, red);
414 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
418 DisplayListBuilder builder;
421 DlColor colors[2] = {
422 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
423 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
430 paint.setColorSource(DlColorSource::MakeLinear(
440 builder.Translate(100, 100);
441 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
445 builder.Translate(100, 400);
446 builder.DrawCircle(
DlPoint(100, 100), 100, paint);
448 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
452 DisplayListBuilder builder;
454 paint.setColor(DlColor::kRed());
458 .top_right = DlSize(25, 50),
459 .bottom_left = DlSize(25, 50),
460 .bottom_right = DlSize(50, 25),
463 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
465 builder.DrawRoundRect(rrect, paint);
467 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
471 auto medium_turquoise =
472 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
474 DisplayListBuilder builder;
475 builder.Scale(0.2, 0.2);
476 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
477 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
481 auto medium_turquoise =
482 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
484 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
486 DisplayListBuilder builder;
487 builder.Scale(0.2, 0.2);
488 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
489 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
490 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
494 DisplayListBuilder builder;
495 builder.Scale(GetContentScale().
x, GetContentScale().y);
498 paint.setColor(DlColor::kPurple());
499 paint.setDrawStyle(DlDrawStyle::kStroke);
500 paint.setStrokeWidth(20.0f);
502 DlPaint thin_paint = paint;
503 thin_paint.setColor(DlColor::kYellow());
504 thin_paint.setStrokeWidth(0.0f);
506 DlRect rect = DlRect::MakeLTRB(10, 10, 90, 90);
507 DlRect thin_tall_rect = DlRect::MakeLTRB(120, 10, 120, 90);
508 DlRect thin_wide_rect = DlRect::MakeLTRB(10, 120, 90, 120);
509 DlRect empty_rect = DlRect::MakeLTRB(120, 120, 120, 120);
539 paint.setStrokeJoin(DlStrokeJoin::kBevel);
540 builder.DrawRect(rect.Shift({100, 100}), paint);
541 builder.DrawRect(rect.Shift({100, 100}), thin_paint);
542 builder.DrawRect(thin_tall_rect.Shift({100, 100}), paint);
543 builder.DrawRect(thin_tall_rect.Shift({100, 100}), thin_paint);
544 builder.DrawRect(thin_wide_rect.Shift({100, 100}), paint);
545 builder.DrawRect(thin_wide_rect.Shift({100, 100}), thin_paint);
546 builder.DrawRect(empty_rect.Shift({100, 100}), paint);
547 builder.DrawRect(empty_rect.Shift({100, 100}), thin_paint);
550 paint.setStrokeJoin(DlStrokeJoin::kRound);
551 builder.DrawRect(rect.Shift({100, 300}), paint);
552 builder.DrawRect(rect.Shift({100, 300}), thin_paint);
553 builder.DrawRect(thin_tall_rect.Shift({100, 300}), paint);
554 builder.DrawRect(thin_tall_rect.Shift({100, 300}), thin_paint);
555 builder.DrawRect(thin_wide_rect.Shift({100, 300}), paint);
556 builder.DrawRect(thin_wide_rect.Shift({100, 300}), thin_paint);
557 builder.DrawRect(empty_rect.Shift({100, 300}), paint);
558 builder.DrawRect(empty_rect.Shift({100, 300}), thin_paint);
561 paint.setStrokeJoin(DlStrokeJoin::kMiter);
563 builder.DrawRect(rect.Shift({100, 500}), paint);
564 builder.DrawRect(rect.Shift({100, 500}), thin_paint);
565 builder.DrawRect(thin_tall_rect.Shift({100, 500}), paint);
566 builder.DrawRect(thin_tall_rect.Shift({100, 500}), thin_paint);
567 builder.DrawRect(thin_wide_rect.Shift({100, 500}), paint);
568 builder.DrawRect(thin_wide_rect.Shift({100, 500}), thin_paint);
569 builder.DrawRect(empty_rect.Shift({100, 500}), paint);
570 builder.DrawRect(empty_rect.Shift({100, 500}), thin_paint);
573 paint.setStrokeJoin(DlStrokeJoin::kMiter);
575 builder.DrawRect(rect.Shift({300, 500}), paint);
576 builder.DrawRect(rect.Shift({300, 500}), thin_paint);
577 builder.DrawRect(thin_tall_rect.Shift({300, 500}), paint);
578 builder.DrawRect(thin_tall_rect.Shift({300, 500}), thin_paint);
579 builder.DrawRect(thin_wide_rect.Shift({300, 500}), paint);
580 builder.DrawRect(thin_wide_rect.Shift({300, 500}), thin_paint);
581 builder.DrawRect(empty_rect.Shift({300, 500}), paint);
582 builder.DrawRect(empty_rect.Shift({300, 500}), thin_paint);
584 paint.setStrokeWidth(120.0f);
585 paint.setColor(DlColor::kBlue());
586 rect = rect.Expand(-20);
589 paint.setStrokeJoin(DlStrokeJoin::kBevel);
590 builder.DrawRect(rect.Shift({500, 100}), paint);
591 builder.DrawRect(rect.Shift({500, 100}), thin_paint);
594 paint.setStrokeJoin(DlStrokeJoin::kRound);
595 builder.DrawRect(rect.Shift({500, 300}), paint);
596 builder.DrawRect(rect.Shift({500, 300}), thin_paint);
599 paint.setStrokeJoin(DlStrokeJoin::kMiter);
601 builder.DrawRect(rect.Shift({500, 500}), paint);
602 builder.DrawRect(rect.Shift({500, 500}), thin_paint);
605 paint.setStrokeJoin(DlStrokeJoin::kMiter);
607 builder.DrawRect(rect.Shift({700, 500}), paint);
608 builder.DrawRect(rect.Shift({700, 500}), thin_paint);
610 DlPaint round_mock_paint;
611 round_mock_paint.setColor(DlColor::kGreen());
612 round_mock_paint.setDrawStyle(DlDrawStyle::kFill);
617 for (
int i = 0; i < 15; i++) {
618 paint.setStrokeWidth(i);
619 paint.setColor(DlColor::kOrange());
620 paint.setStrokeJoin(DlStrokeJoin::kRound);
621 builder.DrawRect(DlRect::MakeXYWH(
x, y, 30, 30), paint);
625 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
629 DisplayListBuilder builder;
630 builder.Scale(GetContentScale().
x, GetContentScale().y);
632 const int color_count = 3;
633 DlColor colors[color_count] = {
636 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
639 paint.setColor(DlColor::kWhite());
640 builder.DrawPaint(paint);
645 paint.setColor(colors[(c_index++) % color_count]);
646 builder.DrawCircle(
DlPoint(10, 10), radius, paint);
654 DlColor gradient_colors[7] = {
655 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
656 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
657 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
658 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
659 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
660 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
661 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
672 auto texture = CreateTextureForFixture(
"airplane.jpg",
676 paint.setColorSource(DlColorSource::MakeRadial(
677 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
678 builder.DrawCircle(
DlPoint(500, 600), 100, paint);
680 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
681 paint.setColorSource(DlColorSource::MakeImage(
682 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
683 DlImageSampling::kNearestNeighbor, &local_matrix));
684 builder.DrawCircle(
DlPoint(800, 300), 100, paint);
686 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
690 DisplayListBuilder builder;
691 builder.Scale(GetContentScale().
x, GetContentScale().y);
693 const int color_count = 3;
694 DlColor colors[color_count] = {
697 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
700 paint.setColor(DlColor::kWhite());
701 builder.DrawPaint(paint);
705 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas,
DlPoint center,
707 for (
int i = 0; i < n; i++) {
708 paint.setColor(colors[(c_index++) % color_count]);
709 canvas.DrawCircle(center, r, paint);
714 paint.setDrawStyle(DlDrawStyle::kStroke);
715 paint.setStrokeWidth(1);
716 draw(builder,
DlPoint(10, 10), 2, 2, 14);
717 paint.setStrokeWidth(5);
718 draw(builder,
DlPoint(10, 10), 35, 10, 56);
720 DlColor gradient_colors[7] = {
721 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
722 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
723 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
724 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
725 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
726 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
727 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
738 auto texture = CreateTextureForFixture(
"airplane.jpg",
742 paint.setColorSource(DlColorSource::MakeRadial(
743 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
744 draw(builder,
DlPoint(500, 600), 5, 10, 10);
746 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
747 paint.setColorSource(DlColorSource::MakeImage(
748 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
749 DlImageSampling::kNearestNeighbor, &local_matrix));
750 draw(builder,
DlPoint(800, 300), 5, 10, 10);
752 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
756 DisplayListBuilder builder;
757 builder.Scale(GetContentScale().
x, GetContentScale().y);
759 const int color_count = 3;
760 DlColor colors[color_count] = {
763 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
766 paint.setColor(DlColor::kWhite());
767 builder.DrawPaint(paint);
770 int long_radius = 600;
771 int short_radius = 600;
772 while (long_radius > 0 && short_radius > 0) {
773 paint.setColor(colors[(c_index++) % color_count]);
774 builder.DrawOval(DlRect::MakeXYWH(10 - long_radius, 10 - short_radius,
775 long_radius * 2, short_radius * 2),
777 builder.DrawOval(DlRect::MakeXYWH(1000 - short_radius, 750 - long_radius,
778 short_radius * 2, long_radius * 2),
780 if (short_radius > 30) {
789 DlColor gradient_colors[7] = {
790 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
791 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
792 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
793 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
794 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
795 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
796 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
807 auto texture = CreateTextureForFixture(
"airplane.jpg",
811 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
813 paint.setColorSource(DlColorSource::MakeRadial(
814 DlPoint(300, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
815 builder.DrawOval(DlRect::MakeXYWH(200, 625, 200, 50), paint);
816 builder.DrawOval(DlRect::MakeXYWH(275, 550, 50, 200), paint);
818 DlMatrix local_matrix = DlMatrix::MakeTranslation({610, 15});
819 paint.setColorSource(DlColorSource::MakeImage(
820 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
821 DlImageSampling::kNearestNeighbor, &local_matrix));
822 builder.DrawOval(DlRect::MakeXYWH(610, 90, 200, 50), paint);
823 builder.DrawOval(DlRect::MakeXYWH(685, 15, 50, 200), paint);
825 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
829 struct ArcFarmOptions {
836 void RenderArcFarm(DisplayListBuilder& builder,
837 const DlPaint& paint,
838 const ArcFarmOptions& opts) {
840 builder.Translate(50, 50);
842 const int sweep_limit = opts.sweeps_over_360 ? 420 : 360;
845 for (
int sweep = 30; sweep <= sweep_limit; sweep += 30) {
846 builder.DrawArc(arc_bounds,
start, opts.full_circles ? 360 : sweep,
847 opts.use_center, paint);
848 builder.Translate(50, 0);
851 builder.Translate(0, 50);
858 DisplayListBuilder builder;
859 builder.Scale(GetContentScale().
x, GetContentScale().y);
860 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
863 paint.setColor(DlColor::kBlue());
865 RenderArcFarm(builder, paint,
868 .full_circles =
false,
871 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
875 DisplayListBuilder builder;
876 builder.Scale(GetContentScale().
x, GetContentScale().y);
877 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
880 paint.setColor(DlColor::kBlue());
882 RenderArcFarm(builder, paint,
885 .full_circles =
false,
888 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
892 DisplayListBuilder builder;
893 builder.Scale(GetContentScale().
x, GetContentScale().y);
894 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
897 paint.setColor(DlColor::kBlue());
899 RenderArcFarm(builder, paint,
902 .full_circles =
false,
903 .vertical_scale = 0.8f,
906 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
910 DisplayListBuilder builder;
911 builder.Scale(GetContentScale().
x, GetContentScale().y);
912 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
915 paint.setColor(DlColor::kBlue());
917 RenderArcFarm(builder, paint,
920 .full_circles =
false,
921 .vertical_scale = 0.8f,
924 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
928 DisplayListBuilder builder;
929 builder.Scale(GetContentScale().
x, GetContentScale().y);
930 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
933 paint.setDrawStyle(DlDrawStyle::kStroke);
934 paint.setStrokeWidth(6.0f);
935 paint.setStrokeCap(DlStrokeCap::kButt);
936 paint.setColor(DlColor::kBlue());
938 RenderArcFarm(builder, paint,
941 .full_circles =
false,
944 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
948 DisplayListBuilder builder;
949 builder.Scale(GetContentScale().
x, GetContentScale().y);
950 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
953 paint.setDrawStyle(DlDrawStyle::kStroke);
954 paint.setStrokeWidth(6.0f);
955 paint.setStrokeCap(DlStrokeCap::kSquare);
956 paint.setColor(DlColor::kBlue());
958 RenderArcFarm(builder, paint,
961 .full_circles =
false,
964 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
968 DisplayListBuilder builder;
969 builder.Scale(GetContentScale().
x, GetContentScale().y);
970 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
973 paint.setDrawStyle(DlDrawStyle::kStroke);
974 paint.setStrokeWidth(6.0f);
975 paint.setStrokeCap(DlStrokeCap::kRound);
976 paint.setColor(DlColor::kBlue());
978 RenderArcFarm(builder, paint,
981 .full_circles =
false,
984 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
988 DisplayListBuilder builder;
989 builder.Scale(GetContentScale().
x, GetContentScale().y);
990 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
993 paint.setDrawStyle(DlDrawStyle::kStroke);
994 paint.setStrokeWidth(6.0f);
995 paint.setStrokeJoin(DlStrokeJoin::kBevel);
996 paint.setColor(DlColor::kBlue());
998 RenderArcFarm(builder, paint,
1001 .full_circles =
false,
1002 .sweeps_over_360 =
true,
1005 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1009 DisplayListBuilder builder;
1010 builder.Scale(GetContentScale().
x, GetContentScale().y);
1011 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1014 paint.setDrawStyle(DlDrawStyle::kStroke);
1015 paint.setStrokeWidth(6.0f);
1016 paint.setStrokeJoin(DlStrokeJoin::kMiter);
1019 paint.setStrokeMiter(3.0f);
1020 paint.setColor(DlColor::kBlue());
1022 RenderArcFarm(builder, paint,
1025 .full_circles =
false,
1026 .sweeps_over_360 =
true,
1029 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1033 DisplayListBuilder builder;
1034 builder.Scale(GetContentScale().
x, GetContentScale().y);
1035 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1038 paint.setDrawStyle(DlDrawStyle::kStroke);
1039 paint.setStrokeWidth(6.0f);
1040 paint.setStrokeJoin(DlStrokeJoin::kRound);
1041 paint.setColor(DlColor::kBlue());
1043 RenderArcFarm(builder, paint,
1046 .full_circles =
false,
1047 .sweeps_over_360 =
true,
1050 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1054 DisplayListBuilder builder;
1055 builder.Scale(GetContentScale().
x, GetContentScale().y);
1056 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1059 paint.setDrawStyle(DlDrawStyle::kStroke);
1060 paint.setStrokeWidth(8.0f);
1061 paint.setStrokeCap(DlStrokeCap::kSquare);
1062 paint.setColor(DlColor::kRed());
1064 RenderArcFarm(builder, paint,
1066 .use_center =
false,
1067 .full_circles =
false,
1070 paint.setStrokeCap(DlStrokeCap::kButt);
1071 paint.setColor(DlColor::kBlue());
1073 RenderArcFarm(builder, paint,
1075 .use_center =
false,
1076 .full_circles =
false,
1079 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1083 DisplayListBuilder builder;
1084 builder.Scale(GetContentScale().
x, GetContentScale().y);
1085 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1088 paint.setDrawStyle(DlDrawStyle::kStroke);
1089 paint.setStrokeWidth(8.0f);
1090 paint.setStrokeCap(DlStrokeCap::kSquare);
1091 paint.setColor(DlColor::kRed());
1093 RenderArcFarm(builder, paint,
1095 .use_center =
false,
1096 .full_circles =
false,
1099 paint.setStrokeCap(DlStrokeCap::kRound);
1100 paint.setColor(DlColor::kGreen());
1102 RenderArcFarm(builder, paint,
1104 .use_center =
false,
1105 .full_circles =
false,
1108 paint.setStrokeCap(DlStrokeCap::kButt);
1109 paint.setColor(DlColor::kBlue());
1111 RenderArcFarm(builder, paint,
1113 .use_center =
false,
1114 .full_circles =
false,
1117 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1132 DisplayListBuilder builder;
1133 builder.Scale(GetContentScale().
x, GetContentScale().y);
1134 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1137 paint.setDrawStyle(DlDrawStyle::kStroke);
1138 paint.setStrokeWidth(6.0f);
1139 paint.setStrokeCap(DlStrokeCap::kButt);
1140 paint.setColor(DlColor::kBlue());
1143 RenderArcFarm(builder, paint,
1145 .use_center =
false,
1146 .full_circles =
true,
1149 paint.setColor(DlColor::kWhite());
1152 RenderArcFarm(builder, paint,
1154 .use_center =
false,
1155 .full_circles =
false,
1158 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1162 DisplayListBuilder builder;
1163 builder.Scale(GetContentScale().
x, GetContentScale().y);
1165 const int color_count = 3;
1166 DlColor colors[color_count] = {
1169 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
1172 paint.setColor(DlColor::kWhite());
1173 builder.DrawPaint(paint);
1176 for (
int i = 0; i < 4; i++) {
1177 for (
int j = 0; j < 4; j++) {
1178 paint.setColor(colors[(c_index++) % color_count]);
1179 builder.DrawRoundRect(
1180 DlRoundRect::MakeRectXY(
1181 DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1182 i * 5 + 10, j * 5 + 10),
1186 paint.setColor(colors[(c_index++) % color_count]);
1187 builder.DrawRoundRect(
1188 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40),
1190 paint.setColor(colors[(c_index++) % color_count]);
1191 builder.DrawRoundRect(
1192 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40),
1195 DlColor gradient_colors[7] = {
1196 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1197 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1198 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1199 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1200 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1201 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1202 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
1213 auto texture = CreateTextureForFixture(
"airplane.jpg",
1217 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1218 paint.setColorSource(DlColorSource::MakeRadial(
1219 DlPoint(550, 550), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1220 for (
int i = 1; i <= 10; i++) {
1222 builder.DrawRoundRect(
1223 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1224 550 + i * 20, 550 + j * 20),
1229 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1230 paint.setColorSource(DlColorSource::MakeRadial(
1231 DlPoint(200, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1232 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1233 builder.DrawRoundRect(
1234 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40),
1236 builder.DrawRoundRect(
1237 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40),
1240 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1241 DlMatrix local_matrix = DlMatrix::MakeTranslation({520, 20});
1242 paint.setColorSource(DlColorSource::MakeImage(
1243 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1244 DlImageSampling::kNearestNeighbor, &local_matrix));
1245 for (
int i = 1; i <= 10; i++) {
1247 builder.DrawRoundRect(
1248 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1249 720 + i * 20, 220 + j * 20),
1254 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1255 local_matrix = DlMatrix::MakeTranslation({800, 300});
1256 paint.setColorSource(DlColorSource::MakeImage(
1257 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1258 DlImageSampling::kNearestNeighbor, &local_matrix));
1259 builder.DrawRoundRect(
1260 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
1262 builder.DrawRoundRect(
1263 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40),
1266 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1270 DisplayListBuilder builder;
1271 builder.Scale(GetContentScale().
x, GetContentScale().y);
1273 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
1275 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
1278 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
1280 for (
int i = 0; i < 5; i++) {
1283 builder.DrawRect(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1284 radius, 60.0f - radius),
1288 paint.setColor(DlColor::kBlue());
1290 for (
int i = 0; i < 5; i++) {
1293 builder.DrawCircle(
DlPoint(
x + 25, y + 25), radius, paint);
1296 paint.setColor(DlColor::kGreen());
1298 for (
int i = 0; i < 5; i++) {
1301 builder.DrawOval(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1302 radius, 60.0f - radius),
1307 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
1309 for (
int i = 0; i < 5; i++) {
1312 builder.DrawRoundRect(
1313 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1319 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
1321 for (
int i = 0; i < 5; i++) {
1324 builder.DrawRoundRect(
1325 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1330 auto dl = builder.Build();
1331 ASSERT_TRUE(OpenPlaygroundHere(dl));
1335 DisplayListBuilder builder;
1337 builder.Scale(GetContentScale().
x, GetContentScale().y);
1340 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1341 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
1342 std::vector<Scalar> stops = {
1347 paint.setColorSource(DlColorSource::MakeLinear(
1356 builder.DrawPaint(paint);
1358 DlRect clip_rect = DlRect::MakeLTRB(50, 50, 400, 300);
1359 DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 100, 100);
1363 builder.ClipRoundRect(clip_rrect, DlClipOp::kIntersect);
1366 auto backdrop_filter = DlImageFilter::MakeColorFilter(
1367 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kExclusion));
1368 builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get());
1370 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1376 auto callback = [&]() -> sk_sp<DisplayList> {
1377 DisplayListBuilder builder;
1381 builder.Translate(300, 300);
1388 paint.setColor(DlColor::kGreen());
1389 builder.DrawPaint(paint);
1390 builder.ClipRect(DlRect::MakeLTRB(-180, -180, 180, 180),
1391 DlClipOp::kDifference);
1393 paint.setColor(DlColor::kBlack());
1394 builder.DrawPaint(paint);
1402 builder.ClipOval(DlRect::MakeLTRB(-200, -200, 200, 200));
1405 Matrix(1.0, 0.0, 0.0, 0.0,
1407 0.0, 0.0, 1.0, 0.003,
1408 0.0, 0.0, 0.0, 1.0) *
1417 -
DlPoint(image->GetSize().width, image->GetSize().height) * 0.5;
1418 builder.DrawImage(image, position, {});
1424 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
1425 builder.DrawCircle(
DlPoint(), 230, paint);
1429 return builder.Build();
1431 ASSERT_TRUE(OpenPlaygroundHere(callback));
1437 DisplayListBuilder builder;
1441 paint.setColor(DlColor::kWhite());
1442 builder.DrawPaint(paint);
1446 DlMatrix matrix = DlMatrix::MakeTranslation({50, 50});
1448 paint.setColorSource(DlColorSource::MakeImage(
1449 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1450 DlImageSampling::kNearestNeighbor, &matrix));
1452 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
1461 Matrix matrix(1, -1, 0, 0,
1465 paint.setColorSource(DlColorSource::MakeImage(
1466 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1467 DlImageSampling::kNearestNeighbor, &matrix));
1468 builder.DrawRect(DlRect::MakeLTRB(100, 0, 200, 100), paint);
1475 builder.Translate(100, 0);
1476 builder.Scale(100, 100);
1479 DlMatrix matrix = DlMatrix::MakeScale({0.005, 0.005, 1});
1480 paint.setColorSource(DlColorSource::MakeImage(
1481 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1482 DlImageSampling::kNearestNeighbor, &matrix));
1484 builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
1491 builder.Translate(150, 150);
1495 DlMatrix::MakePerspective(
Radians{0.5},
ISize{200, 200}, 0.05, 1);
1496 paint.setColorSource(DlColorSource::MakeImage(
1497 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1498 DlImageSampling::kNearestNeighbor, &matrix));
1500 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
1504 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1508 DisplayListBuilder builder;
1513 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1514 paint.setBlendMode(DlBlendMode::kSrc);
1516 DlRect bounds = DlRect::MakeLTRB(0, 0, 200, 200);
1517 builder.SaveLayer(bounds, &paint);
1519 paint.setColor(DlColor::kTransparent());
1520 paint.setBlendMode(DlBlendMode::kSrc);
1521 builder.DrawPaint(paint);
1524 paint.setColor(DlColor::kBlue());
1525 paint.setBlendMode(DlBlendMode::kDstOver);
1526 builder.SaveLayer(std::nullopt, &paint);
1532 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1537 DisplayListBuilder builder;
1538 builder.Scale(GetContentScale().
x, GetContentScale().y);
1539 builder.Translate(100, 100);
1543 DlMatrix translate = DlMatrix::MakeTranslation({300, 0});
1544 paint.setImageFilter(
1545 DlImageFilter::MakeMatrix(translate, DlImageSampling::kLinear));
1546 builder.SaveLayer(std::nullopt, &paint);
1548 DlPaint circle_paint;
1549 circle_paint.setColor(DlColor::kGreen());
1550 builder.DrawCircle(
DlPoint(-300, 0), 100, circle_paint);
1553 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1558 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
1559 DisplayListBuilder builder;
1560 builder.Scale(GetContentScale().
x, GetContentScale().y);
1561 builder.Translate(100, 100);
1566 paint.setImageFilter(DlImageFilter::MakeMatrix(
1567 DlMatrix::MakeTranslation({300, 0}) * DlMatrix::MakeScale({2, 2, 1}),
1568 DlImageSampling::kNearestNeighbor));
1569 builder.SaveLayer(std::nullopt, &paint);
1571 DlPaint circle_paint;
1572 circle_paint.setColor(DlColor::kGreen());
1573 builder.DrawCircle(
DlPoint(-150, 0), 50, circle_paint);
1576 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1581 SetWindowSize({400, 400});
1582 DisplayListBuilder builder;
1584 builder.Scale(GetContentScale().
x, GetContentScale().y);
1587 paint.setColor(DlColor::kRed());
1588 builder.DrawRect(DlRect::MakeLTRB(200, 200, 300, 300), paint);
1590 paint.setImageFilter(DlImageFilter::MakeMatrix(DlMatrix::MakeScale({2, 2, 1}),
1591 DlImageSampling::kLinear));
1592 builder.SaveLayer(std::nullopt, &paint);
1595 paint.setColor(DlColor::kGreen());
1596 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
1599 paint.setColor(DlColor::kRed());
1600 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 800), paint);
1603 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1607 DisplayListBuilder builder;
1608 builder.Scale(GetContentScale().
x, GetContentScale().y);
1611 paint.setColor(DlColor::kRed());
1612 builder.DrawPaint(paint);
1613 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1614 paint.setColor(DlColor::kBlue());
1615 builder.SaveLayer(std::nullopt, &paint);
1618 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1622 DisplayListBuilder builder;
1623 builder.Scale(GetContentScale().
x, GetContentScale().y);
1625 builder.DrawImage(image,
DlPoint(10, 10), {});
1626 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1629 paint.setBlendMode(DlBlendMode::kClear);
1630 builder.SaveLayer(std::nullopt, &paint);
1633 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1637 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
1638 DisplayListBuilder builder;
1641 red.setColor(DlColor::kRed());
1644 green.setColor(DlColor::kGreen());
1647 blue.setColor(DlColor::kBlue());
1650 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1652 DlRect huge_bounds = DlRect::MakeXYWH(0, 0, 100000, 100000);
1653 builder.SaveLayer(huge_bounds, &save);
1655 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1656 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), green);
1657 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), blue);
1661 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1666 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1672 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1679 DisplayListBuilder builder;
1686 builder.Translate(100, 200);
1687 builder.Scale(0.5, 0.5);
1688 builder.DrawImage(image,
DlPoint(100.0, 100.0),
1689 DlImageSampling::kNearestNeighbor);
1696 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1698 builder.SaveLayer(std::nullopt, &alpha);
1701 paint.setColor(DlColor::kRed());
1702 builder.DrawRect(DlRect::MakeXYWH(000, 000, 100, 100), paint);
1703 paint.setColor(DlColor::kGreen());
1704 builder.DrawRect(DlRect::MakeXYWH(020, 020, 100, 100), paint);
1705 paint.setColor(DlColor::kBlue());
1706 builder.DrawRect(DlRect::MakeXYWH(040, 040, 100, 100), paint);
1711 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1715 DisplayListBuilder builder;
1718 paint.setColor(DlColor::kRed());
1719 builder.DrawCircle(
DlPoint(250, 250), 125, paint);
1721 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1725 DisplayListBuilder builder;
1728 red.setColor(DlColor::kRed());
1730 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1732 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1736 DisplayListBuilder builder;
1739 save.setColor(DlColor::kBlack());
1741 DlRect save_bounds = DlRect::MakeXYWH(0, 0, 50, 50);
1742 builder.SaveLayer(save_bounds, &save);
1745 paint.setColor(DlColor::kRed());
1746 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
1747 paint.setColor(DlColor::kGreen());
1748 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), paint);
1749 paint.setColor(DlColor::kBlue());
1750 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), paint);
1754 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1758 DisplayListBuilder builder;
1759 builder.Scale(GetContentScale().
x, GetContentScale().y);
1762 const int color_count = 3;
1763 DlColor colors[color_count] = {
1766 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
1769 paint.setColor(DlColor::kWhite());
1770 builder.DrawPaint(paint);
1773 const DlPaint& paint) {
1774 builder.DrawPath(DlPath::MakeRoundRectXY(rect,
x, y), paint);
1778 for (
int i = 0; i < 4; i++) {
1779 for (
int j = 0; j < 4; j++) {
1780 paint.setColor(colors[(c_index++) % color_count]);
1781 draw_rrect_as_path(DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1782 i * 5 + 10, j * 5 + 10, paint);
1785 paint.setColor(colors[(c_index++) % color_count]);
1786 draw_rrect_as_path(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
1787 paint.setColor(colors[(c_index++) % color_count]);
1788 draw_rrect_as_path(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
1790 std::vector<DlColor> gradient_colors = {
1791 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1792 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1793 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1794 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1795 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1796 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1797 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
1798 std::vector<Scalar> stops = {
1808 CreateTextureForFixture(
"airplane.jpg",
1811 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1812 paint.setColorSource(DlColorSource::MakeRadial(
1815 gradient_colors.size(),
1816 gradient_colors.data(),
1818 DlTileMode::kMirror));
1819 for (
int i = 1; i <= 10; i++) {
1821 draw_rrect_as_path(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1822 550 + i * 20, 550 + j * 20),
1823 i * 10, j * 10, paint);
1825 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1826 paint.setColorSource(DlColorSource::MakeRadial(
1829 gradient_colors.size(),
1830 gradient_colors.data(),
1832 DlTileMode::kMirror));
1833 draw_rrect_as_path(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
1834 draw_rrect_as_path(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
1836 auto matrix = DlMatrix::MakeTranslation({520, 20});
1837 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1838 paint.setColorSource(DlColorSource::MakeImage(
1839 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1840 DlImageSampling::kMipmapLinear, &matrix));
1841 for (
int i = 1; i <= 10; i++) {
1843 draw_rrect_as_path(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1844 720 + i * 20, 220 + j * 20),
1845 i * 10, j * 10, paint);
1847 matrix = DlMatrix::MakeTranslation({800, 300});
1848 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1849 paint.setColorSource(DlColorSource::MakeImage(
1850 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1851 DlImageSampling::kMipmapLinear, &matrix));
1853 draw_rrect_as_path(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
1854 draw_rrect_as_path(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
1856 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1860 auto callback = [&]() -> sk_sp<DisplayList> {
1861 DisplayListBuilder builder;
1862 builder.Scale(GetContentScale().x, GetContentScale().y);
1865 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1867 auto current =
Point{25, 25};
1868 const auto offset =
Point{25, 25};
1869 const auto size =
Size(100, 100);
1874 DlRect bounds = DlRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
1876 DlPaint stroke_paint;
1877 stroke_paint.setColor(DlColor::kYellow());
1878 stroke_paint.setStrokeWidth(5);
1879 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
1880 builder.DrawRect(bounds, stroke_paint);
1882 builder.SaveLayer(bounds, &alpha);
1885 paint.setColor(DlColor::kRed());
1887 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1889 paint.setColor(DlColor::kGreen());
1892 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1894 paint.setColor(DlColor::kBlue());
1897 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1901 return builder.Build();
1904 ASSERT_TRUE(OpenPlaygroundHere(callback));
1909 DisplayListBuilder builder;
1912 paint.setColor(DlColor::kBlack());
1913 DlRect rect = DlRect::MakeXYWH(25, 25, 25, 25);
1914 builder.DrawRect(rect, paint);
1916 builder.Translate(10, 10);
1919 builder.SaveLayer(std::nullopt, &save_paint);
1921 paint.setColor(DlColor::kGreen());
1922 builder.DrawRect(rect, paint);
1926 builder.Translate(10, 10);
1927 paint.setColor(DlColor::kRed());
1928 builder.DrawRect(rect, paint);
1930 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1934 DisplayListBuilder builder;
1936 DlRect rect = DlRect::MakeXYWH(0, 0, 1000, 1000);
1941 DlRect bounds = DlRect::MakeXYWH(25, 25, 25, 25);
1942 builder.SaveLayer(bounds, &save_paint);
1943 paint.setColor(DlColor::kBlack());
1944 builder.DrawRect(rect, paint);
1950 DlRect bounds = DlRect::MakeXYWH(35, 35, 25, 25);
1951 builder.SaveLayer(bounds, &save_paint);
1952 paint.setColor(DlColor::kGreen());
1953 builder.DrawRect(rect, paint);
1959 DlRect bounds = DlRect::MakeXYWH(45, 45, 25, 25);
1960 builder.SaveLayer(bounds, &save_paint);
1961 paint.setColor(DlColor::kRed());
1962 builder.DrawRect(rect, paint);
1966 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1970 DisplayListBuilder builder;
1973 paint.setColor(DlColor::kWhite());
1974 builder.DrawPaint(paint);
1980 builder.ClipPath(path);
1982 DlRect bounds = DlRect::MakeXYWH(50, 50, 100, 100);
1984 builder.SaveLayer(bounds, &save_paint);
1987 paint.setColor(DlColor::kWhite());
1988 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
1991 paint.setColor(DlColor::kGreen());
1992 paint.setBlendMode(DlBlendMode::kHardLight);
1993 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
1996 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2000 DisplayListBuilder builder;
2002 builder.Scale(GetContentScale().
x, GetContentScale().y);
2003 builder.Translate(100, 100);
2006 auto draw_image_layer = [&builder, &texture](
const DlPaint& paint) {
2007 builder.SaveLayer(std::nullopt, &paint);
2008 builder.DrawImage(texture,
DlPoint(), DlImageSampling::kLinear);
2012 DlPaint effect_paint;
2013 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
2014 draw_image_layer(effect_paint);
2016 builder.Translate(300, 300);
2017 builder.Scale(3, 3);
2018 draw_image_layer(effect_paint);
2020 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2024 DisplayListBuilder builder;
2026 builder.Scale(GetContentScale().
x, GetContentScale().y);
2028 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
2031 save_paint.setColor(DlColor::kWhite());
2032 builder.DrawPaint(save_paint);
2034 paint.setColor(DlColor::kBlue());
2035 for (
int i = 0; i < 5; i++) {
2037 Scalar y_radius = i * 15;
2038 for (
int j = 0; j < 5; j++) {
2040 Scalar x_radius = j * 15;
2041 builder.DrawRoundRect(
2042 DlRoundRect::MakeRectXY(
2043 DlRect::MakeXYWH(
x + 50, y + 50, 100.0f, 100.0f),
2044 x_radius, y_radius),
2049 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2053 DisplayListBuilder builder;
2057 builder.SaveLayer(std::nullopt, &paint);
2059 builder.Translate(100, 100);
2060 paint.setColor(DlColor::kBlue());
2061 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2062 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
2064 paint.setColor(DlColor::kGreen());
2065 paint.setBlendMode(DlBlendMode::kSrcOver);
2066 paint.setImageFilter(DlImageFilter::MakeColorFilter(
2067 DlColorFilter::MakeBlend(DlColor::kWhite(), DlBlendMode::kDst)));
2068 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2072 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2080 GTEST_SKIP() <<
"Swiftshader is running out of memory on this example.";
2082 DisplayListBuilder builder(DlRect::MakeSize(DlSize(1000, 1000)));
2084 auto filter = DlImageFilter::MakeMatrix(
2085 DlMatrix::MakeScale({0.001, 0.001, 1}), DlImageSampling::kLinear);
2088 paint.setImageFilter(filter);
2089 builder.SaveLayer(std::nullopt, &paint);
2092 paint.setColor(DlColor::kRed());
2093 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100000, 100000), paint);
2097 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2104 auto callback = [&]() -> sk_sp<DisplayList> {
2106 ImGuiWindowFlags_AlwaysAutoResize)) {
2107 ImGui::SliderFloat(
"width", &width, 0, 200);
2108 ImGui::SliderFloat(
"height", &height, 0, 200);
2109 ImGui::SliderFloat(
"corner", &corner, 0, 1);
2113 DisplayListBuilder builder;
2114 builder.Scale(GetContentScale().
x, GetContentScale().y);
2116 DlPaint background_paint;
2117 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
2118 builder.DrawPaint(background_paint);
2120 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
2121 std::vector<Scalar> stops = {0.0, 1.0};
2124 auto gradient = DlColorSource::MakeLinear(
DlPoint(0, 0),
DlPoint(200, 200),
2125 2, colors.data(), stops.data(),
2126 DlTileMode::kClamp);
2127 paint.setColorSource(gradient);
2128 paint.setColor(DlColor::kWhite());
2129 paint.setDrawStyle(DlDrawStyle::kStroke);
2130 paint.setStrokeWidth(20);
2133 builder.Translate(100, 100);
2135 Scalar corner_x = ((1 - corner) * 50) + 50;
2136 Scalar corner_y = corner * 50 + 50;
2138 DlRect::MakeXYWH(0, 0, width, height), corner_x, corner_y);
2139 builder.DrawRoundRect(rrect, paint);
2141 return builder.Build();
2143 ASSERT_TRUE(OpenPlaygroundHere(callback));
2147 DisplayListBuilder builder;
2149 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
2152 builder.ClipRect(DlRect::MakeLTRB(100, 100, 800, 800));
2156 builder.ClipRect(DlRect::MakeLTRB(600, 600, 800, 800));
2157 builder.DrawPaint(DlPaint().setColor(DlColor::kRed()));
2158 builder.DrawPaint(DlPaint().setColor(DlColor::kBlue().withAlphaF(0.5)));
2159 builder.ClipRect(DlRect::MakeLTRB(700, 700, 750, 800));
2160 builder.DrawPaint(DlPaint().setColor(DlColor::kRed().withAlphaF(0.5)));
2164 auto image_filter = DlImageFilter::MakeBlur(10, 10, DlTileMode::kDecal);
2165 builder.SaveLayer(std::nullopt,
nullptr, image_filter.get());
2168 builder.DrawCircle(
DlPoint(100, 100), 100,
2169 DlPaint().setColor(DlColor::kAqua()));
2171 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 kEhCloseEnough
flutter::DlRoundRect DlRoundRect
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
constexpr const char * PixelFormatToString(PixelFormat format)
flutter::DlScalar DlScalar
void Close(PathBuilder *builder)
static constexpr Color White()
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
static Matrix MakeRotationY(Radians r)
constexpr Quad Transform(const Quad &quad) const
static RoundRect MakeRectXY(const Rect &rect, Scalar x_radius, Scalar y_radius)
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)