Flutter Engine
 
Loading...
Searching...
No Matches
dl_sk_paint_dispatcher_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
7
11#include "gtest/gtest.h"
12
13namespace flutter {
14namespace testing {
15
16class MockDispatchHelper final : public virtual DlOpReceiver,
21 public:
23
25};
26
27static const DlColor kTestColors[2] = {DlColor(0xFF000000),
28 DlColor(0xFFFFFFFF)};
29static const float kTestStops[2] = {0.0f, 1.0f};
30static const auto kTestLinearGradient =
32 DlPoint(100.0f, 100.0f),
33 2,
37 nullptr);
38
39// Regression test for https://github.com/flutter/flutter/issues/100176.
40TEST(DisplayListUtils, OverRestore) {
41 MockDispatchHelper helper;
42 helper.save();
43 helper.restore();
44 // There should be a protection here for over-restore to keep the program from
45 // crashing.
46 helper.restore();
47}
48
49// https://github.com/flutter/flutter/issues/132860.
50TEST(DisplayListUtils, SetColorSourceDithersIfGradient) {
51 MockDispatchHelper helper;
52
54 EXPECT_TRUE(helper.paint(true).isDither());
55 EXPECT_FALSE(helper.paint(false).isDither());
56}
57
58// https://github.com/flutter/flutter/issues/132860.
59TEST(DisplayListUtils, SetColorSourceDoesNotDitherIfNotGradient) {
60 MockDispatchHelper helper;
61
63 helper.setColorSource(nullptr);
64 EXPECT_FALSE(helper.paint(true).isDither());
65 EXPECT_FALSE(helper.paint(false).isDither());
66
67 helper.setColorSource(kTestSource1.get());
68 EXPECT_FALSE(helper.paint(true).isDither());
69 EXPECT_FALSE(helper.paint(false).isDither());
70}
71
72// https://github.com/flutter/flutter/issues/132860.
73TEST(DisplayListUtils, SkDispatcherSetColorSourceDithersIfGradient) {
74 SkCanvas canvas;
75 DlSkCanvasDispatcher dispatcher(&canvas);
76
77 dispatcher.setColorSource(kTestLinearGradient.get());
78 EXPECT_TRUE(dispatcher.paint(true).isDither());
79 EXPECT_FALSE(dispatcher.paint(false).isDither());
80 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
81 // Calling safe_paint(false) returns a nullptr
82}
83
84// https://github.com/flutter/flutter/issues/132860.
85TEST(DisplayListUtils, SkDispatcherSetColorSourceDoesNotDitherIfNotGradient) {
86 SkCanvas canvas;
87 DlSkCanvasDispatcher dispatcher(&canvas);
88
89 dispatcher.setColorSource(kTestLinearGradient.get());
90 dispatcher.setColorSource(nullptr);
91 EXPECT_FALSE(dispatcher.paint(true).isDither());
92 EXPECT_FALSE(dispatcher.paint(false).isDither());
93 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
94 // Calling safe_paint(false) returns a nullptr
95
96 dispatcher.setColorSource(kTestSource1.get());
97 EXPECT_FALSE(dispatcher.paint(true).isDither());
98 EXPECT_FALSE(dispatcher.paint(false).isDither());
99 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
100 // Calling safe_paint(false) returns a nullptr
101}
102
103TEST(DisplayListUtils, DispatchSetColorSupportsWideGamut) {
104 SkCanvas canvas;
105 DlSkCanvasDispatcher dispatcher(&canvas);
106
107 DlColor dl_color(1, 1.05, .5, -0.05, DlColorSpace::kExtendedSRGB);
108 dispatcher.setColor(dl_color);
109 SkColor4f sk_color = dispatcher.paint().getColor4f();
110 EXPECT_EQ(dl_color.getRedF(), sk_color.fR);
111 EXPECT_EQ(dl_color.getGreenF(), sk_color.fG);
112 EXPECT_EQ(dl_color.getBlueF(), sk_color.fB);
113}
114
115} // namespace testing
116} // namespace flutter
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
Internal API for rendering recorded display lists to backends.
virtual void setColorSource(const DlColorSource *source)=0
virtual void setColor(DlColor color)=0
Backend implementation of |DlOpReceiver| for |SkCanvas|.
const SkPaint * safe_paint(bool use_attributes)
const SkPaint & paint(bool uses_shader=true)
void save_opacity(SkScalar opacity_for_children)
static const std::shared_ptr< DlColorSource > kTestSource1
static constexpr float kTestStops[kTestStopCount]
TEST(NativeAssetsManagerTest, NoAvailableAssets)
static constexpr DlColor kTestColors[kTestStopCount]
impeller::Point DlPoint
constexpr DlScalar getRedF() const
Definition dl_color.h:114
constexpr DlScalar getBlueF() const
Definition dl_color.h:116
constexpr DlScalar getGreenF() const
Definition dl_color.h:115