Flutter Engine
The Flutter Engine
dl_paint_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 "flutter/display_list/dl_paint.h"
6
7#include "flutter/display_list/utils/dl_comparable.h"
8#include "gtest/gtest.h"
9
10namespace flutter {
11namespace testing {
12
13TEST(DisplayListPaint, ConstructorDefaults) {
15 EXPECT_FALSE(paint.isAntiAlias());
16 EXPECT_FALSE(paint.isInvertColors());
17 EXPECT_EQ(paint.getColor(), DlPaint::kDefaultColor);
18 EXPECT_EQ(paint.getAlpha(), 0xFF);
19 EXPECT_EQ(paint.getBlendMode(), DlBlendMode::kDefaultMode);
20 EXPECT_EQ(paint.getDrawStyle(), DlDrawStyle::kDefaultStyle);
21 EXPECT_EQ(paint.getStrokeCap(), DlStrokeCap::kDefaultCap);
22 EXPECT_EQ(paint.getStrokeJoin(), DlStrokeJoin::kDefaultJoin);
23 EXPECT_EQ(paint.getStrokeWidth(), DlPaint::kDefaultWidth);
24 EXPECT_EQ(paint.getStrokeMiter(), DlPaint::kDefaultMiter);
25 EXPECT_EQ(paint.getColorSource(), nullptr);
26 EXPECT_EQ(paint.getColorFilter(), nullptr);
27 EXPECT_EQ(paint.getImageFilter(), nullptr);
28 EXPECT_EQ(paint.getMaskFilter(), nullptr);
29 EXPECT_TRUE(paint.isDefault());
30 EXPECT_EQ(paint, DlPaint::kDefault);
31
36
38 EXPECT_EQ(DlPaint::kDefaultWidth, 0.0);
39 EXPECT_EQ(DlPaint::kDefaultMiter, 4.0);
40
41 EXPECT_EQ(paint, DlPaint());
42 EXPECT_EQ(paint, DlPaint(DlColor::kBlack()));
43 EXPECT_EQ(paint, DlPaint(DlColor(0xFF000000)));
44
45 EXPECT_NE(paint, DlPaint().setAntiAlias(true));
46 EXPECT_NE(paint, DlPaint().setInvertColors(true));
47 EXPECT_NE(paint, DlPaint().setColor(DlColor::kGreen()));
48 EXPECT_NE(paint, DlPaint(DlColor::kGreen()));
49 EXPECT_NE(paint, DlPaint(DlColor(0xFF00FF00)));
50 EXPECT_NE(paint, DlPaint().setAlpha(0x7f));
51 EXPECT_NE(paint, DlPaint().setBlendMode(DlBlendMode::kDstIn));
52 EXPECT_NE(paint, DlPaint().setDrawStyle(DlDrawStyle::kStrokeAndFill));
53 EXPECT_NE(paint, DlPaint().setStrokeCap(DlStrokeCap::kRound));
54 EXPECT_NE(paint, DlPaint().setStrokeJoin(DlStrokeJoin::kRound));
55 EXPECT_NE(paint, DlPaint().setStrokeWidth(6));
56 EXPECT_NE(paint, DlPaint().setStrokeMiter(7));
57
59 EXPECT_NE(paint, DlPaint().setColorSource(color_source.shared()));
60
62 EXPECT_NE(paint, DlPaint().setColorFilter(color_filter.shared()));
63
64 DlBlurImageFilter image_filter(1.3, 4.7, DlTileMode::kClamp);
65 EXPECT_NE(paint, DlPaint().setImageFilter(image_filter.shared()));
66
68 EXPECT_NE(paint, DlPaint().setMaskFilter(mask_filter.shared()));
69}
70
71TEST(DisplayListPaint, NullPointerSetGet) {
72 DlColorSource* null_color_source = nullptr;
73 DlColorFilter* null_color_filter = nullptr;
74 DlImageFilter* null_image_filter = nullptr;
75 DlMaskFilter* null_mask_filter = nullptr;
77 EXPECT_EQ(paint.setColorSource(null_color_source).getColorSource(), nullptr);
78 EXPECT_EQ(paint.setColorFilter(null_color_filter).getColorFilter(), nullptr);
79 EXPECT_EQ(paint.setImageFilter(null_image_filter).getImageFilter(), nullptr);
80 EXPECT_EQ(paint.setMaskFilter(null_mask_filter).getMaskFilter(), nullptr);
81}
82
83TEST(DisplayListPaint, NullSharedPointerSetGet) {
84 std::shared_ptr<DlColorSource> null_color_source;
85 std::shared_ptr<DlColorFilter> null_color_filter;
86 std::shared_ptr<DlImageFilter> null_image_filter;
87 std::shared_ptr<DlMaskFilter> null_mask_filter;
89 EXPECT_EQ(paint.setColorSource(null_color_source).getColorSource(), nullptr);
90 EXPECT_EQ(paint.setColorFilter(null_color_filter).getColorFilter(), nullptr);
91 EXPECT_EQ(paint.setImageFilter(null_image_filter).getImageFilter(), nullptr);
92 EXPECT_EQ(paint.setMaskFilter(null_mask_filter).getMaskFilter(), nullptr);
93}
94
95TEST(DisplayListPaint, ChainingConstructor) {
97 DlPaint() //
98 .setAntiAlias(true) //
99 .setInvertColors(true) //
101 .setAlpha(0x7F) //
106 .setStrokeWidth(42) //
107 .setStrokeMiter(1.5) //
111 .shared())
113 DlBlurImageFilter(1.3, 4.7, DlTileMode::kClamp).shared())
115 EXPECT_TRUE(paint.isAntiAlias());
116 EXPECT_TRUE(paint.isInvertColors());
117 EXPECT_EQ(paint.getColor(), DlColor::kGreen().withAlpha(0x7F));
118 EXPECT_EQ(paint.getAlpha(), 0x7F);
119 EXPECT_EQ(paint.getBlendMode(), DlBlendMode::kLuminosity);
120 EXPECT_EQ(paint.getDrawStyle(), DlDrawStyle::kStrokeAndFill);
121 EXPECT_EQ(paint.getStrokeCap(), DlStrokeCap::kSquare);
122 EXPECT_EQ(paint.getStrokeJoin(), DlStrokeJoin::kBevel);
123 EXPECT_EQ(paint.getStrokeWidth(), 42);
124 EXPECT_EQ(paint.getStrokeMiter(), 1.5);
125 EXPECT_EQ(*paint.getColorSource(), DlColorColorSource(DlColor::kMagenta()));
126 EXPECT_EQ(*paint.getColorFilter(),
128 EXPECT_EQ(*paint.getImageFilter(),
130 EXPECT_EQ(*paint.getMaskFilter(),
132
133 EXPECT_NE(paint, DlPaint());
134}
135
136} // namespace testing
137} // namespace flutter
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
std::shared_ptr< DlImageFilter > shared() const override
std::shared_ptr< DlColorSource > shared() const override
DlPaint & setColor(DlColor color)
Definition: dl_paint.h:70
DlPaint & setAntiAlias(bool isAntiAlias)
Definition: dl_paint.h:58
static const DlPaint kDefault
Definition: dl_paint.h:52
DlPaint & setInvertColors(bool isInvertColors)
Definition: dl_paint.h:64
DlPaint & setColorFilter(const std::shared_ptr< const DlColorFilter > &filter)
Definition: dl_paint.h:144
static constexpr float kDefaultWidth
Definition: dl_paint.h:49
DlPaint & setMaskFilter(const std::shared_ptr< DlMaskFilter > &filter)
Definition: dl_paint.h:170
DlPaint & setStrokeCap(DlStrokeCap cap)
Definition: dl_paint.h:102
DlPaint & setStrokeWidth(float width)
Definition: dl_paint.h:116
DlPaint & setAlpha(uint8_t alpha)
Definition: dl_paint.h:76
DlPaint & setStrokeMiter(float miter)
Definition: dl_paint.h:122
DlPaint & setBlendMode(DlBlendMode mode)
Definition: dl_paint.h:86
static constexpr float kDefaultMiter
Definition: dl_paint.h:50
DlPaint & setImageFilter(const std::shared_ptr< const DlImageFilter > &filter)
Definition: dl_paint.h:157
DlPaint & setDrawStyle(DlDrawStyle style)
Definition: dl_paint.h:94
static constexpr DlColor kDefaultColor
Definition: dl_paint.h:48
DlPaint & setStrokeJoin(DlStrokeJoin join)
Definition: dl_paint.h:110
DlPaint & setColorSource(std::shared_ptr< const DlColorSource > source)
Definition: dl_paint.h:131
const Paint & paint
Definition: color_source.cc:38
std::shared_ptr< DlMaskFilter > mask_filter
TEST(DisplayListComplexity, EmptyDisplayList)
@ kMiter
extends to miter limit
@ kBevel
connects outside edges
@ kRound
adds circle
@ kButt
no stroke extension
@ kSquare
adds square
@ kStrokeAndFill
both strokes and fills shapes
@ kFill
fills interior of shapes
@ kInner
fuzzy inside, nothing outside
@ kSrcOver
r = s + (1-sa)*d
@ kLuminosity
luminosity of source with hue and saturation of destination
flutter::DlColor DlColor
flutter::DlPaint DlPaint
static constexpr DlColor kMagenta()
Definition: dl_color.h:28
static constexpr DlColor kBlack()
Definition: dl_color.h:22
static constexpr DlColor kYellow()
Definition: dl_color.h:29
constexpr DlColor withAlpha(uint8_t alpha) const
Definition: dl_color.h:63
static constexpr DlColor kGreen()
Definition: dl_color.h:25
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678