2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ #include " display_list/effects/dl_color_source.h"
5
6
#include " flutter/display_list/skia/dl_sk_paint_dispatcher.h"
6
7
7
8
#include " flutter/display_list/utils/dl_receiver_utils.h"
@@ -21,6 +22,17 @@ class MockDispatchHelper final : public virtual DlOpReceiver,
21
22
void restore () override { DlSkPaintDispatchHelper::restore_opacity (); }
22
23
};
23
24
25
+ static const DlColor kTestColors [2 ] = {0xFF000000 , 0xFFFFFFFF };
26
+ static const float kTestStops [2 ] = {0 .0f , 1 .0f };
27
+ static const auto kTestLinearGradient =
28
+ DlColorSource::MakeLinear (SkPoint::Make(0 .0f , 0 .0f ),
29
+ SkPoint::Make (100 .0f , 100 .0f ),
30
+ 2 ,
31
+ kTestColors ,
32
+ kTestStops ,
33
+ DlTileMode::kClamp ,
34
+ nullptr );
35
+
24
36
// Regression test for https://github.com/flutter/flutter/issues/100176.
25
37
TEST (DisplayListUtils, OverRestore) {
26
38
MockDispatchHelper helper;
@@ -31,5 +43,62 @@ TEST(DisplayListUtils, OverRestore) {
31
43
helper.restore ();
32
44
}
33
45
46
+ // https://github.com/flutter/flutter/issues/132860.
47
+ TEST (DisplayListUtils, SetDitherIgnoredIfColorSourceNotGradient) {
48
+ MockDispatchHelper helper;
49
+ helper.setDither (true );
50
+ EXPECT_FALSE (helper.paint ().isDither ());
51
+ }
52
+
53
+ // https://github.com/flutter/flutter/issues/132860.
54
+ TEST (DisplayListUtils, SetColorSourceClearsDitherIfNotGradient) {
55
+ MockDispatchHelper helper;
56
+ helper.setDither (true );
57
+ helper.setColorSource (nullptr );
58
+ EXPECT_FALSE (helper.paint ().isDither ());
59
+ }
60
+
61
+ // https://github.com/flutter/flutter/issues/132860.
62
+ TEST (DisplayListUtils, SetDitherTrueThenSetColorSourceDithersIfGradient) {
63
+ MockDispatchHelper helper;
64
+
65
+ // A naive implementation would ignore the dither flag here since the current
66
+ // color source is not a gradient.
67
+ helper.setDither (true );
68
+ helper.setColorSource (kTestLinearGradient .get ());
69
+ EXPECT_TRUE (helper.paint ().isDither ());
70
+ }
71
+
72
+ // https://github.com/flutter/flutter/issues/132860.
73
+ TEST (DisplayListUtils, SetDitherTrueThenRenderNonGradientThenRenderGradient) {
74
+ MockDispatchHelper helper;
75
+
76
+ // "Render" a dithered non-gradient.
77
+ helper.setDither (true );
78
+ EXPECT_FALSE (helper.paint ().isDither ());
79
+
80
+ // "Render" a gradient.
81
+ helper.setColorSource (kTestLinearGradient .get ());
82
+ EXPECT_TRUE (helper.paint ().isDither ());
83
+ }
84
+
85
+ // https://github.com/flutter/flutter/issues/132860.
86
+ TEST (DisplayListUtils, SetDitherTrueThenGradientTHenNonGradientThenGradient) {
87
+ MockDispatchHelper helper;
88
+
89
+ // "Render" a dithered gradient.
90
+ helper.setDither (true );
91
+ helper.setColorSource (kTestLinearGradient .get ());
92
+ EXPECT_TRUE (helper.paint ().isDither ());
93
+
94
+ // "Render" a non-gradient.
95
+ helper.setColorSource (nullptr );
96
+ EXPECT_FALSE (helper.paint ().isDither ());
97
+
98
+ // "Render" a gradient again.
99
+ helper.setColorSource (kTestLinearGradient .get ());
100
+ EXPECT_TRUE (helper.paint ().isDither ());
101
+ }
102
+
34
103
} // namespace testing
35
104
} // namespace flutter
0 commit comments