Flutter Engine
 
Loading...
Searching...
No Matches
dl_paint.h
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#ifndef FLUTTER_DISPLAY_LIST_DL_PAINT_H_
6#define FLUTTER_DISPLAY_LIST_DL_PAINT_H_
7
8#include <memory>
9#include <utility>
16
17namespace flutter {
18
19enum class DlDrawStyle {
20 kFill, //!< fills interior of shapes
21 kStroke, //!< strokes boundary of shapes
22 kStrokeAndFill, //!< both strokes and fills shapes
23
26};
27
28enum class DlStrokeCap {
29 kButt, //!< no stroke extension
30 kRound, //!< adds circle
31 kSquare, //!< adds square
32
35};
36
37enum class DlStrokeJoin {
38 kMiter, //!< extends to miter limit
39 kRound, //!< adds circle
40 kBevel, //!< connects outside edges
41
44};
45
46class DlPaint {
47 public:
49 static constexpr float kDefaultWidth = 0.0;
50 static constexpr float kDefaultMiter = 4.0;
51
52 static const DlPaint kDefault;
53
54 DlPaint() : DlPaint(DlColor::kBlack()) {}
55 explicit DlPaint(DlColor color);
56
57 bool isAntiAlias() const { return is_anti_alias_; }
60 return *this;
61 }
62
63 bool isInvertColors() const { return is_invert_colors_; }
68
69 DlColor getColor() const { return color_; }
71 color_ = color;
72 return *this;
73 }
74
75 uint8_t getAlpha() const { return color_.argb() >> 24; }
76 DlPaint& setAlpha(uint8_t alpha) { return setColor(color_.withAlpha(alpha)); }
77 DlScalar getOpacity() const { return color_.getAlphaF(); }
79 return setAlpha(DlColor::toAlpha(opacity));
80 }
81
83 return static_cast<DlBlendMode>(blend_mode_);
84 }
86 blend_mode_ = static_cast<unsigned>(mode);
87 return *this;
88 }
89
91 return static_cast<DlDrawStyle>(draw_style_);
92 }
94 draw_style_ = static_cast<unsigned>(style);
95 return *this;
96 }
97
99 return static_cast<DlStrokeCap>(stroke_cap_);
100 }
102 stroke_cap_ = static_cast<unsigned>(cap);
103 return *this;
104 }
105
107 return static_cast<DlStrokeJoin>(stroke_join_);
108 }
110 stroke_join_ = static_cast<unsigned>(join);
111 return *this;
112 }
113
114 float getStrokeWidth() const { return stroke_width_; }
116 stroke_width_ = width;
117 return *this;
118 }
119
120 float getStrokeMiter() const { return stroke_miter_; }
121 DlPaint& setStrokeMiter(float miter) {
122 stroke_miter_ = miter;
123 return *this;
124 }
125
126 const std::shared_ptr<const DlColorSource>& getColorSource() const {
127 return color_source_;
128 }
129 const DlColorSource* getColorSourcePtr() const { return color_source_.get(); }
130
131 DlPaint& setColorSource(std::nullptr_t source) {
132 color_source_ = nullptr;
133 return *this;
134 }
136 color_source_ = source ? source->shared() : nullptr;
137 return *this;
138 }
139 DlPaint& setColorSource(std::shared_ptr<const DlColorSource> source) {
140 color_source_ = std::move(source);
141 return *this;
142 }
143
144 const std::shared_ptr<const DlColorFilter>& getColorFilter() const {
145 return color_filter_;
146 }
147 const DlColorFilter* getColorFilterPtr() const { return color_filter_.get(); }
148
149 DlPaint& setColorFilter(std::nullptr_t filter) {
150 color_filter_ = nullptr;
151 return *this;
152 }
154 color_filter_ = filter ? filter->shared() : nullptr;
155 return *this;
156 }
157 DlPaint& setColorFilter(const std::shared_ptr<const DlColorFilter>& filter) {
158 color_filter_ = filter;
159 return *this;
160 }
161
162 const std::shared_ptr<DlImageFilter>& getImageFilter() const {
163 return image_filter_;
164 }
165 const DlImageFilter* getImageFilterPtr() const { return image_filter_.get(); }
166
167 DlPaint& setImageFilter(std::nullptr_t filter) {
168 image_filter_ = nullptr;
169 return *this;
170 }
172 image_filter_ = filter ? filter->shared() : nullptr;
173 return *this;
174 }
175 DlPaint& setImageFilter(const std::shared_ptr<DlImageFilter>& filter) {
176 image_filter_ = filter;
177 return *this;
178 }
179
180 const std::shared_ptr<const DlMaskFilter>& getMaskFilter() const {
181 return mask_filter_;
182 }
183 const DlMaskFilter* getMaskFilterPtr() const { return mask_filter_.get(); }
184
185 DlPaint& setMaskFilter(std::nullptr_t filter) {
186 mask_filter_ = nullptr;
187 return *this;
188 }
190 mask_filter_ = filter ? filter->shared() : nullptr;
191 return *this;
192 }
193 DlPaint& setMaskFilter(const std::shared_ptr<DlMaskFilter>& filter) {
194 mask_filter_ = filter;
195 return *this;
196 }
197
198 bool isDefault() const { return *this == kDefault; }
199
200 bool usesRuntimeEffect() const {
201 return ((color_source_ && color_source_->asRuntimeEffect()) ||
202 (image_filter_ && image_filter_->asRuntimeEffectFilter()));
203 }
204
205 bool operator==(DlPaint const& other) const;
206
207 private:
208#define ASSERT_ENUM_FITS(last_enum, num_bits) \
209 static_assert(static_cast<int>(last_enum) < (1 << num_bits) && \
210 static_cast<int>(last_enum) * 2 >= (1 << num_bits))
211
212 static constexpr int kBlendModeBits = 5;
213 static constexpr int kDrawStyleBits = 2;
214 static constexpr int kStrokeCapBits = 2;
215 static constexpr int kStrokeJoinBits = 2;
216 ASSERT_ENUM_FITS(DlBlendMode::kLastMode, kBlendModeBits);
220
221 union {
222 struct {
223 unsigned blend_mode_ : kBlendModeBits = {};
224 unsigned draw_style_ : kDrawStyleBits = {};
225 unsigned stroke_cap_ : kStrokeCapBits = {};
226 unsigned stroke_join_ : kStrokeJoinBits = {};
227 unsigned is_anti_alias_ : 1 = {};
228 unsigned is_invert_colors_ : 1 = {};
229 };
230 };
231
232 DlColor color_;
233 float stroke_width_;
234 float stroke_miter_;
235
236 std::shared_ptr<const DlColorSource> color_source_;
237 std::shared_ptr<const DlColorFilter> color_filter_;
238 std::shared_ptr<DlImageFilter> image_filter_;
239 std::shared_ptr<const DlMaskFilter> mask_filter_;
240};
241
242} // namespace flutter
243
244#endif // FLUTTER_DISPLAY_LIST_DL_PAINT_H_
virtual std::shared_ptr< D > shared() const =0
bool isAntiAlias() const
Definition dl_paint.h:57
bool operator==(DlPaint const &other) const
Definition dl_paint.cc:20
DlStrokeCap getStrokeCap() const
Definition dl_paint.h:98
bool isDefault() const
Definition dl_paint.h:198
DlColor getColor() const
Definition dl_paint.h:69
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
DlBlendMode getBlendMode() const
Definition dl_paint.h:82
DlPaint & setColorFilter(const std::shared_ptr< const DlColorFilter > &filter)
Definition dl_paint.h:157
static constexpr float kDefaultWidth
Definition dl_paint.h:49
unsigned is_anti_alias_
Definition dl_paint.h:227
unsigned stroke_cap_
Definition dl_paint.h:225
DlPaint & setMaskFilter(const std::shared_ptr< DlMaskFilter > &filter)
Definition dl_paint.h:193
float getStrokeMiter() const
Definition dl_paint.h:120
DlPaint & setImageFilter(const DlImageFilter *filter)
Definition dl_paint.h:171
DlStrokeJoin getStrokeJoin() const
Definition dl_paint.h:106
DlPaint & setMaskFilter(const DlMaskFilter *filter)
Definition dl_paint.h:189
bool usesRuntimeEffect() const
Definition dl_paint.h:200
unsigned is_invert_colors_
Definition dl_paint.h:228
uint8_t getAlpha() const
Definition dl_paint.h:75
unsigned draw_style_
Definition dl_paint.h:224
const DlColorSource * getColorSourcePtr() const
Definition dl_paint.h:129
DlPaint & setStrokeCap(DlStrokeCap cap)
Definition dl_paint.h:101
const DlMaskFilter * getMaskFilterPtr() const
Definition dl_paint.h:183
DlPaint & setStrokeWidth(float width)
Definition dl_paint.h:115
DlPaint & setAlpha(uint8_t alpha)
Definition dl_paint.h:76
const DlColorFilter * getColorFilterPtr() const
Definition dl_paint.h:147
DlPaint & setStrokeMiter(float miter)
Definition dl_paint.h:121
unsigned blend_mode_
Definition dl_paint.h:223
DlPaint & setBlendMode(DlBlendMode mode)
Definition dl_paint.h:85
const std::shared_ptr< const DlMaskFilter > & getMaskFilter() const
Definition dl_paint.h:180
DlScalar getOpacity() const
Definition dl_paint.h:77
static constexpr float kDefaultMiter
Definition dl_paint.h:50
const DlImageFilter * getImageFilterPtr() const
Definition dl_paint.h:165
DlPaint & setImageFilter(const std::shared_ptr< DlImageFilter > &filter)
Definition dl_paint.h:175
DlDrawStyle getDrawStyle() const
Definition dl_paint.h:90
DlPaint & setImageFilter(std::nullptr_t filter)
Definition dl_paint.h:167
const std::shared_ptr< const DlColorSource > & getColorSource() const
Definition dl_paint.h:126
const std::shared_ptr< DlImageFilter > & getImageFilter() const
Definition dl_paint.h:162
DlPaint & setColorFilter(const DlColorFilter *filter)
Definition dl_paint.h:153
float getStrokeWidth() const
Definition dl_paint.h:114
const std::shared_ptr< const DlColorFilter > & getColorFilter() const
Definition dl_paint.h:144
DlPaint & setMaskFilter(std::nullptr_t filter)
Definition dl_paint.h:185
DlPaint & setDrawStyle(DlDrawStyle style)
Definition dl_paint.h:93
static constexpr DlColor kDefaultColor
Definition dl_paint.h:48
DlPaint & setStrokeJoin(DlStrokeJoin join)
Definition dl_paint.h:109
DlPaint & setOpacity(DlScalar opacity)
Definition dl_paint.h:78
DlPaint & setColorFilter(std::nullptr_t filter)
Definition dl_paint.h:149
DlPaint & setColorSource(std::shared_ptr< const DlColorSource > source)
Definition dl_paint.h:139
DlPaint & setColorSource(const DlColorSource *source)
Definition dl_paint.h:135
DlPaint & setColorSource(std::nullptr_t source)
Definition dl_paint.h:131
unsigned stroke_join_
Definition dl_paint.h:226
bool isInvertColors() const
Definition dl_paint.h:63
#define ASSERT_ENUM_FITS(last_enum, num_bits)
Definition dl_paint.h:208
impeller::Scalar DlScalar
DlStrokeJoin
Definition dl_paint.h:37
@ kMiter
extends to miter limit
@ kBevel
connects outside edges
DlStrokeCap
Definition dl_paint.h:28
@ kRound
adds circle
@ kButt
no stroke extension
@ kSquare
adds square
DlDrawStyle
Definition dl_paint.h:19
@ kStrokeAndFill
both strokes and fills shapes
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
BlendMode
Definition color.h:58
flutter::DlColor DlColor
int32_t width
static constexpr DlColor kBlack()
Definition dl_color.h:69
constexpr DlScalar getAlphaF() const
Definition dl_color.h:113
static uint8_t toAlpha(DlScalar opacity)
Definition dl_color.h:64
uint32_t argb() const
Definition dl_color.h:158
DlColor withAlpha(uint8_t alpha) const
Definition dl_color.h:120