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()));
39 DisplayListBuilder builder;
41 paint.setColor(DlColor::kRed());
43 builder.DrawImage(image,
DlPoint(100.0, 100.0),
44 DlImageSampling::kNearestNeighbor, &paint);
45 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
49 DisplayListBuilder builder;
51 paint.setColor(DlColor::kRed());
53 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
54 paint.setInvertColors(
true);
57 builder.DrawImage(image,
DlPoint(100.0, 100.0),
58 DlImageSampling::kNearestNeighbor, &paint);
59 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
63 DisplayListBuilder builder;
65 paint.setColor(DlColor::kRed());
67 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
68 paint.setInvertColors(
true);
70 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
71 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
75 DisplayListBuilder builder;
77 paint.setColor(DlColor::kRed());
79 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
80 paint.setInvertColors(
true);
82 builder.DrawPaint(paint);
83 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
87 bool GenerateMipmap(
const std::shared_ptr<Context>& context,
88 std::shared_ptr<Texture> texture,
89 std::string_view label) {
90 auto buffer = context->CreateCommandBuffer();
94 auto pass = buffer->CreateBlitPass();
98 pass->GenerateMipmap(std::move(texture), label);
100 pass->EncodeCommands();
101 return context->GetCommandQueue()->Submit({buffer}).ok();
104 void CanRenderTiledTexture(
AiksTest* aiks_test,
105 DlTileMode tile_mode,
106 Matrix local_matrix = {}) {
107 auto context = aiks_test->GetContext();
108 ASSERT_TRUE(context);
109 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
111 GenerateMipmap(context, texture,
"table_mountain_nx");
113 auto color_source = DlColorSource::MakeImage(
114 image, tile_mode, tile_mode, DlImageSampling::kNearestNeighbor,
117 DisplayListBuilder builder;
119 paint.setColor(DlColor::kWhite());
120 paint.setColorSource(color_source);
122 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
123 builder.Translate(100.0f, 100.0f);
124 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
127 constexpr
auto stroke_width = 64;
128 paint.setDrawStyle(DlDrawStyle::kStroke);
129 paint.setStrokeWidth(stroke_width);
130 if (tile_mode == DlTileMode::kDecal) {
131 builder.DrawRect(DlRect::MakeXYWH(stroke_width, stroke_width, 600, 600),
134 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
139 DlPathBuilder path_builder;
140 path_builder.AddCircle(
DlPoint(150, 150), 150);
141 path_builder.AddRoundRect(
143 DlPath path = path_builder.TakePath();
146 EXPECT_FALSE(path.IsRect(
nullptr));
147 EXPECT_FALSE(path.IsOval(
nullptr));
148 EXPECT_FALSE(path.IsRoundRect(
nullptr));
151 EXPECT_FALSE(path.IsConvex());
153 paint.setDrawStyle(DlDrawStyle::kFill);
154 builder.DrawPath(path, paint);
162 EXPECT_TRUE(circle.IsOval(
nullptr));
164 EXPECT_TRUE(circle.IsConvex());
167 DlPathBuilder path_builder;
170 path_builder.MoveTo({10, 10});
171 path_builder.AddPath(circle);
172 DlPath path = path_builder.TakePath();
175 EXPECT_FALSE(path.IsRect(
nullptr));
176 EXPECT_FALSE(path.IsOval(
nullptr));
177 EXPECT_FALSE(path.IsRoundRect(
nullptr));
180 EXPECT_TRUE(path.IsConvex());
182 paint.setDrawStyle(DlDrawStyle::kFill);
183 builder.DrawPath(path, paint);
186 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
191 CanRenderTiledTexture(
this, DlTileMode::kClamp);
195 CanRenderTiledTexture(
this, DlTileMode::kRepeat);
199 CanRenderTiledTexture(
this, DlTileMode::kMirror);
203 CanRenderTiledTexture(
this, DlTileMode::kDecal);
207 CanRenderTiledTexture(
this, DlTileMode::kClamp,
212 DisplayListBuilder builder;
215 DlISize image_half_size =
216 DlISize(image->GetSize().width * 0.5f, image->GetSize().height * 0.5f);
219 auto source_rect = DlRect::MakeSize(image_half_size);
221 source_rect.Shift(image_half_size.width, image_half_size.height);
223 builder.DrawImageRect(image, source_rect,
224 DlRect::MakeXYWH(100, 100, 600, 600),
225 DlImageSampling::kNearestNeighbor);
226 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
230 DisplayListBuilder builder;
234 auto source_rect = DlRect::MakeXYWH(
235 image->GetSize().width * 0.25f, image->GetSize().height * 0.4f,
236 image->GetSize().width, image->GetSize().height);
238 auto dest_rect = DlRect::MakeXYWH(100, 100, 600, 600);
241 paint.setColor(DlColor::kMidGrey());
242 builder.DrawRect(dest_rect, paint);
244 builder.DrawImageRect(image, source_rect, dest_rect,
245 DlImageSampling::kNearestNeighbor);
246 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
250 DisplayListBuilder builder;
251 builder.Scale(GetContentScale().
x, GetContentScale().y);
254 paint.setColor(DlColor::kWhite());
255 builder.DrawPaint(paint);
257 auto draw = [&builder](
const DlPaint& paint,
Scalar x,
Scalar y) {
259 builder.Translate(
x, y);
262 builder.ClipRect(DlRect::MakeLTRB(50, 50, 150, 150));
263 builder.DrawPaint(paint);
268 builder.ClipOval(DlRect::MakeLTRB(200, 50, 300, 150));
269 builder.DrawPaint(paint);
274 builder.ClipRoundRect(
275 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(50, 200, 150, 300), 20, 20));
276 builder.DrawPaint(paint);
281 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
282 DlRect::MakeLTRB(200, 230, 300, 270), 20, 20));
283 builder.DrawPaint(paint);
288 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
289 DlRect::MakeLTRB(230, 200, 270, 300), 20, 20));
290 builder.DrawPaint(paint);
296 paint.setColor(DlColor::kBlue());
299 DlColor gradient_colors[7] = {
300 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
301 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
302 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
303 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
304 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
305 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
306 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
317 auto texture = CreateTextureForFixture(
"airplane.jpg",
321 paint.setColorSource(DlColorSource::MakeRadial(
322 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
325 paint.setColorSource(
326 DlColorSource::MakeImage(image, DlTileMode::kRepeat, DlTileMode::kRepeat,
327 DlImageSampling::kNearestNeighbor));
330 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
334 DisplayListBuilder builder;
337 red.setColor(DlColor::kRed());
340 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
342 builder.SaveLayer(std::nullopt, &alpha);
344 builder.DrawCircle(
DlPoint(125, 125), 125, red);
348 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
352 DisplayListBuilder builder;
355 DlColor colors[2] = {
356 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
357 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
364 paint.setColorSource(DlColorSource::MakeLinear(
374 builder.Translate(100, 100);
375 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
379 builder.Translate(100, 400);
380 builder.DrawCircle(
DlPoint(100, 100), 100, paint);
382 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
386 DisplayListBuilder builder;
388 paint.setColor(DlColor::kRed());
392 .top_right = DlSize(25, 50),
393 .bottom_left = DlSize(25, 50),
394 .bottom_right = DlSize(50, 25),
397 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
399 builder.DrawRoundRect(rrect, paint);
401 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
405 auto medium_turquoise =
406 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
408 DisplayListBuilder builder;
409 builder.Scale(0.2, 0.2);
410 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
411 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
415 auto medium_turquoise =
416 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
418 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
420 DisplayListBuilder builder;
421 builder.Scale(0.2, 0.2);
422 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
423 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
424 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
428 DisplayListBuilder builder;
429 builder.Scale(GetContentScale().
x, GetContentScale().y);
432 paint.setColor(DlColor::kPurple());
433 paint.setDrawStyle(DlDrawStyle::kStroke);
434 paint.setStrokeWidth(20.0f);
436 DlPaint thin_paint = paint;
437 thin_paint.setColor(DlColor::kYellow());
438 thin_paint.setStrokeWidth(0.0f);
440 DlRect rect = DlRect::MakeLTRB(10, 10, 90, 90);
441 DlRect thin_tall_rect = DlRect::MakeLTRB(120, 10, 120, 90);
442 DlRect thin_wide_rect = DlRect::MakeLTRB(10, 120, 90, 120);
443 DlRect empty_rect = DlRect::MakeLTRB(120, 120, 120, 120);
473 paint.setStrokeJoin(DlStrokeJoin::kBevel);
474 builder.DrawRect(rect.Shift({100, 100}), paint);
475 builder.DrawRect(rect.Shift({100, 100}), thin_paint);
476 builder.DrawRect(thin_tall_rect.Shift({100, 100}), paint);
477 builder.DrawRect(thin_tall_rect.Shift({100, 100}), thin_paint);
478 builder.DrawRect(thin_wide_rect.Shift({100, 100}), paint);
479 builder.DrawRect(thin_wide_rect.Shift({100, 100}), thin_paint);
480 builder.DrawRect(empty_rect.Shift({100, 100}), paint);
481 builder.DrawRect(empty_rect.Shift({100, 100}), thin_paint);
484 paint.setStrokeJoin(DlStrokeJoin::kRound);
485 builder.DrawRect(rect.Shift({100, 300}), paint);
486 builder.DrawRect(rect.Shift({100, 300}), thin_paint);
487 builder.DrawRect(thin_tall_rect.Shift({100, 300}), paint);
488 builder.DrawRect(thin_tall_rect.Shift({100, 300}), thin_paint);
489 builder.DrawRect(thin_wide_rect.Shift({100, 300}), paint);
490 builder.DrawRect(thin_wide_rect.Shift({100, 300}), thin_paint);
491 builder.DrawRect(empty_rect.Shift({100, 300}), paint);
492 builder.DrawRect(empty_rect.Shift({100, 300}), thin_paint);
495 paint.setStrokeJoin(DlStrokeJoin::kMiter);
497 builder.DrawRect(rect.Shift({100, 500}), paint);
498 builder.DrawRect(rect.Shift({100, 500}), thin_paint);
499 builder.DrawRect(thin_tall_rect.Shift({100, 500}), paint);
500 builder.DrawRect(thin_tall_rect.Shift({100, 500}), thin_paint);
501 builder.DrawRect(thin_wide_rect.Shift({100, 500}), paint);
502 builder.DrawRect(thin_wide_rect.Shift({100, 500}), thin_paint);
503 builder.DrawRect(empty_rect.Shift({100, 500}), paint);
504 builder.DrawRect(empty_rect.Shift({100, 500}), thin_paint);
507 paint.setStrokeJoin(DlStrokeJoin::kMiter);
509 builder.DrawRect(rect.Shift({300, 500}), paint);
510 builder.DrawRect(rect.Shift({300, 500}), thin_paint);
511 builder.DrawRect(thin_tall_rect.Shift({300, 500}), paint);
512 builder.DrawRect(thin_tall_rect.Shift({300, 500}), thin_paint);
513 builder.DrawRect(thin_wide_rect.Shift({300, 500}), paint);
514 builder.DrawRect(thin_wide_rect.Shift({300, 500}), thin_paint);
515 builder.DrawRect(empty_rect.Shift({300, 500}), paint);
516 builder.DrawRect(empty_rect.Shift({300, 500}), thin_paint);
518 paint.setStrokeWidth(120.0f);
519 paint.setColor(DlColor::kBlue());
520 rect = rect.Expand(-20);
523 paint.setStrokeJoin(DlStrokeJoin::kBevel);
524 builder.DrawRect(rect.Shift({500, 100}), paint);
525 builder.DrawRect(rect.Shift({500, 100}), thin_paint);
528 paint.setStrokeJoin(DlStrokeJoin::kRound);
529 builder.DrawRect(rect.Shift({500, 300}), paint);
530 builder.DrawRect(rect.Shift({500, 300}), thin_paint);
533 paint.setStrokeJoin(DlStrokeJoin::kMiter);
535 builder.DrawRect(rect.Shift({500, 500}), paint);
536 builder.DrawRect(rect.Shift({500, 500}), thin_paint);
539 paint.setStrokeJoin(DlStrokeJoin::kMiter);
541 builder.DrawRect(rect.Shift({700, 500}), paint);
542 builder.DrawRect(rect.Shift({700, 500}), thin_paint);
544 DlPaint round_mock_paint;
545 round_mock_paint.setColor(DlColor::kGreen());
546 round_mock_paint.setDrawStyle(DlDrawStyle::kFill);
551 for (
int i = 0; i < 15; i++) {
552 paint.setStrokeWidth(i);
553 paint.setColor(DlColor::kOrange());
554 paint.setStrokeJoin(DlStrokeJoin::kRound);
555 builder.DrawRect(DlRect::MakeXYWH(
x, y, 30, 30), paint);
559 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
563 DisplayListBuilder builder;
564 builder.Scale(GetContentScale().
x, GetContentScale().y);
566 const int color_count = 3;
567 DlColor colors[color_count] = {
570 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
573 paint.setColor(DlColor::kWhite());
574 builder.DrawPaint(paint);
579 paint.setColor(colors[(c_index++) % color_count]);
580 builder.DrawCircle(
DlPoint(10, 10), radius, paint);
588 DlColor gradient_colors[7] = {
589 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
590 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
591 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
592 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
593 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
594 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
595 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
606 auto texture = CreateTextureForFixture(
"airplane.jpg",
610 paint.setColorSource(DlColorSource::MakeRadial(
611 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
612 builder.DrawCircle(
DlPoint(500, 600), 100, paint);
614 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
615 paint.setColorSource(DlColorSource::MakeImage(
616 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
617 DlImageSampling::kNearestNeighbor, &local_matrix));
618 builder.DrawCircle(
DlPoint(800, 300), 100, paint);
620 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
624 DisplayListBuilder builder;
625 builder.Scale(GetContentScale().
x, GetContentScale().y);
627 const int color_count = 3;
628 DlColor colors[color_count] = {
631 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
634 paint.setColor(DlColor::kWhite());
635 builder.DrawPaint(paint);
639 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas,
DlPoint center,
641 for (
int i = 0; i < n; i++) {
642 paint.setColor(colors[(c_index++) % color_count]);
643 canvas.DrawCircle(center, r, paint);
648 paint.setDrawStyle(DlDrawStyle::kStroke);
649 paint.setStrokeWidth(1);
650 draw(builder,
DlPoint(10, 10), 2, 2, 14);
651 paint.setStrokeWidth(5);
652 draw(builder,
DlPoint(10, 10), 35, 10, 56);
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 draw(builder,
DlPoint(500, 600), 5, 10, 10);
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 draw(builder,
DlPoint(800, 300), 5, 10, 10);
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);
704 int long_radius = 600;
705 int short_radius = 600;
706 while (long_radius > 0 && short_radius > 0) {
707 paint.setColor(colors[(c_index++) % color_count]);
708 builder.DrawOval(DlRect::MakeXYWH(10 - long_radius, 10 - short_radius,
709 long_radius * 2, short_radius * 2),
711 builder.DrawOval(DlRect::MakeXYWH(1000 - short_radius, 750 - long_radius,
712 short_radius * 2, long_radius * 2),
714 if (short_radius > 30) {
723 DlColor gradient_colors[7] = {
724 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
725 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
726 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
727 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
728 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
729 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
730 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
741 auto texture = CreateTextureForFixture(
"airplane.jpg",
745 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
747 paint.setColorSource(DlColorSource::MakeRadial(
748 DlPoint(300, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
749 builder.DrawOval(DlRect::MakeXYWH(200, 625, 200, 50), paint);
750 builder.DrawOval(DlRect::MakeXYWH(275, 550, 50, 200), paint);
752 DlMatrix local_matrix = DlMatrix::MakeTranslation({610, 15});
753 paint.setColorSource(DlColorSource::MakeImage(
754 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
755 DlImageSampling::kNearestNeighbor, &local_matrix));
756 builder.DrawOval(DlRect::MakeXYWH(610, 90, 200, 50), paint);
757 builder.DrawOval(DlRect::MakeXYWH(685, 15, 50, 200), paint);
759 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
763 struct ArcFarmOptions {
770 void RenderArcFarm(DisplayListBuilder& builder,
771 const DlPaint& paint,
772 const ArcFarmOptions& opts) {
774 builder.Translate(50, 50);
776 const int sweep_limit = opts.sweeps_over_360 ? 420 : 360;
779 for (
int sweep = 30; sweep <= sweep_limit; sweep += 30) {
780 builder.DrawArc(arc_bounds,
start, opts.full_circles ? 360 : sweep,
781 opts.use_center, paint);
782 builder.Translate(50, 0);
785 builder.Translate(0, 50);
792 DisplayListBuilder builder;
793 builder.Scale(GetContentScale().
x, GetContentScale().y);
794 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
797 paint.setColor(DlColor::kBlue());
799 RenderArcFarm(builder, paint,
802 .full_circles =
false,
805 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
809 DisplayListBuilder builder;
810 builder.Scale(GetContentScale().
x, GetContentScale().y);
811 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
814 paint.setColor(DlColor::kBlue());
816 RenderArcFarm(builder, paint,
819 .full_circles =
false,
822 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
826 DisplayListBuilder builder;
827 builder.Scale(GetContentScale().
x, GetContentScale().y);
828 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
831 paint.setColor(DlColor::kBlue());
833 RenderArcFarm(builder, paint,
836 .full_circles =
false,
837 .vertical_scale = 0.8f,
840 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
844 DisplayListBuilder builder;
845 builder.Scale(GetContentScale().
x, GetContentScale().y);
846 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
849 paint.setColor(DlColor::kBlue());
851 RenderArcFarm(builder, paint,
854 .full_circles =
false,
855 .vertical_scale = 0.8f,
858 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
862 DisplayListBuilder builder;
863 builder.Scale(GetContentScale().
x, GetContentScale().y);
864 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
867 paint.setDrawStyle(DlDrawStyle::kStroke);
868 paint.setStrokeWidth(6.0f);
869 paint.setStrokeCap(DlStrokeCap::kButt);
870 paint.setColor(DlColor::kBlue());
872 RenderArcFarm(builder, paint,
875 .full_circles =
false,
878 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
882 DisplayListBuilder builder;
883 builder.Scale(GetContentScale().
x, GetContentScale().y);
884 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
887 paint.setDrawStyle(DlDrawStyle::kStroke);
888 paint.setStrokeWidth(6.0f);
889 paint.setStrokeCap(DlStrokeCap::kSquare);
890 paint.setColor(DlColor::kBlue());
892 RenderArcFarm(builder, paint,
895 .full_circles =
false,
898 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
902 DisplayListBuilder builder;
903 builder.Scale(GetContentScale().
x, GetContentScale().y);
904 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
907 paint.setDrawStyle(DlDrawStyle::kStroke);
908 paint.setStrokeWidth(6.0f);
909 paint.setStrokeCap(DlStrokeCap::kRound);
910 paint.setColor(DlColor::kBlue());
912 RenderArcFarm(builder, paint,
915 .full_circles =
false,
918 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
922 DisplayListBuilder builder;
923 builder.Scale(GetContentScale().
x, GetContentScale().y);
924 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
927 paint.setDrawStyle(DlDrawStyle::kStroke);
928 paint.setStrokeWidth(6.0f);
929 paint.setStrokeJoin(DlStrokeJoin::kBevel);
930 paint.setColor(DlColor::kBlue());
932 RenderArcFarm(builder, paint,
935 .full_circles =
false,
936 .sweeps_over_360 =
true,
939 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
943 DisplayListBuilder builder;
944 builder.Scale(GetContentScale().
x, GetContentScale().y);
945 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
948 paint.setDrawStyle(DlDrawStyle::kStroke);
949 paint.setStrokeWidth(6.0f);
950 paint.setStrokeJoin(DlStrokeJoin::kMiter);
953 paint.setStrokeMiter(3.0f);
954 paint.setColor(DlColor::kBlue());
956 RenderArcFarm(builder, paint,
959 .full_circles =
false,
960 .sweeps_over_360 =
true,
963 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
967 DisplayListBuilder builder;
968 builder.Scale(GetContentScale().
x, GetContentScale().y);
969 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
972 paint.setDrawStyle(DlDrawStyle::kStroke);
973 paint.setStrokeWidth(6.0f);
974 paint.setStrokeJoin(DlStrokeJoin::kRound);
975 paint.setColor(DlColor::kBlue());
977 RenderArcFarm(builder, paint,
980 .full_circles =
false,
981 .sweeps_over_360 =
true,
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(8.0f);
995 paint.setStrokeCap(DlStrokeCap::kSquare);
996 paint.setColor(DlColor::kRed());
998 RenderArcFarm(builder, paint,
1000 .use_center =
false,
1001 .full_circles =
false,
1004 paint.setStrokeCap(DlStrokeCap::kButt);
1005 paint.setColor(DlColor::kBlue());
1007 RenderArcFarm(builder, paint,
1009 .use_center =
false,
1010 .full_circles =
false,
1013 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1017 DisplayListBuilder builder;
1018 builder.Scale(GetContentScale().
x, GetContentScale().y);
1019 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1022 paint.setDrawStyle(DlDrawStyle::kStroke);
1023 paint.setStrokeWidth(8.0f);
1024 paint.setStrokeCap(DlStrokeCap::kSquare);
1025 paint.setColor(DlColor::kRed());
1027 RenderArcFarm(builder, paint,
1029 .use_center =
false,
1030 .full_circles =
false,
1033 paint.setStrokeCap(DlStrokeCap::kRound);
1034 paint.setColor(DlColor::kGreen());
1036 RenderArcFarm(builder, paint,
1038 .use_center =
false,
1039 .full_circles =
false,
1042 paint.setStrokeCap(DlStrokeCap::kButt);
1043 paint.setColor(DlColor::kBlue());
1045 RenderArcFarm(builder, paint,
1047 .use_center =
false,
1048 .full_circles =
false,
1051 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1066 DisplayListBuilder builder;
1067 builder.Scale(GetContentScale().
x, GetContentScale().y);
1068 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1071 paint.setDrawStyle(DlDrawStyle::kStroke);
1072 paint.setStrokeWidth(6.0f);
1073 paint.setStrokeCap(DlStrokeCap::kButt);
1074 paint.setColor(DlColor::kBlue());
1077 RenderArcFarm(builder, paint,
1079 .use_center =
false,
1080 .full_circles =
true,
1083 paint.setColor(DlColor::kWhite());
1086 RenderArcFarm(builder, paint,
1088 .use_center =
false,
1089 .full_circles =
false,
1092 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1096 DisplayListBuilder builder;
1097 builder.Scale(GetContentScale().
x, GetContentScale().y);
1099 const int color_count = 3;
1100 DlColor colors[color_count] = {
1103 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
1106 paint.setColor(DlColor::kWhite());
1107 builder.DrawPaint(paint);
1110 for (
int i = 0; i < 4; i++) {
1111 for (
int j = 0; j < 4; j++) {
1112 paint.setColor(colors[(c_index++) % color_count]);
1113 builder.DrawRoundRect(
1114 DlRoundRect::MakeRectXY(
1115 DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1116 i * 5 + 10, j * 5 + 10),
1120 paint.setColor(colors[(c_index++) % color_count]);
1121 builder.DrawRoundRect(
1122 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40),
1124 paint.setColor(colors[(c_index++) % color_count]);
1125 builder.DrawRoundRect(
1126 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40),
1129 DlColor gradient_colors[7] = {
1130 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1131 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1132 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1133 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1134 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1135 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1136 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
1147 auto texture = CreateTextureForFixture(
"airplane.jpg",
1151 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1152 paint.setColorSource(DlColorSource::MakeRadial(
1153 DlPoint(550, 550), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1154 for (
int i = 1; i <= 10; i++) {
1156 builder.DrawRoundRect(
1157 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1158 550 + i * 20, 550 + j * 20),
1163 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1164 paint.setColorSource(DlColorSource::MakeRadial(
1165 DlPoint(200, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1166 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1167 builder.DrawRoundRect(
1168 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40),
1170 builder.DrawRoundRect(
1171 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40),
1174 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1175 DlMatrix local_matrix = DlMatrix::MakeTranslation({520, 20});
1176 paint.setColorSource(DlColorSource::MakeImage(
1177 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1178 DlImageSampling::kNearestNeighbor, &local_matrix));
1179 for (
int i = 1; i <= 10; i++) {
1181 builder.DrawRoundRect(
1182 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1183 720 + i * 20, 220 + j * 20),
1188 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1189 local_matrix = DlMatrix::MakeTranslation({800, 300});
1190 paint.setColorSource(DlColorSource::MakeImage(
1191 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1192 DlImageSampling::kNearestNeighbor, &local_matrix));
1193 builder.DrawRoundRect(
1194 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
1196 builder.DrawRoundRect(
1197 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40),
1200 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1204 DisplayListBuilder builder;
1205 builder.Scale(GetContentScale().
x, GetContentScale().y);
1207 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
1209 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
1212 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
1214 for (
int i = 0; i < 5; i++) {
1217 builder.DrawRect(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1218 radius, 60.0f - radius),
1222 paint.setColor(DlColor::kBlue());
1224 for (
int i = 0; i < 5; i++) {
1227 builder.DrawCircle(
DlPoint(
x + 25, y + 25), radius, paint);
1230 paint.setColor(DlColor::kGreen());
1232 for (
int i = 0; i < 5; i++) {
1235 builder.DrawOval(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1236 radius, 60.0f - radius),
1241 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
1243 for (
int i = 0; i < 5; i++) {
1246 builder.DrawRoundRect(
1247 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1253 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
1255 for (
int i = 0; i < 5; i++) {
1258 builder.DrawRoundRect(
1259 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1264 auto dl = builder.Build();
1265 ASSERT_TRUE(OpenPlaygroundHere(dl));
1269 DisplayListBuilder builder;
1271 builder.Scale(GetContentScale().
x, GetContentScale().y);
1274 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1275 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
1276 std::vector<Scalar> stops = {
1281 paint.setColorSource(DlColorSource::MakeLinear(
1290 builder.DrawPaint(paint);
1292 DlRect clip_rect = DlRect::MakeLTRB(50, 50, 400, 300);
1293 DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 100, 100);
1297 builder.ClipRoundRect(clip_rrect, DlClipOp::kIntersect);
1300 auto backdrop_filter = DlImageFilter::MakeColorFilter(
1301 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kExclusion));
1302 builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get());
1304 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1310 auto callback = [&]() -> sk_sp<DisplayList> {
1311 DisplayListBuilder builder;
1315 builder.Translate(300, 300);
1322 paint.setColor(DlColor::kGreen());
1323 builder.DrawPaint(paint);
1324 builder.ClipRect(DlRect::MakeLTRB(-180, -180, 180, 180),
1325 DlClipOp::kDifference);
1327 paint.setColor(DlColor::kBlack());
1328 builder.DrawPaint(paint);
1336 builder.ClipOval(DlRect::MakeLTRB(-200, -200, 200, 200));
1339 Matrix(1.0, 0.0, 0.0, 0.0,
1341 0.0, 0.0, 1.0, 0.003,
1342 0.0, 0.0, 0.0, 1.0) *
1351 -
DlPoint(image->GetSize().width, image->GetSize().height) * 0.5;
1352 builder.DrawImage(image, position, {});
1358 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
1359 builder.DrawCircle(
DlPoint(), 230, paint);
1363 return builder.Build();
1365 ASSERT_TRUE(OpenPlaygroundHere(callback));
1371 DisplayListBuilder builder;
1375 paint.setColor(DlColor::kWhite());
1376 builder.DrawPaint(paint);
1380 DlMatrix matrix = DlMatrix::MakeTranslation({50, 50});
1382 paint.setColorSource(DlColorSource::MakeImage(
1383 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1384 DlImageSampling::kNearestNeighbor, &matrix));
1386 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
1395 Matrix matrix(1, -1, 0, 0,
1399 paint.setColorSource(DlColorSource::MakeImage(
1400 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1401 DlImageSampling::kNearestNeighbor, &matrix));
1402 builder.DrawRect(DlRect::MakeLTRB(100, 0, 200, 100), paint);
1409 builder.Translate(100, 0);
1410 builder.Scale(100, 100);
1413 DlMatrix matrix = DlMatrix::MakeScale({0.005, 0.005, 1});
1414 paint.setColorSource(DlColorSource::MakeImage(
1415 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1416 DlImageSampling::kNearestNeighbor, &matrix));
1418 builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
1425 builder.Translate(150, 150);
1429 DlMatrix::MakePerspective(
Radians{0.5},
ISize{200, 200}, 0.05, 1);
1430 paint.setColorSource(DlColorSource::MakeImage(
1431 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1432 DlImageSampling::kNearestNeighbor, &matrix));
1434 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
1438 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1442 DisplayListBuilder builder;
1447 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1448 paint.setBlendMode(DlBlendMode::kSrc);
1450 DlRect bounds = DlRect::MakeLTRB(0, 0, 200, 200);
1451 builder.SaveLayer(bounds, &paint);
1453 paint.setColor(DlColor::kTransparent());
1454 paint.setBlendMode(DlBlendMode::kSrc);
1455 builder.DrawPaint(paint);
1458 paint.setColor(DlColor::kBlue());
1459 paint.setBlendMode(DlBlendMode::kDstOver);
1460 builder.SaveLayer(std::nullopt, &paint);
1466 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1471 DisplayListBuilder builder;
1472 builder.Scale(GetContentScale().
x, GetContentScale().y);
1473 builder.Translate(100, 100);
1477 DlMatrix translate = DlMatrix::MakeTranslation({300, 0});
1478 paint.setImageFilter(
1479 DlImageFilter::MakeMatrix(translate, DlImageSampling::kLinear));
1480 builder.SaveLayer(std::nullopt, &paint);
1482 DlPaint circle_paint;
1483 circle_paint.setColor(DlColor::kGreen());
1484 builder.DrawCircle(
DlPoint(-300, 0), 100, circle_paint);
1487 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1492 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
1493 DisplayListBuilder builder;
1494 builder.Scale(GetContentScale().
x, GetContentScale().y);
1495 builder.Translate(100, 100);
1500 paint.setImageFilter(DlImageFilter::MakeMatrix(
1501 DlMatrix::MakeTranslation({300, 0}) * DlMatrix::MakeScale({2, 2, 1}),
1502 DlImageSampling::kNearestNeighbor));
1503 builder.SaveLayer(std::nullopt, &paint);
1505 DlPaint circle_paint;
1506 circle_paint.setColor(DlColor::kGreen());
1507 builder.DrawCircle(
DlPoint(-150, 0), 50, circle_paint);
1510 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1515 SetWindowSize({400, 400});
1516 DisplayListBuilder builder;
1518 builder.Scale(GetContentScale().
x, GetContentScale().y);
1521 paint.setColor(DlColor::kRed());
1522 builder.DrawRect(DlRect::MakeLTRB(200, 200, 300, 300), paint);
1524 paint.setImageFilter(DlImageFilter::MakeMatrix(DlMatrix::MakeScale({2, 2, 1}),
1525 DlImageSampling::kLinear));
1526 builder.SaveLayer(std::nullopt, &paint);
1529 paint.setColor(DlColor::kGreen());
1530 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
1533 paint.setColor(DlColor::kRed());
1534 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 800), paint);
1537 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1541 DisplayListBuilder builder;
1542 builder.Scale(GetContentScale().
x, GetContentScale().y);
1545 paint.setColor(DlColor::kRed());
1546 builder.DrawPaint(paint);
1547 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1548 paint.setColor(DlColor::kBlue());
1549 builder.SaveLayer(std::nullopt, &paint);
1552 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1556 DisplayListBuilder builder;
1557 builder.Scale(GetContentScale().
x, GetContentScale().y);
1559 builder.DrawImage(image,
DlPoint(10, 10), {});
1560 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1563 paint.setBlendMode(DlBlendMode::kClear);
1564 builder.SaveLayer(std::nullopt, &paint);
1567 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1571 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
1572 DisplayListBuilder builder;
1575 red.setColor(DlColor::kRed());
1578 green.setColor(DlColor::kGreen());
1581 blue.setColor(DlColor::kBlue());
1584 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1586 DlRect huge_bounds = DlRect::MakeXYWH(0, 0, 100000, 100000);
1587 builder.SaveLayer(huge_bounds, &save);
1589 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1590 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), green);
1591 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), blue);
1595 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1600 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1606 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1613 DisplayListBuilder builder;
1620 builder.Translate(100, 200);
1621 builder.Scale(0.5, 0.5);
1622 builder.DrawImage(image,
DlPoint(100.0, 100.0),
1623 DlImageSampling::kNearestNeighbor);
1630 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1632 builder.SaveLayer(std::nullopt, &alpha);
1635 paint.setColor(DlColor::kRed());
1636 builder.DrawRect(DlRect::MakeXYWH(000, 000, 100, 100), paint);
1637 paint.setColor(DlColor::kGreen());
1638 builder.DrawRect(DlRect::MakeXYWH(020, 020, 100, 100), paint);
1639 paint.setColor(DlColor::kBlue());
1640 builder.DrawRect(DlRect::MakeXYWH(040, 040, 100, 100), paint);
1645 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1649 DisplayListBuilder builder;
1652 paint.setColor(DlColor::kRed());
1653 builder.DrawCircle(
DlPoint(250, 250), 125, paint);
1655 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1659 DisplayListBuilder builder;
1662 red.setColor(DlColor::kRed());
1664 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1666 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1670 DisplayListBuilder builder;
1673 save.setColor(DlColor::kBlack());
1675 DlRect save_bounds = DlRect::MakeXYWH(0, 0, 50, 50);
1676 builder.SaveLayer(save_bounds, &save);
1679 paint.setColor(DlColor::kRed());
1680 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
1681 paint.setColor(DlColor::kGreen());
1682 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), paint);
1683 paint.setColor(DlColor::kBlue());
1684 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), paint);
1688 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1692 DisplayListBuilder builder;
1693 builder.Scale(GetContentScale().
x, GetContentScale().y);
1696 const int color_count = 3;
1697 DlColor colors[color_count] = {
1700 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
1703 paint.setColor(DlColor::kWhite());
1704 builder.DrawPaint(paint);
1707 const DlPaint& paint) {
1708 builder.DrawPath(DlPath::MakeRoundRectXY(rect,
x, y), paint);
1712 for (
int i = 0; i < 4; i++) {
1713 for (
int j = 0; j < 4; j++) {
1714 paint.setColor(colors[(c_index++) % color_count]);
1715 draw_rrect_as_path(DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1716 i * 5 + 10, j * 5 + 10, paint);
1719 paint.setColor(colors[(c_index++) % color_count]);
1720 draw_rrect_as_path(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
1721 paint.setColor(colors[(c_index++) % color_count]);
1722 draw_rrect_as_path(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
1724 std::vector<DlColor> gradient_colors = {
1725 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1726 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1727 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1728 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1729 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1730 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1731 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
1732 std::vector<Scalar> stops = {
1742 CreateTextureForFixture(
"airplane.jpg",
1745 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1746 paint.setColorSource(DlColorSource::MakeRadial(
1749 gradient_colors.size(),
1750 gradient_colors.data(),
1752 DlTileMode::kMirror));
1753 for (
int i = 1; i <= 10; i++) {
1755 draw_rrect_as_path(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1756 550 + i * 20, 550 + j * 20),
1757 i * 10, j * 10, paint);
1759 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1760 paint.setColorSource(DlColorSource::MakeRadial(
1763 gradient_colors.size(),
1764 gradient_colors.data(),
1766 DlTileMode::kMirror));
1767 draw_rrect_as_path(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
1768 draw_rrect_as_path(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
1770 auto matrix = DlMatrix::MakeTranslation({520, 20});
1771 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1772 paint.setColorSource(DlColorSource::MakeImage(
1773 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1774 DlImageSampling::kMipmapLinear, &matrix));
1775 for (
int i = 1; i <= 10; i++) {
1777 draw_rrect_as_path(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1778 720 + i * 20, 220 + j * 20),
1779 i * 10, j * 10, paint);
1781 matrix = DlMatrix::MakeTranslation({800, 300});
1782 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1783 paint.setColorSource(DlColorSource::MakeImage(
1784 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1785 DlImageSampling::kMipmapLinear, &matrix));
1787 draw_rrect_as_path(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
1788 draw_rrect_as_path(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
1790 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1794 auto callback = [&]() -> sk_sp<DisplayList> {
1795 DisplayListBuilder builder;
1796 builder.Scale(GetContentScale().x, GetContentScale().y);
1799 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1801 auto current =
Point{25, 25};
1802 const auto offset =
Point{25, 25};
1803 const auto size =
Size(100, 100);
1808 DlRect bounds = DlRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
1810 DlPaint stroke_paint;
1811 stroke_paint.setColor(DlColor::kYellow());
1812 stroke_paint.setStrokeWidth(5);
1813 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
1814 builder.DrawRect(bounds, stroke_paint);
1816 builder.SaveLayer(bounds, &alpha);
1819 paint.setColor(DlColor::kRed());
1821 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1823 paint.setColor(DlColor::kGreen());
1826 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1828 paint.setColor(DlColor::kBlue());
1831 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1835 return builder.Build();
1838 ASSERT_TRUE(OpenPlaygroundHere(callback));
1843 DisplayListBuilder builder;
1846 paint.setColor(DlColor::kBlack());
1847 DlRect rect = DlRect::MakeXYWH(25, 25, 25, 25);
1848 builder.DrawRect(rect, paint);
1850 builder.Translate(10, 10);
1853 builder.SaveLayer(std::nullopt, &save_paint);
1855 paint.setColor(DlColor::kGreen());
1856 builder.DrawRect(rect, paint);
1860 builder.Translate(10, 10);
1861 paint.setColor(DlColor::kRed());
1862 builder.DrawRect(rect, paint);
1864 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1868 DisplayListBuilder builder;
1870 DlRect rect = DlRect::MakeXYWH(0, 0, 1000, 1000);
1875 DlRect bounds = DlRect::MakeXYWH(25, 25, 25, 25);
1876 builder.SaveLayer(bounds, &save_paint);
1877 paint.setColor(DlColor::kBlack());
1878 builder.DrawRect(rect, paint);
1884 DlRect bounds = DlRect::MakeXYWH(35, 35, 25, 25);
1885 builder.SaveLayer(bounds, &save_paint);
1886 paint.setColor(DlColor::kGreen());
1887 builder.DrawRect(rect, paint);
1893 DlRect bounds = DlRect::MakeXYWH(45, 45, 25, 25);
1894 builder.SaveLayer(bounds, &save_paint);
1895 paint.setColor(DlColor::kRed());
1896 builder.DrawRect(rect, paint);
1900 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1904 DisplayListBuilder builder;
1907 paint.setColor(DlColor::kWhite());
1908 builder.DrawPaint(paint);
1914 builder.ClipPath(path);
1916 DlRect bounds = DlRect::MakeXYWH(50, 50, 100, 100);
1918 builder.SaveLayer(bounds, &save_paint);
1921 paint.setColor(DlColor::kWhite());
1922 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
1925 paint.setColor(DlColor::kGreen());
1926 paint.setBlendMode(DlBlendMode::kHardLight);
1927 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
1930 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1934 DisplayListBuilder builder;
1936 builder.Scale(GetContentScale().
x, GetContentScale().y);
1937 builder.Translate(100, 100);
1940 auto draw_image_layer = [&builder, &texture](
const DlPaint& paint) {
1941 builder.SaveLayer(std::nullopt, &paint);
1942 builder.DrawImage(texture,
DlPoint(), DlImageSampling::kLinear);
1946 DlPaint effect_paint;
1947 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
1948 draw_image_layer(effect_paint);
1950 builder.Translate(300, 300);
1951 builder.Scale(3, 3);
1952 draw_image_layer(effect_paint);
1954 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1958 DisplayListBuilder builder;
1960 builder.Scale(GetContentScale().
x, GetContentScale().y);
1962 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
1965 save_paint.setColor(DlColor::kWhite());
1966 builder.DrawPaint(save_paint);
1968 paint.setColor(DlColor::kBlue());
1969 for (
int i = 0; i < 5; i++) {
1971 Scalar y_radius = i * 15;
1972 for (
int j = 0; j < 5; j++) {
1974 Scalar x_radius = j * 15;
1975 builder.DrawRoundRect(
1976 DlRoundRect::MakeRectXY(
1977 DlRect::MakeXYWH(
x + 50, y + 50, 100.0f, 100.0f),
1978 x_radius, y_radius),
1983 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1987 DisplayListBuilder builder;
1991 builder.SaveLayer(std::nullopt, &paint);
1993 builder.Translate(100, 100);
1994 paint.setColor(DlColor::kBlue());
1995 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
1996 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1998 paint.setColor(DlColor::kGreen());
1999 paint.setBlendMode(DlBlendMode::kSrcOver);
2000 paint.setImageFilter(DlImageFilter::MakeColorFilter(
2001 DlColorFilter::MakeBlend(DlColor::kWhite(), DlBlendMode::kDst)));
2002 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2006 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2014 GTEST_SKIP() <<
"Swiftshader is running out of memory on this example.";
2016 DisplayListBuilder builder(DlRect::MakeSize(DlSize(1000, 1000)));
2018 auto filter = DlImageFilter::MakeMatrix(
2019 DlMatrix::MakeScale({0.001, 0.001, 1}), DlImageSampling::kLinear);
2022 paint.setImageFilter(filter);
2023 builder.SaveLayer(std::nullopt, &paint);
2026 paint.setColor(DlColor::kRed());
2027 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100000, 100000), paint);
2031 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2038 auto callback = [&]() -> sk_sp<DisplayList> {
2040 ImGuiWindowFlags_AlwaysAutoResize)) {
2041 ImGui::SliderFloat(
"width", &width, 0, 200);
2042 ImGui::SliderFloat(
"height", &height, 0, 200);
2043 ImGui::SliderFloat(
"corner", &corner, 0, 1);
2047 DisplayListBuilder builder;
2048 builder.Scale(GetContentScale().
x, GetContentScale().y);
2050 DlPaint background_paint;
2051 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
2052 builder.DrawPaint(background_paint);
2054 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
2055 std::vector<Scalar> stops = {0.0, 1.0};
2058 auto gradient = DlColorSource::MakeLinear(
DlPoint(0, 0),
DlPoint(200, 200),
2059 2, colors.data(), stops.data(),
2060 DlTileMode::kClamp);
2061 paint.setColorSource(gradient);
2062 paint.setColor(DlColor::kWhite());
2063 paint.setDrawStyle(DlDrawStyle::kStroke);
2064 paint.setStrokeWidth(20);
2067 builder.Translate(100, 100);
2069 Scalar corner_x = ((1 - corner) * 50) + 50;
2070 Scalar corner_y = corner * 50 + 50;
2072 DlRect::MakeXYWH(0, 0, width, height), corner_x, corner_y);
2073 builder.DrawRoundRect(rrect, paint);
2075 return builder.Build();
2077 ASSERT_TRUE(OpenPlaygroundHere(callback));
2081 DisplayListBuilder builder;
2083 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
2086 builder.ClipRect(DlRect::MakeLTRB(100, 100, 800, 800));
2090 builder.ClipRect(DlRect::MakeLTRB(600, 600, 800, 800));
2091 builder.DrawPaint(DlPaint().setColor(DlColor::kRed()));
2092 builder.DrawPaint(DlPaint().setColor(DlColor::kBlue().withAlphaF(0.5)));
2093 builder.ClipRect(DlRect::MakeLTRB(700, 700, 750, 800));
2094 builder.DrawPaint(DlPaint().setColor(DlColor::kRed().withAlphaF(0.5)));
2098 auto image_filter = DlImageFilter::MakeBlur(10, 10, DlTileMode::kDecal);
2099 builder.SaveLayer(std::nullopt,
nullptr, image_filter.get());
2102 builder.DrawCircle(
DlPoint(100, 100), 100,
2103 DlPaint().setColor(DlColor::kAqua()));
2105 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
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)