22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ #include " display_list/effects/dl_color_source.h"
56#include " flutter/display_list/skia/dl_sk_paint_dispatcher.h"
67
78#include " flutter/display_list/utils/dl_receiver_utils.h"
@@ -21,6 +22,17 @@ class MockDispatchHelper final : public virtual DlOpReceiver,
2122 void restore () override { DlSkPaintDispatchHelper::restore_opacity (); }
2223};
2324
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+
2436// Regression test for https://github.com/flutter/flutter/issues/100176.
2537TEST (DisplayListUtils, OverRestore) {
2638 MockDispatchHelper helper;
@@ -31,5 +43,62 @@ TEST(DisplayListUtils, OverRestore) {
3143 helper.restore ();
3244}
3345
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+
34103} // namespace testing
35104} // namespace flutter
0 commit comments