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()));
40 DisplayListBuilder builder;
42 paint.setColor(DlColor::kBlue());
43 builder.DrawRect(DlRect::MakeXYWH(100.f, 100.f, 100.f, 100.f), paint);
44 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
49 std::function<void(DisplayListBuilder&,
const DlRect&,
const DlPaint&)>;
51 sk_sp<DisplayList> MakeWideStrokedRects(
Point scale,
52 const DrawRectProc& draw_rect) {
53 DisplayListBuilder builder;
54 builder.Scale(scale.
x, scale.
y);
55 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
58 paint.setColor(DlColor::kBlue().withAlphaF(0.5));
59 paint.setDrawStyle(DlDrawStyle::kStroke);
60 paint.setStrokeWidth(30.0f);
66 paint.setStrokeJoin(DlStrokeJoin::kBevel);
67 draw_rect(builder, DlRect::MakeXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
68 draw_rect(builder, DlRect::MakeXYWH(250.0f, 100.0f, 10.0f, 100.0f), paint);
69 draw_rect(builder, DlRect::MakeXYWH(100.0f, 250.0f, 100.0f, 10.0f), paint);
71 paint.setStrokeJoin(DlStrokeJoin::kRound);
72 draw_rect(builder, DlRect::MakeXYWH(350.0f, 100.0f, 100.0f, 100.0f), paint);
73 draw_rect(builder, DlRect::MakeXYWH(500.0f, 100.0f, 10.0f, 100.0f), paint);
74 draw_rect(builder, DlRect::MakeXYWH(350.0f, 250.0f, 100.0f, 10.0f), paint);
76 paint.setStrokeJoin(DlStrokeJoin::kMiter);
77 draw_rect(builder, DlRect::MakeXYWH(600.0f, 100.0f, 100.0f, 100.0f), paint);
78 draw_rect(builder, DlRect::MakeXYWH(750.0f, 100.0f, 10.0f, 100.0f), paint);
79 draw_rect(builder, DlRect::MakeXYWH(600.0f, 250.0f, 100.0f, 10.0f), paint);
83 paint.setStrokeWidth(110.0f);
85 paint.setStrokeJoin(DlStrokeJoin::kBevel);
86 draw_rect(builder, DlRect::MakeXYWH(100.0f, 400.0f, 100.0f, 100.0f), paint);
88 paint.setStrokeJoin(DlStrokeJoin::kRound);
89 draw_rect(builder, DlRect::MakeXYWH(350.0f, 400.0f, 100.0f, 100.0f), paint);
91 paint.setStrokeJoin(DlStrokeJoin::kMiter);
92 draw_rect(builder, DlRect::MakeXYWH(600.0f, 400.0f, 100.0f, 100.0f), paint);
94 return builder.Build();
99 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
100 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
101 const DlPaint& paint) {
103 builder.DrawRect(rect, paint);
108 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
109 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
110 const DlPaint& paint) {
112 builder.DrawPath(DlPath::MakeRect(rect), paint);
117 DisplayListBuilder builder;
119 paint.setColor(DlColor::kRed());
121 builder.DrawImage(image,
DlPoint(100.0, 100.0),
122 DlImageSampling::kNearestNeighbor, &paint);
123 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
127 DisplayListBuilder builder;
129 paint.setColor(DlColor::kRed());
130 paint.setColorFilter(
131 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
132 paint.setInvertColors(
true);
135 builder.DrawImage(image,
DlPoint(100.0, 100.0),
136 DlImageSampling::kNearestNeighbor, &paint);
137 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
141 DisplayListBuilder builder;
143 paint.setColor(DlColor::kRed());
144 paint.setColorFilter(
145 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
146 paint.setInvertColors(
true);
148 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
149 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
153 DisplayListBuilder builder;
155 paint.setColor(DlColor::kRed());
156 paint.setColorFilter(
157 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
158 paint.setInvertColors(
true);
160 builder.DrawPaint(paint);
161 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
165 bool GenerateMipmap(
const std::shared_ptr<Context>& context,
166 std::shared_ptr<Texture> texture,
167 std::string_view label) {
168 auto buffer = context->CreateCommandBuffer();
172 auto pass = buffer->CreateBlitPass();
176 pass->GenerateMipmap(std::move(texture), label);
178 pass->EncodeCommands();
179 return context->GetCommandQueue()->Submit({buffer}).ok();
182 void CanRenderTiledTexture(
AiksTest* aiks_test,
183 DlTileMode tile_mode,
184 Matrix local_matrix = {}) {
185 auto context = aiks_test->GetContext();
186 ASSERT_TRUE(context);
187 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
189 GenerateMipmap(context, texture,
"table_mountain_nx");
191 auto color_source = DlColorSource::MakeImage(
192 image, tile_mode, tile_mode, DlImageSampling::kNearestNeighbor,
195 DisplayListBuilder builder;
197 paint.setColor(DlColor::kWhite());
198 paint.setColorSource(color_source);
200 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
201 builder.Translate(100.0f, 100.0f);
202 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
205 constexpr
auto stroke_width = 64;
206 paint.setDrawStyle(DlDrawStyle::kStroke);
207 paint.setStrokeWidth(stroke_width);
208 if (tile_mode == DlTileMode::kDecal) {
209 builder.DrawRect(DlRect::MakeXYWH(stroke_width, stroke_width, 600, 600),
212 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
217 DlPathBuilder path_builder;
218 path_builder.AddCircle(
DlPoint(150, 150), 150);
219 path_builder.AddRoundRect(
221 DlPath path = path_builder.TakePath();
224 EXPECT_FALSE(path.IsRect(
nullptr));
225 EXPECT_FALSE(path.IsOval(
nullptr));
226 EXPECT_FALSE(path.IsRoundRect(
nullptr));
229 EXPECT_FALSE(path.IsConvex());
231 paint.setDrawStyle(DlDrawStyle::kFill);
232 builder.DrawPath(path, paint);
239 constexpr
float kConicWeight = 0.707106781f;
240 const DlPath path = DlPathBuilder()
242 .ConicCurveTo({300, 300}, {300, 450}, kConicWeight)
243 .ConicCurveTo({300, 600}, {150, 600}, kConicWeight)
244 .ConicCurveTo({0, 600}, {0, 450}, kConicWeight)
245 .ConicCurveTo({0, 300}, {150, 300}, kConicWeight)
250 EXPECT_FALSE(path.IsRect(
nullptr));
251 EXPECT_FALSE(path.IsOval(
nullptr));
252 EXPECT_FALSE(path.IsRoundRect(
nullptr));
255 EXPECT_TRUE(path.IsConvex());
257 paint.setDrawStyle(DlDrawStyle::kFill);
258 builder.DrawPath(path, paint);
261 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
266 CanRenderTiledTexture(
this, DlTileMode::kClamp);
270 CanRenderTiledTexture(
this, DlTileMode::kRepeat);
274 CanRenderTiledTexture(
this, DlTileMode::kMirror);
278 CanRenderTiledTexture(
this, DlTileMode::kDecal);
282 CanRenderTiledTexture(
this, DlTileMode::kClamp,
287 DisplayListBuilder builder;
290 DlISize image_half_size =
291 DlISize(image->GetSize().width * 0.5f, image->GetSize().height * 0.5f);
294 auto source_rect = DlRect::MakeSize(image_half_size);
296 source_rect.Shift(image_half_size.width, image_half_size.height);
298 builder.DrawImageRect(image, source_rect,
299 DlRect::MakeXYWH(100, 100, 600, 600),
300 DlImageSampling::kNearestNeighbor);
301 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
305 DisplayListBuilder builder;
309 auto source_rect = DlRect::MakeXYWH(
310 image->GetSize().width * 0.25f, image->GetSize().height * 0.4f,
311 image->GetSize().width, image->GetSize().height);
313 auto dest_rect = DlRect::MakeXYWH(100, 100, 600, 600);
316 paint.setColor(DlColor::kMidGrey());
317 builder.DrawRect(dest_rect, paint);
319 builder.DrawImageRect(image, source_rect, dest_rect,
320 DlImageSampling::kNearestNeighbor);
321 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
325 DisplayListBuilder builder;
326 builder.Scale(GetContentScale().
x, GetContentScale().y);
329 paint.setColor(DlColor::kWhite());
330 builder.DrawPaint(paint);
332 auto draw = [&builder](
const DlPaint& paint,
Scalar x,
Scalar y) {
334 builder.Translate(
x, y);
337 builder.ClipRect(DlRect::MakeLTRB(50, 50, 150, 150));
338 builder.DrawPaint(paint);
343 builder.ClipOval(DlRect::MakeLTRB(200, 50, 300, 150));
344 builder.DrawPaint(paint);
349 builder.ClipRoundRect(
350 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(50, 200, 150, 300), 20, 20));
351 builder.DrawPaint(paint);
356 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
357 DlRect::MakeLTRB(200, 230, 300, 270), 20, 20));
358 builder.DrawPaint(paint);
363 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
364 DlRect::MakeLTRB(230, 200, 270, 300), 20, 20));
365 builder.DrawPaint(paint);
371 paint.setColor(DlColor::kBlue());
374 DlColor gradient_colors[7] = {
375 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
376 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
377 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
378 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
379 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
380 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
381 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
392 auto texture = CreateTextureForFixture(
"airplane.jpg",
396 paint.setColorSource(DlColorSource::MakeRadial(
397 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
400 paint.setColorSource(
401 DlColorSource::MakeImage(image, DlTileMode::kRepeat, DlTileMode::kRepeat,
402 DlImageSampling::kNearestNeighbor));
405 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
409 DisplayListBuilder builder;
412 red.setColor(DlColor::kRed());
415 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
417 builder.SaveLayer(std::nullopt, &alpha);
419 builder.DrawCircle(
DlPoint(125, 125), 125, red);
423 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
427 DisplayListBuilder builder;
430 DlColor colors[2] = {
431 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
432 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
439 paint.setColorSource(DlColorSource::MakeLinear(
449 builder.Translate(100, 100);
450 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
454 builder.Translate(100, 400);
455 builder.DrawCircle(
DlPoint(100, 100), 100, paint);
457 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
461 DisplayListBuilder builder;
463 paint.setColor(DlColor::kRed());
467 .top_right = DlSize(25, 50),
468 .bottom_left = DlSize(25, 50),
469 .bottom_right = DlSize(50, 25),
472 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
474 builder.DrawRoundRect(rrect, paint);
476 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
480 auto medium_turquoise =
481 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
483 DisplayListBuilder builder;
484 builder.Scale(0.2, 0.2);
485 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
486 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
490 auto medium_turquoise =
491 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
493 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
495 DisplayListBuilder builder;
496 builder.Scale(0.2, 0.2);
497 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
498 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
499 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
503 DisplayListBuilder builder;
504 builder.Scale(GetContentScale().
x, GetContentScale().y);
507 paint.setColor(DlColor::kPurple());
508 paint.setDrawStyle(DlDrawStyle::kStroke);
509 paint.setStrokeWidth(20.0f);
511 DlPaint thin_paint = paint;
512 thin_paint.setColor(DlColor::kYellow());
513 thin_paint.setStrokeWidth(0.0f);
515 DlRect rect = DlRect::MakeLTRB(10, 10, 90, 90);
516 DlRect thin_tall_rect = DlRect::MakeLTRB(120, 10, 120, 90);
517 DlRect thin_wide_rect = DlRect::MakeLTRB(10, 120, 90, 120);
518 DlRect empty_rect = DlRect::MakeLTRB(120, 120, 120, 120);
548 paint.setStrokeJoin(DlStrokeJoin::kBevel);
549 builder.DrawRect(rect.Shift({100, 100}), paint);
550 builder.DrawRect(rect.Shift({100, 100}), thin_paint);
551 builder.DrawRect(thin_tall_rect.Shift({100, 100}), paint);
552 builder.DrawRect(thin_tall_rect.Shift({100, 100}), thin_paint);
553 builder.DrawRect(thin_wide_rect.Shift({100, 100}), paint);
554 builder.DrawRect(thin_wide_rect.Shift({100, 100}), thin_paint);
555 builder.DrawRect(empty_rect.Shift({100, 100}), paint);
556 builder.DrawRect(empty_rect.Shift({100, 100}), thin_paint);
559 paint.setStrokeJoin(DlStrokeJoin::kRound);
560 builder.DrawRect(rect.Shift({100, 300}), paint);
561 builder.DrawRect(rect.Shift({100, 300}), thin_paint);
562 builder.DrawRect(thin_tall_rect.Shift({100, 300}), paint);
563 builder.DrawRect(thin_tall_rect.Shift({100, 300}), thin_paint);
564 builder.DrawRect(thin_wide_rect.Shift({100, 300}), paint);
565 builder.DrawRect(thin_wide_rect.Shift({100, 300}), thin_paint);
566 builder.DrawRect(empty_rect.Shift({100, 300}), paint);
567 builder.DrawRect(empty_rect.Shift({100, 300}), thin_paint);
570 paint.setStrokeJoin(DlStrokeJoin::kMiter);
572 builder.DrawRect(rect.Shift({100, 500}), paint);
573 builder.DrawRect(rect.Shift({100, 500}), thin_paint);
574 builder.DrawRect(thin_tall_rect.Shift({100, 500}), paint);
575 builder.DrawRect(thin_tall_rect.Shift({100, 500}), thin_paint);
576 builder.DrawRect(thin_wide_rect.Shift({100, 500}), paint);
577 builder.DrawRect(thin_wide_rect.Shift({100, 500}), thin_paint);
578 builder.DrawRect(empty_rect.Shift({100, 500}), paint);
579 builder.DrawRect(empty_rect.Shift({100, 500}), thin_paint);
582 paint.setStrokeJoin(DlStrokeJoin::kMiter);
584 builder.DrawRect(rect.Shift({300, 500}), paint);
585 builder.DrawRect(rect.Shift({300, 500}), thin_paint);
586 builder.DrawRect(thin_tall_rect.Shift({300, 500}), paint);
587 builder.DrawRect(thin_tall_rect.Shift({300, 500}), thin_paint);
588 builder.DrawRect(thin_wide_rect.Shift({300, 500}), paint);
589 builder.DrawRect(thin_wide_rect.Shift({300, 500}), thin_paint);
590 builder.DrawRect(empty_rect.Shift({300, 500}), paint);
591 builder.DrawRect(empty_rect.Shift({300, 500}), thin_paint);
593 paint.setStrokeWidth(120.0f);
594 paint.setColor(DlColor::kBlue());
595 rect = rect.Expand(-20);
598 paint.setStrokeJoin(DlStrokeJoin::kBevel);
599 builder.DrawRect(rect.Shift({500, 100}), paint);
600 builder.DrawRect(rect.Shift({500, 100}), thin_paint);
603 paint.setStrokeJoin(DlStrokeJoin::kRound);
604 builder.DrawRect(rect.Shift({500, 300}), paint);
605 builder.DrawRect(rect.Shift({500, 300}), thin_paint);
608 paint.setStrokeJoin(DlStrokeJoin::kMiter);
610 builder.DrawRect(rect.Shift({500, 500}), paint);
611 builder.DrawRect(rect.Shift({500, 500}), thin_paint);
614 paint.setStrokeJoin(DlStrokeJoin::kMiter);
616 builder.DrawRect(rect.Shift({700, 500}), paint);
617 builder.DrawRect(rect.Shift({700, 500}), thin_paint);
619 DlPaint round_mock_paint;
620 round_mock_paint.setColor(DlColor::kGreen());
621 round_mock_paint.setDrawStyle(DlDrawStyle::kFill);
626 for (
int i = 0; i < 15; i++) {
627 paint.setStrokeWidth(i);
628 paint.setColor(DlColor::kOrange());
629 paint.setStrokeJoin(DlStrokeJoin::kRound);
630 builder.DrawRect(DlRect::MakeXYWH(
x, y, 30, 30), paint);
634 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
638 DisplayListBuilder builder;
639 builder.Scale(GetContentScale().
x, GetContentScale().y);
641 const int color_count = 3;
642 DlColor colors[color_count] = {
645 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
648 paint.setColor(DlColor::kWhite());
649 builder.DrawPaint(paint);
654 paint.setColor(colors[(c_index++) % color_count]);
655 builder.DrawCircle(
DlPoint(10, 10), radius, paint);
663 DlColor gradient_colors[7] = {
664 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
665 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
666 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
667 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
668 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
669 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
670 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
681 auto texture = CreateTextureForFixture(
"airplane.jpg",
685 paint.setColorSource(DlColorSource::MakeRadial(
686 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
687 builder.DrawCircle(
DlPoint(500, 600), 100, paint);
689 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
690 paint.setColorSource(DlColorSource::MakeImage(
691 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
692 DlImageSampling::kNearestNeighbor, &local_matrix));
693 builder.DrawCircle(
DlPoint(800, 300), 100, paint);
695 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
699 auto callback = [&]() {
700 static float stroked_radius = 100.0;
701 static float stroke_width = 0.0;
702 static float stroke_width_fine = 2.0;
703 static float stroked_alpha = 255.0;
704 static float stroked_scale[2] = {1.0, 1.0};
707 ImGuiWindowFlags_AlwaysAutoResize)) {
708 ImGui::SliderFloat(
"Stroked Radius", &stroked_radius, 0, 500);
709 ImGui::SliderFloat(
"Stroked Width", &stroke_width, 0, 500);
710 ImGui::SliderFloat(
"Stroked Width Fine", &stroke_width_fine, 0, 5);
711 ImGui::SliderFloat(
"Stroked Alpha", &stroked_alpha, 0, 10.0);
712 ImGui::SliderFloat2(
"Stroked Scale", stroked_scale, 0, 10.0);
716 flutter::DisplayListBuilder builder;
718 DlPaint background_paint;
719 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
720 builder.DrawPaint(background_paint);
722 flutter::DlPaint paint;
724 paint.setColor(flutter::DlColor::kRed().withAlpha(stroked_alpha));
725 paint.setDrawStyle(flutter::DlDrawStyle::kStroke);
726 paint.setStrokeWidth(stroke_width + stroke_width_fine);
728 builder.Translate(250, 250);
729 builder.Scale(stroked_scale[0], stroked_scale[1]);
730 builder.Translate(-250, -250);
731 builder.DrawCircle(
DlPoint(250, 250), stroked_radius, paint);
733 return builder.Build();
736 ASSERT_TRUE(OpenPlaygroundHere(callback));
740 DisplayListBuilder builder;
741 builder.Scale(GetContentScale().
x, GetContentScale().y);
743 const int color_count = 3;
744 DlColor colors[color_count] = {
747 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
750 paint.setColor(DlColor::kWhite());
751 builder.DrawPaint(paint);
755 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas,
DlPoint center,
757 for (
int i = 0; i < n; i++) {
758 paint.setColor(colors[(c_index++) % color_count]);
759 canvas.DrawCircle(center, r, paint);
764 paint.setDrawStyle(DlDrawStyle::kStroke);
765 paint.setStrokeWidth(1);
766 draw(builder,
DlPoint(10, 10), 2, 2, 14);
767 paint.setStrokeWidth(5);
768 draw(builder,
DlPoint(10, 10), 35, 10, 56);
770 DlColor gradient_colors[7] = {
771 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
772 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
773 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
774 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
775 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
776 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
777 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
788 auto texture = CreateTextureForFixture(
"airplane.jpg",
792 paint.setColorSource(DlColorSource::MakeRadial(
793 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
794 draw(builder,
DlPoint(500, 600), 5, 10, 10);
796 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
797 paint.setColorSource(DlColorSource::MakeImage(
798 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
799 DlImageSampling::kNearestNeighbor, &local_matrix));
800 draw(builder,
DlPoint(800, 300), 5, 10, 10);
802 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
807 DlPathBuilder path_builder;
810 const Scalar k = 0.5522847498f;
812 path_builder.MoveTo(
DlPoint(0.0f, -radius));
814 path_builder.CubicCurveTo(
DlPoint(radius * k, -radius),
818 path_builder.CubicCurveTo(
DlPoint(radius, radius * k),
822 path_builder.CubicCurveTo(
DlPoint(-radius * k, radius),
826 path_builder.CubicCurveTo(
DlPoint(-radius, -radius * k),
829 path_builder.Close();
830 return path_builder.TakePath();
833 void DrawStrokedAndFilledCirclesWithZoom(
AiksTest* test,
837 DisplayListBuilder builder;
838 builder.Scale(test->GetContentScale().x, test->GetContentScale().y);
839 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
842 fill_paint.setColor(DlColor::kBlue());
844 DlPaint stroke_paint;
845 stroke_paint.setColor(DlColor::kGreen());
846 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
847 stroke_paint.setStrokeWidth(stroke_width);
849 DlPath path = ManuallyConstructCirclePath(radius);
851 constexpr
Scalar kLeftX = 300.0f;
852 constexpr
Scalar kRightX = 680.0f;
853 constexpr
Scalar kTopY = 200.0f;
854 constexpr
Scalar kBottomY = 580.0f;
858 builder.Translate(kLeftX, kTopY);
859 builder.Scale(zoom, zoom);
860 builder.DrawPath(path, fill_paint);
861 builder.DrawPath(path, stroke_paint);
866 builder.Translate(kRightX, kTopY);
867 builder.Scale(zoom, zoom);
868 builder.DrawPath(path, fill_paint);
873 builder.Translate(kLeftX, kBottomY);
874 builder.Scale(zoom, zoom);
875 builder.DrawPath(path, stroke_paint);
881 builder.Translate(kRightX, kBottomY);
882 builder.Scale(zoom, zoom);
883 builder.DrawCircle({}, radius + stroke_width * 0.5f, fill_paint);
886 ASSERT_TRUE(test->OpenPlaygroundHere(builder.Build()));
891 DrawStrokedAndFilledCirclesWithZoom(
this, 80.0f, 2.0f,
896 DrawStrokedAndFilledCirclesWithZoom(
this, 1.0f, 1.0f,
901 DisplayListBuilder builder;
902 builder.Scale(GetContentScale().
x, GetContentScale().y);
904 const int color_count = 3;
905 DlColor colors[color_count] = {
908 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
911 paint.setColor(DlColor::kWhite());
912 builder.DrawPaint(paint);
915 int long_radius = 600;
916 int short_radius = 600;
917 while (long_radius > 0 && short_radius > 0) {
918 paint.setColor(colors[(c_index++) % color_count]);
919 builder.DrawOval(DlRect::MakeXYWH(10 - long_radius, 10 - short_radius,
920 long_radius * 2, short_radius * 2),
922 builder.DrawOval(DlRect::MakeXYWH(1000 - short_radius, 750 - long_radius,
923 short_radius * 2, long_radius * 2),
925 if (short_radius > 30) {
934 DlColor gradient_colors[7] = {
935 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
936 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
937 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
938 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
939 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
940 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
941 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
952 auto texture = CreateTextureForFixture(
"airplane.jpg",
956 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
958 paint.setColorSource(DlColorSource::MakeRadial(
959 DlPoint(300, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
960 builder.DrawOval(DlRect::MakeXYWH(200, 625, 200, 50), paint);
961 builder.DrawOval(DlRect::MakeXYWH(275, 550, 50, 200), paint);
963 DlMatrix local_matrix = DlMatrix::MakeTranslation({610, 15});
964 paint.setColorSource(DlColorSource::MakeImage(
965 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
966 DlImageSampling::kNearestNeighbor, &local_matrix));
967 builder.DrawOval(DlRect::MakeXYWH(610, 90, 200, 50), paint);
968 builder.DrawOval(DlRect::MakeXYWH(685, 15, 50, 200), paint);
970 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
974 struct ArcFarmOptions {
981 void RenderArcFarm(DisplayListBuilder& builder,
982 const DlPaint& paint,
983 const ArcFarmOptions& opts) {
985 builder.Translate(50, 50);
987 const int sweep_limit = opts.sweeps_over_360 ? 420 : 360;
990 for (
int sweep = 30; sweep <= sweep_limit; sweep += 30) {
991 builder.DrawArc(arc_bounds,
start, opts.full_circles ? 360 : sweep,
992 opts.use_center, paint);
993 builder.Translate(50, 0);
996 builder.Translate(0, 50);
1001 void RenderArcFarmForOverlappingCapsTest(DisplayListBuilder& builder,
1002 const DlPaint& paint) {
1004 builder.Translate(40, 30);
1006 for (
int stroke_width = 10; stroke_width <= 40; stroke_width += 3) {
1007 DlPaint modified_paint = DlPaint(paint);
1008 modified_paint.setStrokeWidth(stroke_width);
1010 for (
int sweep = 160; sweep <= 360; sweep += 20) {
1011 builder.DrawArc(arc_bounds, 0, sweep,
false, modified_paint);
1012 builder.Translate(84, 0);
1015 builder.Translate(0, 44 + stroke_width);
1022 DisplayListBuilder builder;
1023 builder.Scale(GetContentScale().
x, GetContentScale().y);
1024 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1027 paint.setColor(DlColor::kBlue());
1029 RenderArcFarm(builder, paint,
1031 .use_center =
false,
1032 .full_circles =
false,
1035 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1039 DisplayListBuilder builder;
1040 builder.Scale(GetContentScale().
x, GetContentScale().y);
1041 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1044 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1046 RenderArcFarm(builder, paint,
1048 .use_center =
false,
1049 .full_circles =
false,
1052 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1056 DisplayListBuilder builder;
1057 builder.Scale(GetContentScale().
x, GetContentScale().y);
1058 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1061 paint.setColor(DlColor::kBlue());
1063 RenderArcFarm(builder, paint,
1066 .full_circles =
false,
1069 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1073 DisplayListBuilder builder;
1074 builder.Scale(GetContentScale().
x, GetContentScale().y);
1075 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1078 paint.setColor(DlColor::kBlue());
1080 RenderArcFarm(builder, paint,
1082 .use_center =
false,
1083 .full_circles =
false,
1084 .vertical_scale = 0.8f,
1087 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1091 DisplayListBuilder builder;
1092 builder.Scale(GetContentScale().
x, GetContentScale().y);
1093 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1096 paint.setColor(DlColor::kBlue());
1098 RenderArcFarm(builder, paint,
1101 .full_circles =
false,
1102 .vertical_scale = 0.8f,
1105 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1109 DisplayListBuilder builder;
1110 builder.Scale(GetContentScale().
x, GetContentScale().y);
1111 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1114 paint.setDrawStyle(DlDrawStyle::kStroke);
1115 paint.setStrokeWidth(6.0f);
1116 paint.setStrokeCap(DlStrokeCap::kButt);
1117 paint.setColor(DlColor::kBlue());
1119 RenderArcFarm(builder, paint,
1121 .use_center =
false,
1122 .full_circles =
false,
1125 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1129 DisplayListBuilder builder;
1130 builder.Scale(GetContentScale().
x, GetContentScale().y);
1131 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1134 paint.setDrawStyle(DlDrawStyle::kStroke);
1135 paint.setStrokeWidth(6.0f);
1136 paint.setStrokeCap(DlStrokeCap::kSquare);
1137 paint.setColor(DlColor::kBlue());
1139 RenderArcFarm(builder, paint,
1141 .use_center =
false,
1142 .full_circles =
false,
1145 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1149 DisplayListBuilder builder;
1150 builder.Scale(GetContentScale().
x, GetContentScale().y);
1151 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1154 paint.setDrawStyle(DlDrawStyle::kStroke);
1155 paint.setStrokeCap(DlStrokeCap::kSquare);
1156 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1158 RenderArcFarmForOverlappingCapsTest(builder, paint);
1160 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1164 DisplayListBuilder builder;
1165 builder.Scale(GetContentScale().
x, GetContentScale().y);
1166 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1169 paint.setDrawStyle(DlDrawStyle::kStroke);
1170 paint.setStrokeWidth(6.0f);
1171 paint.setStrokeCap(DlStrokeCap::kRound);
1172 paint.setColor(DlColor::kBlue());
1174 RenderArcFarm(builder, paint,
1176 .use_center =
false,
1177 .full_circles =
false,
1180 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1184 DisplayListBuilder builder;
1185 builder.Scale(GetContentScale().
x, GetContentScale().y);
1186 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1189 paint.setDrawStyle(DlDrawStyle::kStroke);
1190 paint.setStrokeCap(DlStrokeCap::kRound);
1191 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1193 RenderArcFarmForOverlappingCapsTest(builder, paint);
1195 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1199 DisplayListBuilder builder;
1200 builder.Scale(GetContentScale().
x, GetContentScale().y);
1201 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1204 paint.setDrawStyle(DlDrawStyle::kStroke);
1205 paint.setStrokeWidth(6.0f);
1206 paint.setStrokeJoin(DlStrokeJoin::kBevel);
1207 paint.setColor(DlColor::kBlue());
1209 RenderArcFarm(builder, paint,
1212 .full_circles =
false,
1213 .sweeps_over_360 =
true,
1216 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1220 DisplayListBuilder builder;
1221 builder.Scale(GetContentScale().
x, GetContentScale().y);
1222 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1225 paint.setDrawStyle(DlDrawStyle::kStroke);
1226 paint.setStrokeWidth(6.0f);
1227 paint.setStrokeJoin(DlStrokeJoin::kMiter);
1230 paint.setStrokeMiter(3.0f);
1231 paint.setColor(DlColor::kBlue());
1233 RenderArcFarm(builder, paint,
1236 .full_circles =
false,
1237 .sweeps_over_360 =
true,
1240 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1244 DisplayListBuilder builder;
1245 builder.Scale(GetContentScale().
x, GetContentScale().y);
1246 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1249 paint.setDrawStyle(DlDrawStyle::kStroke);
1250 paint.setStrokeWidth(6.0f);
1251 paint.setStrokeJoin(DlStrokeJoin::kRound);
1252 paint.setColor(DlColor::kBlue());
1254 RenderArcFarm(builder, paint,
1257 .full_circles =
false,
1258 .sweeps_over_360 =
true,
1261 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1265 DisplayListBuilder builder;
1266 builder.Scale(GetContentScale().
x, GetContentScale().y);
1267 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1270 paint.setDrawStyle(DlDrawStyle::kStroke);
1271 paint.setStrokeWidth(8.0f);
1272 paint.setStrokeCap(DlStrokeCap::kSquare);
1273 paint.setColor(DlColor::kRed());
1275 RenderArcFarm(builder, paint,
1277 .use_center =
false,
1278 .full_circles =
false,
1281 paint.setStrokeCap(DlStrokeCap::kButt);
1282 paint.setColor(DlColor::kBlue());
1284 RenderArcFarm(builder, paint,
1286 .use_center =
false,
1287 .full_circles =
false,
1290 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1294 DisplayListBuilder builder;
1295 builder.Scale(GetContentScale().
x, GetContentScale().y);
1296 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1299 paint.setDrawStyle(DlDrawStyle::kStroke);
1300 paint.setStrokeWidth(8.0f);
1301 paint.setStrokeCap(DlStrokeCap::kSquare);
1302 paint.setColor(DlColor::kRed());
1304 RenderArcFarm(builder, paint,
1306 .use_center =
false,
1307 .full_circles =
false,
1310 paint.setStrokeCap(DlStrokeCap::kRound);
1311 paint.setColor(DlColor::kGreen());
1313 RenderArcFarm(builder, paint,
1315 .use_center =
false,
1316 .full_circles =
false,
1319 paint.setStrokeCap(DlStrokeCap::kButt);
1320 paint.setColor(DlColor::kBlue());
1322 RenderArcFarm(builder, paint,
1324 .use_center =
false,
1325 .full_circles =
false,
1328 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1343 DisplayListBuilder builder;
1344 builder.Scale(GetContentScale().
x, GetContentScale().y);
1345 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1348 paint.setDrawStyle(DlDrawStyle::kStroke);
1349 paint.setStrokeWidth(6.0f);
1350 paint.setStrokeCap(DlStrokeCap::kButt);
1351 paint.setColor(DlColor::kBlue());
1354 RenderArcFarm(builder, paint,
1356 .use_center =
false,
1357 .full_circles =
true,
1360 paint.setColor(DlColor::kWhite());
1363 RenderArcFarm(builder, paint,
1365 .use_center =
false,
1366 .full_circles =
false,
1369 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1373 DisplayListBuilder builder;
1374 builder.Scale(GetContentScale().
x, GetContentScale().y);
1376 const int color_count = 3;
1377 DlColor colors[color_count] = {
1380 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
1383 paint.setColor(DlColor::kWhite());
1384 builder.DrawPaint(paint);
1387 for (
int i = 0; i < 4; i++) {
1388 for (
int j = 0; j < 4; j++) {
1389 paint.setColor(colors[(c_index++) % color_count]);
1390 builder.DrawRoundRect(
1391 DlRoundRect::MakeRectXY(
1392 DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1393 i * 5 + 10, j * 5 + 10),
1397 paint.setColor(colors[(c_index++) % color_count]);
1398 builder.DrawRoundRect(
1399 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40),
1401 paint.setColor(colors[(c_index++) % color_count]);
1402 builder.DrawRoundRect(
1403 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40),
1406 DlColor gradient_colors[7] = {
1407 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1408 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1409 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1410 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1411 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1412 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1413 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
1424 auto texture = CreateTextureForFixture(
"airplane.jpg",
1428 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1429 paint.setColorSource(DlColorSource::MakeRadial(
1430 DlPoint(550, 550), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1431 for (
int i = 1; i <= 10; i++) {
1433 builder.DrawRoundRect(
1434 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1435 550 + i * 20, 550 + j * 20),
1440 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1441 paint.setColorSource(DlColorSource::MakeRadial(
1442 DlPoint(200, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1443 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1444 builder.DrawRoundRect(
1445 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40),
1447 builder.DrawRoundRect(
1448 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40),
1451 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1452 DlMatrix local_matrix = DlMatrix::MakeTranslation({520, 20});
1453 paint.setColorSource(DlColorSource::MakeImage(
1454 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1455 DlImageSampling::kNearestNeighbor, &local_matrix));
1456 for (
int i = 1; i <= 10; i++) {
1458 builder.DrawRoundRect(
1459 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1460 720 + i * 20, 220 + j * 20),
1465 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1466 local_matrix = DlMatrix::MakeTranslation({800, 300});
1467 paint.setColorSource(DlColorSource::MakeImage(
1468 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1469 DlImageSampling::kNearestNeighbor, &local_matrix));
1470 builder.DrawRoundRect(
1471 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
1473 builder.DrawRoundRect(
1474 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40),
1477 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1481 DisplayListBuilder builder;
1482 builder.Scale(GetContentScale().
x, GetContentScale().y);
1484 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
1486 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
1489 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
1491 for (
int i = 0; i < 5; i++) {
1494 builder.DrawRect(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1495 radius, 60.0f - radius),
1499 paint.setColor(DlColor::kBlue());
1501 for (
int i = 0; i < 5; i++) {
1504 builder.DrawCircle(
DlPoint(
x + 25, y + 25), radius, paint);
1507 paint.setColor(DlColor::kGreen());
1509 for (
int i = 0; i < 5; i++) {
1512 builder.DrawOval(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1513 radius, 60.0f - radius),
1518 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
1520 for (
int i = 0; i < 5; i++) {
1523 builder.DrawRoundRect(
1524 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1530 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
1532 for (
int i = 0; i < 5; i++) {
1535 builder.DrawRoundRect(
1536 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1541 auto dl = builder.Build();
1542 ASSERT_TRUE(OpenPlaygroundHere(dl));
1546 DisplayListBuilder builder;
1548 builder.Scale(GetContentScale().
x, GetContentScale().y);
1551 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1552 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
1553 std::vector<Scalar> stops = {
1558 paint.setColorSource(DlColorSource::MakeLinear(
1567 builder.DrawPaint(paint);
1569 DlRect clip_rect = DlRect::MakeLTRB(50, 50, 400, 300);
1570 DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 100, 100);
1574 builder.ClipRoundRect(clip_rrect, DlClipOp::kIntersect);
1577 auto backdrop_filter = DlImageFilter::MakeColorFilter(
1578 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kExclusion));
1579 builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get());
1581 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1587 auto callback = [&]() -> sk_sp<DisplayList> {
1588 DisplayListBuilder builder;
1592 builder.Translate(300, 300);
1599 paint.setColor(DlColor::kGreen());
1600 builder.DrawPaint(paint);
1601 builder.ClipRect(DlRect::MakeLTRB(-180, -180, 180, 180),
1602 DlClipOp::kDifference);
1604 paint.setColor(DlColor::kBlack());
1605 builder.DrawPaint(paint);
1613 builder.ClipOval(DlRect::MakeLTRB(-200, -200, 200, 200));
1616 Matrix(1.0, 0.0, 0.0, 0.0,
1618 0.0, 0.0, 1.0, 0.003,
1619 0.0, 0.0, 0.0, 1.0) *
1628 -
DlPoint(image->GetSize().width, image->GetSize().height) * 0.5;
1629 builder.DrawImage(image, position, {});
1635 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
1636 builder.DrawCircle(
DlPoint(), 230, paint);
1640 return builder.Build();
1642 ASSERT_TRUE(OpenPlaygroundHere(callback));
1648 DisplayListBuilder builder;
1652 paint.setColor(DlColor::kWhite());
1653 builder.DrawPaint(paint);
1657 DlMatrix matrix = DlMatrix::MakeTranslation({50, 50});
1659 paint.setColorSource(DlColorSource::MakeImage(
1660 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1661 DlImageSampling::kNearestNeighbor, &matrix));
1663 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
1672 Matrix matrix(1, -1, 0, 0,
1676 paint.setColorSource(DlColorSource::MakeImage(
1677 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1678 DlImageSampling::kNearestNeighbor, &matrix));
1679 builder.DrawRect(DlRect::MakeLTRB(100, 0, 200, 100), paint);
1686 builder.Translate(100, 0);
1687 builder.Scale(100, 100);
1690 DlMatrix matrix = DlMatrix::MakeScale({0.005, 0.005, 1});
1691 paint.setColorSource(DlColorSource::MakeImage(
1692 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1693 DlImageSampling::kNearestNeighbor, &matrix));
1695 builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
1702 builder.Translate(150, 150);
1706 DlMatrix::MakePerspective(
Radians{0.5},
ISize{200, 200}, 0.05, 1);
1707 paint.setColorSource(DlColorSource::MakeImage(
1708 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1709 DlImageSampling::kNearestNeighbor, &matrix));
1711 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
1715 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1719 DisplayListBuilder builder;
1724 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1725 paint.setBlendMode(DlBlendMode::kSrc);
1727 DlRect bounds = DlRect::MakeLTRB(0, 0, 200, 200);
1728 builder.SaveLayer(bounds, &paint);
1730 paint.setColor(DlColor::kTransparent());
1731 paint.setBlendMode(DlBlendMode::kSrc);
1732 builder.DrawPaint(paint);
1735 paint.setColor(DlColor::kBlue());
1736 paint.setBlendMode(DlBlendMode::kDstOver);
1737 builder.SaveLayer(std::nullopt, &paint);
1743 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1748 DisplayListBuilder builder;
1749 builder.Scale(GetContentScale().
x, GetContentScale().y);
1750 builder.Translate(100, 100);
1754 DlMatrix translate = DlMatrix::MakeTranslation({300, 0});
1755 paint.setImageFilter(
1756 DlImageFilter::MakeMatrix(translate, DlImageSampling::kLinear));
1757 builder.SaveLayer(std::nullopt, &paint);
1759 DlPaint circle_paint;
1760 circle_paint.setColor(DlColor::kGreen());
1761 builder.DrawCircle(
DlPoint(-300, 0), 100, circle_paint);
1764 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1769 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
1770 DisplayListBuilder builder;
1771 builder.Scale(GetContentScale().
x, GetContentScale().y);
1772 builder.Translate(100, 100);
1777 paint.setImageFilter(DlImageFilter::MakeMatrix(
1778 DlMatrix::MakeTranslation({300, 0}) * DlMatrix::MakeScale({2, 2, 1}),
1779 DlImageSampling::kNearestNeighbor));
1780 builder.SaveLayer(std::nullopt, &paint);
1782 DlPaint circle_paint;
1783 circle_paint.setColor(DlColor::kGreen());
1784 builder.DrawCircle(
DlPoint(-150, 0), 50, circle_paint);
1787 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1792 SetWindowSize({400, 400});
1793 DisplayListBuilder builder;
1795 builder.Scale(GetContentScale().
x, GetContentScale().y);
1798 paint.setColor(DlColor::kRed());
1799 builder.DrawRect(DlRect::MakeLTRB(200, 200, 300, 300), paint);
1801 paint.setImageFilter(DlImageFilter::MakeMatrix(DlMatrix::MakeScale({2, 2, 1}),
1802 DlImageSampling::kLinear));
1803 builder.SaveLayer(std::nullopt, &paint);
1806 paint.setColor(DlColor::kGreen());
1807 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
1810 paint.setColor(DlColor::kRed());
1811 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 800), paint);
1814 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1818 DisplayListBuilder builder;
1819 builder.Scale(GetContentScale().
x, GetContentScale().y);
1822 paint.setColor(DlColor::kRed());
1823 builder.DrawPaint(paint);
1824 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1825 paint.setColor(DlColor::kBlue());
1826 builder.SaveLayer(std::nullopt, &paint);
1829 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1833 DisplayListBuilder builder;
1834 builder.Scale(GetContentScale().
x, GetContentScale().y);
1836 builder.DrawImage(image,
DlPoint(10, 10), {});
1837 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1840 paint.setBlendMode(DlBlendMode::kClear);
1841 builder.SaveLayer(std::nullopt, &paint);
1844 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1848 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
1849 DisplayListBuilder builder;
1852 red.setColor(DlColor::kRed());
1855 green.setColor(DlColor::kGreen());
1858 blue.setColor(DlColor::kBlue());
1861 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1863 DlRect huge_bounds = DlRect::MakeXYWH(0, 0, 100000, 100000);
1864 builder.SaveLayer(huge_bounds, &save);
1866 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1867 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), green);
1868 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), blue);
1872 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1877 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1883 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1890 DisplayListBuilder builder;
1897 builder.Translate(100, 200);
1898 builder.Scale(0.5, 0.5);
1899 builder.DrawImage(image,
DlPoint(100.0, 100.0),
1900 DlImageSampling::kNearestNeighbor);
1907 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1909 builder.SaveLayer(std::nullopt, &alpha);
1912 paint.setColor(DlColor::kRed());
1913 builder.DrawRect(DlRect::MakeXYWH(000, 000, 100, 100), paint);
1914 paint.setColor(DlColor::kGreen());
1915 builder.DrawRect(DlRect::MakeXYWH(020, 020, 100, 100), paint);
1916 paint.setColor(DlColor::kBlue());
1917 builder.DrawRect(DlRect::MakeXYWH(040, 040, 100, 100), paint);
1922 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1926 DisplayListBuilder builder;
1929 paint.setColor(DlColor::kRed());
1930 builder.DrawCircle(
DlPoint(250, 250), 125, paint);
1932 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1936 DisplayListBuilder builder;
1939 red.setColor(DlColor::kRed());
1941 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1943 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1947 DisplayListBuilder builder;
1950 save.setColor(DlColor::kBlack());
1952 DlRect save_bounds = DlRect::MakeXYWH(0, 0, 50, 50);
1953 builder.SaveLayer(save_bounds, &save);
1956 paint.setColor(DlColor::kRed());
1957 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
1958 paint.setColor(DlColor::kGreen());
1959 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), paint);
1960 paint.setColor(DlColor::kBlue());
1961 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), paint);
1965 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1969 DisplayListBuilder builder;
1970 builder.Scale(GetContentScale().
x, GetContentScale().y);
1973 const int color_count = 3;
1974 DlColor colors[color_count] = {
1977 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
1980 paint.setColor(DlColor::kWhite());
1981 builder.DrawPaint(paint);
1984 const DlPaint& paint) {
1985 builder.DrawPath(DlPath::MakeRoundRectXY(rect,
x, y), paint);
1989 for (
int i = 0; i < 4; i++) {
1990 for (
int j = 0; j < 4; j++) {
1991 paint.setColor(colors[(c_index++) % color_count]);
1992 draw_rrect_as_path(DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1993 i * 5 + 10, j * 5 + 10, paint);
1996 paint.setColor(colors[(c_index++) % color_count]);
1997 draw_rrect_as_path(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
1998 paint.setColor(colors[(c_index++) % color_count]);
1999 draw_rrect_as_path(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
2001 std::vector<DlColor> gradient_colors = {
2002 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
2003 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
2004 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
2005 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
2006 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
2007 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
2008 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
2009 std::vector<Scalar> stops = {
2019 CreateTextureForFixture(
"airplane.jpg",
2022 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
2023 paint.setColorSource(DlColorSource::MakeRadial(
2026 gradient_colors.size(),
2027 gradient_colors.data(),
2029 DlTileMode::kMirror));
2030 for (
int i = 1; i <= 10; i++) {
2032 draw_rrect_as_path(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
2033 550 + i * 20, 550 + j * 20),
2034 i * 10, j * 10, paint);
2036 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
2037 paint.setColorSource(DlColorSource::MakeRadial(
2040 gradient_colors.size(),
2041 gradient_colors.data(),
2043 DlTileMode::kMirror));
2044 draw_rrect_as_path(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
2045 draw_rrect_as_path(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
2047 auto matrix = DlMatrix::MakeTranslation({520, 20});
2048 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
2049 paint.setColorSource(DlColorSource::MakeImage(
2050 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
2051 DlImageSampling::kMipmapLinear, &matrix));
2052 for (
int i = 1; i <= 10; i++) {
2054 draw_rrect_as_path(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
2055 720 + i * 20, 220 + j * 20),
2056 i * 10, j * 10, paint);
2058 matrix = DlMatrix::MakeTranslation({800, 300});
2059 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
2060 paint.setColorSource(DlColorSource::MakeImage(
2061 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
2062 DlImageSampling::kMipmapLinear, &matrix));
2064 draw_rrect_as_path(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
2065 draw_rrect_as_path(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
2067 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2071 auto callback = [&]() -> sk_sp<DisplayList> {
2072 DisplayListBuilder builder;
2073 builder.Scale(GetContentScale().x, GetContentScale().y);
2076 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
2078 auto current =
Point{25, 25};
2079 const auto offset =
Point{25, 25};
2080 const auto size =
Size(100, 100);
2085 DlRect bounds = DlRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
2087 DlPaint stroke_paint;
2088 stroke_paint.setColor(DlColor::kYellow());
2089 stroke_paint.setStrokeWidth(5);
2090 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
2091 builder.DrawRect(bounds, stroke_paint);
2093 builder.SaveLayer(bounds, &alpha);
2096 paint.setColor(DlColor::kRed());
2098 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2100 paint.setColor(DlColor::kGreen());
2103 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2105 paint.setColor(DlColor::kBlue());
2108 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2112 return builder.Build();
2115 ASSERT_TRUE(OpenPlaygroundHere(callback));
2120 DisplayListBuilder builder;
2123 paint.setColor(DlColor::kBlack());
2124 DlRect rect = DlRect::MakeXYWH(25, 25, 25, 25);
2125 builder.DrawRect(rect, paint);
2127 builder.Translate(10, 10);
2130 builder.SaveLayer(std::nullopt, &save_paint);
2132 paint.setColor(DlColor::kGreen());
2133 builder.DrawRect(rect, paint);
2137 builder.Translate(10, 10);
2138 paint.setColor(DlColor::kRed());
2139 builder.DrawRect(rect, paint);
2141 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2145 DisplayListBuilder builder;
2147 DlRect rect = DlRect::MakeXYWH(0, 0, 1000, 1000);
2152 DlRect bounds = DlRect::MakeXYWH(25, 25, 25, 25);
2153 builder.SaveLayer(bounds, &save_paint);
2154 paint.setColor(DlColor::kBlack());
2155 builder.DrawRect(rect, paint);
2161 DlRect bounds = DlRect::MakeXYWH(35, 35, 25, 25);
2162 builder.SaveLayer(bounds, &save_paint);
2163 paint.setColor(DlColor::kGreen());
2164 builder.DrawRect(rect, paint);
2170 DlRect bounds = DlRect::MakeXYWH(45, 45, 25, 25);
2171 builder.SaveLayer(bounds, &save_paint);
2172 paint.setColor(DlColor::kRed());
2173 builder.DrawRect(rect, paint);
2177 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2181 DisplayListBuilder builder;
2184 paint.setColor(DlColor::kWhite());
2185 builder.DrawPaint(paint);
2191 builder.ClipPath(path);
2193 DlRect bounds = DlRect::MakeXYWH(50, 50, 100, 100);
2195 builder.SaveLayer(bounds, &save_paint);
2198 paint.setColor(DlColor::kWhite());
2199 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2202 paint.setColor(DlColor::kGreen());
2203 paint.setBlendMode(DlBlendMode::kHardLight);
2204 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2207 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2211 DisplayListBuilder builder;
2213 builder.Scale(GetContentScale().
x, GetContentScale().y);
2214 builder.Translate(100, 100);
2217 auto draw_image_layer = [&builder, &texture](
const DlPaint& paint) {
2218 builder.SaveLayer(std::nullopt, &paint);
2219 builder.DrawImage(texture,
DlPoint(), DlImageSampling::kLinear);
2223 DlPaint effect_paint;
2224 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
2225 draw_image_layer(effect_paint);
2227 builder.Translate(300, 300);
2228 builder.Scale(3, 3);
2229 draw_image_layer(effect_paint);
2231 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2235 DisplayListBuilder builder;
2237 builder.Scale(GetContentScale().
x, GetContentScale().y);
2239 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
2242 save_paint.setColor(DlColor::kWhite());
2243 builder.DrawPaint(save_paint);
2245 paint.setColor(DlColor::kBlue());
2246 for (
int i = 0; i < 5; i++) {
2248 Scalar y_radius = i * 15;
2249 for (
int j = 0; j < 5; j++) {
2251 Scalar x_radius = j * 15;
2252 builder.DrawRoundRect(
2253 DlRoundRect::MakeRectXY(
2254 DlRect::MakeXYWH(
x + 50, y + 50, 100.0f, 100.0f),
2255 x_radius, y_radius),
2260 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2264 DisplayListBuilder builder;
2268 builder.SaveLayer(std::nullopt, &paint);
2270 builder.Translate(100, 100);
2271 paint.setColor(DlColor::kBlue());
2272 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2273 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
2275 paint.setColor(DlColor::kGreen());
2276 paint.setBlendMode(DlBlendMode::kSrcOver);
2277 paint.setImageFilter(DlImageFilter::MakeColorFilter(
2278 DlColorFilter::MakeBlend(DlColor::kWhite(), DlBlendMode::kDst)));
2279 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2283 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2291 GTEST_SKIP() <<
"Swiftshader is running out of memory on this example.";
2293 DisplayListBuilder builder(DlRect::MakeSize(DlSize(1000, 1000)));
2295 auto filter = DlImageFilter::MakeMatrix(
2296 DlMatrix::MakeScale({0.001, 0.001, 1}), DlImageSampling::kLinear);
2299 paint.setImageFilter(filter);
2300 builder.SaveLayer(std::nullopt, &paint);
2303 paint.setColor(DlColor::kRed());
2304 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100000, 100000), paint);
2308 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2315 auto callback = [&]() -> sk_sp<DisplayList> {
2317 ImGuiWindowFlags_AlwaysAutoResize)) {
2318 ImGui::SliderFloat(
"width", &width, 0, 200);
2319 ImGui::SliderFloat(
"height", &height, 0, 200);
2320 ImGui::SliderFloat(
"corner", &corner, 0, 1);
2324 DisplayListBuilder builder;
2325 builder.Scale(GetContentScale().
x, GetContentScale().y);
2327 DlPaint background_paint;
2328 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
2329 builder.DrawPaint(background_paint);
2331 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
2332 std::vector<Scalar> stops = {0.0, 1.0};
2335 auto gradient = DlColorSource::MakeLinear(
DlPoint(0, 0),
DlPoint(200, 200),
2336 2, colors.data(), stops.data(),
2337 DlTileMode::kClamp);
2338 paint.setColorSource(gradient);
2339 paint.setColor(DlColor::kWhite());
2340 paint.setDrawStyle(DlDrawStyle::kStroke);
2341 paint.setStrokeWidth(20);
2344 builder.Translate(100, 100);
2346 Scalar corner_x = ((1 - corner) * 50) + 50;
2347 Scalar corner_y = corner * 50 + 50;
2349 DlRect::MakeXYWH(0, 0, width, height), corner_x, corner_y);
2350 builder.DrawRoundRect(rrect, paint);
2352 return builder.Build();
2354 ASSERT_TRUE(OpenPlaygroundHere(callback));
2358 DisplayListBuilder builder;
2360 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
2363 builder.ClipRect(DlRect::MakeLTRB(100, 100, 800, 800));
2367 builder.ClipRect(DlRect::MakeLTRB(600, 600, 800, 800));
2368 builder.DrawPaint(DlPaint().setColor(DlColor::kRed()));
2369 builder.DrawPaint(DlPaint().setColor(DlColor::kBlue().withAlphaF(0.5)));
2370 builder.ClipRect(DlRect::MakeLTRB(700, 700, 750, 800));
2371 builder.DrawPaint(DlPaint().setColor(DlColor::kRed().withAlphaF(0.5)));
2375 auto image_filter = DlImageFilter::MakeBlur(10, 10, DlTileMode::kDecal);
2376 builder.SaveLayer(std::nullopt,
nullptr, image_filter.get());
2379 builder.DrawCircle(
DlPoint(100, 100), 100,
2380 DlPaint().setColor(DlColor::kAqua()));
2382 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2386 int perspective = 58;
2387 bool use_clip =
true;
2388 bool diff_clip =
false;
2390 auto callback = [&]() -> sk_sp<DisplayList> {
2392 ImGuiWindowFlags_AlwaysAutoResize)) {
2393 ImGui::SliderInt(
"perspective%", &perspective, 0, 100);
2394 ImGui::Checkbox(
"use clip", &use_clip);
2396 ImGui::Checkbox(
"diff clip", &diff_clip);
2398 ImGui::SetWindowPos(
"Controls", ImVec2(500, 100));
2402 DisplayListBuilder builder;
2404 Scalar val = perspective * -0.00005f;
2405 builder.TransformFullPerspective(
2407 1.0f, 0.0f, 0.0f, 400.0f,
2408 0.0f, 1.0f, 0.0f, 400.0f,
2409 0.0f, 0.0f, 1.0f, 0.0f,
2410 0.0f, val, 0.0f, 2.2f
2415 Rect clip = DlRect::MakeLTRB(0, 0, 400, 800);
2416 DlClipOp clip_op = DlClipOp::kIntersect;
2419 clip_op = DlClipOp::kDifference;
2421 builder.ClipRect(clip, clip_op);
2425 paint.setColor(DlColor::kBlue());
2426 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 800), paint);
2428 builder.DrawColor(DlColor::kWhite().withAlphaF(0.5f),
2429 DlBlendMode::kSrcOver);
2431 return builder.Build();
2433 ASSERT_TRUE(OpenPlaygroundHere(callback));
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 TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)