Flutter Engine
The Flutter Engine
dl_color_source_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
6#include <vector>
7
9#include "flutter/display_list/dl_sampling_options.h"
10#include "flutter/display_list/effects/dl_color_source.h"
11#include "flutter/display_list/effects/dl_runtime_effect.h"
12#include "flutter/display_list/image/dl_image.h"
13#include "flutter/display_list/testing/dl_test_equality.h"
14
17
18namespace flutter {
19namespace testing {
20
23 if (SkColorGetA(color) < 255) {
25 } else {
29 }
30 SkCanvas* canvas = surface->getCanvas();
31 canvas->drawColor(color);
32 return DlImage::Make(surface->makeImageSnapshot());
33}
34
38 SkString("vec4 main(vec2 p) { return vec4(0); }"))
39 .effect);
43 SkString("vec4 main(vec2 p) { return vec4(1); }"))
44 .effect);
45
49// clang-format off
50static const SkMatrix kTestMatrix1 =
51 SkMatrix::MakeAll(2, 0, 10,
52 0, 3, 12,
53 0, 0, 1);
54static const SkMatrix kTestMatrix2 =
55 SkMatrix::MakeAll(4, 0, 15,
56 0, 7, 17,
57 0, 0, 1);
58// clang-format on
59static constexpr int kTestStopCount = 3;
60static constexpr DlColor kTestColors[kTestStopCount] = {
64};
69};
70static constexpr float kTestStops[kTestStopCount] = {
71 0.0f,
72 0.7f,
73 1.0f,
74};
75static constexpr float kTestStops2[kTestStopCount] = {
76 0.0f,
77 0.3f,
78 1.0f,
79};
80static constexpr SkPoint kTestPoints[2] = {
81 SkPoint::Make(5, 15),
82 SkPoint::Make(7, 18),
83};
84static constexpr SkPoint kTestPoints2[2] = {
85 SkPoint::Make(100, 115),
86 SkPoint::Make(107, 118),
87};
88
89TEST(DisplayListColorSource, ColorConstructor) {
91}
92
93TEST(DisplayListColorSource, ColorShared) {
95 ASSERT_NE(source.shared().get(), &source);
96 ASSERT_EQ(*source.shared(), source);
97}
98
99TEST(DisplayListColorSource, ColorAsColor) {
101 ASSERT_NE(source.asColor(), nullptr);
102 ASSERT_EQ(source.asColor(), &source);
103
104 ASSERT_EQ(source.asImage(), nullptr);
105 ASSERT_EQ(source.asLinearGradient(), nullptr);
106 ASSERT_EQ(source.asRadialGradient(), nullptr);
107 ASSERT_EQ(source.asConicalGradient(), nullptr);
108 ASSERT_EQ(source.asSweepGradient(), nullptr);
109 ASSERT_EQ(source.asRuntimeEffect(), nullptr);
110}
111
112TEST(DisplayListColorSource, ColorContents) {
114 ASSERT_EQ(source.color(), DlColor::kRed());
115 ASSERT_EQ(source.is_opaque(), true);
116 for (int i = 0; i < 255; i++) {
117 SkColor alpha_color = SkColorSetA(SK_ColorRED, i);
118 auto const alpha_source = DlColorColorSource(DlColor(alpha_color));
119 ASSERT_EQ(alpha_source.color(), alpha_color);
120 ASSERT_EQ(alpha_source.is_opaque(), false);
121 }
122}
123
124TEST(DisplayListColorSource, ColorEquals) {
127 TestEquals(source1, source2);
128}
129
130TEST(DisplayListColorSource, ColorNotEquals) {
133 TestNotEquals(source1, source2, "Color differs");
134}
135
136TEST(DisplayListColorSource, ImageConstructor) {
139}
140
141TEST(DisplayListColorSource, ImageShared) {
144 ASSERT_NE(source.shared().get(), &source);
145 ASSERT_EQ(*source.shared(), source);
146}
147
148TEST(DisplayListColorSource, ImageAsImage) {
151 ASSERT_NE(source.asImage(), nullptr);
152 ASSERT_EQ(source.asImage(), &source);
153
154 ASSERT_EQ(source.asColor(), nullptr);
155 ASSERT_EQ(source.asLinearGradient(), nullptr);
156 ASSERT_EQ(source.asRadialGradient(), nullptr);
157 ASSERT_EQ(source.asConicalGradient(), nullptr);
158 ASSERT_EQ(source.asSweepGradient(), nullptr);
159}
160
161TEST(DisplayListColorSource, ImageContents) {
164 &kTestMatrix1);
165 ASSERT_EQ(source.image(), kTestImage1);
166 ASSERT_EQ(source.horizontal_tile_mode(), DlTileMode::kRepeat);
167 ASSERT_EQ(source.vertical_tile_mode(), DlTileMode::kMirror);
168 ASSERT_EQ(source.sampling(), DlImageSampling::kLinear);
169 ASSERT_EQ(source.matrix(), kTestMatrix1);
170 ASSERT_EQ(source.is_opaque(), true);
171}
172
173TEST(DisplayListColorSource, AlphaImageContents) {
176 &kTestMatrix1);
177 ASSERT_EQ(source.image(), kTestAlphaImage1);
178 ASSERT_EQ(source.horizontal_tile_mode(), DlTileMode::kRepeat);
179 ASSERT_EQ(source.vertical_tile_mode(), DlTileMode::kMirror);
180 ASSERT_EQ(source.sampling(), DlImageSampling::kLinear);
181 ASSERT_EQ(source.matrix(), kTestMatrix1);
182 ASSERT_EQ(source.is_opaque(), false);
183}
184
185TEST(DisplayListColorSource, ImageEquals) {
188 &kTestMatrix1);
191 &kTestMatrix1);
192 TestEquals(source1, source2);
193}
194
195TEST(DisplayListColorSource, ImageNotEquals) {
198 &kTestMatrix1);
199 {
202 &kTestMatrix1);
203 TestNotEquals(source1, source2, "Image differs");
204 }
205 {
208 &kTestMatrix1);
209 TestNotEquals(source1, source2, "hTileMode differs");
210 }
211 {
214 &kTestMatrix1);
215 TestNotEquals(source1, source2, "vTileMode differs");
216 }
217 {
220 &kTestMatrix1);
221 TestNotEquals(source1, source2, "Sampling differs");
222 }
223 {
226 &kTestMatrix2);
227 TestNotEquals(source1, source2, "Matrix differs");
228 }
229}
230
231TEST(DisplayListColorSource, LinearGradientConstructor) {
232 std::shared_ptr<DlColorSource> source = DlColorSource::MakeLinear(
235}
236
237TEST(DisplayListColorSource, LinearGradientShared) {
238 std::shared_ptr<DlColorSource> source = DlColorSource::MakeLinear(
241 ASSERT_NE(source->shared().get(), source.get());
242 ASSERT_EQ(*source->shared().get(), *source.get());
243}
244
245TEST(DisplayListColorSource, LinearGradientAsLinear) {
246 std::shared_ptr<DlColorSource> source = DlColorSource::MakeLinear(
249 ASSERT_NE(source->asLinearGradient(), nullptr);
250 ASSERT_EQ(source->asLinearGradient(), source.get());
251
252 ASSERT_EQ(source->asColor(), nullptr);
253 ASSERT_EQ(source->asImage(), nullptr);
254 ASSERT_EQ(source->asRadialGradient(), nullptr);
255 ASSERT_EQ(source->asConicalGradient(), nullptr);
256 ASSERT_EQ(source->asSweepGradient(), nullptr);
257 ASSERT_EQ(source->asRuntimeEffect(), nullptr);
258}
259
260TEST(DisplayListColorSource, LinearGradientContents) {
261 std::shared_ptr<DlColorSource> source = DlColorSource::MakeLinear(
264 ASSERT_EQ(source->asLinearGradient()->start_point(), kTestPoints[0]);
265 ASSERT_EQ(source->asLinearGradient()->end_point(), kTestPoints[1]);
266 ASSERT_EQ(source->asLinearGradient()->stop_count(), kTestStopCount);
267 for (int i = 0; i < kTestStopCount; i++) {
268 ASSERT_EQ(source->asLinearGradient()->colors()[i], kTestColors[i]);
269 ASSERT_EQ(source->asLinearGradient()->stops()[i], kTestStops[i]);
270 }
271 ASSERT_EQ(source->asLinearGradient()->tile_mode(), DlTileMode::kClamp);
272 ASSERT_EQ(source->asLinearGradient()->matrix(), kTestMatrix1);
273 ASSERT_EQ(source->is_opaque(), true);
274}
275
276TEST(DisplayListColorSource, AlphaLinearGradientContents) {
277 std::shared_ptr<DlColorSource> source = DlColorSource::MakeLinear(
280 ASSERT_EQ(source->asLinearGradient()->start_point(), kTestPoints[0]);
281 ASSERT_EQ(source->asLinearGradient()->end_point(), kTestPoints[1]);
282 ASSERT_EQ(source->asLinearGradient()->stop_count(), kTestStopCount);
283 for (int i = 0; i < kTestStopCount; i++) {
284 ASSERT_EQ(source->asLinearGradient()->colors()[i], kTestAlphaColors[i]);
285 ASSERT_EQ(source->asLinearGradient()->stops()[i], kTestStops[i]);
286 }
287 ASSERT_EQ(source->asLinearGradient()->tile_mode(), DlTileMode::kClamp);
288 ASSERT_EQ(source->asLinearGradient()->matrix(), kTestMatrix1);
289 ASSERT_EQ(source->is_opaque(), false);
290}
291
292TEST(DisplayListColorSource, LinearGradientEquals) {
293 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeLinear(
296 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
299 TestEquals(*source1, *source2);
300}
301
302TEST(DisplayListColorSource, LinearGradientNotEquals) {
303 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeLinear(
306 {
307 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
310 TestNotEquals(*source1, *source2, "Point 0 differs");
311 }
312 {
313 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
316 TestNotEquals(*source1, *source2, "Point 1 differs");
317 }
318 {
319 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
322 TestNotEquals(*source1, *source2, "Stop count differs");
323 }
324 {
325 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
328 TestNotEquals(*source1, *source2, "Colors differ");
329 }
330 {
331 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
334 TestNotEquals(*source1, *source2, "Stops differ");
335 }
336 {
337 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
340 TestNotEquals(*source1, *source2, "Tile Mode differs");
341 }
342 {
343 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeLinear(
346 TestNotEquals(*source1, *source2, "Matrix differs");
347 }
348}
349
350TEST(DisplayListColorSource, RadialGradientConstructor) {
351 std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
354}
355
356TEST(DisplayListColorSource, RadialGradientShared) {
357 std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
360 ASSERT_NE(source->shared().get(), source.get());
361 ASSERT_EQ(*source->shared().get(), *source.get());
362}
363
364TEST(DisplayListColorSource, RadialGradientAsRadial) {
365 std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
368 ASSERT_NE(source->asRadialGradient(), nullptr);
369 ASSERT_EQ(source->asRadialGradient(), source.get());
370
371 ASSERT_EQ(source->asColor(), nullptr);
372 ASSERT_EQ(source->asImage(), nullptr);
373 ASSERT_EQ(source->asLinearGradient(), nullptr);
374 ASSERT_EQ(source->asConicalGradient(), nullptr);
375 ASSERT_EQ(source->asSweepGradient(), nullptr);
376 ASSERT_EQ(source->asRuntimeEffect(), nullptr);
377}
378
379TEST(DisplayListColorSource, RadialGradientContents) {
380 std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
383 ASSERT_EQ(source->asRadialGradient()->center(), kTestPoints[0]);
384 ASSERT_EQ(source->asRadialGradient()->radius(), 10.0);
385 ASSERT_EQ(source->asRadialGradient()->stop_count(), kTestStopCount);
386 for (int i = 0; i < kTestStopCount; i++) {
387 ASSERT_EQ(source->asRadialGradient()->colors()[i], kTestColors[i]);
388 ASSERT_EQ(source->asRadialGradient()->stops()[i], kTestStops[i]);
389 }
390 ASSERT_EQ(source->asRadialGradient()->tile_mode(), DlTileMode::kClamp);
391 ASSERT_EQ(source->asRadialGradient()->matrix(), kTestMatrix1);
392 ASSERT_EQ(source->is_opaque(), true);
393}
394
395TEST(DisplayListColorSource, AlphaRadialGradientContents) {
396 std::shared_ptr<DlColorSource> source = DlColorSource::MakeRadial(
399 ASSERT_EQ(source->asRadialGradient()->center(), kTestPoints[0]);
400 ASSERT_EQ(source->asRadialGradient()->radius(), 10.0);
401 ASSERT_EQ(source->asRadialGradient()->stop_count(), kTestStopCount);
402 for (int i = 0; i < kTestStopCount; i++) {
403 ASSERT_EQ(source->asRadialGradient()->colors()[i], kTestAlphaColors[i]);
404 ASSERT_EQ(source->asRadialGradient()->stops()[i], kTestStops[i]);
405 }
406 ASSERT_EQ(source->asRadialGradient()->tile_mode(), DlTileMode::kClamp);
407 ASSERT_EQ(source->asRadialGradient()->matrix(), kTestMatrix1);
408 ASSERT_EQ(source->is_opaque(), false);
409}
410
411TEST(DisplayListColorSource, RadialGradientEquals) {
412 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeRadial(
415 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
418 TestEquals(*source1, *source2);
419}
420
421TEST(DisplayListColorSource, RadialGradientNotEquals) {
422 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeRadial(
425 {
426 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
429 TestNotEquals(*source1, *source2, "Center differs");
430 }
431 {
432 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
435 TestNotEquals(*source1, *source2, "Radius differs");
436 }
437 {
438 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
439 kTestPoints[0], 10.0, 2, kTestColors, kTestStops, //
441 TestNotEquals(*source1, *source2, "Stop count differs");
442 }
443 {
444 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
447 TestNotEquals(*source1, *source2, "Colors differ");
448 }
449 {
450 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
453 TestNotEquals(*source1, *source2, "Stops differ");
454 }
455 {
456 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
459 TestNotEquals(*source1, *source2, "Tile Mode differs");
460 }
461 {
462 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeRadial(
465 TestNotEquals(*source1, *source2, "Matrix differs");
466 }
467}
468
469TEST(DisplayListColorSource, ConicalGradientConstructor) {
470 std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
473}
474
475TEST(DisplayListColorSource, ConicalGradientShared) {
476 std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
479 ASSERT_NE(source->shared().get(), source.get());
480 ASSERT_EQ(*source->shared().get(), *source.get());
481}
482
483TEST(DisplayListColorSource, ConicalGradientAsConical) {
484 std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
487 ASSERT_NE(source->asConicalGradient(), nullptr);
488 ASSERT_EQ(source->asConicalGradient(), source.get());
489
490 ASSERT_EQ(source->asColor(), nullptr);
491 ASSERT_EQ(source->asImage(), nullptr);
492 ASSERT_EQ(source->asLinearGradient(), nullptr);
493 ASSERT_EQ(source->asRadialGradient(), nullptr);
494 ASSERT_EQ(source->asSweepGradient(), nullptr);
495 ASSERT_EQ(source->asRuntimeEffect(), nullptr);
496}
497
498TEST(DisplayListColorSource, ConicalGradientContents) {
499 std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
502 ASSERT_EQ(source->asConicalGradient()->start_center(), kTestPoints[0]);
503 ASSERT_EQ(source->asConicalGradient()->start_radius(), 10.0);
504 ASSERT_EQ(source->asConicalGradient()->end_center(), kTestPoints[1]);
505 ASSERT_EQ(source->asConicalGradient()->end_radius(), 20.0);
506 ASSERT_EQ(source->asConicalGradient()->stop_count(), kTestStopCount);
507 for (int i = 0; i < kTestStopCount; i++) {
508 ASSERT_EQ(source->asConicalGradient()->colors()[i], kTestColors[i]);
509 ASSERT_EQ(source->asConicalGradient()->stops()[i], kTestStops[i]);
510 }
511 ASSERT_EQ(source->asConicalGradient()->tile_mode(), DlTileMode::kClamp);
512 ASSERT_EQ(source->asConicalGradient()->matrix(), kTestMatrix1);
513 ASSERT_EQ(source->is_opaque(), true);
514}
515
516TEST(DisplayListColorSource, AlphaConicalGradientContents) {
517 std::shared_ptr<DlColorSource> source = DlColorSource::MakeConical(
518 kTestPoints[0], 10.0, kTestPoints[1], 20.0, kTestStopCount,
520 ASSERT_EQ(source->asConicalGradient()->start_center(), kTestPoints[0]);
521 ASSERT_EQ(source->asConicalGradient()->start_radius(), 10.0);
522 ASSERT_EQ(source->asConicalGradient()->end_center(), kTestPoints[1]);
523 ASSERT_EQ(source->asConicalGradient()->end_radius(), 20.0);
524 ASSERT_EQ(source->asConicalGradient()->stop_count(), kTestStopCount);
525 for (int i = 0; i < kTestStopCount; i++) {
526 ASSERT_EQ(source->asConicalGradient()->colors()[i], kTestAlphaColors[i]);
527 ASSERT_EQ(source->asConicalGradient()->stops()[i], kTestStops[i]);
528 }
529 ASSERT_EQ(source->asConicalGradient()->tile_mode(), DlTileMode::kClamp);
530 ASSERT_EQ(source->asConicalGradient()->matrix(), kTestMatrix1);
531 ASSERT_EQ(source->is_opaque(), false);
532}
533
534TEST(DisplayListColorSource, ConicalGradientEquals) {
535 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeConical(
538 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
541 TestEquals(*source1, *source2);
542}
543
544TEST(DisplayListColorSource, ConicalGradientNotEquals) {
545 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeConical(
548 {
549 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
550 kTestPoints2[0], 10.0, kTestPoints[1], 20.0, kTestStopCount,
552 TestNotEquals(*source1, *source2, "Start Center differs");
553 }
554 {
555 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
558 TestNotEquals(*source1, *source2, "Start Radius differs");
559 }
560 {
561 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
562 kTestPoints[0], 10.0, kTestPoints2[1], 20.0, kTestStopCount,
564 TestNotEquals(*source1, *source2, "End Center differs");
565 }
566 {
567 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
570 TestNotEquals(*source1, *source2, "End Radius differs");
571 }
572 {
573 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
574 kTestPoints[0], 10.0, kTestPoints[1], 20.0, 2, kTestColors, kTestStops,
576 TestNotEquals(*source1, *source2, "Stop count differs");
577 }
578 {
579 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
580 kTestPoints[0], 10.0, kTestPoints[1], 20.0, kTestStopCount,
582 TestNotEquals(*source1, *source2, "Colors differ");
583 }
584 {
585 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
588 TestNotEquals(*source1, *source2, "Stops differ");
589 }
590 {
591 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
594 TestNotEquals(*source1, *source2, "Tile Mode differs");
595 }
596 {
597 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeConical(
600 TestNotEquals(*source1, *source2, "Matrix differs");
601 }
602}
603
604TEST(DisplayListColorSource, SweepGradientConstructor) {
605 std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
608}
609
610TEST(DisplayListColorSource, SweepGradientShared) {
611 std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
614 ASSERT_NE(source->shared().get(), source.get());
615 ASSERT_EQ(*source->shared().get(), *source.get());
616}
617
618TEST(DisplayListColorSource, SweepGradientAsSweep) {
619 std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
622 ASSERT_NE(source->asSweepGradient(), nullptr);
623 ASSERT_EQ(source->asSweepGradient(), source.get());
624
625 ASSERT_EQ(source->asColor(), nullptr);
626 ASSERT_EQ(source->asImage(), nullptr);
627 ASSERT_EQ(source->asLinearGradient(), nullptr);
628 ASSERT_EQ(source->asRadialGradient(), nullptr);
629 ASSERT_EQ(source->asConicalGradient(), nullptr);
630 ASSERT_EQ(source->asRuntimeEffect(), nullptr);
631}
632
633TEST(DisplayListColorSource, SweepGradientContents) {
634 std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
637 ASSERT_EQ(source->asSweepGradient()->center(), kTestPoints[0]);
638 ASSERT_EQ(source->asSweepGradient()->start(), 10.0);
639 ASSERT_EQ(source->asSweepGradient()->end(), 20.0);
640 ASSERT_EQ(source->asSweepGradient()->stop_count(), kTestStopCount);
641 for (int i = 0; i < kTestStopCount; i++) {
642 ASSERT_EQ(source->asSweepGradient()->colors()[i], kTestColors[i]);
643 ASSERT_EQ(source->asSweepGradient()->stops()[i], kTestStops[i]);
644 }
645 ASSERT_EQ(source->asSweepGradient()->tile_mode(), DlTileMode::kClamp);
646 ASSERT_EQ(source->asSweepGradient()->matrix(), kTestMatrix1);
647 ASSERT_EQ(source->is_opaque(), true);
648}
649
650TEST(DisplayListColorSource, AlphaSweepGradientContents) {
651 std::shared_ptr<DlColorSource> source = DlColorSource::MakeSweep(
654 ASSERT_EQ(source->asSweepGradient()->center(), kTestPoints[0]);
655 ASSERT_EQ(source->asSweepGradient()->start(), 10.0);
656 ASSERT_EQ(source->asSweepGradient()->end(), 20.0);
657 ASSERT_EQ(source->asSweepGradient()->stop_count(), kTestStopCount);
658 for (int i = 0; i < kTestStopCount; i++) {
659 ASSERT_EQ(source->asSweepGradient()->colors()[i], kTestAlphaColors[i]);
660 ASSERT_EQ(source->asSweepGradient()->stops()[i], kTestStops[i]);
661 }
662 ASSERT_EQ(source->asSweepGradient()->tile_mode(), DlTileMode::kClamp);
663 ASSERT_EQ(source->asSweepGradient()->matrix(), kTestMatrix1);
664 ASSERT_EQ(source->is_opaque(), false);
665}
666
667TEST(DisplayListColorSource, SweepGradientEquals) {
668 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeSweep(
671 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
674 TestEquals(*source1, *source2);
675}
676
677TEST(DisplayListColorSource, SweepGradientNotEquals) {
678 std::shared_ptr<DlColorSource> source1 = DlColorSource::MakeSweep(
681 {
682 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
685 TestNotEquals(*source1, *source2, "Center differs");
686 }
687 {
688 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
691 TestNotEquals(*source1, *source2, "Start Angle differs");
692 }
693 {
694 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
697 TestNotEquals(*source1, *source2, "End Angle differs");
698 }
699 {
700 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
701 kTestPoints[0], 10.0, 20.0, 2, kTestColors, kTestStops, //
703 TestNotEquals(*source1, *source2, "Stop count differs");
704 }
705 {
706 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
709 TestNotEquals(*source1, *source2, "Colors differ");
710 }
711 {
712 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
715 TestNotEquals(*source1, *source2, "Stops differ");
716 }
717 {
718 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
721 TestNotEquals(*source1, *source2, "Tile Mode differs");
722 }
723 {
724 std::shared_ptr<DlColorSource> source2 = DlColorSource::MakeSweep(
727 TestNotEquals(*source1, *source2, "Matrix differs");
728 }
729}
730
731TEST(DisplayListColorSource, RuntimeEffect) {
732 std::shared_ptr<DlRuntimeEffectColorSource> source1 =
734 kTestRuntimeEffect1, {}, std::make_shared<std::vector<uint8_t>>());
735 std::shared_ptr<DlRuntimeEffectColorSource> source2 =
737 kTestRuntimeEffect2, {}, std::make_shared<std::vector<uint8_t>>());
738 std::shared_ptr<DlRuntimeEffectColorSource> source3 =
740 nullptr, {}, std::make_shared<std::vector<uint8_t>>());
741
742 ASSERT_EQ(source1->type(), DlColorSourceType::kRuntimeEffect);
743 ASSERT_EQ(source1->asRuntimeEffect(), source1.get());
744 ASSERT_NE(source2->asRuntimeEffect(), source1.get());
745
746 ASSERT_EQ(source1->asImage(), nullptr);
747 ASSERT_EQ(source1->asColor(), nullptr);
748 ASSERT_EQ(source1->asLinearGradient(), nullptr);
749 ASSERT_EQ(source1->asRadialGradient(), nullptr);
750 ASSERT_EQ(source1->asConicalGradient(), nullptr);
751 ASSERT_EQ(source1->asSweepGradient(), nullptr);
752
753 TestEquals(source1, source1);
754 TestEquals(source3, source3);
755 TestNotEquals(source1, source2, "SkRuntimeEffect differs");
756 TestNotEquals(source2, source3, "SkRuntimeEffect differs");
757}
758
759} // namespace testing
760} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Definition: SkColor.h:82
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkColorGetA(color)
Definition: SkColor.h:61
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
static Result MakeForShader(SkString sksl, const Options &)
static std::shared_ptr< DlConicalGradientColorSource > MakeConical(SkPoint start_center, SkScalar start_radius, SkPoint end_center, SkScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlRuntimeEffectColorSource > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
static std::shared_ptr< DlLinearGradientColorSource > MakeLinear(const SkPoint start_point, const SkPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlSweepGradientColorSource > MakeSweep(SkPoint center, SkScalar start, SkScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlRadialGradientColorSource > MakeRadial(SkPoint center, SkScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static sk_sp< DlImage > Make(const SkImage *image)
Definition: dl_image.cc:11
static sk_sp< DlRuntimeEffect > MakeSkia(const sk_sp< SkRuntimeEffect > &runtime_effect)
DlColor color
VkSurfaceKHR surface
Definition: main.cc:49
SkBitmap source
Definition: examples.cpp:28
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static const sk_sp< DlImage > kTestAlphaImage1
static constexpr float kTestStops2[kTestStopCount]
static const sk_sp< DlRuntimeEffect > kTestRuntimeEffect1
static const SkMatrix kTestMatrix2
static constexpr int kTestStopCount
static constexpr SkPoint kTestPoints[2]
static constexpr float kTestStops[kTestStopCount]
static const sk_sp< DlRuntimeEffect > kTestRuntimeEffect2
static const SkMatrix kTestMatrix1
static const sk_sp< DlImage > kTestImage1
static const DlColor kTestAlphaColors[kTestStopCount]
static constexpr SkPoint kTestPoints2[2]
static sk_sp< DlImage > MakeTestImage(int w, int h, SkColor color)
static constexpr DlColor kTestColors[kTestStopCount]
static void TestNotEquals(T &source1, T &source2, const std::string &label)
static void TestEquals(T &source1, T &source2)
TEST(DisplayListComplexity, EmptyDisplayList)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
Definition: switches.h:59
flutter::DlColor DlColor
SkScalar w
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr DlColor kBlue()
Definition: dl_color.h:26
constexpr DlColor withAlpha(uint8_t alpha) const
Definition: dl_color.h:63
static constexpr DlColor kRed()
Definition: dl_color.h:24
static constexpr DlColor kGreen()
Definition: dl_color.h:25