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"
20 #include "flutter/testing/display_list_testing.h"
21 #include "flutter/testing/testing.h"
23 #include "include/core/SkMatrix.h"
29 SkM44 FromImpellerMatrix(
const Matrix& matrix) {
30 return SkM44::ColMajor(matrix.m);
37 DisplayListBuilder builder;
39 paint.setColor(DlColor::kBlue());
40 SkPath path = SkPath();
41 path.addRect(SkRect::MakeXYWH(100.0, 100.0, 100.0, 100.0));
42 builder.DrawPath(path, paint);
43 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
47 DisplayListBuilder builder;
49 paint.setColor(DlColor::kRed());
51 builder.DrawImage(image, SkPoint::Make(100.0, 100.0),
52 DlImageSampling::kNearestNeighbor, &paint);
53 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
57 DisplayListBuilder builder;
59 paint.setColor(DlColor::kRed());
61 DlBlendColorFilter::Make(DlColor::kYellow(), DlBlendMode::kSrcOver));
62 paint.setInvertColors(
true);
65 builder.DrawImage(image, SkPoint::Make(100.0, 100.0),
66 DlImageSampling::kNearestNeighbor, &paint);
67 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
71 DisplayListBuilder builder;
73 paint.setColor(DlColor::kRed());
75 DlBlendColorFilter::Make(DlColor::kYellow(), DlBlendMode::kSrcOver));
76 paint.setInvertColors(
true);
78 builder.DrawRect(SkRect::MakeLTRB(0, 0, 100, 100), paint);
79 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
83 DisplayListBuilder builder;
85 paint.setColor(DlColor::kRed());
87 DlBlendColorFilter::Make(DlColor::kYellow(), DlBlendMode::kSrcOver));
88 paint.setInvertColors(
true);
90 builder.DrawPaint(paint);
91 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
95 bool GenerateMipmap(
const std::shared_ptr<Context>& context,
96 std::shared_ptr<Texture> texture,
98 auto buffer = context->CreateCommandBuffer();
102 auto pass = buffer->CreateBlitPass();
106 pass->GenerateMipmap(std::move(texture), std::move(label));
108 pass->EncodeCommands(context->GetResourceAllocator());
109 return context->GetCommandQueue()->Submit({buffer}).ok();
112 void CanRenderTiledTexture(
AiksTest* aiks_test,
113 DlTileMode tile_mode,
114 Matrix local_matrix = {}) {
115 auto context = aiks_test->GetContext();
116 ASSERT_TRUE(context);
117 auto texture = aiks_test->CreateTextureForFixture(
"table_mountain_nx.png",
119 GenerateMipmap(context, texture,
"table_mountain_nx");
121 SkMatrix sk_local_matrix =
ToSkMatrix(local_matrix);
122 DlImageColorSource color_source(image, tile_mode, tile_mode,
123 DlImageSampling::kNearestNeighbor,
126 DisplayListBuilder builder;
128 paint.setColor(DlColor::kWhite());
129 paint.setColorSource(&color_source);
131 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
132 builder.Translate(100.0f, 100.0f);
133 builder.DrawRect(SkRect::MakeXYWH(0, 0, 600, 600), paint);
137 paint.setDrawStyle(DlDrawStyle::kStroke);
139 if (tile_mode == DlTileMode::kDecal) {
143 builder.DrawRect(SkRect::MakeXYWH(0, 0, 600, 600), paint);
149 path.addCircle(150, 150, 150);
150 path.addRoundRect(SkRect::MakeLTRB(300, 300, 600, 600), 10, 10);
153 EXPECT_FALSE(path.isRect(
nullptr));
154 EXPECT_FALSE(path.isOval(
nullptr));
155 EXPECT_FALSE(path.isRRect(
nullptr));
158 EXPECT_FALSE(path.isConvex());
160 paint.setDrawStyle(DlDrawStyle::kFill);
161 builder.DrawPath(path, paint);
167 circle.addCircle(150, 450, 150);
170 EXPECT_TRUE(circle.isOval(
nullptr));
172 EXPECT_TRUE(circle.isConvex());
179 path.addPath(circle);
182 EXPECT_FALSE(path.isRect(
nullptr));
183 EXPECT_FALSE(path.isOval(
nullptr));
184 EXPECT_FALSE(path.isRRect(
nullptr));
187 EXPECT_TRUE(path.isConvex());
189 paint.setDrawStyle(DlDrawStyle::kFill);
190 builder.DrawPath(path, paint);
193 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(builder.Build()));
198 CanRenderTiledTexture(
this, DlTileMode::kClamp);
202 CanRenderTiledTexture(
this, DlTileMode::kRepeat);
206 CanRenderTiledTexture(
this, DlTileMode::kMirror);
210 CanRenderTiledTexture(
this, DlTileMode::kDecal);
214 CanRenderTiledTexture(
this, DlTileMode::kClamp,
219 DisplayListBuilder builder;
222 SkSize image_half_size = SkSize::Make(image->dimensions().fWidth * 0.5f,
223 image->dimensions().fHeight * 0.5f);
226 auto source_rect = SkRect::MakeSize(image_half_size);
228 source_rect.makeOffset(image_half_size.fWidth, image_half_size.fHeight);
230 builder.DrawImageRect(image, source_rect,
231 SkRect::MakeXYWH(100, 100, 600, 600),
232 DlImageSampling::kNearestNeighbor);
233 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
237 DisplayListBuilder builder;
238 builder.Scale(GetContentScale().x, GetContentScale().y);
241 paint.setColor(DlColor::kWhite());
242 builder.DrawPaint(paint);
244 auto draw = [&builder](
const DlPaint& paint,
Scalar x,
Scalar y) {
246 builder.Translate(x, y);
249 builder.ClipRect(SkRect::MakeLTRB(50, 50, 150, 150));
250 builder.DrawPaint(paint);
255 builder.ClipOval(SkRect::MakeLTRB(200, 50, 300, 150));
256 builder.DrawPaint(paint);
262 SkRRect::MakeRectXY(SkRect::MakeLTRB(50, 200, 150, 300), 20, 20));
263 builder.DrawPaint(paint);
269 SkRRect::MakeRectXY(SkRect::MakeLTRB(200, 230, 300, 270), 20, 20));
270 builder.DrawPaint(paint);
276 SkRRect::MakeRectXY(SkRect::MakeLTRB(230, 200, 270, 300), 20, 20));
277 builder.DrawPaint(paint);
283 paint.setColor(DlColor::kBlue());
286 DlColor gradient_colors[7] = {
287 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
288 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
289 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
290 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
291 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
292 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
293 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
304 auto texture = CreateTextureForFixture(
"airplane.jpg",
308 paint.setColorSource(DlColorSource::MakeRadial(
309 {500, 600}, 75, 7, gradient_colors, stops, DlTileMode::kMirror));
312 DlImageColorSource image_source(image, DlTileMode::kRepeat,
314 DlImageSampling::kNearestNeighbor);
315 paint.setColorSource(&image_source);
318 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
322 DisplayListBuilder builder;
325 red.setColor(DlColor::kRed());
328 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
330 builder.SaveLayer(
nullptr, &alpha);
332 builder.DrawCircle({125, 125}, 125, red);
336 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
340 DisplayListBuilder builder;
343 DlColor colors[2] = {
344 DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
345 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0),
352 paint.setColorSource(DlColorSource::MakeLinear(
362 builder.Translate(100, 100);
363 builder.DrawRect(SkRect::MakeXYWH(0, 0, 200, 200), paint);
367 builder.Translate(100, 400);
368 builder.DrawCircle({100, 100}, 100, paint);
370 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
374 DisplayListBuilder builder;
376 paint.setColor(DlColor::kRed());
379 SkVector radii[4] = {
385 rrect.setRectRadii(SkRect::MakeXYWH(100, 100, 500, 500), radii);
387 builder.DrawRRect(rrect, paint);
389 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
393 auto medium_turquoise =
394 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
396 DisplayListBuilder builder;
397 builder.Scale(0.2, 0.2);
398 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
399 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
403 auto medium_turquoise =
404 DlColor::RGBA(72.0f / 255.0f, 209.0f / 255.0f, 204.0f / 255.0f, 1.0f);
406 DlColor::RGBA(255.0f / 255.0f, 69.0f / 255.0f, 0.0f / 255.0f, 1.0f);
408 DisplayListBuilder builder;
409 builder.Scale(0.2, 0.2);
410 builder.DrawPaint(DlPaint().setColor(medium_turquoise));
411 builder.DrawPaint(DlPaint().setColor(orange_red.modulateOpacity(0.5f)));
412 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
416 DisplayListBuilder builder;
417 builder.Scale(GetContentScale().x, GetContentScale().y);
419 const int color_count = 3;
420 DlColor colors[color_count] = {
423 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
426 paint.setColor(DlColor::kWhite());
427 builder.DrawPaint(paint);
432 paint.setColor(colors[(c_index++) % color_count]);
433 builder.DrawCircle({10, 10}, radius, paint);
441 DlColor gradient_colors[7] = {
442 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
443 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
444 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
445 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
446 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
447 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
448 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
459 auto texture = CreateTextureForFixture(
"airplane.jpg",
463 paint.setColorSource(DlColorSource::MakeRadial(
464 {500, 600}, 75, 7, gradient_colors, stops, DlTileMode::kMirror));
465 builder.DrawCircle({500, 600}, 100, paint);
467 SkMatrix local_matrix = SkMatrix::Translate(700, 200);
468 DlImageColorSource image_source(
469 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
470 DlImageSampling::kNearestNeighbor, &local_matrix);
471 paint.setColorSource(&image_source);
472 builder.DrawCircle({800, 300}, 100, paint);
474 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
478 DisplayListBuilder builder;
479 builder.Scale(GetContentScale().x, GetContentScale().y);
481 const int color_count = 3;
482 DlColor colors[color_count] = {
485 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
488 paint.setColor(DlColor::kWhite());
489 builder.DrawPaint(paint);
493 auto draw = [&paint, &colors, &c_index](DlCanvas& canvas, SkPoint center,
495 for (
int i = 0; i < n; i++) {
496 paint.setColor(colors[(c_index++) % color_count]);
497 canvas.DrawCircle(center, r, paint);
502 paint.setDrawStyle(DlDrawStyle::kStroke);
503 paint.setStrokeWidth(1);
504 draw(builder, {10, 10}, 2, 2, 14);
505 paint.setStrokeWidth(5);
506 draw(builder, {10, 10}, 35, 10, 56);
508 DlColor gradient_colors[7] = {
509 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
510 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
511 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
512 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
513 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
514 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
515 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
526 auto texture = CreateTextureForFixture(
"airplane.jpg",
530 paint.setColorSource(DlColorSource::MakeRadial(
531 {500, 600}, 75, 7, gradient_colors, stops, DlTileMode::kMirror));
532 draw(builder, {500, 600}, 5, 10, 10);
534 SkMatrix local_matrix = SkMatrix::Translate(700, 200);
535 DlImageColorSource image_source(
536 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
537 DlImageSampling::kNearestNeighbor, &local_matrix);
538 paint.setColorSource(&image_source);
539 draw(builder, {800, 300}, 5, 10, 10);
541 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
545 DisplayListBuilder builder;
546 builder.Scale(GetContentScale().x, GetContentScale().y);
548 const int color_count = 3;
549 DlColor colors[color_count] = {
552 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
555 paint.setColor(DlColor::kWhite());
556 builder.DrawPaint(paint);
559 int long_radius = 600;
560 int short_radius = 600;
561 while (long_radius > 0 && short_radius > 0) {
562 paint.setColor(colors[(c_index++) % color_count]);
563 builder.DrawOval(SkRect::MakeXYWH(10 - long_radius, 10 - short_radius,
564 long_radius * 2, short_radius * 2),
566 builder.DrawOval(SkRect::MakeXYWH(1000 - short_radius, 750 - long_radius,
567 short_radius * 2, long_radius * 2),
569 if (short_radius > 30) {
578 DlColor gradient_colors[7] = {
579 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
580 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
581 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
582 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
583 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
584 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
585 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
596 auto texture = CreateTextureForFixture(
"airplane.jpg",
600 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
602 paint.setColorSource(DlColorSource::MakeRadial(
603 {300, 650}, 75, 7, gradient_colors, stops, DlTileMode::kMirror));
604 builder.DrawOval(SkRect::MakeXYWH(200, 625, 200, 50), paint);
605 builder.DrawOval(SkRect::MakeXYWH(275, 550, 50, 200), paint);
607 SkMatrix local_matrix = SkMatrix::Translate(610, 15);
608 DlImageColorSource image_source(
609 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
610 DlImageSampling::kNearestNeighbor, &local_matrix);
611 paint.setColorSource(&image_source);
612 builder.DrawOval(SkRect::MakeXYWH(610, 90, 200, 50), paint);
613 builder.DrawOval(SkRect::MakeXYWH(685, 15, 50, 200), paint);
615 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
619 DisplayListBuilder builder;
620 builder.Scale(GetContentScale().x, GetContentScale().y);
622 const int color_count = 3;
623 DlColor colors[color_count] = {
626 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f),
629 paint.setColor(DlColor::kWhite());
630 builder.DrawPaint(paint);
633 for (
int i = 0; i < 4; i++) {
634 for (
int j = 0; j < 4; j++) {
635 paint.setColor(colors[(c_index++) % color_count]);
638 SkRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
639 i * 5 + 10, j * 5 + 10),
643 paint.setColor(colors[(c_index++) % color_count]);
645 SkRRect::MakeRectXY(SkRect::MakeXYWH(10, 420, 380, 80), 40, 40), paint);
646 paint.setColor(colors[(c_index++) % color_count]);
648 SkRRect::MakeRectXY(SkRect::MakeXYWH(410, 20, 80, 380), 40, 40), paint);
650 DlColor gradient_colors[7] = {
651 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
652 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
653 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
654 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
655 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
656 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
657 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0),
668 auto texture = CreateTextureForFixture(
"airplane.jpg",
672 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
673 paint.setColorSource(DlColorSource::MakeRadial(
674 {550, 550}, 75, 7, gradient_colors, stops, DlTileMode::kMirror));
675 for (
int i = 1; i <= 10; i++) {
678 SkRRect::MakeRectXY(SkRect::MakeLTRB(550 - i * 20, 550 - j * 20,
679 550 + i * 20, 550 + j * 20),
684 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
685 paint.setColorSource(DlColorSource::MakeRadial(
686 {200, 650}, 75, 7, gradient_colors, stops, DlTileMode::kMirror));
687 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
689 SkRRect::MakeRectXY(SkRect::MakeLTRB(100, 610, 300, 690), 40, 40), paint);
691 SkRRect::MakeRectXY(SkRect::MakeLTRB(160, 550, 240, 750), 40, 40), paint);
693 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
694 SkMatrix local_matrix = SkMatrix::Translate(520, 20);
695 DlImageColorSource image_source(
696 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
697 DlImageSampling::kNearestNeighbor, &local_matrix);
698 paint.setColorSource(&image_source);
699 for (
int i = 1; i <= 10; i++) {
702 SkRRect::MakeRectXY(SkRect::MakeLTRB(720 - i * 20, 220 - j * 20,
703 720 + i * 20, 220 + j * 20),
708 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
709 local_matrix = SkMatrix::Translate(800, 300);
710 DlImageColorSource image_source2(
711 image, DlTileMode::kRepeat, DlTileMode::kRepeat,
712 DlImageSampling::kNearestNeighbor, &local_matrix);
713 paint.setColorSource(&image_source2);
715 SkRRect::MakeRectXY(SkRect::MakeLTRB(800, 410, 1000, 490), 40, 40),
718 SkRRect::MakeRectXY(SkRect::MakeLTRB(860, 350, 940, 550), 40, 40), paint);
720 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
724 DisplayListBuilder builder;
725 builder.Scale(GetContentScale().x, GetContentScale().y);
727 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1.0f));
729 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
732 DlColor::RGBA(220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f, 1.0f));
734 for (
int i = 0; i < 5; i++) {
736 Scalar radius = x / 10.0f;
737 builder.DrawRect(SkRect::MakeXYWH(x + 25 - radius / 2, y + radius / 2,
738 radius, 60.0f - radius),
742 paint.setColor(DlColor::kBlue());
744 for (
int i = 0; i < 5; i++) {
746 Scalar radius = x / 10.0f;
747 builder.DrawCircle({x + 25, y + 25}, radius, paint);
750 paint.setColor(DlColor::kGreen());
752 for (
int i = 0; i < 5; i++) {
754 Scalar radius = x / 10.0f;
755 builder.DrawOval(SkRect::MakeXYWH(x + 25 - radius / 2, y + radius / 2,
756 radius, 60.0f - radius),
761 DlColor::RGBA(128.0f / 255.0f, 0.0f / 255.0f, 128.0f / 255.0f, 1.0f));
763 for (
int i = 0; i < 5; i++) {
765 Scalar radius = x / 20.0f;
766 builder.DrawRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(x, y, 60.0f, 60.0f),
772 DlColor::RGBA(255.0f / 255.0f, 165.0f / 255.0f, 0.0f / 255.0f, 1.0f));
774 for (
int i = 0; i < 5; i++) {
776 Scalar radius = x / 20.0f;
778 SkRRect::MakeRectXY(SkRect::MakeXYWH(x, y, 60.0f, 60.0f), radius, 5.0f),
782 auto dl = builder.Build();
783 ASSERT_TRUE(OpenPlaygroundHere(dl));
787 DisplayListBuilder builder;
789 builder.Scale(GetContentScale().x, GetContentScale().y);
792 std::vector<DlColor> colors = {DlColor::RGBA(0.9568, 0.2627, 0.2118, 1.0),
793 DlColor::RGBA(0.1294, 0.5882, 0.9529, 1.0)};
794 std::vector<Scalar> stops = {
799 paint.setColorSource(DlColorSource::MakeLinear(
808 builder.DrawPaint(paint);
810 SkRect clip_rect = SkRect::MakeLTRB(50, 50, 400, 300);
811 SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 100, 100);
815 builder.ClipRRect(clip_rrect, DlCanvas::ClipOp::kIntersect);
818 auto backdrop_filter = std::make_shared<DlColorFilterImageFilter>(
819 DlBlendColorFilter::Make(DlColor::kRed(), DlBlendMode::kExclusion));
820 builder.SaveLayer(&clip_rect, &save_paint, backdrop_filter.get());
822 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
828 auto callback = [&]() -> sk_sp<DisplayList> {
829 DisplayListBuilder builder;
833 builder.Translate(300, 300);
840 paint.setColor(DlColor::kGreen());
841 builder.DrawPaint(paint);
842 builder.ClipRect(SkRect::MakeLTRB(-180, -180, 180, 180),
843 DlCanvas::ClipOp::kDifference);
845 paint.setColor(DlColor::kBlack());
846 builder.DrawPaint(paint);
854 builder.ClipOval(SkRect::MakeLTRB(-200, -200, 200, 200));
857 Matrix(1.0, 0.0, 0.0, 0.0,
859 0.0, 0.0, 1.0, 0.003,
860 0.0, 0.0, 0.0, 1.0) *
864 builder.
Transform(FromImpellerMatrix(result));
868 auto position = -SkPoint::Make(image->dimensions().fWidth,
869 image->dimensions().fHeight) *
871 builder.DrawImage(image, position, {});
877 paint.setColor(DlColor::kBlue().modulateOpacity(0.4));
878 builder.DrawCircle({}, 230, paint);
882 return builder.Build();
884 ASSERT_TRUE(OpenPlaygroundHere(callback));
890 DisplayListBuilder builder;
894 paint.setColor(DlColor::kWhite());
895 builder.DrawPaint(paint);
899 SkMatrix matrix = SkMatrix::Translate(50, 50);
901 paint.setColorSource(std::make_shared<DlImageColorSource>(
902 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
903 DlImageSampling::kNearestNeighbor, &matrix));
905 builder.DrawRect(SkRect::MakeLTRB(0, 0, 100, 100), paint);
914 Matrix impeller_matrix(1, -1, 0, 0,
918 SkMatrix matrix = SkM44::ColMajor(impeller_matrix.
m).asM33();
919 paint.setColorSource(std::make_shared<DlImageColorSource>(
920 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
921 DlImageSampling::kNearestNeighbor, &matrix));
922 builder.DrawRect(SkRect::MakeLTRB(100, 0, 200, 100), paint);
928 builder.Translate(100, 0);
929 builder.Scale(100, 100);
932 SkMatrix matrix = SkMatrix::Scale(0.005, 0.005);
933 paint.setColorSource(std::make_shared<DlImageColorSource>(
934 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
935 DlImageSampling::kNearestNeighbor, &matrix));
937 builder.DrawRect(SkRect::MakeLTRB(0, 0, 1, 1), paint);
940 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
944 DisplayListBuilder builder;
949 paint.setColor(DlColor::kBlue().modulateOpacity(0.5));
950 paint.setBlendMode(DlBlendMode::kSrc);
952 SkRect bounds = SkRect::MakeLTRB(0, 0, 200, 200);
953 builder.SaveLayer(&bounds, &paint);
955 paint.setColor(DlColor::kTransparent());
956 paint.setBlendMode(DlBlendMode::kSrc);
957 builder.DrawPaint(paint);
960 paint.setColor(DlColor::kBlue());
961 paint.setBlendMode(DlBlendMode::kDstOver);
962 builder.SaveLayer(
nullptr, &paint);
968 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
973 DisplayListBuilder builder;
974 builder.Scale(GetContentScale().x, GetContentScale().y);
975 builder.Translate(100, 100);
979 SkMatrix translate = SkMatrix::Translate(300, 0);
980 paint.setImageFilter(
981 DlMatrixImageFilter::Make(translate, DlImageSampling::kLinear));
982 builder.SaveLayer(
nullptr, &paint);
984 DlPaint circle_paint;
985 circle_paint.setColor(DlColor::kGreen());
986 builder.DrawCircle({-300, 0}, 100, circle_paint);
989 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
994 MatrixImageFilterDoesntCullWhenScaledAndTranslatedFromOffscreen) {
995 DisplayListBuilder builder;
996 builder.Scale(GetContentScale().x, GetContentScale().y);
997 builder.Translate(100, 100);
1002 paint.setImageFilter(DlMatrixImageFilter::Make(
1003 SkMatrix::Translate(300, 0) * SkMatrix::Scale(2, 2),
1004 DlImageSampling::kNearestNeighbor));
1005 builder.SaveLayer(
nullptr, &paint);
1007 DlPaint circle_paint;
1008 circle_paint.setColor(DlColor::kGreen());
1009 builder.DrawCircle({-150, 0}, 50, circle_paint);
1012 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1017 SetWindowSize({400, 400});
1018 DisplayListBuilder builder;
1020 builder.Scale(GetContentScale().x, GetContentScale().y);
1023 paint.setColor(DlColor::kRed());
1024 builder.DrawRect(SkRect::MakeLTRB(200, 200, 300, 300), paint);
1026 paint.setImageFilter(DlMatrixImageFilter::Make(SkMatrix::Scale(2, 2),
1027 DlImageSampling::kLinear));
1028 builder.SaveLayer(
nullptr, &paint);
1031 paint.setColor(DlColor::kGreen());
1032 builder.DrawRect(SkRect::MakeLTRB(0, 0, 400, 400), paint);
1035 paint.setColor(DlColor::kRed());
1036 builder.DrawRect(SkRect::MakeLTRB(0, 0, 800, 800), paint);
1039 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1043 DisplayListBuilder builder;
1044 builder.Scale(GetContentScale().x, GetContentScale().y);
1047 paint.setColor(DlColor::kRed());
1048 builder.DrawPaint(paint);
1049 builder.ClipRect(SkRect::MakeXYWH(100, 100, 200, 200));
1050 paint.setColor(DlColor::kBlue());
1051 builder.SaveLayer(
nullptr, &paint);
1054 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1058 DisplayListBuilder builder;
1059 builder.Scale(GetContentScale().x, GetContentScale().y);
1061 builder.DrawImage(image, {10, 10}, {});
1062 builder.ClipRect(SkRect::MakeXYWH(100, 100, 200, 200));
1065 paint.setBlendMode(DlBlendMode::kClear);
1066 builder.SaveLayer(
nullptr, &paint);
1069 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1073 CanPerformSaveLayerWithBoundsAndLargerIntermediateIsNotAllocated) {
1074 DisplayListBuilder builder;
1077 red.setColor(DlColor::kRed());
1080 green.setColor(DlColor::kGreen());
1083 blue.setColor(DlColor::kBlue());
1086 save.setColor(DlColor::kBlack().modulateOpacity(0.5));
1088 SkRect huge_bounds = SkRect::MakeXYWH(0, 0, 100000, 100000);
1089 builder.SaveLayer(&huge_bounds, &save);
1091 builder.DrawRect(SkRect::MakeXYWH(0, 0, 100, 100), red);
1092 builder.DrawRect(SkRect::MakeXYWH(10, 10, 100, 100), green);
1093 builder.DrawRect(SkRect::MakeXYWH(20, 20, 100, 100), blue);
1097 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1102 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1108 GetContext()->GetCapabilities()->GetDefaultColorFormat();
1115 DisplayListBuilder builder;
1122 builder.Translate(100, 200);
1123 builder.Scale(0.5, 0.5);
1124 builder.DrawImage(image, SkPoint::Make(100.0, 100.0),
1125 DlImageSampling::kNearestNeighbor);
1132 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1134 builder.SaveLayer(
nullptr, &alpha);
1137 paint.setColor(DlColor::kRed());
1138 builder.DrawRect(SkRect::MakeXYWH(000, 000, 100, 100), paint);
1139 paint.setColor(DlColor::kGreen());
1140 builder.DrawRect(SkRect::MakeXYWH(020, 020, 100, 100), paint);
1141 paint.setColor(DlColor::kBlue());
1142 builder.DrawRect(SkRect::MakeXYWH(040, 040, 100, 100), paint);
1147 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1151 DisplayListBuilder builder;
1154 paint.setColor(DlColor::kRed());
1155 builder.DrawCircle(SkPoint::Make(250, 250), 125, paint);
1157 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1161 DisplayListBuilder builder;
1164 red.setColor(DlColor::kRed());
1166 builder.DrawRect(SkRect::MakeXYWH(0, 0, 100, 100), red);
1168 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1172 DisplayListBuilder builder;
1175 save.setColor(DlColor::kBlack());
1177 SkRect save_bounds = SkRect::MakeXYWH(0, 0, 50, 50);
1178 builder.SaveLayer(&save_bounds, &save);
1181 paint.setColor(DlColor::kRed());
1182 builder.DrawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
1183 paint.setColor(DlColor::kGreen());
1184 builder.DrawRect(SkRect::MakeXYWH(10, 10, 100, 100), paint);
1185 paint.setColor(DlColor::kBlue());
1186 builder.DrawRect(SkRect::MakeXYWH(20, 20, 100, 100), paint);
1190 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1194 DisplayListBuilder builder;
1195 builder.Scale(GetContentScale().x, GetContentScale().y);
1198 const int color_count = 3;
1199 DlColor colors[color_count] = {
1202 DlColor::ARGB(1.0, 220.0f / 255.0f, 20.0f / 255.0f, 60.0f / 255.0f),
1205 paint.setColor(DlColor::kWhite());
1206 builder.DrawPaint(paint);
1208 auto draw_rrect_as_path = [&builder](
const SkRect& rect,
Scalar x,
Scalar y,
1209 const DlPaint& paint) {
1211 path.addRoundRect(rect, x, y);
1212 builder.DrawPath(path, paint);
1216 for (
int i = 0; i < 4; i++) {
1217 for (
int j = 0; j < 4; j++) {
1218 paint.setColor(colors[(c_index++) % color_count]);
1219 draw_rrect_as_path(SkRect::MakeXYWH(i * 100 + 10, j * 100 + 20, 80, 80),
1220 i * 5 + 10, j * 5 + 10, paint);
1223 paint.setColor(colors[(c_index++) % color_count]);
1224 draw_rrect_as_path(SkRect::MakeXYWH(10, 420, 380, 80), 40, 40, paint);
1225 paint.setColor(colors[(c_index++) % color_count]);
1226 draw_rrect_as_path(SkRect::MakeXYWH(410, 20, 80, 380), 40, 40, paint);
1228 std::vector<DlColor> gradient_colors = {
1229 DlColor::RGBA(0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0),
1230 DlColor::RGBA(0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0),
1231 DlColor::RGBA(0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0),
1232 DlColor::RGBA(0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0),
1233 DlColor::RGBA(0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0),
1234 DlColor::RGBA(0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0),
1235 DlColor::RGBA(0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0)};
1236 std::vector<Scalar> stops = {
1246 CreateTextureForFixture(
"airplane.jpg",
1249 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1250 paint.setColorSource(DlColorSource::MakeRadial(
1253 gradient_colors.size(),
1254 gradient_colors.data(),
1256 DlTileMode::kMirror));
1257 for (
int i = 1; i <= 10; i++) {
1259 draw_rrect_as_path(SkRect::MakeLTRB(550 - i * 20, 550 - j * 20,
1260 550 + i * 20, 550 + j * 20),
1261 i * 10, j * 10, paint);
1263 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1264 paint.setColorSource(DlColorSource::MakeRadial(
1267 gradient_colors.size(),
1268 gradient_colors.data(),
1270 DlTileMode::kMirror));
1271 draw_rrect_as_path(SkRect::MakeLTRB(100, 610, 300, 690), 40, 40, paint);
1272 draw_rrect_as_path(SkRect::MakeLTRB(160, 550, 240, 750), 40, 40, paint);
1274 auto matrix = SkMatrix::Translate(520, 20);
1275 paint.setColor(DlColor::kWhite().modulateOpacity(0.1));
1276 paint.setColorSource(std::make_shared<DlImageColorSource>(
1277 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1278 DlImageSampling::kMipmapLinear, &matrix));
1279 for (
int i = 1; i <= 10; i++) {
1281 draw_rrect_as_path(SkRect::MakeLTRB(720 - i * 20, 220 - j * 20,
1282 720 + i * 20, 220 + j * 20),
1283 i * 10, j * 10, paint);
1285 matrix = SkMatrix::Translate(800, 300);
1286 paint.setColor(DlColor::kWhite().modulateOpacity(0.5));
1287 paint.setColorSource(std::make_shared<DlImageColorSource>(
1288 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
1289 DlImageSampling::kMipmapLinear, &matrix));
1291 draw_rrect_as_path(SkRect::MakeLTRB(800, 410, 1000, 490), 40, 40, paint);
1292 draw_rrect_as_path(SkRect::MakeLTRB(860, 350, 940, 550), 40, 40, paint);
1294 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1298 auto callback = [&]() -> sk_sp<DisplayList> {
1299 DisplayListBuilder builder;
1300 builder.Scale(GetContentScale().x, GetContentScale().y);
1303 alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
1305 auto current =
Point{25, 25};
1307 const auto size =
Size(100, 100);
1312 SkRect bounds = SkRect::MakeLTRB(b0.x, b0.y, b1.x, b1.y);
1314 DlPaint stroke_paint;
1315 stroke_paint.setColor(DlColor::kYellow());
1316 stroke_paint.setStrokeWidth(5);
1317 stroke_paint.setDrawStyle(DlDrawStyle::kStroke);
1318 builder.DrawRect(bounds, stroke_paint);
1320 builder.SaveLayer(&bounds, &alpha);
1323 paint.setColor(DlColor::kRed());
1325 SkRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1327 paint.setColor(DlColor::kGreen());
1330 SkRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1332 paint.setColor(DlColor::kBlue());
1335 SkRect::MakeXYWH(current.x, current.y, size.width, size.height), paint);
1339 return builder.Build();
1342 ASSERT_TRUE(OpenPlaygroundHere(callback));
1347 DisplayListBuilder builder;
1350 paint.setColor(DlColor::kBlack());
1351 SkRect rect = SkRect::MakeXYWH(25, 25, 25, 25);
1352 builder.DrawRect(rect, paint);
1354 builder.Translate(10, 10);
1357 builder.SaveLayer(
nullptr, &save_paint);
1359 paint.setColor(DlColor::kGreen());
1360 builder.DrawRect(rect, paint);
1364 builder.Translate(10, 10);
1365 paint.setColor(DlColor::kRed());
1366 builder.DrawRect(rect, paint);
1368 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1372 DisplayListBuilder builder;
1374 SkRect rect = SkRect::MakeXYWH(0, 0, 1000, 1000);
1379 SkRect bounds = SkRect::MakeXYWH(25, 25, 25, 25);
1380 builder.SaveLayer(&bounds, &save_paint);
1381 paint.setColor(DlColor::kBlack());
1382 builder.DrawRect(rect, paint);
1388 SkRect bounds = SkRect::MakeXYWH(35, 35, 25, 25);
1389 builder.SaveLayer(&bounds, &save_paint);
1390 paint.setColor(DlColor::kGreen());
1391 builder.DrawRect(rect, paint);
1397 SkRect bounds = SkRect::MakeXYWH(45, 45, 25, 25);
1398 builder.SaveLayer(&bounds, &save_paint);
1399 paint.setColor(DlColor::kRed());
1400 builder.DrawRect(rect, paint);
1404 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1408 DisplayListBuilder builder;
1411 paint.setColor(DlColor::kWhite());
1412 builder.DrawPaint(paint);
1417 SkPath path = SkPath::Circle(100, 100, 50);
1418 builder.ClipPath(path);
1420 SkRect bounds = SkRect::MakeXYWH(50, 50, 100, 100);
1422 builder.SaveLayer(&bounds, &save_paint);
1425 paint.setColor(DlColor::kWhite());
1426 builder.DrawRect(SkRect::MakeSize(SkSize{400, 400}), paint);
1429 paint.setColor(DlColor::kGreen());
1430 paint.setBlendMode(DlBlendMode::kHardLight);
1431 builder.DrawRect(SkRect::MakeSize(SkSize{400, 400}), paint);
1434 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1438 DisplayListBuilder builder;
1440 builder.Scale(GetContentScale().x, GetContentScale().y);
1441 builder.Translate(100, 100);
1444 auto draw_image_layer = [&builder, &texture](
const DlPaint& paint) {
1445 builder.SaveLayer(
nullptr, &paint);
1446 builder.DrawImage(texture, {}, DlImageSampling::kLinear);
1450 DlPaint effect_paint;
1451 effect_paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 6));
1452 draw_image_layer(effect_paint);
1454 builder.Translate(300, 300);
1455 builder.Scale(3, 3);
1456 draw_image_layer(effect_paint);
1458 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1462 DisplayListBuilder builder;
1464 builder.Scale(GetContentScale().x, GetContentScale().y);
1466 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 1));
1469 save_paint.setColor(DlColor::kWhite());
1470 builder.DrawPaint(save_paint);
1472 paint.setColor(DlColor::kBlue());
1473 for (
int i = 0; i < 5; i++) {
1475 Scalar y_radius = i * 15;
1476 for (
int j = 0; j < 5; j++) {
1478 Scalar x_radius = j * 15;
1480 SkRRect::MakeRectXY(SkRect::MakeXYWH(x + 50, y + 50, 100.0f, 100.0f),
1481 x_radius, y_radius),
1486 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1490 DisplayListBuilder builder;
1494 builder.SaveLayer(
nullptr, &paint);
1496 builder.Translate(100, 100);
1497 paint.setColor(DlColor::kBlue());
1498 builder.DrawCircle(SkPoint::Make(200, 200), 200, paint);
1499 builder.ClipRect(SkRect::MakeXYWH(100, 100, 200, 200));
1501 paint.setColor(DlColor::kGreen());
1502 paint.setBlendMode(DlBlendMode::kSrcOver);
1503 paint.setImageFilter(DlColorFilterImageFilter::Make(
1504 DlBlendColorFilter::Make(DlColor::kWhite(), DlBlendMode::kDst)));
1505 builder.DrawCircle(SkPoint::Make(200, 200), 200, paint);
1509 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1517 GTEST_SKIP() <<
"Swiftshader is running out of memory on this example.";
1519 DisplayListBuilder builder(SkRect::MakeSize(SkSize::Make(1000, 1000)));
1521 auto filter = DlMatrixImageFilter::Make(SkMatrix::Scale(0.001, 0.001),
1522 DlImageSampling::kLinear);
1525 paint.setImageFilter(filter);
1526 builder.SaveLayer(
nullptr, &paint);
1529 paint.setColor(DlColor::kRed());
1530 builder.DrawRect(SkRect::MakeLTRB(0, 0, 100000, 100000), paint);
1534 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));