Flutter Engine
The 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
6#include "flutter/display_list/skia/dl_sk_paint_dispatcher.h"
7
8#include "flutter/display_list/skia/dl_sk_dispatcher.h"
9#include "flutter/display_list/testing/dl_test_snippets.h"
10#include "flutter/display_list/utils/dl_receiver_utils.h"
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 SkPoint::Make(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 DlColorColorSource color_color_source(DlColor::kBlue());
68 helper.setColorSource(&color_color_source);
69 EXPECT_FALSE(helper.paint(true).isDither());
70 EXPECT_FALSE(helper.paint(false).isDither());
71
73 EXPECT_FALSE(helper.paint(true).isDither());
74 EXPECT_FALSE(helper.paint(false).isDither());
75}
76
77// https://github.com/flutter/flutter/issues/132860.
78TEST(DisplayListUtils, SkDispatcherSetColorSourceDithersIfGradient) {
79 SkCanvas canvas;
80 DlSkCanvasDispatcher dispatcher(&canvas);
81
82 dispatcher.setColorSource(kTestLinearGradient.get());
83 EXPECT_TRUE(dispatcher.paint(true).isDither());
84 EXPECT_FALSE(dispatcher.paint(false).isDither());
85 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
86 // Calling safe_paint(false) returns a nullptr
87}
88
89// https://github.com/flutter/flutter/issues/132860.
90TEST(DisplayListUtils, SkDispatcherSetColorSourceDoesNotDitherIfNotGradient) {
91 SkCanvas canvas;
92 DlSkCanvasDispatcher dispatcher(&canvas);
93
94 dispatcher.setColorSource(kTestLinearGradient.get());
95 dispatcher.setColorSource(nullptr);
96 EXPECT_FALSE(dispatcher.paint(true).isDither());
97 EXPECT_FALSE(dispatcher.paint(false).isDither());
98 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
99 // Calling safe_paint(false) returns a nullptr
100
101 DlColorColorSource color_color_source(DlColor::kBlue());
102 dispatcher.setColorSource(&color_color_source);
103 EXPECT_FALSE(dispatcher.paint(true).isDither());
104 EXPECT_FALSE(dispatcher.paint(false).isDither());
105 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
106 // Calling safe_paint(false) returns a nullptr
107
108 dispatcher.setColorSource(&kTestSource1);
109 EXPECT_FALSE(dispatcher.paint(true).isDither());
110 EXPECT_FALSE(dispatcher.paint(false).isDither());
111 EXPECT_FALSE(dispatcher.safe_paint(true)->isDither());
112 // Calling safe_paint(false) returns a nullptr
113}
114
115} // namespace testing
116} // namespace flutter
#define TEST(S, s, D, expected)
bool isDither() const
Definition SkPaint.h:175
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)
Internal API for rendering recorded display lists to backends.
virtual void setColorSource(const DlColorSource *source)=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 DlImageColorSource kTestSource1(TestImage1, DlTileMode::kClamp, DlTileMode::kMirror, kLinearSampling)
static constexpr float kTestStops[kTestStopCount]
static constexpr DlColor kTestColors[kTestStopCount]
static constexpr SkPoint Make(float x, float y)
static constexpr DlColor kBlue()
Definition dl_color.h:26
#define EXPECT_TRUE(handle)
Definition unit_test.h:685