5 #include "display_list/dl_sampling_options.h"
6 #include "display_list/dl_tile_mode.h"
7 #include "display_list/effects/dl_color_source.h"
8 #include "display_list/effects/dl_mask_filter.h"
11 #include "flutter/display_list/dl_blend_mode.h"
12 #include "flutter/display_list/dl_builder.h"
13 #include "flutter/display_list/dl_color.h"
14 #include "flutter/display_list/dl_paint.h"
15 #include "flutter/display_list/effects/dl_color_filter.h"
16 #include "flutter/testing/testing.h"
20 #include "include/core/SkMatrix.h"
21 #include "include/core/SkPath.h"
22 #include "include/core/SkPathTypes.h"
23 #include "include/core/SkRRect.h"
31 DisplayListBuilder builder;
32 builder.Transform(SkMatrix::Translate(300, 300) * SkMatrix::RotateDeg(90));
37 arrow_stem.moveTo({120, 190}).lineTo({120, 50});
38 arrow_head.moveTo({50, 120}).lineTo({120, 190}).lineTo({190, 120});
41 DlBlendColorFilter::Make(DlColor::kAliceBlue(), DlBlendMode::kSrcIn);
44 paint.setStrokeWidth(15.0);
45 paint.setStrokeCap(DlStrokeCap::kRound);
46 paint.setStrokeJoin(DlStrokeJoin::kRound);
47 paint.setDrawStyle(DlDrawStyle::kStroke);
48 paint.setColorFilter(filter);
49 paint.setColor(DlColor::kBlack());
51 builder.DrawPath(arrow_stem, paint);
52 builder.DrawPath(arrow_head, paint);
54 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
58 DisplayListBuilder builder;
60 paint.setColor(DlColor::kRed());
61 paint.setStrokeWidth(20);
62 paint.setDrawStyle(DlDrawStyle::kStroke);
64 builder.DrawPath(SkPath::Line({200, 100}, {800, 100}), paint);
66 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
70 DisplayListBuilder builder;
72 paint.setColor(DlColor::kRed());
73 paint.setStrokeWidth(25);
74 paint.setDrawStyle(DlDrawStyle::kStroke);
76 builder.DrawPath(SkPath::Circle(500, 500, 250), paint);
78 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
82 DisplayListBuilder builder;
84 paint.setColor(DlColor::kRed());
85 paint.setStrokeWidth(100);
86 paint.setDrawStyle(DlDrawStyle::kStroke);
88 builder.DrawPath(SkPath::Circle(100, 100, 50), paint);
90 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
94 DisplayListBuilder builder;
96 paint.setColor(DlColor::kRed());
97 paint.setStrokeWidth(0.01);
98 paint.setDrawStyle(DlDrawStyle::kStroke);
100 builder.DrawPath(SkPath::Circle(100, 100, 50), paint);
102 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
106 DisplayListBuilder builder;
108 paint.setColor(DlColor::kRed());
109 paint.setStrokeWidth(200);
110 paint.setDrawStyle(DlDrawStyle::kStroke);
113 path.arcTo(SkRect::MakeXYWH(100, 100, 200, 200), 0, 90,
false);
115 builder.DrawPath(path, paint);
117 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
121 DisplayListBuilder builder;
124 paint.setColor(DlColor::kRed());
125 paint.setStrokeWidth(20);
126 paint.setDrawStyle(DlDrawStyle::kStroke);
130 path.cubicTo(50, 400, 350, 0, 400, 200);
132 builder.DrawPath(path, paint);
133 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
137 DisplayListBuilder builder;
140 paint.setColor(DlColor::kRed());
141 paint.setStrokeWidth(50);
142 paint.setDrawStyle(DlDrawStyle::kStroke);
143 paint.setStrokeCap(DlStrokeCap::kRound);
148 path.moveTo(250, 250);
149 path.quadTo(100, 100, 250, 250);
151 builder.DrawPath(path, paint);
153 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
157 DisplayListBuilder builder;
160 paint.setColor(DlColor::kRed());
162 SkPoint radii[4] = {{50, 25}, {25, 50}, {50, 25}, {25, 50}};
165 rrect.setRectRadii(SkRect::MakeXYWH(100, 100, 200, 200), radii);
166 path.addRRect(rrect);
167 path.addCircle(200, 200, 50);
168 path.setFillType(SkPathFillType::kEvenOdd);
173 builder.DrawPath(path, paint);
175 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
182 DisplayListBuilder builder;
190 path.lineTo(50, 100);
191 path.lineTo(100, 100);
192 path.lineTo(100, 50);
195 paint.setColor(DlColor::kRed());
196 paint.setDrawStyle(DlDrawStyle::kStroke);
197 paint.setStrokeWidth(10);
199 builder.DrawPath(path, paint);
201 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
205 DisplayListBuilder builder;
212 path.lineTo(520, 120);
213 path.lineTo(300, 310);
214 path.lineTo(100, 50);
218 paint.setColor(DlColor::kRed());
219 paint.setDrawStyle(DlDrawStyle::kStroke);
220 paint.setStrokeWidth(10);
222 builder.DrawPath(path, paint);
224 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
229 auto callback = [&]() -> sk_sp<DisplayList> {
231 static float scale = 3;
232 static bool add_circle_clip =
true;
235 ImGuiWindowFlags_AlwaysAutoResize)) {
236 ImGui::ColorEdit4(
"Color",
reinterpret_cast<float*
>(&
color));
237 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
238 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
242 DisplayListBuilder builder;
243 builder.Scale(GetContentScale().x, GetContentScale().y);
246 paint.setColor(DlColor::kWhite());
247 builder.DrawPaint(paint);
251 paint.setDrawStyle(DlDrawStyle::kStroke);
252 paint.setStrokeWidth(10);
255 path.moveTo({20, 20});
256 path.quadTo({60, 20}, {60, 60});
258 path.moveTo({60, 20});
259 path.quadTo({60, 60}, {20, 60});
263 if (add_circle_clip) {
268 auto [handle_a, handle_b] =
271 SkMatrix screen_to_canvas = SkMatrix::I();
272 if (!builder.GetTransform().invert(&screen_to_canvas)) {
277 screen_to_canvas.mapPoint(SkPoint::Make(handle_a.x, handle_a.y));
279 screen_to_canvas.mapPoint(SkPoint::Make(handle_b.x, handle_b.y));
281 SkPoint middle = point_a + point_b;
282 middle.scale(GetContentScale().x / 2);
284 auto radius = SkPoint::Distance(point_a, middle);
286 builder.ClipPath(SkPath::Circle(middle.x(), middle.y(), radius));
290 {DlStrokeJoin::kBevel, DlStrokeJoin::kRound, DlStrokeJoin::kMiter}) {
291 paint.setStrokeJoin(join);
293 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
294 paint.setStrokeCap(cap);
295 builder.DrawPath(path, paint);
296 builder.Translate(80, 0);
298 builder.Translate(-240, 60);
301 return builder.Build();
304 ASSERT_TRUE(OpenPlaygroundHere(callback));
308 DisplayListBuilder builder;
309 builder.Scale(GetContentScale().x, GetContentScale().y);
312 paint.setColor(DlColor::kBlue());
313 paint.setStrokeWidth(10);
315 auto draw = [&builder](DlPaint& paint) {
317 {DlStrokeCap::kButt, DlStrokeCap::kSquare, DlStrokeCap::kRound}) {
318 paint.setStrokeCap(cap);
319 SkPoint origin = {100, 100};
320 builder.DrawLine({150, 100}, {250, 100}, paint);
321 for (
int d = 15; d < 90; d += 15) {
323 Point origin = {100, 100};
326 auto a = origin + m * p0;
327 auto b = origin + m * p1;
329 builder.DrawLine(SkPoint::Make(a.x, a.y), SkPoint::Make(
b.x,
b.y),
332 builder.DrawLine({100, 150}, {100, 250}, paint);
333 builder.DrawCircle({origin}, 35, paint);
335 builder.DrawLine({250, 250}, {250, 250}, paint);
337 builder.Translate(250, 0);
339 builder.Translate(-750, 250);
342 std::vector<DlColor> colors = {
343 DlColor::ARGB(1, 0x1f / 255.0, 0.0, 0x5c / 255.0),
344 DlColor::ARGB(1, 0x5b / 255.0, 0.0, 0x60 / 255.0),
345 DlColor::ARGB(1, 0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0),
346 DlColor::ARGB(1, 0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0),
347 DlColor::ARGB(1, 0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0),
348 DlColor::ARGB(1, 0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0),
349 DlColor::ARGB(1, 0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0)};
350 std::vector<Scalar> stops = {
361 CreateTextureForFixture(
"airplane.jpg",
366 paint.setColorSource(DlColorSource::MakeRadial({100, 100}, 200, stops.size(),
367 colors.data(), stops.data(),
368 DlTileMode::kMirror));
371 SkMatrix matrix = SkMatrix::Translate(-150, 75);
372 paint.setColorSource(std::make_shared<DlImageColorSource>(
373 texture, DlTileMode::kRepeat, DlTileMode::kRepeat,
374 DlImageSampling::kMipmapLinear, &matrix));
377 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
381 DisplayListBuilder builder;
383 paint.setColor(DlColor::kRed());
384 paint.setDrawStyle(DlDrawStyle::kStroke);
385 paint.setStrokeWidth(10);
387 builder.Translate(100, 100);
388 builder.DrawPath(
SkPath::Rect(SkRect::MakeSize(SkSize{100, 100})), {paint});
390 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
394 DisplayListBuilder builder;
396 paint.setColor(DlColor::kRed());
397 paint.setDrawStyle(DlDrawStyle::kStroke);
398 paint.setStrokeWidth(10);
399 paint.setStrokeJoin(DlStrokeJoin::kBevel);
401 builder.Translate(100, 100);
402 builder.DrawPath(
SkPath::Rect(SkRect::MakeSize(SkSize{100, 100})), paint);
404 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
409 for (
auto i = 0; i < 10; i++) {
411 path.addCircle(100 + 50 * i, 100 + 50 * i, 100);
414 path.moveTo({100.f + 50.f * i - 100, 100.f + 50.f * i});
415 path.lineTo({100.f + 50.f * i, 100.f + 50.f * i - 100});
416 path.lineTo({100.f + 50.f * i - 100, 100.f + 50.f * i - 100});
421 DisplayListBuilder builder;
423 paint.setColor(DlColor::kRed().withAlpha(102));
424 builder.DrawPath(path, paint);
426 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
430 DisplayListBuilder builder;
431 builder.Scale(GetContentScale().x, GetContentScale().y);
434 paint.setColor(DlColor::kRed());
436 std::vector<DlColor> colors = {DlColor::RGBA(1.0, 0.0, 0.0, 1.0),
437 DlColor::RGBA(0.0, 0.0, 0.0, 1.0)};
438 std::vector<Scalar> stops = {0.0, 1.0};
440 paint.setColorSource(
441 DlColorSource::MakeSweep({100, 100}, 45, 135, stops.size(), colors.data(),
442 stops.data(), DlTileMode::kMirror));
443 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 20));
446 path.addArc(SkRect::MakeXYWH(10, 10, 100, 100), 0, 0);
447 builder.DrawPath(path, paint);
454 DisplayListBuilder builder;
456 paint.setColor(DlColor::kFuchsia());
458 builder.ClipPath(
SkPath::Rect(SkRect::MakeXYWH(0, 0, 500, 500)));
459 builder.DrawPath(SkPath::Circle(500, 500, 250), paint);
461 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
465 DisplayListBuilder builder;
468 paint.setColor(DlColor::kRed());
470 SkPoint radii[4] = {{50, 50}, {50, 50}, {50, 50}, {50, 50}};
472 const Scalar kTriangleHeight = 100;
475 SkRect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f,
476 kTriangleHeight, kTriangleHeight),
480 builder.Translate(200, 200);
485 path.moveTo(0, kTriangleHeight);
486 path.lineTo(-kTriangleHeight / 2.0f, 0);
487 path.lineTo(kTriangleHeight / 2.0f, 0);
489 path.addRRect(rrect);
491 builder.DrawPath(path, paint);
493 builder.Translate(100, 0);
497 path.moveTo(0, kTriangleHeight);
498 path.lineTo(-kTriangleHeight / 2.0f, 0);
500 path.lineTo(kTriangleHeight / 2.0f, 0);
502 path.addRRect(rrect);
504 builder.DrawPath(path, paint);
507 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));