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"
15 #include "flutter/display_list/dl_blend_mode.h"
16 #include "flutter/display_list/dl_builder.h"
17 #include "flutter/display_list/dl_color.h"
18 #include "flutter/display_list/dl_paint.h"
19 #include "flutter/display_list/geometry/dl_path_builder.h"
22 #include "flutter/testing/display_list_testing.h"
23 #include "flutter/testing/testing.h"
33 DisplayListBuilder builder;
35 paint.setColor(DlColor::kBlue());
36 builder.DrawPath(DlPath::MakeRectXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
37 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
41 DisplayListBuilder builder;
43 paint.setColor(DlColor::kBlue());
44 builder.DrawRect(DlRect::MakeXYWH(100.f, 100.f, 100.f, 100.f), paint);
45 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
50 std::function<void(DisplayListBuilder&,
const DlRect&,
const DlPaint&)>;
52 sk_sp<DisplayList> MakeWideStrokedRects(
Point scale,
53 const DrawRectProc& draw_rect) {
54 DisplayListBuilder builder;
55 builder.Scale(scale.
x, scale.
y);
56 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
59 paint.setColor(DlColor::kBlue().withAlphaF(0.5));
60 paint.setDrawStyle(DlDrawStyle::kStroke);
61 paint.setStrokeWidth(30.0f);
67 paint.setStrokeJoin(DlStrokeJoin::kBevel);
68 draw_rect(builder, DlRect::MakeXYWH(100.0f, 100.0f, 100.0f, 100.0f), paint);
69 draw_rect(builder, DlRect::MakeXYWH(250.0f, 100.0f, 10.0f, 100.0f), paint);
70 draw_rect(builder, DlRect::MakeXYWH(100.0f, 250.0f, 100.0f, 10.0f), paint);
72 paint.setStrokeJoin(DlStrokeJoin::kRound);
73 draw_rect(builder, DlRect::MakeXYWH(350.0f, 100.0f, 100.0f, 100.0f), paint);
74 draw_rect(builder, DlRect::MakeXYWH(500.0f, 100.0f, 10.0f, 100.0f), paint);
75 draw_rect(builder, DlRect::MakeXYWH(350.0f, 250.0f, 100.0f, 10.0f), paint);
77 paint.setStrokeJoin(DlStrokeJoin::kMiter);
78 draw_rect(builder, DlRect::MakeXYWH(600.0f, 100.0f, 100.0f, 100.0f), paint);
79 draw_rect(builder, DlRect::MakeXYWH(750.0f, 100.0f, 10.0f, 100.0f), paint);
80 draw_rect(builder, DlRect::MakeXYWH(600.0f, 250.0f, 100.0f, 10.0f), paint);
84 paint.setStrokeWidth(110.0f);
86 paint.setStrokeJoin(DlStrokeJoin::kBevel);
87 draw_rect(builder, DlRect::MakeXYWH(100.0f, 400.0f, 100.0f, 100.0f), paint);
89 paint.setStrokeJoin(DlStrokeJoin::kRound);
90 draw_rect(builder, DlRect::MakeXYWH(350.0f, 400.0f, 100.0f, 100.0f), paint);
92 paint.setStrokeJoin(DlStrokeJoin::kMiter);
93 draw_rect(builder, DlRect::MakeXYWH(600.0f, 400.0f, 100.0f, 100.0f), paint);
95 return builder.Build();
100 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
101 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
102 const DlPaint& paint) {
104 builder.DrawRect(rect, paint);
109 ASSERT_TRUE(OpenPlaygroundHere(MakeWideStrokedRects(
110 GetContentScale(), [](DisplayListBuilder& builder,
const DlRect& rect,
111 const DlPaint& paint) {
113 builder.DrawPath(DlPath::MakeRect(rect), paint);
118 DisplayListBuilder builder;
120 paint.setColor(DlColor::kRed());
122 builder.DrawImage(image,
DlPoint(100.0, 100.0),
123 DlImageSampling::kNearestNeighbor, &paint);
124 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
128 DisplayListBuilder builder;
130 paint.setColor(DlColor::kRed());
131 paint.setColorFilter(
132 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
133 paint.setInvertColors(
true);
136 builder.DrawImage(image,
DlPoint(100.0, 100.0),
137 DlImageSampling::kNearestNeighbor, &paint);
138 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
142 DisplayListBuilder builder;
144 paint.setColor(DlColor::kRed());
145 paint.setColorFilter(
146 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
147 paint.setInvertColors(
true);
149 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
150 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
154 DisplayListBuilder builder;
156 paint.setColor(DlColor::kRed());
157 paint.setColorFilter(
158 DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kSrcOver));
159 paint.setInvertColors(
true);
161 builder.DrawPaint(paint);
162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
166 bool GenerateMipmap(
const std::shared_ptr<Context>&
context,
167 std::shared_ptr<Texture> texture,
168 std::string_view label) {
169 auto buffer =
context->CreateCommandBuffer();
173 auto pass = buffer->CreateBlitPass();
177 pass->GenerateMipmap(std::move(texture), label);
179 pass->EncodeCommands();
180 return context->GetCommandQueue()->Submit({buffer}).ok();
183 void CanRenderTiledTexture(
AiksTest* aiks_test,
184 DlTileMode tile_mode,
185 Matrix local_matrix = {}) {
186 auto context = aiks_test->GetContext();
188 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
190 GenerateMipmap(
context, texture,
"table_mountain_nx");
192 auto color_source = DlColorSource::MakeImage(
193 image, tile_mode, tile_mode, DlImageSampling::kNearestNeighbor,
196 DisplayListBuilder builder;
198 paint.setColor(DlColor::kWhite());
199 paint.setColorSource(color_source);
201 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
202 builder.Translate(100.0f, 100.0f);
203 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
206 constexpr
auto stroke_width = 64;
207 paint.setDrawStyle(DlDrawStyle::kStroke);
208 paint.setStrokeWidth(stroke_width);
209 if (tile_mode == DlTileMode::kDecal) {
210 builder.DrawRect(DlRect::MakeXYWH(stroke_width, stroke_width, 600, 600),
213 builder.DrawRect(DlRect::MakeXYWH(0, 0, 600, 600), paint);
218 DlPathBuilder path_builder;
219 path_builder.AddCircle(
DlPoint(150, 150), 150);
220 path_builder.AddRoundRect(
222 DlPath path = path_builder.TakePath();
225 EXPECT_FALSE(path.IsRect(
nullptr));
226 EXPECT_FALSE(path.IsOval(
nullptr));
227 EXPECT_FALSE(path.IsRoundRect(
nullptr));
230 EXPECT_FALSE(path.IsConvex());
232 paint.setDrawStyle(DlDrawStyle::kFill);
233 builder.DrawPath(path, paint);
240 constexpr
float kConicWeight = 0.707106781f;
241 const DlPath path = DlPathBuilder()
243 .ConicCurveTo({300, 300}, {300, 450}, kConicWeight)
244 .ConicCurveTo({300, 600}, {150, 600}, kConicWeight)
245 .ConicCurveTo({0, 600}, {0, 450}, kConicWeight)
246 .ConicCurveTo({0, 300}, {150, 300}, kConicWeight)
251 EXPECT_FALSE(path.IsRect(
nullptr));
252 EXPECT_FALSE(path.IsOval(
nullptr));
253 EXPECT_FALSE(path.IsRoundRect(
nullptr));
256 EXPECT_TRUE(path.IsConvex());
258 paint.setDrawStyle(DlDrawStyle::kFill);
259 builder.DrawPath(path, paint);
262 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
267 CanRenderTiledTexture(
this, DlTileMode::kClamp);
271 CanRenderTiledTexture(
this, DlTileMode::kRepeat);
275 CanRenderTiledTexture(
this, DlTileMode::kMirror);
279 CanRenderTiledTexture(
this, DlTileMode::kDecal);
283 CanRenderTiledTexture(
this, DlTileMode::kClamp,
288 DisplayListBuilder builder;
291 DlISize image_half_size =
292 DlISize(image->GetSize().width * 0.5f, image->GetSize().height * 0.5f);
295 auto source_rect = DlRect::MakeSize(image_half_size);
297 source_rect.Shift(image_half_size.width, image_half_size.height);
299 builder.DrawImageRect(image, source_rect,
300 DlRect::MakeXYWH(100, 100, 600, 600),
301 DlImageSampling::kNearestNeighbor);
302 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
306 DisplayListBuilder builder;
310 auto source_rect = DlRect::MakeXYWH(
311 image->GetSize().width * 0.25f, image->GetSize().height * 0.4f,
312 image->GetSize().width, image->GetSize().height);
314 auto dest_rect = DlRect::MakeXYWH(100, 100, 600, 600);
317 paint.setColor(DlColor::kMidGrey());
318 builder.DrawRect(dest_rect, paint);
320 builder.DrawImageRect(image, source_rect, dest_rect,
321 DlImageSampling::kNearestNeighbor);
322 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
326 DisplayListBuilder builder;
327 builder.Scale(GetContentScale().
x, GetContentScale().y);
330 paint.setColor(DlColor::kWhite());
331 builder.DrawPaint(paint);
333 auto draw = [&builder](
const DlPaint& paint,
Scalar x,
Scalar y) {
335 builder.Translate(
x, y);
338 builder.ClipRect(DlRect::MakeLTRB(50, 50, 150, 150));
339 builder.DrawPaint(paint);
344 builder.ClipOval(DlRect::MakeLTRB(200, 50, 300, 150));
345 builder.DrawPaint(paint);
350 builder.ClipRoundRect(
351 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(50, 200, 150, 300), 20, 20));
352 builder.DrawPaint(paint);
357 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
358 DlRect::MakeLTRB(200, 230, 300, 270), 20, 20));
359 builder.DrawPaint(paint);
364 builder.ClipRoundRect(DlRoundRect::MakeRectXY(
365 DlRect::MakeLTRB(230, 200, 270, 300), 20, 20));
366 builder.DrawPaint(paint);
372 paint.setColor(DlColor::kBlue());
375 DlColor gradient_colors[7] = {
376 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
377 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
378 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
379 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
380 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
381 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
382 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
393 auto texture = CreateTextureForFixture(
"airplane.jpg",
397 paint.setColorSource(DlColorSource::MakeRadial(
398 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
401 paint.setColorSource(
402 DlColorSource::MakeImage(image, DlTileMode::kRepeat, DlTileMode::kRepeat,
403 DlImageSampling::kNearestNeighbor));
406 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
410 DisplayListBuilder builder;
413 red.setColor(DlColor::kRed());
416 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
418 builder.SaveLayer(std::nullopt, &alpha);
420 builder.DrawCircle(
DlPoint(125, 125), 125, red);
424 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
428 DisplayListBuilder builder;
431 DlColor colors[2] = {
432 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
433 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
440 paint.setColorSource(DlColorSource::MakeLinear(
450 builder.Translate(100, 100);
451 builder.DrawRect(DlRect::MakeXYWH(0, 0, 200, 200), paint);
455 builder.Translate(100, 400);
456 builder.DrawCircle(
DlPoint(100, 100), 100, paint);
458 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
462 DisplayListBuilder builder;
464 paint.setColor(DlColor::kRed());
468 .top_right = DlSize(25, 50),
469 .bottom_left = DlSize(25, 50),
470 .bottom_right = DlSize(50, 25),
473 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
475 builder.DrawRoundRect(rrect, paint);
477 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
483 Scalar bottom_left = 60.f;
484 Scalar bottom_right = 80.f;
485 auto callback = [&]() -> sk_sp<DisplayList> {
487 ImGuiWindowFlags_AlwaysAutoResize)) {
488 ImGui::SliderFloat(
"top_left", &top_left, 0, 250);
489 ImGui::SliderFloat(
"top_right", &top_right, 0, 250);
490 ImGui::SliderFloat(
"bottom_left", &bottom_left, 0, 250);
491 ImGui::SliderFloat(
"bottom_right", &bottom_right, 0, 250);
495 DisplayListBuilder builder;
497 paint.setColor(DlColor::kRed());
500 .
top_left = DlSize(top_left, top_left),
501 .top_right = DlSize(top_right, top_right),
502 .bottom_left = DlSize(bottom_left, bottom_left),
503 .bottom_right = DlSize(bottom_right, bottom_right),
506 DlRoundRect::MakeRectRadii(DlRect::MakeXYWH(100, 100, 500, 500), radii);
508 builder.DrawRoundRect(rrect, paint);
509 return builder.Build();
512 ASSERT_TRUE(OpenPlaygroundHere(callback));
516 auto medium_turquoise =
517 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
519 DisplayListBuilder builder;
520 builder.Scale(0.2, 0.2);
521 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
522 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
526 auto medium_turquoise =
527 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
529 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
531 DisplayListBuilder builder;
532 builder.Scale(0.2, 0.2);
533 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
534 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
535 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
539 DisplayListBuilder builder;
540 builder.Scale(GetContentScale().
x, GetContentScale().y);
543 paint.setColor(DlColor::kPurple());
544 paint.setDrawStyle(DlDrawStyle::kStroke);
545 paint.setStrokeWidth(20.0f);
547 DlPaint thin_paint = paint;
548 thin_paint.setColor(DlColor::kYellow());
549 thin_paint.setStrokeWidth(0.0f);
551 DlRect rect = DlRect::MakeLTRB(10, 10, 90, 90);
552 DlRect thin_tall_rect = DlRect::MakeLTRB(120, 10, 120, 90);
553 DlRect thin_wide_rect = DlRect::MakeLTRB(10, 120, 90, 120);
554 DlRect empty_rect = DlRect::MakeLTRB(120, 120, 120, 120);
584 paint.setStrokeJoin(DlStrokeJoin::kBevel);
585 builder.DrawRect(rect.Shift({100, 100}), paint);
586 builder.DrawRect(rect.Shift({100, 100}), thin_paint);
587 builder.DrawRect(thin_tall_rect.Shift({100, 100}), paint);
588 builder.DrawRect(thin_tall_rect.Shift({100, 100}), thin_paint);
589 builder.DrawRect(thin_wide_rect.Shift({100, 100}), paint);
590 builder.DrawRect(thin_wide_rect.Shift({100, 100}), thin_paint);
591 builder.DrawRect(empty_rect.Shift({100, 100}), paint);
592 builder.DrawRect(empty_rect.Shift({100, 100}), thin_paint);
595 paint.setStrokeJoin(DlStrokeJoin::kRound);
596 builder.DrawRect(rect.Shift({100, 300}), paint);
597 builder.DrawRect(rect.Shift({100, 300}), thin_paint);
598 builder.DrawRect(thin_tall_rect.Shift({100, 300}), paint);
599 builder.DrawRect(thin_tall_rect.Shift({100, 300}), thin_paint);
600 builder.DrawRect(thin_wide_rect.Shift({100, 300}), paint);
601 builder.DrawRect(thin_wide_rect.Shift({100, 300}), thin_paint);
602 builder.DrawRect(empty_rect.Shift({100, 300}), paint);
603 builder.DrawRect(empty_rect.Shift({100, 300}), thin_paint);
606 paint.setStrokeJoin(DlStrokeJoin::kMiter);
608 builder.DrawRect(rect.Shift({100, 500}), paint);
609 builder.DrawRect(rect.Shift({100, 500}), thin_paint);
610 builder.DrawRect(thin_tall_rect.Shift({100, 500}), paint);
611 builder.DrawRect(thin_tall_rect.Shift({100, 500}), thin_paint);
612 builder.DrawRect(thin_wide_rect.Shift({100, 500}), paint);
613 builder.DrawRect(thin_wide_rect.Shift({100, 500}), thin_paint);
614 builder.DrawRect(empty_rect.Shift({100, 500}), paint);
615 builder.DrawRect(empty_rect.Shift({100, 500}), thin_paint);
618 paint.setStrokeJoin(DlStrokeJoin::kMiter);
620 builder.DrawRect(rect.Shift({300, 500}), paint);
621 builder.DrawRect(rect.Shift({300, 500}), thin_paint);
622 builder.DrawRect(thin_tall_rect.Shift({300, 500}), paint);
623 builder.DrawRect(thin_tall_rect.Shift({300, 500}), thin_paint);
624 builder.DrawRect(thin_wide_rect.Shift({300, 500}), paint);
625 builder.DrawRect(thin_wide_rect.Shift({300, 500}), thin_paint);
626 builder.DrawRect(empty_rect.Shift({300, 500}), paint);
627 builder.DrawRect(empty_rect.Shift({300, 500}), thin_paint);
629 paint.setStrokeWidth(120.0f);
630 paint.setColor(DlColor::kBlue());
631 rect = rect.Expand(-20);
634 paint.setStrokeJoin(DlStrokeJoin::kBevel);
635 builder.DrawRect(rect.Shift({500, 100}), paint);
636 builder.DrawRect(rect.Shift({500, 100}), thin_paint);
639 paint.setStrokeJoin(DlStrokeJoin::kRound);
640 builder.DrawRect(rect.Shift({500, 300}), paint);
641 builder.DrawRect(rect.Shift({500, 300}), thin_paint);
644 paint.setStrokeJoin(DlStrokeJoin::kMiter);
646 builder.DrawRect(rect.Shift({500, 500}), paint);
647 builder.DrawRect(rect.Shift({500, 500}), thin_paint);
650 paint.setStrokeJoin(DlStrokeJoin::kMiter);
652 builder.DrawRect(rect.Shift({700, 500}), paint);
653 builder.DrawRect(rect.Shift({700, 500}), thin_paint);
655 DlPaint round_mock_paint;
656 round_mock_paint.setColor(DlColor::kGreen());
657 round_mock_paint.setDrawStyle(DlDrawStyle::kFill);
662 for (
int i = 0; i < 15; i++) {
663 paint.setStrokeWidth(i);
664 paint.setColor(DlColor::kOrange());
665 paint.setStrokeJoin(DlStrokeJoin::kRound);
666 builder.DrawRect(DlRect::MakeXYWH(
x, y, 30, 30), paint);
670 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
674 DisplayListBuilder builder;
675 builder.Scale(GetContentScale().
x, GetContentScale().y);
677 const int color_count = 3;
678 DlColor colors[color_count] = {
681 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
684 paint.setColor(DlColor::kWhite());
685 builder.DrawPaint(paint);
690 paint.setColor(colors[(c_index++) % color_count]);
691 builder.DrawCircle(
DlPoint(10, 10), radius, paint);
699 DlColor gradient_colors[7] = {
700 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
701 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
702 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
703 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
704 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
705 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
706 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
717 auto texture = CreateTextureForFixture(
"airplane.jpg",
721 paint.setColorSource(DlColorSource::MakeRadial(
722 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
723 builder.DrawCircle(
DlPoint(500, 600), 100, paint);
725 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
726 paint.setColorSource(DlColorSource::MakeImage(
727 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
728 DlImageSampling::kNearestNeighbor, &local_matrix));
729 builder.DrawCircle(
DlPoint(800, 300), 100, paint);
731 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
735 auto callback = [&]() {
736 static float stroked_radius = 100.0;
737 static float stroke_width = 0.0;
738 static float stroke_width_fine = 2.0;
739 static float stroked_alpha = 255.0;
740 static float stroked_scale[2] = {1.0, 1.0};
743 ImGuiWindowFlags_AlwaysAutoResize)) {
744 ImGui::SliderFloat(
"Stroked Radius", &stroked_radius, 0, 500);
745 ImGui::SliderFloat(
"Stroked Width", &stroke_width, 0, 500);
746 ImGui::SliderFloat(
"Stroked Width Fine", &stroke_width_fine, 0, 5);
747 ImGui::SliderFloat(
"Stroked Alpha", &stroked_alpha, 0, 10.0);
748 ImGui::SliderFloat2(
"Stroked Scale", stroked_scale, 0, 10.0);
752 flutter::DisplayListBuilder builder;
754 DlPaint background_paint;
755 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
756 builder.DrawPaint(background_paint);
758 flutter::DlPaint paint;
760 paint.setColor(flutter::DlColor::kRed().withAlpha(stroked_alpha));
761 paint.setDrawStyle(flutter::DlDrawStyle::kStroke);
762 paint.setStrokeWidth(stroke_width + stroke_width_fine);
764 builder.Translate(250, 250);
765 builder.Scale(stroked_scale[0], stroked_scale[1]);
766 builder.Translate(-250, -250);
767 builder.DrawCircle(
DlPoint(250, 250), stroked_radius, paint);
769 return builder.Build();
772 ASSERT_TRUE(OpenPlaygroundHere(callback));
776 DisplayListBuilder builder;
777 builder.Scale(GetContentScale().
x, GetContentScale().y);
779 const int color_count = 3;
780 DlColor colors[color_count] = {
783 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
786 paint.setColor(DlColor::kWhite());
787 builder.DrawPaint(paint);
791 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas,
DlPoint center,
793 for (
int i = 0; i < n; i++) {
794 paint.setColor(colors[(c_index++) % color_count]);
795 canvas.DrawCircle(center, r, paint);
800 paint.setDrawStyle(DlDrawStyle::kStroke);
801 paint.setStrokeWidth(1);
802 draw(builder,
DlPoint(10, 10), 2, 2, 14);
803 paint.setStrokeWidth(5);
804 draw(builder,
DlPoint(10, 10), 35, 10, 56);
806 DlColor gradient_colors[7] = {
807 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
808 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
809 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
810 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
811 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
812 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
813 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
824 auto texture = CreateTextureForFixture(
"airplane.jpg",
828 paint.setColorSource(DlColorSource::MakeRadial(
829 DlPoint(500, 600), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
830 draw(builder,
DlPoint(500, 600), 5, 10, 10);
832 DlMatrix local_matrix = DlMatrix::MakeTranslation({700, 200});
833 paint.setColorSource(DlColorSource::MakeImage(
834 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
835 DlImageSampling::kNearestNeighbor, &local_matrix));
836 draw(builder,
DlPoint(800, 300), 5, 10, 10);
838 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
843 DlPathBuilder path_builder;
846 const Scalar k = 0.5522847498f;
848 path_builder.MoveTo(
DlPoint(0.0f, -radius));
850 path_builder.CubicCurveTo(
DlPoint(radius * k, -radius),
854 path_builder.CubicCurveTo(
DlPoint(radius, radius * k),
858 path_builder.CubicCurveTo(
DlPoint(-radius * k, radius),
862 path_builder.CubicCurveTo(
DlPoint(-radius, -radius * k),
865 path_builder.Close();
866 return path_builder.TakePath();
869 void DrawStrokedAndFilledCirclesWithZoom(
AiksTest* test,
873 DisplayListBuilder builder;
874 builder.Scale(test->GetContentScale().x, test->GetContentScale().y);
875 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
878 fill_paint.setColor(DlColor::kBlue());
880 DlPaint stroke_paint;
881 stroke_paint.setColor(DlColor::kGreen());
882 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
883 stroke_paint.setStrokeWidth(stroke_width);
885 DlPath path = ManuallyConstructCirclePath(radius);
887 constexpr
Scalar kLeftX = 300.0f;
888 constexpr
Scalar kRightX = 680.0f;
889 constexpr
Scalar kTopY = 200.0f;
890 constexpr
Scalar kBottomY = 580.0f;
894 builder.Translate(kLeftX, kTopY);
895 builder.Scale(zoom, zoom);
896 builder.DrawPath(path, fill_paint);
897 builder.DrawPath(path, stroke_paint);
902 builder.Translate(kRightX, kTopY);
903 builder.Scale(zoom, zoom);
904 builder.DrawPath(path, fill_paint);
909 builder.Translate(kLeftX, kBottomY);
910 builder.Scale(zoom, zoom);
911 builder.DrawPath(path, stroke_paint);
917 builder.Translate(kRightX, kBottomY);
918 builder.Scale(zoom, zoom);
919 builder.DrawCircle({}, radius + stroke_width * 0.5f, fill_paint);
922 ASSERT_TRUE(test->OpenPlaygroundHere(builder.Build()));
927 DrawStrokedAndFilledCirclesWithZoom(
this, 80.0f, 2.0f,
932 DrawStrokedAndFilledCirclesWithZoom(
this, 1.0f, 1.0f,
937 DisplayListBuilder builder;
938 builder.Scale(GetContentScale().
x, GetContentScale().y);
940 const int color_count = 3;
941 DlColor colors[color_count] = {
944 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
947 paint.setColor(DlColor::kWhite());
948 builder.DrawPaint(paint);
951 int long_radius = 600;
952 int short_radius = 600;
953 while (long_radius > 0 && short_radius > 0) {
954 paint.setColor(colors[(c_index++) % color_count]);
956 DlRect::MakeEllipseBounds({10, 10},
Size(long_radius, short_radius)),
959 DlRect::MakeEllipseBounds({1000, 750},
Size(short_radius, long_radius)),
961 if (short_radius > 30) {
970 DlColor gradient_colors[7] = {
971 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
972 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
973 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
974 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
975 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
976 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
977 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
988 auto texture = CreateTextureForFixture(
"airplane.jpg",
992 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
994 paint.setColorSource(DlColorSource::MakeRadial(
995 DlPoint(300, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
996 builder.DrawOval(DlRect::MakeXYWH(200, 625, 200, 50), paint);
997 builder.DrawOval(DlRect::MakeXYWH(275, 550, 50, 200), paint);
999 DlMatrix local_matrix = DlMatrix::MakeTranslation({610, 15});
1000 paint.setColorSource(DlColorSource::MakeImage(
1001 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1002 DlImageSampling::kNearestNeighbor, &local_matrix));
1003 builder.DrawOval(DlRect::MakeXYWH(610, 90, 200, 50), paint);
1004 builder.DrawOval(DlRect::MakeXYWH(685, 15, 50, 200), paint);
1006 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1010 struct ArcFarmOptions {
1017 void RenderArcFarm(DisplayListBuilder& builder,
1018 const DlPaint& paint,
1019 const ArcFarmOptions& opts) {
1021 builder.Translate(50, 50);
1023 const int sweep_limit = opts.sweeps_over_360 ? 420 : 360;
1026 for (
int sweep = 30; sweep <= sweep_limit; sweep += 30) {
1027 builder.DrawArc(arc_bounds,
start, opts.full_circles ? 360 : sweep,
1028 opts.use_center, paint);
1029 builder.Translate(50, 0);
1032 builder.Translate(0, 50);
1037 void RenderArcFarmForOverlappingCapsTest(DisplayListBuilder& builder,
1038 const DlPaint& paint) {
1040 builder.Translate(40, 30);
1042 for (
int stroke_width = 10; stroke_width <= 40; stroke_width += 3) {
1043 DlPaint modified_paint = DlPaint(paint);
1044 modified_paint.setStrokeWidth(stroke_width);
1046 for (
int sweep = 160; sweep <= 360; sweep += 20) {
1047 builder.DrawArc(arc_bounds, 0, sweep,
false, modified_paint);
1048 builder.Translate(84, 0);
1051 builder.Translate(0, 44 + stroke_width);
1058 DisplayListBuilder builder;
1059 builder.Scale(GetContentScale().
x, GetContentScale().y);
1060 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1063 paint.setColor(DlColor::kBlue());
1065 RenderArcFarm(builder, paint,
1067 .use_center =
false,
1068 .full_circles =
false,
1071 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1075 DisplayListBuilder builder;
1076 builder.Scale(GetContentScale().
x, GetContentScale().y);
1077 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1080 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1082 RenderArcFarm(builder, paint,
1084 .use_center =
false,
1085 .full_circles =
false,
1088 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1092 DisplayListBuilder builder;
1093 builder.Scale(GetContentScale().
x, GetContentScale().y);
1094 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1097 paint.setColor(DlColor::kBlue());
1099 RenderArcFarm(builder, paint,
1102 .full_circles =
false,
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.setColor(DlColor::kBlue());
1116 RenderArcFarm(builder, paint,
1118 .use_center =
false,
1119 .full_circles =
false,
1120 .vertical_scale = 0.8f,
1123 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1127 DisplayListBuilder builder;
1128 builder.Scale(GetContentScale().
x, GetContentScale().y);
1129 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1132 paint.setColor(DlColor::kBlue());
1134 RenderArcFarm(builder, paint,
1137 .full_circles =
false,
1138 .vertical_scale = 0.8f,
1141 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1145 DisplayListBuilder builder;
1146 builder.Scale(GetContentScale().
x, GetContentScale().y);
1147 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1150 paint.setDrawStyle(DlDrawStyle::kStroke);
1151 paint.setStrokeWidth(6.0f);
1152 paint.setStrokeCap(DlStrokeCap::kButt);
1153 paint.setColor(DlColor::kBlue());
1155 RenderArcFarm(builder, paint,
1157 .use_center =
false,
1158 .full_circles =
false,
1161 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1165 DisplayListBuilder builder;
1166 builder.Scale(GetContentScale().
x, GetContentScale().y);
1167 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1170 paint.setDrawStyle(DlDrawStyle::kStroke);
1171 paint.setStrokeWidth(6.0f);
1172 paint.setStrokeCap(DlStrokeCap::kSquare);
1173 paint.setColor(DlColor::kBlue());
1175 RenderArcFarm(builder, paint,
1177 .use_center =
false,
1178 .full_circles =
false,
1181 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1185 DisplayListBuilder builder;
1186 builder.Scale(GetContentScale().
x, GetContentScale().y);
1187 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1190 paint.setDrawStyle(DlDrawStyle::kStroke);
1191 paint.setStrokeCap(DlStrokeCap::kSquare);
1192 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1194 RenderArcFarmForOverlappingCapsTest(builder, paint);
1196 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1200 DisplayListBuilder builder;
1201 builder.Scale(GetContentScale().
x, GetContentScale().y);
1202 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1205 paint.setDrawStyle(DlDrawStyle::kStroke);
1206 paint.setStrokeWidth(6.0f);
1207 paint.setStrokeCap(DlStrokeCap::kRound);
1208 paint.setColor(DlColor::kBlue());
1210 RenderArcFarm(builder, paint,
1212 .use_center =
false,
1213 .full_circles =
false,
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.setStrokeCap(DlStrokeCap::kRound);
1227 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1229 RenderArcFarmForOverlappingCapsTest(builder, paint);
1231 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1235 DisplayListBuilder builder;
1236 builder.Scale(GetContentScale().
x, GetContentScale().y);
1237 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1240 paint.setDrawStyle(DlDrawStyle::kStroke);
1241 paint.setStrokeWidth(6.0f);
1242 paint.setStrokeJoin(DlStrokeJoin::kBevel);
1243 paint.setColor(DlColor::kBlue());
1245 RenderArcFarm(builder, paint,
1248 .full_circles =
false,
1249 .sweeps_over_360 =
true,
1252 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1256 DisplayListBuilder builder;
1257 builder.Scale(GetContentScale().
x, GetContentScale().y);
1258 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1261 paint.setDrawStyle(DlDrawStyle::kStroke);
1262 paint.setStrokeWidth(6.0f);
1263 paint.setStrokeJoin(DlStrokeJoin::kMiter);
1266 paint.setStrokeMiter(3.0f);
1267 paint.setColor(DlColor::kBlue());
1269 RenderArcFarm(builder, paint,
1272 .full_circles =
false,
1273 .sweeps_over_360 =
true,
1276 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1280 DisplayListBuilder builder;
1281 builder.Scale(GetContentScale().
x, GetContentScale().y);
1282 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1285 paint.setDrawStyle(DlDrawStyle::kStroke);
1286 paint.setStrokeWidth(6.0f);
1287 paint.setStrokeJoin(DlStrokeJoin::kRound);
1288 paint.setColor(DlColor::kBlue());
1290 RenderArcFarm(builder, paint,
1293 .full_circles =
false,
1294 .sweeps_over_360 =
true,
1297 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1301 DisplayListBuilder builder;
1302 builder.Scale(GetContentScale().
x, GetContentScale().y);
1303 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1306 paint.setDrawStyle(DlDrawStyle::kStroke);
1307 paint.setStrokeWidth(8.0f);
1308 paint.setStrokeCap(DlStrokeCap::kSquare);
1309 paint.setColor(DlColor::kRed());
1311 RenderArcFarm(builder, paint,
1313 .use_center =
false,
1314 .full_circles =
false,
1317 paint.setStrokeCap(DlStrokeCap::kButt);
1318 paint.setColor(DlColor::kBlue());
1320 RenderArcFarm(builder, paint,
1322 .use_center =
false,
1323 .full_circles =
false,
1326 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1330 DisplayListBuilder builder;
1331 builder.Scale(GetContentScale().
x, GetContentScale().y);
1332 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1335 paint.setDrawStyle(DlDrawStyle::kStroke);
1336 paint.setStrokeWidth(8.0f);
1337 paint.setStrokeCap(DlStrokeCap::kSquare);
1338 paint.setColor(DlColor::kRed());
1340 RenderArcFarm(builder, paint,
1342 .use_center =
false,
1343 .full_circles =
false,
1346 paint.setStrokeCap(DlStrokeCap::kRound);
1347 paint.setColor(DlColor::kGreen());
1349 RenderArcFarm(builder, paint,
1351 .use_center =
false,
1352 .full_circles =
false,
1355 paint.setStrokeCap(DlStrokeCap::kButt);
1356 paint.setColor(DlColor::kBlue());
1358 RenderArcFarm(builder, paint,
1360 .use_center =
false,
1361 .full_circles =
false,
1364 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1379 DisplayListBuilder builder;
1380 builder.Scale(GetContentScale().
x, GetContentScale().y);
1381 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
1384 paint.setDrawStyle(DlDrawStyle::kStroke);
1385 paint.setStrokeWidth(6.0f);
1386 paint.setStrokeCap(DlStrokeCap::kButt);
1387 paint.setColor(DlColor::kBlue());
1390 RenderArcFarm(builder, paint,
1392 .use_center =
false,
1393 .full_circles =
true,
1396 paint.setColor(DlColor::kWhite());
1399 RenderArcFarm(builder, paint,
1401 .use_center =
false,
1402 .full_circles =
false,
1405 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1409 DisplayListBuilder builder;
1410 builder.Scale(GetContentScale().
x, GetContentScale().y);
1412 const int color_count = 3;
1413 DlColor colors[color_count] = {
1416 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
1419 paint.setColor(DlColor::kWhite());
1420 builder.DrawPaint(paint);
1423 for (
int i = 0; i < 4; i++) {
1424 for (
int j = 0; j < 4; j++) {
1425 paint.setColor(colors[(c_index++) % color_count]);
1426 builder.DrawRoundRect(
1427 DlRoundRect::MakeRectXY(
1428 DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1429 i * 5 + 10, j * 5 + 10),
1433 paint.setColor(colors[(c_index++) % color_count]);
1434 builder.DrawRoundRect(
1435 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40),
1437 paint.setColor(colors[(c_index++) % color_count]);
1438 builder.DrawRoundRect(
1439 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40),
1442 DlColor gradient_colors[7] = {
1443 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1444 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1445 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1446 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1447 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1448 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1449 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
1460 auto texture = CreateTextureForFixture(
"airplane.jpg",
1464 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1465 paint.setColorSource(DlColorSource::MakeRadial(
1466 DlPoint(550, 550), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1467 for (
int i = 1; i <= 10; i++) {
1469 builder.DrawRoundRect(
1470 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1471 550 + i * 20, 550 + j * 20),
1476 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1477 paint.setColorSource(DlColorSource::MakeRadial(
1478 DlPoint(200, 650), 75, 7, gradient_colors, stops, DlTileMode::kMirror));
1479 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1480 builder.DrawRoundRect(
1481 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40),
1483 builder.DrawRoundRect(
1484 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40),
1487 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1488 DlMatrix local_matrix = DlMatrix::MakeTranslation({520, 20});
1489 paint.setColorSource(DlColorSource::MakeImage(
1490 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1491 DlImageSampling::kNearestNeighbor, &local_matrix));
1492 for (
int i = 1; i <= 10; i++) {
1494 builder.DrawRoundRect(
1495 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1496 720 + i * 20, 220 + j * 20),
1501 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1502 local_matrix = DlMatrix::MakeTranslation({800, 300});
1503 paint.setColorSource(DlColorSource::MakeImage(
1504 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
1505 DlImageSampling::kNearestNeighbor, &local_matrix));
1506 builder.DrawRoundRect(
1507 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
1509 builder.DrawRoundRect(
1510 DlRoundRect::MakeRectXY(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40),
1513 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1517 DisplayListBuilder builder;
1518 builder.Scale(GetContentScale().
x, GetContentScale().y);
1520 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
1522 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
1525 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
1527 for (
int i = 0; i < 5; i++) {
1530 builder.DrawRect(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1531 radius, 60.0f - radius),
1535 paint.setColor(DlColor::kBlue());
1537 for (
int i = 0; i < 5; i++) {
1540 builder.DrawCircle(
DlPoint(
x + 25, y + 25), radius, paint);
1543 paint.setColor(DlColor::kGreen());
1545 for (
int i = 0; i < 5; i++) {
1548 builder.DrawOval(DlRect::MakeXYWH(
x + 25 - radius / 2, y + radius / 2,
1549 radius, 60.0f - radius),
1554 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
1556 for (
int i = 0; i < 5; i++) {
1559 builder.DrawRoundRect(
1560 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1566 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
1568 for (
int i = 0; i < 5; i++) {
1571 builder.DrawRoundRect(
1572 DlRoundRect::MakeRectXY(DlRect::MakeXYWH(
x, y, 60.0f, 60.0f),
1577 auto dl = builder.Build();
1578 ASSERT_TRUE(OpenPlaygroundHere(dl));
1582 DisplayListBuilder builder;
1584 builder.Scale(GetContentScale().
x, GetContentScale().y);
1587 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
1588 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
1589 std::vector<Scalar> stops = {
1594 paint.setColorSource(DlColorSource::MakeLinear(
1603 builder.DrawPaint(paint);
1605 DlRect clip_rect = DlRect::MakeLTRB(50, 50, 400, 300);
1606 DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 100, 100);
1610 builder.ClipRoundRect(clip_rrect, DlClipOp::kIntersect);
1613 auto backdrop_filter = DlImageFilter::MakeColorFilter(
1614 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kExclusion));
1615 builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get());
1617 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1623 auto callback = [&]() -> sk_sp<DisplayList> {
1624 DisplayListBuilder builder;
1628 builder.Translate(300, 300);
1635 paint.setColor(DlColor::kGreen());
1636 builder.DrawPaint(paint);
1637 builder.ClipRect(DlRect::MakeLTRB(-180, -180, 180, 180),
1638 DlClipOp::kDifference);
1640 paint.setColor(DlColor::kBlack());
1641 builder.DrawPaint(paint);
1649 builder.ClipOval(DlRect::MakeLTRB(-200, -200, 200, 200));
1652 Matrix(1.0, 0.0, 0.0, 0.0,
1654 0.0, 0.0, 1.0, 0.003,
1655 0.0, 0.0, 0.0, 1.0) *
1664 -
DlPoint(image->GetSize().width, image->GetSize().height) * 0.5;
1665 builder.DrawImage(image, position, {});
1671 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
1672 builder.DrawCircle(
DlPoint(), 230, paint);
1676 return builder.Build();
1678 ASSERT_TRUE(OpenPlaygroundHere(callback));
1684 DisplayListBuilder builder;
1688 paint.setColor(DlColor::kWhite());
1689 builder.DrawPaint(paint);
1693 DlMatrix matrix = DlMatrix::MakeTranslation({50, 50});
1695 paint.setColorSource(DlColorSource::MakeImage(
1696 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1697 DlImageSampling::kNearestNeighbor, &matrix));
1699 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), paint);
1708 Matrix matrix(1, -1, 0, 0,
1712 paint.setColorSource(DlColorSource::MakeImage(
1713 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1714 DlImageSampling::kNearestNeighbor, &matrix));
1715 builder.DrawRect(DlRect::MakeLTRB(100, 0, 200, 100), paint);
1722 builder.Translate(100, 0);
1723 builder.Scale(100, 100);
1726 DlMatrix matrix = DlMatrix::MakeScale({0.005, 0.005, 1});
1727 paint.setColorSource(DlColorSource::MakeImage(
1728 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1729 DlImageSampling::kNearestNeighbor, &matrix));
1731 builder.DrawRect(DlRect::MakeLTRB(0, 0, 1, 1), paint);
1738 builder.Translate(150, 150);
1742 DlMatrix::MakePerspective(
Radians{0.5},
ISize{200, 200}, 0.05, 1);
1743 paint.setColorSource(DlColorSource::MakeImage(
1744 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1745 DlImageSampling::kNearestNeighbor, &matrix));
1747 builder.DrawRect(DlRect::MakeLTRB(0, 0, 200, 200), paint);
1751 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1755 DisplayListBuilder builder;
1760 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
1761 paint.setBlendMode(DlBlendMode::kSrc);
1763 DlRect bounds = DlRect::MakeLTRB(0, 0, 200, 200);
1764 builder.SaveLayer(bounds, &paint);
1766 paint.setColor(DlColor::kTransparent());
1767 paint.setBlendMode(DlBlendMode::kSrc);
1768 builder.DrawPaint(paint);
1771 paint.setColor(DlColor::kBlue());
1772 paint.setBlendMode(DlBlendMode::kDstOver);
1773 builder.SaveLayer(std::nullopt, &paint);
1779 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1784 DisplayListBuilder builder;
1785 builder.Scale(GetContentScale().
x, GetContentScale().y);
1786 builder.Translate(100, 100);
1790 DlMatrix translate = DlMatrix::MakeTranslation({300, 0});
1791 paint.setImageFilter(
1792 DlImageFilter::MakeMatrix(translate, DlImageSampling::kLinear));
1793 builder.SaveLayer(std::nullopt, &paint);
1795 DlPaint circle_paint;
1796 circle_paint.setColor(DlColor::kGreen());
1797 builder.DrawCircle(
DlPoint(-300, 0), 100, circle_paint);
1800 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1805 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
1806 DisplayListBuilder builder;
1807 builder.Scale(GetContentScale().
x, GetContentScale().y);
1808 builder.Translate(100, 100);
1813 paint.setImageFilter(DlImageFilter::MakeMatrix(
1814 DlMatrix::MakeTranslation({300, 0}) * DlMatrix::MakeScale({2, 2, 1}),
1815 DlImageSampling::kNearestNeighbor));
1816 builder.SaveLayer(std::nullopt, &paint);
1818 DlPaint circle_paint;
1819 circle_paint.setColor(DlColor::kGreen());
1820 builder.DrawCircle(
DlPoint(-150, 0), 50, circle_paint);
1823 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1828 SetWindowSize({400, 400});
1829 DisplayListBuilder builder;
1831 builder.Scale(GetContentScale().
x, GetContentScale().y);
1834 paint.setColor(DlColor::kRed());
1835 builder.DrawRect(DlRect::MakeLTRB(200, 200, 300, 300), paint);
1837 paint.setImageFilter(DlImageFilter::MakeMatrix(DlMatrix::MakeScale({2, 2, 1}),
1838 DlImageSampling::kLinear));
1839 builder.SaveLayer(std::nullopt, &paint);
1842 paint.setColor(DlColor::kGreen());
1843 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
1846 paint.setColor(DlColor::kRed());
1847 builder.DrawRect(DlRect::MakeLTRB(0, 0, 800, 800), paint);
1850 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1854 DisplayListBuilder builder;
1855 builder.Scale(GetContentScale().
x, GetContentScale().y);
1858 paint.setColor(DlColor::kRed());
1859 builder.DrawPaint(paint);
1860 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1861 paint.setColor(DlColor::kBlue());
1862 builder.SaveLayer(std::nullopt, &paint);
1865 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1869 DisplayListBuilder builder;
1870 builder.Scale(GetContentScale().
x, GetContentScale().y);
1872 builder.DrawImage(image,
DlPoint(10, 10), {});
1873 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
1876 paint.setBlendMode(DlBlendMode::kClear);
1877 builder.SaveLayer(std::nullopt, &paint);
1880 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1884 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
1885 DisplayListBuilder builder;
1888 red.setColor(DlColor::kRed());
1891 green.setColor(DlColor::kGreen());
1894 blue.setColor(DlColor::kBlue());
1897 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1899 DlRect huge_bounds = DlRect::MakeXYWH(0, 0, 100000, 100000);
1900 builder.SaveLayer(huge_bounds, &save);
1902 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1903 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), green);
1904 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), blue);
1908 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1915 if (!EnsureContextSupportsWideGamut()) {
1916 GTEST_SKIP() <<
"This backend doesn't yet support wide gamut.";
1919 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1925 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1932 DisplayListBuilder builder;
1939 builder.Translate(100, 200);
1940 builder.Scale(0.5, 0.5);
1941 builder.DrawImage(image,
DlPoint(100.0, 100.0),
1942 DlImageSampling::kNearestNeighbor);
1949 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1951 builder.SaveLayer(std::nullopt, &alpha);
1954 paint.setColor(DlColor::kRed());
1955 builder.DrawRect(DlRect::MakeXYWH(000, 000, 100, 100), paint);
1956 paint.setColor(DlColor::kGreen());
1957 builder.DrawRect(DlRect::MakeXYWH(020, 020, 100, 100), paint);
1958 paint.setColor(DlColor::kBlue());
1959 builder.DrawRect(DlRect::MakeXYWH(040, 040, 100, 100), paint);
1964 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1968 DisplayListBuilder builder;
1971 paint.setColor(DlColor::kRed());
1972 builder.DrawCircle(
DlPoint(250, 250), 125, paint);
1974 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1978 DisplayListBuilder builder;
1981 red.setColor(DlColor::kRed());
1983 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), red);
1985 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1989 DisplayListBuilder builder;
1992 save.setColor(DlColor::kBlack());
1994 DlRect save_bounds = DlRect::MakeXYWH(0, 0, 50, 50);
1995 builder.SaveLayer(save_bounds, &save);
1998 paint.setColor(DlColor::kRed());
1999 builder.DrawRect(DlRect::MakeXYWH(0, 0, 100, 100), paint);
2000 paint.setColor(DlColor::kGreen());
2001 builder.DrawRect(DlRect::MakeXYWH(10, 10, 100, 100), paint);
2002 paint.setColor(DlColor::kBlue());
2003 builder.DrawRect(DlRect::MakeXYWH(20, 20, 100, 100), paint);
2007 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2011 DisplayListBuilder builder;
2012 builder.Scale(GetContentScale().
x, GetContentScale().y);
2015 const int color_count = 3;
2016 DlColor colors[color_count] = {
2019 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
2022 paint.setColor(DlColor::kWhite());
2023 builder.DrawPaint(paint);
2026 const DlPaint& paint) {
2027 builder.DrawPath(DlPath::MakeRoundRectXY(rect,
x, y), paint);
2031 for (
int i = 0; i < 4; i++) {
2032 for (
int j = 0; j < 4; j++) {
2033 paint.setColor(colors[(c_index++) % color_count]);
2034 draw_rrect_as_path(DlRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
2035 i * 5 + 10, j * 5 + 10, paint);
2038 paint.setColor(colors[(c_index++) % color_count]);
2039 draw_rrect_as_path(DlRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
2040 paint.setColor(colors[(c_index++) % color_count]);
2041 draw_rrect_as_path(DlRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
2043 std::vector<DlColor> gradient_colors = {
2044 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
2045 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
2046 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
2047 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
2048 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
2049 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
2050 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
2051 std::vector<Scalar> stops = {
2061 CreateTextureForFixture(
"airplane.jpg",
2064 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
2065 paint.setColorSource(DlColorSource::MakeRadial(
2068 gradient_colors.size(),
2069 gradient_colors.data(),
2071 DlTileMode::kMirror));
2072 for (
int i = 1; i <= 10; i++) {
2074 draw_rrect_as_path(DlRect::MakeLTRB(550 - i * 20, 550 - j * 20,
2075 550 + i * 20, 550 + j * 20),
2076 i * 10, j * 10, paint);
2078 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
2079 paint.setColorSource(DlColorSource::MakeRadial(
2082 gradient_colors.size(),
2083 gradient_colors.data(),
2085 DlTileMode::kMirror));
2086 draw_rrect_as_path(DlRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
2087 draw_rrect_as_path(DlRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
2089 auto matrix = DlMatrix::MakeTranslation({520, 20});
2090 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
2091 paint.setColorSource(DlColorSource::MakeImage(
2092 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
2093 DlImageSampling::kMipmapLinear, &matrix));
2094 for (
int i = 1; i <= 10; i++) {
2096 draw_rrect_as_path(DlRect::MakeLTRB(720 - i * 20, 220 - j * 20,
2097 720 + i * 20, 220 + j * 20),
2098 i * 10, j * 10, paint);
2100 matrix = DlMatrix::MakeTranslation({800, 300});
2101 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
2102 paint.setColorSource(DlColorSource::MakeImage(
2103 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
2104 DlImageSampling::kMipmapLinear, &matrix));
2106 draw_rrect_as_path(DlRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
2107 draw_rrect_as_path(DlRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
2109 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2113 auto callback = [&]() -> sk_sp<DisplayList> {
2114 DisplayListBuilder builder;
2115 builder.Scale(GetContentScale().x, GetContentScale().y);
2118 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
2120 auto current =
Point{25, 25};
2121 const auto offset =
Point{25, 25};
2122 const auto size =
Size(100, 100);
2127 DlRect bounds = DlRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
2129 DlPaint stroke_paint;
2130 stroke_paint.setColor(DlColor::kYellow());
2131 stroke_paint.setStrokeWidth(5);
2132 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
2133 builder.DrawRect(bounds, stroke_paint);
2135 builder.SaveLayer(bounds, &alpha);
2138 paint.setColor(DlColor::kRed());
2140 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2142 paint.setColor(DlColor::kGreen());
2145 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2147 paint.setColor(DlColor::kBlue());
2150 DlRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
2154 return builder.Build();
2157 ASSERT_TRUE(OpenPlaygroundHere(callback));
2162 DisplayListBuilder builder;
2165 paint.setColor(DlColor::kBlack());
2166 DlRect rect = DlRect::MakeXYWH(25, 25, 25, 25);
2167 builder.DrawRect(rect, paint);
2169 builder.Translate(10, 10);
2172 builder.SaveLayer(std::nullopt, &save_paint);
2174 paint.setColor(DlColor::kGreen());
2175 builder.DrawRect(rect, paint);
2179 builder.Translate(10, 10);
2180 paint.setColor(DlColor::kRed());
2181 builder.DrawRect(rect, paint);
2183 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2187 DisplayListBuilder builder;
2189 DlRect rect = DlRect::MakeXYWH(0, 0, 1000, 1000);
2194 DlRect bounds = DlRect::MakeXYWH(25, 25, 25, 25);
2195 builder.SaveLayer(bounds, &save_paint);
2196 paint.setColor(DlColor::kBlack());
2197 builder.DrawRect(rect, paint);
2203 DlRect bounds = DlRect::MakeXYWH(35, 35, 25, 25);
2204 builder.SaveLayer(bounds, &save_paint);
2205 paint.setColor(DlColor::kGreen());
2206 builder.DrawRect(rect, paint);
2212 DlRect bounds = DlRect::MakeXYWH(45, 45, 25, 25);
2213 builder.SaveLayer(bounds, &save_paint);
2214 paint.setColor(DlColor::kRed());
2215 builder.DrawRect(rect, paint);
2219 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2223 DisplayListBuilder builder;
2226 paint.setColor(DlColor::kWhite());
2227 builder.DrawPaint(paint);
2233 builder.ClipPath(path);
2235 DlRect bounds = DlRect::MakeXYWH(50, 50, 100, 100);
2237 builder.SaveLayer(bounds, &save_paint);
2240 paint.setColor(DlColor::kWhite());
2241 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2244 paint.setColor(DlColor::kGreen());
2245 paint.setBlendMode(DlBlendMode::kHardLight);
2246 builder.DrawRect(DlRect::MakeSize(DlSize(400, 400)), paint);
2249 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2253 DisplayListBuilder builder;
2255 builder.Scale(GetContentScale().
x, GetContentScale().y);
2256 builder.Translate(100, 100);
2259 auto draw_image_layer = [&builder, &texture](
const DlPaint& paint) {
2260 builder.SaveLayer(std::nullopt, &paint);
2261 builder.DrawImage(texture,
DlPoint(), DlImageSampling::kLinear);
2265 DlPaint effect_paint;
2266 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
2267 draw_image_layer(effect_paint);
2269 builder.Translate(300, 300);
2270 builder.Scale(3, 3);
2271 draw_image_layer(effect_paint);
2273 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2277 DisplayListBuilder builder;
2279 builder.Scale(GetContentScale().
x, GetContentScale().y);
2281 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
2284 save_paint.setColor(DlColor::kWhite());
2285 builder.DrawPaint(save_paint);
2287 paint.setColor(DlColor::kBlue());
2288 for (
int i = 0; i < 5; i++) {
2290 Scalar y_radius = i * 15;
2291 for (
int j = 0; j < 5; j++) {
2293 Scalar x_radius = j * 15;
2294 builder.DrawRoundRect(
2295 DlRoundRect::MakeRectXY(
2296 DlRect::MakeXYWH(
x + 50, y + 50, 100.0f, 100.0f),
2297 x_radius, y_radius),
2302 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2306 DisplayListBuilder builder;
2310 builder.SaveLayer(std::nullopt, &paint);
2312 builder.Translate(100, 100);
2313 paint.setColor(DlColor::kBlue());
2314 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2315 builder.ClipRect(DlRect::MakeXYWH(100, 100, 200, 200));
2317 paint.setColor(DlColor::kGreen());
2318 paint.setBlendMode(DlBlendMode::kSrcOver);
2319 paint.setImageFilter(DlImageFilter::MakeColorFilter(
2320 DlColorFilter::MakeBlend(DlColor::kWhite(), DlBlendMode::kDst)));
2321 builder.DrawCircle(
DlPoint(200, 200), 200, paint);
2325 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2333 GTEST_SKIP() <<
"Swiftshader is running out of memory on this example.";
2335 DisplayListBuilder builder(DlRect::MakeSize(DlSize(1000, 1000)));
2337 auto filter = DlImageFilter::MakeMatrix(
2338 DlMatrix::MakeScale({0.001, 0.001, 1}), DlImageSampling::kLinear);
2341 paint.setImageFilter(filter);
2342 builder.SaveLayer(std::nullopt, &paint);
2345 paint.setColor(DlColor::kRed());
2346 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100000, 100000), paint);
2350 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2357 bool stroked =
true;
2358 auto callback = [&]() -> sk_sp<DisplayList> {
2360 ImGuiWindowFlags_AlwaysAutoResize)) {
2361 ImGui::SliderFloat(
"width", &width, 0, 200);
2362 ImGui::SliderFloat(
"height", &height, 0, 200);
2363 ImGui::SliderFloat(
"corner", &corner, 0, 1);
2364 ImGui::Checkbox(
"stroked", &stroked);
2368 DisplayListBuilder builder;
2369 builder.Scale(GetContentScale().
x, GetContentScale().y);
2371 DlPaint background_paint;
2372 background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
2373 builder.DrawPaint(background_paint);
2375 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
2376 std::vector<Scalar> stops = {0.0, 1.0};
2379 auto gradient = DlColorSource::MakeLinear(
DlPoint(0, 0),
DlPoint(200, 200),
2380 2, colors.data(), stops.data(),
2381 DlTileMode::kClamp);
2382 paint.setColorSource(gradient);
2383 paint.setColor(DlColor::kWhite());
2385 paint.setDrawStyle(DlDrawStyle::kStroke);
2386 paint.setStrokeWidth(20);
2388 paint.setDrawStyle(DlDrawStyle::kFill);
2392 builder.Translate(100, 100);
2394 Scalar corner_x = ((1 - corner) * 50) + 50;
2395 Scalar corner_y = corner * 50 + 50;
2397 DlRect::MakeXYWH(0, 0, width, height), corner_x, corner_y);
2398 builder.DrawRoundRect(rrect, paint);
2400 return builder.Build();
2402 ASSERT_TRUE(OpenPlaygroundHere(callback));
2406 DisplayListBuilder builder;
2408 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
2411 builder.ClipRect(DlRect::MakeLTRB(100, 100, 800, 800));
2415 builder.ClipRect(DlRect::MakeLTRB(600, 600, 800, 800));
2416 builder.DrawPaint(DlPaint().setColor(DlColor::kRed()));
2417 builder.DrawPaint(DlPaint().setColor(DlColor::kBlue().withAlphaF(0.5)));
2418 builder.ClipRect(DlRect::MakeLTRB(700, 700, 750, 800));
2419 builder.DrawPaint(DlPaint().setColor(DlColor::kRed().withAlphaF(0.5)));
2423 auto image_filter = DlImageFilter::MakeBlur(10, 10, DlTileMode::kDecal);
2424 builder.SaveLayer(std::nullopt,
nullptr, image_filter.get());
2427 builder.DrawCircle(
DlPoint(100, 100), 100,
2428 DlPaint().setColor(DlColor::kAqua()));
2430 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2434 int perspective = 58;
2435 bool use_clip =
true;
2436 bool diff_clip =
false;
2438 auto callback = [&]() -> sk_sp<DisplayList> {
2440 ImGuiWindowFlags_AlwaysAutoResize)) {
2441 ImGui::SliderInt(
"perspective%", &perspective, 0, 100);
2442 ImGui::Checkbox(
"use clip", &use_clip);
2444 ImGui::Checkbox(
"diff clip", &diff_clip);
2446 ImGui::SetWindowPos(
"Controls", ImVec2(500, 100));
2450 DisplayListBuilder builder;
2452 Scalar val = perspective * -0.00005f;
2453 builder.TransformFullPerspective(
2455 1.0f, 0.0f, 0.0f, 400.0f,
2456 0.0f, 1.0f, 0.0f, 400.0f,
2457 0.0f, 0.0f, 1.0f, 0.0f,
2458 0.0f, val, 0.0f, 2.2f
2463 Rect clip = DlRect::MakeLTRB(0, 0, 400, 800);
2464 DlClipOp clip_op = DlClipOp::kIntersect;
2467 clip_op = DlClipOp::kDifference;
2469 builder.ClipRect(clip, clip_op);
2473 paint.setColor(DlColor::kBlue());
2474 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 800), paint);
2476 builder.DrawColor(DlColor::kWhite().withAlphaF(0.5f),
2477 DlBlendMode::kSrcOver);
2479 return builder.Build();
2481 ASSERT_TRUE(OpenPlaygroundHere(callback));
2485 DisplayListBuilder builder;
2486 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2488 paint.setColor(DlColor::kBlue());
2491 builder.DrawRoundSuperellipse(
2492 DlRoundSuperellipse::MakeRectRadius(
2493 DlRect::MakeXYWH(50, 50, 100, 100), 20),
2496 builder.DrawRoundSuperellipse(
2497 DlRoundSuperellipse::MakeRectRadius(
2498 DlRect::MakeXYWH(200, 50, 60, 140), 20),
2501 builder.DrawRoundSuperellipse(
2502 DlRoundSuperellipse::MakeRectRadius(
2503 DlRect::MakeXYWH(310, 50, 140, 60), 20),
2506 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2510 DisplayListBuilder builder;
2511 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2513 paint.setColor(DlColor::kBlue());
2515 builder.DrawRoundSuperellipse(
2516 DlRoundSuperellipse::MakeRectRadii(
2517 DlRect::MakeXYWH(50, 50, 440, 440),
2519 .top_left =
Size(60.0f, 240.0f),
2520 .top_right =
Size(200.0f, 40.0f),
2521 .bottom_left =
Size(180.0f, 20.0f),
2522 .bottom_right =
Size(40.0f, 200.0f),
2526 builder.DrawRoundSuperellipse(
2527 DlRoundSuperellipse::MakeRectRadii(
2528 DlRect::MakeXYWH(550, 50, 440, 440),
2530 .top_left =
Size(240.0f, 40.0f),
2531 .top_right =
Size(40.0f, 240.0f),
2532 .bottom_left =
Size(40.0f, 240.0f),
2533 .bottom_right =
Size(240.0f, 40.0f),
2537 builder.DrawRoundSuperellipse(
2538 DlRoundSuperellipse::MakeRectRadii(
2539 DlRect::MakeXYWH(50, 550, 400, 400),
2541 .top_left =
Size(240.0f, 240.0f),
2542 .top_right =
Size(40.0f, 40.0f),
2543 .bottom_left =
Size(40.0f, 40.0f),
2544 .bottom_right =
Size(40.0f, 40.0f),
2548 builder.DrawRoundSuperellipse(
2549 DlRoundSuperellipse::MakeRectRadii(
2550 DlRect::MakeXYWH(550, 550, 400, 400),
2552 .top_left =
Size(240.0f, 240.0f),
2553 .top_right =
Size(40.0f, 40.0f),
2554 .bottom_left =
Size(40.0f, 40.0f),
2555 .bottom_right =
Size(240.0f, 240.0f),
2559 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2563 DisplayListBuilder builder;
2564 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2566 paint.setColor(DlColor::kBlue());
2567 paint.setDrawStyle(DlDrawStyle::kStroke);
2568 paint.setStrokeWidth(5.0f);
2571 builder.DrawRoundSuperellipse(
2572 DlRoundSuperellipse::MakeRectRadius(
2573 DlRect::MakeXYWH(50, 50, 100, 100), 20),
2576 builder.DrawRoundSuperellipse(
2577 DlRoundSuperellipse::MakeRectRadius(
2578 DlRect::MakeXYWH(200, 50, 60, 140), 20),
2581 builder.DrawRoundSuperellipse(
2582 DlRoundSuperellipse::MakeRectRadius(
2583 DlRect::MakeXYWH(310, 50, 140, 60), 20),
2586 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2590 DisplayListBuilder builder;
2591 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2593 paint.setColor(DlColor::kBlue());
2596 builder.DrawRoundSuperellipse(
2597 DlRoundSuperellipse::MakeRectRadius(
2598 DlRect::MakeXYWH(50, 50, 100, 100), 2),
2601 builder.DrawRoundSuperellipse(
2602 DlRoundSuperellipse::MakeRectRadius(
2603 DlRect::MakeXYWH(200, 50, 60, 140), 2),
2606 builder.DrawRoundSuperellipse(
2607 DlRoundSuperellipse::MakeRectRadius(
2608 DlRect::MakeXYWH(310, 50, 140, 60), 2),
2611 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2615 DisplayListBuilder builder;
2616 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2618 paint.setColor(DlColor::kBlue().withAlphaF(0.5));
2619 paint.setDrawStyle(DlDrawStyle::kStroke);
2620 paint.setStrokeWidth(40.0f);
2623 builder.DrawRoundSuperellipse(
2624 DlRoundSuperellipse::MakeRectRadius(
2625 DlRect::MakeXYWH(50, 50, 100, 100), 30),
2628 builder.DrawRoundSuperellipse(
2629 DlRoundSuperellipse::MakeRectRadius(
2630 DlRect::MakeXYWH(200, 50, 60, 140), 30),
2633 builder.DrawRoundSuperellipse(
2634 DlRoundSuperellipse::MakeRectRadius(
2635 DlRect::MakeXYWH(310, 50, 140, 60), 30),
2638 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2642 DisplayListBuilder builder;
2643 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2645 paint.setColor(DlColor::kBlue());
2647 DlScalar radii[] = {10.0f, 30.0f, 50.0f};
2649 for (
int row = 0; row < 3; row++) {
2654 builder.DrawRoundSuperellipse(
2655 DlRoundSuperellipse::MakeRectRadius(
2656 DlRect::MakeXYWH(50, y, 100, 100), radius),
2659 builder.DrawRoundSuperellipse(
2660 DlRoundSuperellipse::MakeRectRadius(
2661 DlRect::MakeXYWH(200, y, 60, 140), radius),
2664 builder.DrawRoundSuperellipse(
2665 DlRoundSuperellipse::MakeRectRadius(
2666 DlRect::MakeXYWH(310, y, 140, 60), radius),
2670 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2674 DisplayListBuilder builder;
2675 builder.DrawColor(DlColor::kWhite(), DlBlendMode::kSrc);
2678 builder.Translate(200, 200);
2679 builder.Rotate(45.0f);
2680 builder.Scale(1.5f, 0.8f);
2683 paint.setColor(DlColor::kBlue());
2684 builder.DrawRoundSuperellipse(
2685 DlRoundSuperellipse::MakeRectRadius(
2686 DlRect::MakeXYWH(-70, -30, 140, 60), 20),
2690 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2694 DisplayListBuilder builder;
2695 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
2698 paint.setColor(DlColor::kWhite());
2700 DlRect bounds = DlRect::MakeXYWH(75, 75, 50, 50);
2703 DlPaint layer_paint_left;
2704 layer_paint_left.setImageFilter(DlImageFilter::MakeMatrix(
2705 DlMatrix::MakeTranslation({200, 300}) * DlMatrix::MakeScale({8, 8, 1}) *
2706 DlMatrix::MakeTranslation({-100, -100}),
2707 DlImageSampling::kNearestNeighbor));
2708 builder.SaveLayer(bounds, &layer_paint_left);
2710 paint.setAntiAlias(
true);
2711 builder.DrawRoundRect(
2712 DlRoundRect::MakeRectRadius(DlRect::MakeXYWH(100, 100, 200, 200), 50.0f),
2717 DlPaint layer_paint_right;
2718 layer_paint_right.setImageFilter(DlImageFilter::MakeMatrix(
2719 DlMatrix::MakeTranslation({600, 300}) * DlMatrix::MakeScale({8, 8, 1}) *
2720 DlMatrix::MakeTranslation({-100, -100}),
2721 DlImageSampling::kNearestNeighbor));
2722 builder.SaveLayer(bounds, &layer_paint_right);
2724 paint.setAntiAlias(
false);
2725 builder.DrawRoundRect(
2726 DlRoundRect::MakeRectRadius(DlRect::MakeXYWH(100, 100, 200, 200), 50.0f),
2730 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2734 DisplayListBuilder builder;
2735 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
2737 DlRect outer_rect = DlRect::MakeXYWH(0, 0, 100, 100);
2738 DlRoundingRadii outer_radii = {.top_left = DlSize(5.0f),
2739 .top_right = DlSize(10.0f),
2740 .bottom_left = DlSize(20.0f),
2741 .bottom_right = DlSize(50.0f)};
2742 DlRoundRect outer_rrect = DlRoundRect::MakeRectRadii(outer_rect, outer_radii);
2745 DlRect inner_rect = outer_rect.Expand(-inner_inset);
2746 DlRoundingRadii inner_radii = {
2747 .top_left = DlSize(outer_radii.top_left.width - inner_inset),
2748 .top_right = DlSize(outer_radii.top_right.width - inner_inset),
2749 .bottom_left = DlSize(outer_radii.bottom_left.width - inner_inset),
2750 .bottom_right = DlSize(outer_radii.bottom_right.width - inner_inset)};
2751 DlRoundRect inner_rrect = DlRoundRect::MakeRectRadii(inner_rect, inner_radii);
2753 builder.Translate(50, 50);
2756 builder.DrawDiffRoundRect(outer_rrect, inner_rrect,
2757 DlPaint().setColor(DlColor::kSkyBlue()));
2761 builder.Translate(200, 0);
2762 builder.DrawRoundRect(outer_rrect, DlPaint().setColor(DlColor::kSkyBlue()));
2763 builder.DrawRoundRect(inner_rrect,
2764 DlPaint().setBlendMode(DlBlendMode::kClear));
2766 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
2770 DisplayListBuilder builder;
2771 builder.Scale(GetContentScale().
x, GetContentScale().y);
2772 builder.DrawColor(DlColor::kBlack(), DlBlendMode::kSrc);
2774 const float line_length = 30.0f;
2775 const float stroke_width = 10.0f;
2776 const float spacing = 50.0f;
2778 const std::vector<flutter::DlStrokeCap> caps = {
2779 flutter::DlStrokeCap::kButt,
2780 flutter::DlStrokeCap::kSquare,
2781 flutter::DlStrokeCap::kRound,
2783 const std::vector<float> alphas = {1.0f, 0.75f, 0.5f, 0.25f};
2784 const std::vector<Radians> angles = {
2790 paint.setDrawStyle(DlDrawStyle::kStroke);
2791 paint.setStrokeWidth(stroke_width);
2793 for (
const DlStrokeCap cap : caps) {
2794 builder.Translate(spacing, 0.0f);
2795 paint.setStrokeCap(cap);
2797 for (
const float alpha : alphas) {
2798 builder.Translate(spacing, 0.0f);
2799 paint.setColor(DlColor::kWhite().withAlphaF(alpha));
2802 for (
const Radians angle : angles) {
2803 builder.Translate(0.0f, spacing);
2804 builder.DrawLine(
DlPoint(0.0f, 0.0f),
2805 DlPoint(cos(angle.radians) * line_length,
2806 sin(angle.radians) * line_length),
2813 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)
std::shared_ptr< ContextGLES > context
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)