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"
32 DisplayListBuilder builder;
34 paint.setColor(DlColor::kBlue());
35 builder.DrawPath(DlPath::MakeRectXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
36 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
41 std::function<void(DisplayListBuilder&,
const DlRect&,
const DlPaint&)>;
43 sk_sp<DisplayList> MakeWideStrokedRects(
Point scale,
44 const DrawRectProc& draw_rect) {
45 DisplayListBuilder builder;
46 builder.Scale(scale.
x, scale.
y);
47 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
50 paint.setColor(DlColor::kBlue().withAlphaF(0.5));
51 paint.setDrawStyle(DlDrawStyle::kStroke);
52 paint.setStrokeWidth(30.0f);
58 paint.setStrokeJoin(DlStrokeJoin::kBevel);
59 draw_rect(builder, DlRect::MakeXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
60 draw_rect(builder, DlRect::MakeXYWH(250.0f, 100.0f, 10.0f, 100.0f), paint);
61 draw_rect(builder, DlRect::MakeXYWH(100.0f, 250.0f, 100.0f, 10.0f), paint);
63 paint.setStrokeJoin(DlStrokeJoin::kRound);
64 draw_rect(builder, DlRect::MakeXYWH(350.0f, 100.0f, 100.0f, 100.0f), paint);
65 draw_rect(builder, DlRect::MakeXYWH(500.0f, 100.0f, 10.0f, 100.0f), paint);
66 draw_rect(builder, DlRect::MakeXYWH(350.0f, 250.0f, 100.0f, 10.0f), paint);
68 paint.setStrokeJoin(DlStrokeJoin::kMiter);
69 draw_rect(builder, DlRect::MakeXYWH(600.0f, 100.0f, 100.0f, 100.0f), paint);
70 draw_rect(builder, DlRect::MakeXYWH(750.0f, 100.0f, 10.0f, 100.0f), paint);
71 draw_rect(builder, DlRect::MakeXYWH(600.0f, 250.0f, 100.0f, 10.0f), paint);
75 paint.setStrokeWidth(110.0f);
77 paint.setStrokeJoin(DlStrokeJoin::kBevel);
78 draw_rect(builder, DlRect::MakeXYWH(100.0f, 400.0f, 100.0f, 100.0f), paint);
80 paint.setStrokeJoin(DlStrokeJoin::kRound);
81 draw_rect(builder, DlRect::MakeXYWH(350.0f, 400.0f, 100.0f, 100.0f), paint);
83 paint.setStrokeJoin(DlStrokeJoin::kMiter);
84 draw_rect(builder, DlRect::MakeXYWH(600.0f, 400.0f, 100.0f, 100.0f), paint);
86 return builder.Build();
91 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
92 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
93 const DlPaint& paint) {
95 builder.DrawRect(rect, paint);
100 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
101 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
102 const DlPaint& paint) {
104 builder.DrawPath(DlPath::MakeRect(rect), paint);
109 DisplayListBuilder builder;
111 paint.setColor(DlColor::kRed());
113 builder.DrawImage(image,
DlPoint(100.0, 100.0),
114 DlImageSampling::kNearestNeighbor, &paint);
115 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
119 DisplayListBuilder builder;
121 paint.setColor(DlColor::kRed());
122 paint.setColorFilter(
123 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
124 paint.setInvertColors(
true);
127 builder.DrawImage(image,
DlPoint(100.0, 100.0),
128 DlImageSampling::kNearestNeighbor, &paint);
129 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
133 DisplayListBuilder builder;
135 paint.setColor(DlColor::kRed());
136 paint.setColorFilter(
137 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
138 paint.setInvertColors(
true);
140 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
141 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
145 DisplayListBuilder builder;
147 paint.setColor(DlColor::kRed());
148 paint.setColorFilter(
149 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
150 paint.setInvertColors(
true);
152 builder.DrawPaint(paint);
153 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
157 bool GenerateMipmap(
const std::shared_ptr<Context>& context,
158 std::shared_ptr<Texture> texture,
159 std::string_view label) {
160 auto buffer = context->CreateCommandBuffer();
164 auto pass = buffer->CreateBlitPass();
168 pass->GenerateMipmap(std::move(texture), label);
170 pass->EncodeCommands();
171 return context->GetCommandQueue()->Submit({buffer}).ok();
174 void CanRenderTiledTexture(
AiksTest* aiks_test,
175 DlTileMode tile_mode,
176 Matrix local_matrix = {}) {
177 auto context = aiks_test->GetContext();
178 ASSERT_TRUE(context);
179 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
181 GenerateMipmap(context, texture,
"table_mountain_nx");
183 auto color_source = DlColorSource::MakeImage(
184 image, tile_mode, tile_mode, DlImageSampling::kNearestNeighbor,
187 DisplayListBuilder builder;
189 paint.setColor(DlColor::kWhite());
190 paint.setColorSource(color_source);
192 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
193 builder.Translate(100.0f, 100.0f);
194 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
197 constexpr
auto stroke_width = 64;
198 paint.setDrawStyle(DlDrawStyle::kStroke);
199 paint.setStrokeWidth(stroke_width);
200 if (tile_mode == DlTileMode::kDecal) {
201 builder.DrawRect(DlRect::MakeXYWH(stroke_width, stroke_width, 600, 600),
204 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
209 DlPathBuilder path_builder;
210 path_builder.AddCircle(
DlPoint(150, 150), 150);
211 path_builder.AddRoundRect(
213 DlPath path = path_builder.TakePath();
216 EXPECT_FALSE(path.IsRect(
nullptr));
217 EXPECT_FALSE(path.IsOval(
nullptr));
218 EXPECT_FALSE(path.IsRoundRect(
nullptr));
221 EXPECT_FALSE(path.IsConvex());
223 paint.setDrawStyle(DlDrawStyle::kFill);
224 builder.DrawPath(path, paint);
231 constexpr
float kConicWeight = 0.707106781f;
232 const DlPath path = DlPathBuilder()
234 .ConicCurveTo({300, 300}, {300, 450}, kConicWeight)
235 .ConicCurveTo({300, 600}, {150, 600}, kConicWeight)
236 .ConicCurveTo({0, 600}, {0, 450}, kConicWeight)
237 .ConicCurveTo({0, 300}, {150, 300}, kConicWeight)
242 EXPECT_FALSE(path.IsRect(
nullptr));
243 EXPECT_FALSE(path.IsOval(
nullptr));
244 EXPECT_FALSE(path.IsRoundRect(
nullptr));
247 EXPECT_TRUE(path.IsConvex());
249 paint.setDrawStyle(DlDrawStyle::kFill);
250 builder.DrawPath(path, paint);
253 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
258 CanRenderTiledTexture(
this, DlTileMode::kClamp);
262 CanRenderTiledTexture(
this, DlTileMode::kRepeat);
266 CanRenderTiledTexture(
this, DlTileMode::kMirror);
270 CanRenderTiledTexture(
this, DlTileMode::kDecal);
274 CanRenderTiledTexture(
this, DlTileMode::kClamp,
279 DisplayListBuilder builder;
282 DlISize image_half_size =
283 DlISize(image->GetSize().width * 0.5f, image->GetSize().height * 0.5f);
286 auto source_rect = DlRect::MakeSize(image_half_size);
288 source_rect.Shift(image_half_size.width, image_half_size.height);
290 builder.DrawImageRect(image, source_rect,
291 DlRect::MakeXYWH(100, 100, 600, 600),
292 DlImageSampling::kNearestNeighbor);
293 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
297 DisplayListBuilder builder;
301 auto source_rect = DlRect::MakeXYWH(
302 image->GetSize().width * 0.25f, image->GetSize().height * 0.4f,
303 image->GetSize().width, image->GetSize().height);
305 auto dest_rect = DlRect::MakeXYWH(100, 100, 600, 600);
308 paint.setColor(DlColor::kMidGrey());
309 builder.DrawRect(dest_rect, paint);
311 builder.DrawImageRect(image, source_rect, dest_rect,
312 DlImageSampling::kNearestNeighbor);
313 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
317 DisplayListBuilder builder;
318 builder.Scale(GetContentScale().
x, GetContentScale().y);
321 paint.setColor(DlColor::kWhite());
322 builder.DrawPaint(paint);
324 auto draw = [&builder](
const DlPaint& paint,
Scalar x,
Scalar y) {
326 builder.Translate(
x, y);
329 builder.ClipRect(DlRect::MakeLTRB(50, 50, 150, 150));
330 builder.DrawPaint(paint);
335 builder.ClipOval(DlRect::MakeLTRB(200, 50, 300, 150));
336 builder.DrawPaint(paint);
341 builder.ClipRoundRect(
342 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(50, 200, 150, 300), 20, 20));
343 builder.DrawPaint(paint);
348 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
349 DlRect::MakeLTRB(200, 230, 300, 270), 20, 20));
350 builder.DrawPaint(paint);
355 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
356 DlRect::MakeLTRB(230, 200, 270, 300), 20, 20));
357 builder.DrawPaint(paint);
363 paint.setColor(DlColor::kBlue());
366 DlColor gradient_colors[7] = {
367 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
368 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
369 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
370 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
371 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
372 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
373 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
384 auto texture = CreateTextureForFixture(
"airplane.jpg",
388 paint.setColorSource(DlColorSource::MakeRadial(
389 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
392 paint.setColorSource(
393 DlColorSource::MakeImage(image, DlTileMode::kRepeat, DlTileMode::kRepeat,
394 DlImageSampling::kNearestNeighbor));
397 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
401 DisplayListBuilder builder;
404 red.setColor(DlColor::kRed());
407 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
409 builder.SaveLayer(std::nullopt, &alpha);
411 builder.DrawCircle(
DlPoint(125, 125), 125, red);
415 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
419 DisplayListBuilder builder;
422 DlColor colors[2] = {
423 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
424 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
431 paint.setColorSource(DlColorSource::MakeLinear(
441 builder.Translate(100, 100);
442 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
446 builder.Translate(100, 400);
447 builder.DrawCircle(
DlPoint(100, 100), 100, paint);
449 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
453 DisplayListBuilder builder;
455 paint.setColor(DlColor::kRed());
459 .top_right = DlSize(25, 50),
460 .bottom_left = DlSize(25, 50),
461 .bottom_right = DlSize(50, 25),
464 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
466 builder.DrawRoundRect(rrect, paint);
468 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
472 auto medium_turquoise =
473 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
475 DisplayListBuilder builder;
476 builder.Scale(0.2, 0.2);
477 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
478 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
482 auto medium_turquoise =
483 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
485 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
487 DisplayListBuilder builder;
488 builder.Scale(0.2, 0.2);
489 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
490 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
491 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
495 DisplayListBuilder builder;
496 builder.Scale(GetContentScale().
x, GetContentScale().y);
499 paint.setColor(DlColor::kPurple());
500 paint.setDrawStyle(DlDrawStyle::kStroke);
501 paint.setStrokeWidth(20.0f);
503 DlPaint thin_paint = paint;
504 thin_paint.setColor(DlColor::kYellow());
505 thin_paint.setStrokeWidth(0.0f);
507 DlRect rect = DlRect::MakeLTRB(10, 10, 90, 90);
508 DlRect thin_tall_rect = DlRect::MakeLTRB(120, 10, 120, 90);
509 DlRect thin_wide_rect = DlRect::MakeLTRB(10, 120, 90, 120);
510 DlRect empty_rect = DlRect::MakeLTRB(120, 120, 120, 120);
540 paint.setStrokeJoin(DlStrokeJoin::kBevel);
541 builder.DrawRect(rect.Shift({100, 100}), paint);
542 builder.DrawRect(rect.Shift({100, 100}), thin_paint);
543 builder.DrawRect(thin_tall_rect.Shift({100, 100}), paint);
544 builder.DrawRect(thin_tall_rect.Shift({100, 100}), thin_paint);
545 builder.DrawRect(thin_wide_rect.Shift({100, 100}), paint);
546 builder.DrawRect(thin_wide_rect.Shift({100, 100}), thin_paint);
547 builder.DrawRect(empty_rect.Shift({100, 100}), paint);
548 builder.DrawRect(empty_rect.Shift({100, 100}), thin_paint);
551 paint.setStrokeJoin(DlStrokeJoin::kRound);
552 builder.DrawRect(rect.Shift({100, 300}), paint);
553 builder.DrawRect(rect.Shift({100, 300}), thin_paint);
554 builder.DrawRect(thin_tall_rect.Shift({100, 300}), paint);
555 builder.DrawRect(thin_tall_rect.Shift({100, 300}), thin_paint);
556 builder.DrawRect(thin_wide_rect.Shift({100, 300}), paint);
557 builder.DrawRect(thin_wide_rect.Shift({100, 300}), thin_paint);
558 builder.DrawRect(empty_rect.Shift({100, 300}), paint);
559 builder.DrawRect(empty_rect.Shift({100, 300}), thin_paint);
562 paint.setStrokeJoin(DlStrokeJoin::kMiter);
564 builder.DrawRect(rect.Shift({100, 500}), paint);
565 builder.DrawRect(rect.Shift({100, 500}), thin_paint);
566 builder.DrawRect(thin_tall_rect.Shift({100, 500}), paint);
567 builder.DrawRect(thin_tall_rect.Shift({100, 500}), thin_paint);
568 builder.DrawRect(thin_wide_rect.Shift({100, 500}), paint);
569 builder.DrawRect(thin_wide_rect.Shift({100, 500}), thin_paint);
570 builder.DrawRect(empty_rect.Shift({100, 500}), paint);
571 builder.DrawRect(empty_rect.Shift({100, 500}), thin_paint);
574 paint.setStrokeJoin(DlStrokeJoin::kMiter);
576 builder.DrawRect(rect.Shift({300, 500}), paint);
577 builder.DrawRect(rect.Shift({300, 500}), thin_paint);
578 builder.DrawRect(thin_tall_rect.Shift({300, 500}), paint);
579 builder.DrawRect(thin_tall_rect.Shift({300, 500}), thin_paint);
580 builder.DrawRect(thin_wide_rect.Shift({300, 500}), paint);
581 builder.DrawRect(thin_wide_rect.Shift({300, 500}), thin_paint);
582 builder.DrawRect(empty_rect.Shift({300, 500}), paint);
583 builder.DrawRect(empty_rect.Shift({300, 500}), thin_paint);
585 paint.setStrokeWidth(120.0f);
586 paint.setColor(DlColor::kBlue());
587 rect = rect.Expand(-20);
590 paint.setStrokeJoin(DlStrokeJoin::kBevel);
591 builder.DrawRect(rect.Shift({500, 100}), paint);
592 builder.DrawRect(rect.Shift({500, 100}), thin_paint);
595 paint.setStrokeJoin(DlStrokeJoin::kRound);
596 builder.DrawRect(rect.Shift({500, 300}), paint);
597 builder.DrawRect(rect.Shift({500, 300}), thin_paint);
600 paint.setStrokeJoin(DlStrokeJoin::kMiter);
602 builder.DrawRect(rect.Shift({500, 500}), paint);
603 builder.DrawRect(rect.Shift({500, 500}), thin_paint);
606 paint.setStrokeJoin(DlStrokeJoin::kMiter);
608 builder.DrawRect(rect.Shift({700, 500}), paint);
609 builder.DrawRect(rect.Shift({700, 500}), thin_paint);
611 DlPaint round_mock_paint;
612 round_mock_paint.setColor(DlColor::kGreen());
613 round_mock_paint.setDrawStyle(DlDrawStyle::kFill);
618 for (
int i = 0; i < 15; i++) {
619 paint.setStrokeWidth(i);
620 paint.setColor(DlColor::kOrange());
621 paint.setStrokeJoin(DlStrokeJoin::kRound);
622 builder.DrawRect(DlRect::MakeXYWH(
x, y, 30, 30), paint);
626 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
630 DisplayListBuilder builder;
631 builder.Scale(GetContentScale().
x, GetContentScale().y);
633 const int color_count = 3;
634 DlColor colors[color_count] = {
637 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
640 paint.setColor(DlColor::kWhite());
641 builder.DrawPaint(paint);
646 paint.setColor(colors[(c_index++) % color_count]);
647 builder.DrawCircle(
DlPoint(10, 10), radius, paint);
655 DlColor gradient_colors[7] = {
656 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
657 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
658 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
659 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
660 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
661 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
662 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
673 auto texture = CreateTextureForFixture(
"airplane.jpg",
677 paint.setColorSource(DlColorSource::MakeRadial(
678 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
679 builder.DrawCircle(
DlPoint(500, 600), 100, paint);
681 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
682 paint.setColorSource(DlColorSource::MakeImage(
683 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
684 DlImageSampling::kNearestNeighbor, &local_matrix));
685 builder.DrawCircle(
DlPoint(800, 300), 100, paint);
687 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
691 auto callback = [&]() {
692 static float stroked_radius = 100.0;
693 static float stroke_width = 0.0;
694 static float stroke_width_fine = 2.0;
695 static float stroked_alpha = 255.0;
696 static float stroked_scale[2] = {1.0, 1.0};
699 ImGuiWindowFlags_AlwaysAutoResize)) {
700 ImGui::SliderFloat(
"Stroked Radius", &stroked_radius, 0, 500);
701 ImGui::SliderFloat(
"Stroked Width", &stroke_width, 0, 500);
702 ImGui::SliderFloat(
"Stroked Width Fine", &stroke_width_fine, 0, 5);
703 ImGui::SliderFloat(
"Stroked Alpha", &stroked_alpha, 0, 10.0);
704 ImGui::SliderFloat2(
"Stroked Scale", stroked_scale, 0, 10.0);
708 flutter::DisplayListBuilder builder;
710 DlPaint background_paint;
711 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
712 builder.DrawPaint(background_paint);
714 flutter::DlPaint paint;
716 paint.setColor(flutter::DlColor::kRed().withAlpha(stroked_alpha));
717 paint.setDrawStyle(flutter::DlDrawStyle::kStroke);
718 paint.setStrokeWidth(stroke_width + stroke_width_fine);
720 builder.Translate(250, 250);
721 builder.Scale(stroked_scale[0], stroked_scale[1]);
722 builder.Translate(-250, -250);
723 builder.DrawCircle(
DlPoint(250, 250), stroked_radius, paint);
725 return builder.Build();
728 ASSERT_TRUE(OpenPlaygroundHere(callback));
732 DisplayListBuilder builder;
733 builder.Scale(GetContentScale().
x, GetContentScale().y);
735 const int color_count = 3;
736 DlColor colors[color_count] = {
739 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
742 paint.setColor(DlColor::kWhite());
743 builder.DrawPaint(paint);
747 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas,
DlPoint center,
749 for (
int i = 0; i < n; i++) {
750 paint.setColor(colors[(c_index++) % color_count]);
751 canvas.DrawCircle(center, r, paint);
756 paint.setDrawStyle(DlDrawStyle::kStroke);
757 paint.setStrokeWidth(1);
758 draw(builder,
DlPoint(10, 10), 2, 2, 14);
759 paint.setStrokeWidth(5);
760 draw(builder,
DlPoint(10, 10), 35, 10, 56);
762 DlColor gradient_colors[7] = {
763 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
764 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
765 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
766 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
767 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
768 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
769 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
780 auto texture = CreateTextureForFixture(
"airplane.jpg",
784 paint.setColorSource(DlColorSource::MakeRadial(
785 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
786 draw(builder,
DlPoint(500, 600), 5, 10, 10);
788 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
789 paint.setColorSource(DlColorSource::MakeImage(
790 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
791 DlImageSampling::kNearestNeighbor, &local_matrix));
792 draw(builder,
DlPoint(800, 300), 5, 10, 10);
794 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
798 DisplayListBuilder builder;
799 builder.Scale(GetContentScale().
x, GetContentScale().y);
801 const int color_count = 3;
802 DlColor colors[color_count] = {
805 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
808 paint.setColor(DlColor::kWhite());
809 builder.DrawPaint(paint);
812 int long_radius = 600;
813 int short_radius = 600;
814 while (long_radius > 0 && short_radius > 0) {
815 paint.setColor(colors[(c_index++) % color_count]);
816 builder.DrawOval(DlRect::MakeXYWH(10 - long_radius, 10 - short_radius,
817 long_radius * 2, short_radius * 2),
819 builder.DrawOval(DlRect::MakeXYWH(1000 - short_radius, 750 - long_radius,
820 short_radius * 2, long_radius * 2),
822 if (short_radius > 30) {
831 DlColor gradient_colors[7] = {
832 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
833 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
834 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
835 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
836 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
837 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
838 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
849 auto texture = CreateTextureForFixture(
"airplane.jpg",
853 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
855 paint.setColorSource(DlColorSource::MakeRadial(
856 DlPoint(300, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
857 builder.DrawOval(DlRect::MakeXYWH(200, 625, 200, 50), paint);
858 builder.DrawOval(DlRect::MakeXYWH(275, 550, 50, 200), paint);
860 DlMatrix local_matrix = DlMatrix::MakeTranslation({610, 15});
861 paint.setColorSource(DlColorSource::MakeImage(
862 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
863 DlImageSampling::kNearestNeighbor, &local_matrix));
864 builder.DrawOval(DlRect::MakeXYWH(610, 90, 200, 50), paint);
865 builder.DrawOval(DlRect::MakeXYWH(685, 15, 50, 200), paint);
867 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
871 struct ArcFarmOptions {
878 void RenderArcFarm(DisplayListBuilder& builder,
879 const DlPaint& paint,
880 const ArcFarmOptions& opts) {
882 builder.Translate(50, 50);
884 const int sweep_limit = opts.sweeps_over_360 ? 420 : 360;
887 for (
int sweep = 30; sweep <= sweep_limit; sweep += 30) {
888 builder.DrawArc(arc_bounds,
start, opts.full_circles ? 360 : sweep,
889 opts.use_center, paint);
890 builder.Translate(50, 0);
893 builder.Translate(0, 50);
898 void RenderArcFarmForOverlappingCapsTest(DisplayListBuilder& builder,
899 const DlPaint& paint) {
901 builder.Translate(40, 30);
903 for (
int stroke_width = 10; stroke_width <= 40; stroke_width += 3) {
904 DlPaint modified_paint = DlPaint(paint);
905 modified_paint.setStrokeWidth(stroke_width);
907 for (
int sweep = 160; sweep <= 360; sweep += 20) {
908 builder.DrawArc(arc_bounds, 0, sweep,
false, modified_paint);
909 builder.Translate(84, 0);
912 builder.Translate(0, 44 + stroke_width);
919 DisplayListBuilder builder;
920 builder.Scale(GetContentScale().
x, GetContentScale().y);
921 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
924 paint.setColor(DlColor::kBlue());
926 RenderArcFarm(builder, paint,
929 .full_circles =
false,
932 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
936 DisplayListBuilder builder;
937 builder.Scale(GetContentScale().
x, GetContentScale().y);
938 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
941 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
943 RenderArcFarm(builder, paint,
946 .full_circles =
false,
949 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
953 DisplayListBuilder builder;
954 builder.Scale(GetContentScale().
x, GetContentScale().y);
955 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
958 paint.setColor(DlColor::kBlue());
960 RenderArcFarm(builder, paint,
963 .full_circles =
false,
966 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
970 DisplayListBuilder builder;
971 builder.Scale(GetContentScale().
x, GetContentScale().y);
972 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
975 paint.setColor(DlColor::kBlue());
977 RenderArcFarm(builder, paint,
980 .full_circles =
false,
981 .vertical_scale = 0.8f,
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.setColor(DlColor::kBlue());
995 RenderArcFarm(builder, paint,
998 .full_circles =
false,
999 .vertical_scale = 0.8f,
1002 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1006 DisplayListBuilder builder;
1007 builder.Scale(GetContentScale().
x, GetContentScale().y);
1008 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1011 paint.setDrawStyle(DlDrawStyle::kStroke);
1012 paint.setStrokeWidth(6.0f);
1013 paint.setStrokeCap(DlStrokeCap::kButt);
1014 paint.setColor(DlColor::kBlue());
1016 RenderArcFarm(builder, paint,
1018 .use_center =
false,
1019 .full_circles =
false,
1022 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1026 DisplayListBuilder builder;
1027 builder.Scale(GetContentScale().
x, GetContentScale().y);
1028 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1031 paint.setDrawStyle(DlDrawStyle::kStroke);
1032 paint.setStrokeWidth(6.0f);
1033 paint.setStrokeCap(DlStrokeCap::kSquare);
1034 paint.setColor(DlColor::kBlue());
1036 RenderArcFarm(builder, paint,
1038 .use_center =
false,
1039 .full_circles =
false,
1042 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1046 DisplayListBuilder builder;
1047 builder.Scale(GetContentScale().
x, GetContentScale().y);
1048 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1051 paint.setDrawStyle(DlDrawStyle::kStroke);
1052 paint.setStrokeCap(DlStrokeCap::kSquare);
1053 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1055 RenderArcFarmForOverlappingCapsTest(builder, paint);
1057 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1061 DisplayListBuilder builder;
1062 builder.Scale(GetContentScale().
x, GetContentScale().y);
1063 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1066 paint.setDrawStyle(DlDrawStyle::kStroke);
1067 paint.setStrokeWidth(6.0f);
1068 paint.setStrokeCap(DlStrokeCap::kRound);
1069 paint.setColor(DlColor::kBlue());
1071 RenderArcFarm(builder, paint,
1073 .use_center =
false,
1074 .full_circles =
false,
1077 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1081 DisplayListBuilder builder;
1082 builder.Scale(GetContentScale().
x, GetContentScale().y);
1083 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1086 paint.setDrawStyle(DlDrawStyle::kStroke);
1087 paint.setStrokeCap(DlStrokeCap::kRound);
1088 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1090 RenderArcFarmForOverlappingCapsTest(builder, paint);
1092 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1096 DisplayListBuilder builder;
1097 builder.Scale(GetContentScale().
x, GetContentScale().y);
1098 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1101 paint.setDrawStyle(DlDrawStyle::kStroke);
1102 paint.setStrokeWidth(6.0f);
1103 paint.setStrokeJoin(DlStrokeJoin::kBevel);
1104 paint.setColor(DlColor::kBlue());
1106 RenderArcFarm(builder, paint,
1109 .full_circles =
false,
1110 .sweeps_over_360 =
true,
1113 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1117 DisplayListBuilder builder;
1118 builder.Scale(GetContentScale().
x, GetContentScale().y);
1119 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1122 paint.setDrawStyle(DlDrawStyle::kStroke);
1123 paint.setStrokeWidth(6.0f);
1124 paint.setStrokeJoin(DlStrokeJoin::kMiter);
1127 paint.setStrokeMiter(3.0f);
1128 paint.setColor(DlColor::kBlue());
1130 RenderArcFarm(builder, paint,
1133 .full_circles =
false,
1134 .sweeps_over_360 =
true,
1137 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1141 DisplayListBuilder builder;
1142 builder.Scale(GetContentScale().
x, GetContentScale().y);
1143 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1146 paint.setDrawStyle(DlDrawStyle::kStroke);
1147 paint.setStrokeWidth(6.0f);
1148 paint.setStrokeJoin(DlStrokeJoin::kRound);
1149 paint.setColor(DlColor::kBlue());
1151 RenderArcFarm(builder, paint,
1154 .full_circles =
false,
1155 .sweeps_over_360 =
true,
1158 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1162 DisplayListBuilder builder;
1163 builder.Scale(GetContentScale().
x, GetContentScale().y);
1164 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1167 paint.setDrawStyle(DlDrawStyle::kStroke);
1168 paint.setStrokeWidth(8.0f);
1169 paint.setStrokeCap(DlStrokeCap::kSquare);
1170 paint.setColor(DlColor::kRed());
1172 RenderArcFarm(builder, paint,
1174 .use_center =
false,
1175 .full_circles =
false,
1178 paint.setStrokeCap(DlStrokeCap::kButt);
1179 paint.setColor(DlColor::kBlue());
1181 RenderArcFarm(builder, paint,
1183 .use_center =
false,
1184 .full_circles =
false,
1187 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1191 DisplayListBuilder builder;
1192 builder.Scale(GetContentScale().
x, GetContentScale().y);
1193 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1196 paint.setDrawStyle(DlDrawStyle::kStroke);
1197 paint.setStrokeWidth(8.0f);
1198 paint.setStrokeCap(DlStrokeCap::kSquare);
1199 paint.setColor(DlColor::kRed());
1201 RenderArcFarm(builder, paint,
1203 .use_center =
false,
1204 .full_circles =
false,
1207 paint.setStrokeCap(DlStrokeCap::kRound);
1208 paint.setColor(DlColor::kGreen());
1210 RenderArcFarm(builder, paint,
1212 .use_center =
false,
1213 .full_circles =
false,
1216 paint.setStrokeCap(DlStrokeCap::kButt);
1217 paint.setColor(DlColor::kBlue());
1219 RenderArcFarm(builder, paint,
1221 .use_center =
false,
1222 .full_circles =
false,
1225 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1240 DisplayListBuilder builder;
1241 builder.Scale(GetContentScale().
x, GetContentScale().y);
1242 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1245 paint.setDrawStyle(DlDrawStyle::kStroke);
1246 paint.setStrokeWidth(6.0f);
1247 paint.setStrokeCap(DlStrokeCap::kButt);
1248 paint.setColor(DlColor::kBlue());
1251 RenderArcFarm(builder, paint,
1253 .use_center =
false,
1254 .full_circles =
true,
1257 paint.setColor(DlColor::kWhite());
1260 RenderArcFarm(builder, paint,
1262 .use_center =
false,
1263 .full_circles =
false,
1266 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1270 DisplayListBuilder builder;
1271 builder.Scale(GetContentScale().
x, GetContentScale().y);
1273 const int color_count = 3;
1274 DlColor colors[color_count] = {
1277 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
1280 paint.setColor(DlColor::kWhite());
1281 builder.DrawPaint(paint);
1284 for (
int i = 0; i < 4; i++) {
1285 for (
int j = 0; j < 4; j++) {
1286 paint.setColor(colors[(c_index++) % color_count]);
1287 builder.DrawRoundRect(
1288 DlRoundRect::MakeRectXY(
1289 DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1290 i * 5 + 10, j * 5 + 10),
1294 paint.setColor(colors[(c_index++) % color_count]);
1295 builder.DrawRoundRect(
1296 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40),
1298 paint.setColor(colors[(c_index++) % color_count]);
1299 builder.DrawRoundRect(
1300 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40),
1303 DlColor gradient_colors[7] = {
1304 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1305 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1306 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1307 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1308 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1309 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1310 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
1321 auto texture = CreateTextureForFixture(
"airplane.jpg",
1325 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1326 paint.setColorSource(DlColorSource::MakeRadial(
1327 DlPoint(550, 550), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1328 for (
int i = 1; i <= 10; i++) {
1330 builder.DrawRoundRect(
1331 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1332 550 + i * 20, 550 + j * 20),
1337 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1338 paint.setColorSource(DlColorSource::MakeRadial(
1339 DlPoint(200, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1340 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1341 builder.DrawRoundRect(
1342 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40),
1344 builder.DrawRoundRect(
1345 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40),
1348 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1349 DlMatrix local_matrix = DlMatrix::MakeTranslation({520, 20});
1350 paint.setColorSource(DlColorSource::MakeImage(
1351 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1352 DlImageSampling::kNearestNeighbor, &local_matrix));
1353 for (
int i = 1; i <= 10; i++) {
1355 builder.DrawRoundRect(
1356 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1357 720 + i * 20, 220 + j * 20),
1362 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1363 local_matrix = DlMatrix::MakeTranslation({800, 300});
1364 paint.setColorSource(DlColorSource::MakeImage(
1365 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1366 DlImageSampling::kNearestNeighbor, &local_matrix));
1367 builder.DrawRoundRect(
1368 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
1370 builder.DrawRoundRect(
1371 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40),
1374 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1378 DisplayListBuilder builder;
1379 builder.Scale(GetContentScale().
x, GetContentScale().y);
1381 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
1383 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
1386 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
1388 for (
int i = 0; i < 5; i++) {
1391 builder.DrawRect(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1392 radius, 60.0f - radius),
1396 paint.setColor(DlColor::kBlue());
1398 for (
int i = 0; i < 5; i++) {
1401 builder.DrawCircle(
DlPoint(
x + 25, y + 25), radius, paint);
1404 paint.setColor(DlColor::kGreen());
1406 for (
int i = 0; i < 5; i++) {
1409 builder.DrawOval(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1410 radius, 60.0f - radius),
1415 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
1417 for (
int i = 0; i < 5; i++) {
1420 builder.DrawRoundRect(
1421 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1427 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
1429 for (
int i = 0; i < 5; i++) {
1432 builder.DrawRoundRect(
1433 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1438 auto dl = builder.Build();
1439 ASSERT_TRUE(OpenPlaygroundHere(dl));
1443 DisplayListBuilder builder;
1445 builder.Scale(GetContentScale().
x, GetContentScale().y);
1448 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1449 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
1450 std::vector<Scalar> stops = {
1455 paint.setColorSource(DlColorSource::MakeLinear(
1464 builder.DrawPaint(paint);
1466 DlRect clip_rect = DlRect::MakeLTRB(50, 50, 400, 300);
1467 DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 100, 100);
1471 builder.ClipRoundRect(clip_rrect, DlClipOp::kIntersect);
1474 auto backdrop_filter = DlImageFilter::MakeColorFilter(
1475 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kExclusion));
1476 builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get());
1478 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1484 auto callback = [&]() -> sk_sp<DisplayList> {
1485 DisplayListBuilder builder;
1489 builder.Translate(300, 300);
1496 paint.setColor(DlColor::kGreen());
1497 builder.DrawPaint(paint);
1498 builder.ClipRect(DlRect::MakeLTRB(-180, -180, 180, 180),
1499 DlClipOp::kDifference);
1501 paint.setColor(DlColor::kBlack());
1502 builder.DrawPaint(paint);
1510 builder.ClipOval(DlRect::MakeLTRB(-200, -200, 200, 200));
1513 Matrix(1.0, 0.0, 0.0, 0.0,
1515 0.0, 0.0, 1.0, 0.003,
1516 0.0, 0.0, 0.0, 1.0) *
1525 -
DlPoint(image->GetSize().width, image->GetSize().height) * 0.5;
1526 builder.DrawImage(image, position, {});
1532 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
1533 builder.DrawCircle(
DlPoint(), 230, paint);
1537 return builder.Build();
1539 ASSERT_TRUE(OpenPlaygroundHere(callback));
1545 DisplayListBuilder builder;
1549 paint.setColor(DlColor::kWhite());
1550 builder.DrawPaint(paint);
1554 DlMatrix matrix = DlMatrix::MakeTranslation({50, 50});
1556 paint.setColorSource(DlColorSource::MakeImage(
1557 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1558 DlImageSampling::kNearestNeighbor, &matrix));
1560 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
1569 Matrix matrix(1, -1, 0, 0,
1573 paint.setColorSource(DlColorSource::MakeImage(
1574 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1575 DlImageSampling::kNearestNeighbor, &matrix));
1576 builder.DrawRect(DlRect::MakeLTRB(100, 0, 200, 100), paint);
1583 builder.Translate(100, 0);
1584 builder.Scale(100, 100);
1587 DlMatrix matrix = DlMatrix::MakeScale({0.005, 0.005, 1});
1588 paint.setColorSource(DlColorSource::MakeImage(
1589 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1590 DlImageSampling::kNearestNeighbor, &matrix));
1592 builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
1599 builder.Translate(150, 150);
1603 DlMatrix::MakePerspective(
Radians{0.5},
ISize{200, 200}, 0.05, 1);
1604 paint.setColorSource(DlColorSource::MakeImage(
1605 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1606 DlImageSampling::kNearestNeighbor, &matrix));
1608 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
1612 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1616 DisplayListBuilder builder;
1621 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1622 paint.setBlendMode(DlBlendMode::kSrc);
1624 DlRect bounds = DlRect::MakeLTRB(0, 0, 200, 200);
1625 builder.SaveLayer(bounds, &paint);
1627 paint.setColor(DlColor::kTransparent());
1628 paint.setBlendMode(DlBlendMode::kSrc);
1629 builder.DrawPaint(paint);
1632 paint.setColor(DlColor::kBlue());
1633 paint.setBlendMode(DlBlendMode::kDstOver);
1634 builder.SaveLayer(std::nullopt, &paint);
1640 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1645 DisplayListBuilder builder;
1646 builder.Scale(GetContentScale().
x, GetContentScale().y);
1647 builder.Translate(100, 100);
1651 DlMatrix translate = DlMatrix::MakeTranslation({300, 0});
1652 paint.setImageFilter(
1653 DlImageFilter::MakeMatrix(translate, DlImageSampling::kLinear));
1654 builder.SaveLayer(std::nullopt, &paint);
1656 DlPaint circle_paint;
1657 circle_paint.setColor(DlColor::kGreen());
1658 builder.DrawCircle(
DlPoint(-300, 0), 100, circle_paint);
1661 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1666 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
1667 DisplayListBuilder builder;
1668 builder.Scale(GetContentScale().
x, GetContentScale().y);
1669 builder.Translate(100, 100);
1674 paint.setImageFilter(DlImageFilter::MakeMatrix(
1675 DlMatrix::MakeTranslation({300, 0}) * DlMatrix::MakeScale({2, 2, 1}),
1676 DlImageSampling::kNearestNeighbor));
1677 builder.SaveLayer(std::nullopt, &paint);
1679 DlPaint circle_paint;
1680 circle_paint.setColor(DlColor::kGreen());
1681 builder.DrawCircle(
DlPoint(-150, 0), 50, circle_paint);
1684 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1689 SetWindowSize({400, 400});
1690 DisplayListBuilder builder;
1692 builder.Scale(GetContentScale().
x, GetContentScale().y);
1695 paint.setColor(DlColor::kRed());
1696 builder.DrawRect(DlRect::MakeLTRB(200, 200, 300, 300), paint);
1698 paint.setImageFilter(DlImageFilter::MakeMatrix(DlMatrix::MakeScale({2, 2, 1}),
1699 DlImageSampling::kLinear));
1700 builder.SaveLayer(std::nullopt, &paint);
1703 paint.setColor(DlColor::kGreen());
1704 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
1707 paint.setColor(DlColor::kRed());
1708 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 800), paint);
1711 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1715 DisplayListBuilder builder;
1716 builder.Scale(GetContentScale().
x, GetContentScale().y);
1719 paint.setColor(DlColor::kRed());
1720 builder.DrawPaint(paint);
1721 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1722 paint.setColor(DlColor::kBlue());
1723 builder.SaveLayer(std::nullopt, &paint);
1726 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1730 DisplayListBuilder builder;
1731 builder.Scale(GetContentScale().
x, GetContentScale().y);
1733 builder.DrawImage(image,
DlPoint(10, 10), {});
1734 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1737 paint.setBlendMode(DlBlendMode::kClear);
1738 builder.SaveLayer(std::nullopt, &paint);
1741 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1745 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
1746 DisplayListBuilder builder;
1749 red.setColor(DlColor::kRed());
1752 green.setColor(DlColor::kGreen());
1755 blue.setColor(DlColor::kBlue());
1758 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1760 DlRect huge_bounds = DlRect::MakeXYWH(0, 0, 100000, 100000);
1761 builder.SaveLayer(huge_bounds, &save);
1763 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1764 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), green);
1765 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), blue);
1769 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1774 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1780 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1787 DisplayListBuilder builder;
1794 builder.Translate(100, 200);
1795 builder.Scale(0.5, 0.5);
1796 builder.DrawImage(image,
DlPoint(100.0, 100.0),
1797 DlImageSampling::kNearestNeighbor);
1804 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1806 builder.SaveLayer(std::nullopt, &alpha);
1809 paint.setColor(DlColor::kRed());
1810 builder.DrawRect(DlRect::MakeXYWH(000, 000, 100, 100), paint);
1811 paint.setColor(DlColor::kGreen());
1812 builder.DrawRect(DlRect::MakeXYWH(020, 020, 100, 100), paint);
1813 paint.setColor(DlColor::kBlue());
1814 builder.DrawRect(DlRect::MakeXYWH(040, 040, 100, 100), paint);
1819 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1823 DisplayListBuilder builder;
1826 paint.setColor(DlColor::kRed());
1827 builder.DrawCircle(
DlPoint(250, 250), 125, paint);
1829 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1833 DisplayListBuilder builder;
1836 red.setColor(DlColor::kRed());
1838 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1840 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1844 DisplayListBuilder builder;
1847 save.setColor(DlColor::kBlack());
1849 DlRect save_bounds = DlRect::MakeXYWH(0, 0, 50, 50);
1850 builder.SaveLayer(save_bounds, &save);
1853 paint.setColor(DlColor::kRed());
1854 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
1855 paint.setColor(DlColor::kGreen());
1856 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), paint);
1857 paint.setColor(DlColor::kBlue());
1858 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), paint);
1862 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1866 DisplayListBuilder builder;
1867 builder.Scale(GetContentScale().
x, GetContentScale().y);
1870 const int color_count = 3;
1871 DlColor colors[color_count] = {
1874 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
1877 paint.setColor(DlColor::kWhite());
1878 builder.DrawPaint(paint);
1881 const DlPaint& paint) {
1882 builder.DrawPath(DlPath::MakeRoundRectXY(rect,
x, y), paint);
1886 for (
int i = 0; i < 4; i++) {
1887 for (
int j = 0; j < 4; j++) {
1888 paint.setColor(colors[(c_index++) % color_count]);
1889 draw_rrect_as_path(DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1890 i * 5 + 10, j * 5 + 10, paint);
1893 paint.setColor(colors[(c_index++) % color_count]);
1894 draw_rrect_as_path(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
1895 paint.setColor(colors[(c_index++) % color_count]);
1896 draw_rrect_as_path(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
1898 std::vector<DlColor> gradient_colors = {
1899 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1900 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1901 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1902 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1903 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1904 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1905 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
1906 std::vector<Scalar> stops = {
1916 CreateTextureForFixture(
"airplane.jpg",
1919 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1920 paint.setColorSource(DlColorSource::MakeRadial(
1923 gradient_colors.size(),
1924 gradient_colors.data(),
1926 DlTileMode::kMirror));
1927 for (
int i = 1; i <= 10; i++) {
1929 draw_rrect_as_path(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1930 550 + i * 20, 550 + j * 20),
1931 i * 10, j * 10, paint);
1933 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1934 paint.setColorSource(DlColorSource::MakeRadial(
1937 gradient_colors.size(),
1938 gradient_colors.data(),
1940 DlTileMode::kMirror));
1941 draw_rrect_as_path(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
1942 draw_rrect_as_path(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
1944 auto matrix = DlMatrix::MakeTranslation({520, 20});
1945 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1946 paint.setColorSource(DlColorSource::MakeImage(
1947 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1948 DlImageSampling::kMipmapLinear, &matrix));
1949 for (
int i = 1; i <= 10; i++) {
1951 draw_rrect_as_path(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1952 720 + i * 20, 220 + j * 20),
1953 i * 10, j * 10, paint);
1955 matrix = DlMatrix::MakeTranslation({800, 300});
1956 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1957 paint.setColorSource(DlColorSource::MakeImage(
1958 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1959 DlImageSampling::kMipmapLinear, &matrix));
1961 draw_rrect_as_path(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
1962 draw_rrect_as_path(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
1964 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1968 auto callback = [&]() -> sk_sp<DisplayList> {
1969 DisplayListBuilder builder;
1970 builder.Scale(GetContentScale().x, GetContentScale().y);
1973 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1975 auto current =
Point{25, 25};
1976 const auto offset =
Point{25, 25};
1977 const auto size =
Size(100, 100);
1982 DlRect bounds = DlRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
1984 DlPaint stroke_paint;
1985 stroke_paint.setColor(DlColor::kYellow());
1986 stroke_paint.setStrokeWidth(5);
1987 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
1988 builder.DrawRect(bounds, stroke_paint);
1990 builder.SaveLayer(bounds, &alpha);
1993 paint.setColor(DlColor::kRed());
1995 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1997 paint.setColor(DlColor::kGreen());
2000 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2002 paint.setColor(DlColor::kBlue());
2005 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2009 return builder.Build();
2012 ASSERT_TRUE(OpenPlaygroundHere(callback));
2017 DisplayListBuilder builder;
2020 paint.setColor(DlColor::kBlack());
2021 DlRect rect = DlRect::MakeXYWH(25, 25, 25, 25);
2022 builder.DrawRect(rect, paint);
2024 builder.Translate(10, 10);
2027 builder.SaveLayer(std::nullopt, &save_paint);
2029 paint.setColor(DlColor::kGreen());
2030 builder.DrawRect(rect, paint);
2034 builder.Translate(10, 10);
2035 paint.setColor(DlColor::kRed());
2036 builder.DrawRect(rect, paint);
2038 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2042 DisplayListBuilder builder;
2044 DlRect rect = DlRect::MakeXYWH(0, 0, 1000, 1000);
2049 DlRect bounds = DlRect::MakeXYWH(25, 25, 25, 25);
2050 builder.SaveLayer(bounds, &save_paint);
2051 paint.setColor(DlColor::kBlack());
2052 builder.DrawRect(rect, paint);
2058 DlRect bounds = DlRect::MakeXYWH(35, 35, 25, 25);
2059 builder.SaveLayer(bounds, &save_paint);
2060 paint.setColor(DlColor::kGreen());
2061 builder.DrawRect(rect, paint);
2067 DlRect bounds = DlRect::MakeXYWH(45, 45, 25, 25);
2068 builder.SaveLayer(bounds, &save_paint);
2069 paint.setColor(DlColor::kRed());
2070 builder.DrawRect(rect, paint);
2074 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2078 DisplayListBuilder builder;
2081 paint.setColor(DlColor::kWhite());
2082 builder.DrawPaint(paint);
2088 builder.ClipPath(path);
2090 DlRect bounds = DlRect::MakeXYWH(50, 50, 100, 100);
2092 builder.SaveLayer(bounds, &save_paint);
2095 paint.setColor(DlColor::kWhite());
2096 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2099 paint.setColor(DlColor::kGreen());
2100 paint.setBlendMode(DlBlendMode::kHardLight);
2101 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2104 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2108 DisplayListBuilder builder;
2110 builder.Scale(GetContentScale().
x, GetContentScale().y);
2111 builder.Translate(100, 100);
2114 auto draw_image_layer = [&builder, &texture](
const DlPaint& paint) {
2115 builder.SaveLayer(std::nullopt, &paint);
2116 builder.DrawImage(texture,
DlPoint(), DlImageSampling::kLinear);
2120 DlPaint effect_paint;
2121 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
2122 draw_image_layer(effect_paint);
2124 builder.Translate(300, 300);
2125 builder.Scale(3, 3);
2126 draw_image_layer(effect_paint);
2128 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2132 DisplayListBuilder builder;
2134 builder.Scale(GetContentScale().
x, GetContentScale().y);
2136 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
2139 save_paint.setColor(DlColor::kWhite());
2140 builder.DrawPaint(save_paint);
2142 paint.setColor(DlColor::kBlue());
2143 for (
int i = 0; i < 5; i++) {
2145 Scalar y_radius = i * 15;
2146 for (
int j = 0; j < 5; j++) {
2148 Scalar x_radius = j * 15;
2149 builder.DrawRoundRect(
2150 DlRoundRect::MakeRectXY(
2151 DlRect::MakeXYWH(
x + 50, y + 50, 100.0f, 100.0f),
2152 x_radius, y_radius),
2157 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2161 DisplayListBuilder builder;
2165 builder.SaveLayer(std::nullopt, &paint);
2167 builder.Translate(100, 100);
2168 paint.setColor(DlColor::kBlue());
2169 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2170 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
2172 paint.setColor(DlColor::kGreen());
2173 paint.setBlendMode(DlBlendMode::kSrcOver);
2174 paint.setImageFilter(DlImageFilter::MakeColorFilter(
2175 DlColorFilter::MakeBlend(DlColor::kWhite(), DlBlendMode::kDst)));
2176 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2180 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2188 GTEST_SKIP() <<
"Swiftshader is running out of memory on this example.";
2190 DisplayListBuilder builder(DlRect::MakeSize(DlSize(1000, 1000)));
2192 auto filter = DlImageFilter::MakeMatrix(
2193 DlMatrix::MakeScale({0.001, 0.001, 1}), DlImageSampling::kLinear);
2196 paint.setImageFilter(filter);
2197 builder.SaveLayer(std::nullopt, &paint);
2200 paint.setColor(DlColor::kRed());
2201 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100000, 100000), paint);
2205 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2212 auto callback = [&]() -> sk_sp<DisplayList> {
2214 ImGuiWindowFlags_AlwaysAutoResize)) {
2215 ImGui::SliderFloat(
"width", &width, 0, 200);
2216 ImGui::SliderFloat(
"height", &height, 0, 200);
2217 ImGui::SliderFloat(
"corner", &corner, 0, 1);
2221 DisplayListBuilder builder;
2222 builder.Scale(GetContentScale().
x, GetContentScale().y);
2224 DlPaint background_paint;
2225 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
2226 builder.DrawPaint(background_paint);
2228 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
2229 std::vector<Scalar> stops = {0.0, 1.0};
2232 auto gradient = DlColorSource::MakeLinear(
DlPoint(0, 0),
DlPoint(200, 200),
2233 2, colors.data(), stops.data(),
2234 DlTileMode::kClamp);
2235 paint.setColorSource(gradient);
2236 paint.setColor(DlColor::kWhite());
2237 paint.setDrawStyle(DlDrawStyle::kStroke);
2238 paint.setStrokeWidth(20);
2241 builder.Translate(100, 100);
2243 Scalar corner_x = ((1 - corner) * 50) + 50;
2244 Scalar corner_y = corner * 50 + 50;
2246 DlRect::MakeXYWH(0, 0, width, height), corner_x, corner_y);
2247 builder.DrawRoundRect(rrect, paint);
2249 return builder.Build();
2251 ASSERT_TRUE(OpenPlaygroundHere(callback));
2255 DisplayListBuilder builder;
2257 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
2260 builder.ClipRect(DlRect::MakeLTRB(100, 100, 800, 800));
2264 builder.ClipRect(DlRect::MakeLTRB(600, 600, 800, 800));
2265 builder.DrawPaint(DlPaint().setColor(DlColor::kRed()));
2266 builder.DrawPaint(DlPaint().setColor(DlColor::kBlue().withAlphaF(0.5)));
2267 builder.ClipRect(DlRect::MakeLTRB(700, 700, 750, 800));
2268 builder.DrawPaint(DlPaint().setColor(DlColor::kRed().withAlphaF(0.5)));
2272 auto image_filter = DlImageFilter::MakeBlur(10, 10, DlTileMode::kDecal);
2273 builder.SaveLayer(std::nullopt,
nullptr, image_filter.get());
2276 builder.DrawCircle(
DlPoint(100, 100), 100,
2277 DlPaint().setColor(DlColor::kAqua()));
2279 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)