Flutter Engine
 
Loading...
Searching...
No Matches
dl_op_flags.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_OP_FLAGS_H_
6#define FLUTTER_DISPLAY_LIST_DL_OP_FLAGS_H_
7
10
11namespace flutter {
12
13/// The base class for the classes that maintain a list of
14/// attributes that might be important for a number of operations
15/// including which rendering attributes need to be set before
16/// calling a rendering method (all |drawSomething| calls),
17/// or for determining which exceptional conditions may need
18/// to be accounted for in bounds calculations.
19/// This class contains only protected definitions and helper methods
20/// for the public classes |DisplayListAttributeFlags| and
21/// |DisplayListSpecialGeometryFlags|.
23 protected:
24 // A drawing operation that is not geometric in nature (but which
25 // may still apply a MaskFilter - see |kUsesMaskFilter| below).
26 static constexpr int kIsNonGeometric = 0;
27
28 // A geometric operation that is defined as a fill operation
29 // regardless of what the current paint Style is set to.
30 // This flag will automatically assume |kUsesMaskFilter|.
31 static constexpr int kIsFilledGeometry = 1 << 0;
32
33 // A geometric operation that is defined as a stroke operation
34 // regardless of what the current paint Style is set to.
35 // This flag will automatically assume |kUsesMaskFilter|.
36 static constexpr int kIsStrokedGeometry = 1 << 1;
37
38 // A geometric operation that may be a stroke or fill operation
39 // depending on the current state of the paint Style attribute.
40 // This flag will automatically assume |kUsesMaskFilter|.
41 static constexpr int kIsDrawnGeometry = 1 << 2;
42
43 static constexpr int kIsAnyGeometryMask = //
47
48 // A primitive that floods the surface (or clip) with no
49 // natural bounds, such as |drawColor| or |drawPaint|.
50 static constexpr int kFloodsSurface = 1 << 3;
51
52 static constexpr int kMayHaveCaps = 1 << 4;
53 static constexpr int kMayHaveJoins = 1 << 5;
54 static constexpr int kButtCapIsSquare = 1 << 6;
55
56 // A geometric operation which has a path that might have
57 // end caps that are not rectilinear which means that square
58 // end caps might project further than half the stroke width
59 // from the geometry bounds.
60 // A rectilinear path such as |drawRect| will not have
61 // diagonal end caps. |drawLine| might have diagonal end
62 // caps depending on the angle of the line, and more likely
63 // |drawPath| will often have such end caps.
64 static constexpr int kMayHaveDiagonalCaps = 1 << 7;
65
66 // A geometric operation which has joined vertices that are
67 // not guaranteed to be smooth (angles of incoming and outgoing)
68 // segments at some joins may not have the same angle) or
69 // rectilinear (squares have right angles at the corners, but
70 // those corners will never extend past the bounding box of
71 // the geometry pre-transform).
72 // |drawRect|, |drawOval| and |drawRRect| all have well
73 // behaved joins, but |drawPath| might have joins that cause
74 // mitered extensions outside the pre-transformed bounding box.
75 static constexpr int kMayHaveAcuteJoins = 1 << 8;
76
77 static constexpr int kAnySpecialGeometryMask = //
80
81 // clang-format off
82 static constexpr int kUsesAntiAlias = 1 << 10;
83 static constexpr int kUsesAlpha = 1 << 11;
84 static constexpr int kUsesColor = 1 << 12;
85 static constexpr int kUsesBlend = 1 << 13;
86 static constexpr int kUsesShader = 1 << 14;
87 static constexpr int kUsesColorFilter = 1 << 15;
88 static constexpr int kUsesMaskFilter = 1 << 16;
89 static constexpr int kUsesImageFilter = 1 << 17;
90
91 // Some ops have an optional paint argument. If the version
92 // stored in the DisplayList ignores the paint, but there
93 // is an option to render the same op with a paint then
94 // both of the following flags are set to indicate that
95 // a default paint object can be constructed when rendering
96 // the op to carry information imposed from outside the
97 // DisplayList (for example, the opacity override).
98 static constexpr int kIgnoresPaint = 1 << 30;
99 // clang-format on
100
101 static constexpr int kAnyAttributeMask = //
104};
105
107 protected:
108 explicit constexpr DisplayListFlagsBase(int flags) : flags_(flags) {}
109
110 const int flags_;
111
112 constexpr bool has_any(int qFlags) const { return (flags_ & qFlags) != 0; }
113 constexpr bool has_all(int qFlags) const {
114 return (flags_ & qFlags) == qFlags;
115 }
116 constexpr bool has_none(int qFlags) const { return (flags_ & qFlags) == 0; }
117};
118
119/// An attribute class for advertising specific properties of
120/// a geometric attribute that can affect the computation of
121/// the bounds of the primitive.
123 public:
124 /// The geometry may have segments that end without closing the path.
125 constexpr bool may_have_end_caps() const { return has_any(kMayHaveCaps); }
126
127 /// The geometry may have segments connect non-continuously.
128 constexpr bool may_have_joins() const { return has_any(kMayHaveJoins); }
129
130 /// Mainly for drawPoints(PointMode) where Butt caps are rendered as squares.
131 constexpr bool butt_cap_becomes_square() const {
133 }
134
135 /// The geometry may have segments that end on a diagonal
136 /// such that their end caps extend further than the default
137 /// |strokeWidth * 0.5| margin around the geometry.
138 constexpr bool may_have_diagonal_caps() const {
140 }
141
142 /// The geometry may have segments that meet at vertices at
143 /// an acute angle such that the miter joins will extend
144 /// further than the default |strokeWidth * 0.5| margin around
145 /// the geometry.
146 constexpr bool may_have_acute_joins() const {
148 }
149
150 private:
151 explicit constexpr DisplayListSpecialGeometryFlags(int flags)
152 : DisplayListFlagsBase(flags) {
153 FML_DCHECK((flags & kAnySpecialGeometryMask) == flags);
154 }
155
156 const DisplayListSpecialGeometryFlags with(int extra) const {
157 return extra == 0 ? *this : DisplayListSpecialGeometryFlags(flags_ | extra);
158 }
159
161};
162
164 public:
166 return special_flags_;
167 }
168
169 constexpr bool ignores_paint() const { return has_any(kIgnoresPaint); }
170
171 constexpr bool applies_anti_alias() const { return has_any(kUsesAntiAlias); }
172 constexpr bool applies_color() const { return has_any(kUsesColor); }
173 constexpr bool applies_alpha() const { return has_any(kUsesAlpha); }
174 constexpr bool applies_alpha_or_color() const {
175 return has_any(kUsesAlpha | kUsesColor);
176 }
177
178 /// The primitive dynamically determines whether it is a stroke or fill
179 /// operation (or both) based on the setting of the |Style| attribute.
180 constexpr bool applies_style() const { return has_any(kIsDrawnGeometry); }
181 /// The primitive can use any of the stroke attributes, such as
182 /// StrokeWidth, StrokeMiter, StrokeCap, or StrokeJoin. This
183 /// method will return if the primitive is defined as one that
184 /// strokes its geometry (such as |drawLine|) or if it is defined
185 /// as one that honors the Style attribute. If the Style attribute
186 /// is known then a more accurate answer can be returned from
187 /// the |is_stroked| method by supplying the actual setting of
188 /// the style.
189 // bool applies_stroke_attributes() const { return is_stroked(); }
190
191 constexpr bool applies_shader() const { return has_any(kUsesShader); }
192 /// The primitive honors the current DlColorFilter, including
193 /// the related attribute InvertColors
194 constexpr bool applies_color_filter() const {
196 }
197 /// The primitive honors the DlBlendMode
198 constexpr bool applies_blend() const { return has_any(kUsesBlend); }
199 /// The primitive honors the DlMaskFilter whether set using the
200 /// filter object or using the convenience method |setMaskBlurFilter|
201 constexpr bool applies_mask_filter() const {
202 return has_any(kUsesMaskFilter);
203 }
204 constexpr bool applies_image_filter() const {
206 }
207
208 constexpr bool is_geometric() const { return has_any(kIsAnyGeometryMask); }
209 constexpr bool always_stroked() const { return has_any(kIsStrokedGeometry); }
210 constexpr bool is_stroked(DlDrawStyle style = DlDrawStyle::kStroke) const {
211 return (has_any(kIsStrokedGeometry) ||
213 }
214
215 constexpr bool is_flood() const { return has_any(kFloodsSurface); }
216
217 constexpr bool operator==(DisplayListAttributeFlags const& other) const {
218 return flags_ == other.flags_;
219 }
220
221 private:
222 explicit constexpr DisplayListAttributeFlags(int flags)
223 : DisplayListFlagsBase(flags),
224 special_flags_(flags & kAnySpecialGeometryMask) {
229 FML_DCHECK(((flags & kAnyAttributeMask) == 0) !=
230 ((flags & kIgnoresPaint) == 0));
231 FML_DCHECK((flags & kIsAnyGeometryMask) != 0 ||
232 (flags & kAnySpecialGeometryMask) == 0);
233 }
234
235 constexpr DisplayListAttributeFlags operator+(int extra) const {
236 return extra == 0 ? *this : DisplayListAttributeFlags(flags_ | extra);
237 }
238
239 constexpr DisplayListAttributeFlags operator-(int remove) const {
240 FML_DCHECK(has_all(remove));
241 return DisplayListAttributeFlags(flags_ & ~remove);
242 }
243
244 const DisplayListSpecialGeometryFlags special_flags_;
245
246 friend class DisplayListOpFlags;
247};
248
250 private:
251 // Flags common to all primitives that apply colors
252 static constexpr int kBasePaintFlags = (kUsesColor | //
253 kUsesAlpha | //
254 kUsesBlend | //
255 kUsesShader | //
258
259 // Flags common to all primitives that stroke or fill
260 static constexpr int kBaseStrokeOrFillFlags = (kIsDrawnGeometry | //
261 kUsesAntiAlias | //
263
264 // Flags common to primitives that stroke geometry
265 static constexpr int kBaseStrokeFlags = (kIsStrokedGeometry | //
266 kUsesAntiAlias | //
268
269 // Flags common to primitives that render an image with paint attributes
270 static constexpr int kBaseImageFlags = (kIsNonGeometric | //
271 kUsesAlpha | //
272 kUsesBlend | //
275
276 public:
292 kBasePaintFlags | //
294 };
295 // Special case flags for horizonal and vertical lines
297 kBasePaintFlags | //
298 kBaseStrokeFlags | //
299 kMayHaveCaps //
300 };
306 kBasePaintFlags | //
307 kBaseStrokeOrFillFlags | //
309 };
311 kBasePaintFlags | //
312 kBaseStrokeOrFillFlags //
313 };
315 kBasePaintFlags | //
316 kBaseStrokeOrFillFlags //
317 };
319 kBasePaintFlags | //
320 kBaseStrokeOrFillFlags //
321 };
323 kBasePaintFlags | //
324 kBaseStrokeOrFillFlags //
325 };
327 kBasePaintFlags | //
328 kBaseStrokeOrFillFlags //
329 };
331 kBasePaintFlags | //
332 kBaseStrokeOrFillFlags | //
333 kMayHaveCaps | //
335 kMayHaveJoins | //
337 };
339 kBasePaintFlags | //
340 kBaseStrokeOrFillFlags | //
341 kMayHaveCaps | //
343 };
345 kBasePaintFlags | //
346 kBaseStrokeOrFillFlags | //
347 kMayHaveJoins | //
349 };
351 kBasePaintFlags | //
352 kBaseStrokeFlags | //
353 kMayHaveCaps | //
355 };
357 kBasePaintFlags | //
358 kBaseStrokeFlags | //
359 kMayHaveCaps | //
361 };
362 // Polygon mode just draws (count-1) separate lines, no joins
364 kBasePaintFlags | //
365 kBaseStrokeFlags | //
366 kMayHaveCaps | //
368 };
370 kIsNonGeometric | //
371 kUsesAlpha | //
372 kUsesShader | //
373 kUsesBlend | //
376 };
381 kBaseImageFlags | //
382 kUsesAntiAlias | //
384 };
389 kBaseImageFlags | //
390 kUsesAntiAlias | //
392 };
397 kBaseImageFlags //
398 };
403 kBaseImageFlags //
404 };
409 DisplayListAttributeFlags(kBasePaintFlags | //
410 kBaseStrokeOrFillFlags | //
411 kMayHaveJoins) //
412 - kUsesAntiAlias //
413 };
417
418 // Flags for usage in drawParagraph internal conversion.
420 kBasePaintFlags | //
421 kBaseStrokeOrFillFlags | //
423 };
424};
425
426} // namespace flutter
427
428#endif // FLUTTER_DISPLAY_LIST_DL_OP_FLAGS_H_
constexpr bool applies_color() const
constexpr bool is_stroked(DlDrawStyle style=DlDrawStyle::kStroke) const
constexpr bool applies_alpha() const
constexpr bool applies_color_filter() const
constexpr bool ignores_paint() const
constexpr bool is_geometric() const
constexpr bool applies_alpha_or_color() const
constexpr bool applies_image_filter() const
constexpr bool applies_shader() const
const DisplayListSpecialGeometryFlags GeometryFlags(bool is_stroked) const
constexpr bool applies_anti_alias() const
constexpr bool always_stroked() const
constexpr bool operator==(DisplayListAttributeFlags const &other) const
constexpr bool applies_mask_filter() const
constexpr bool applies_blend() const
The primitive honors the DlBlendMode.
constexpr bool applies_style() const
constexpr bool is_flood() const
constexpr DisplayListFlagsBase(int flags)
constexpr bool has_none(int qFlags) const
constexpr bool has_any(int qFlags) const
constexpr bool has_all(int qFlags) const
static constexpr int kUsesShader
Definition dl_op_flags.h:86
static constexpr int kIsStrokedGeometry
Definition dl_op_flags.h:36
static constexpr int kUsesAlpha
Definition dl_op_flags.h:83
static constexpr int kUsesColorFilter
Definition dl_op_flags.h:87
static constexpr int kAnyAttributeMask
static constexpr int kMayHaveDiagonalCaps
Definition dl_op_flags.h:64
static constexpr int kIsFilledGeometry
Definition dl_op_flags.h:31
static constexpr int kMayHaveAcuteJoins
Definition dl_op_flags.h:75
static constexpr int kMayHaveCaps
Definition dl_op_flags.h:52
static constexpr int kButtCapIsSquare
Definition dl_op_flags.h:54
static constexpr int kIsDrawnGeometry
Definition dl_op_flags.h:41
static constexpr int kIsAnyGeometryMask
Definition dl_op_flags.h:43
static constexpr int kAnySpecialGeometryMask
Definition dl_op_flags.h:77
static constexpr int kMayHaveJoins
Definition dl_op_flags.h:53
static constexpr int kIsNonGeometric
Definition dl_op_flags.h:26
static constexpr int kFloodsSurface
Definition dl_op_flags.h:50
static constexpr int kUsesMaskFilter
Definition dl_op_flags.h:88
static constexpr int kUsesColor
Definition dl_op_flags.h:84
static constexpr int kUsesBlend
Definition dl_op_flags.h:85
static constexpr int kUsesImageFilter
Definition dl_op_flags.h:89
static constexpr int kIgnoresPaint
Definition dl_op_flags.h:98
static constexpr int kUsesAntiAlias
Definition dl_op_flags.h:82
static constexpr DisplayListAttributeFlags kDrawParagraphFlags
static constexpr DisplayListAttributeFlags kDrawAtlasFlags
static constexpr DisplayListAttributeFlags kDrawVerticesFlags
static constexpr DisplayListAttributeFlags kDrawArcWithCenterFlags
static constexpr DisplayListAttributeFlags kDrawPaintFlags
static constexpr DisplayListAttributeFlags kDrawArcNoCenterFlags
static constexpr DisplayListAttributeFlags kDrawImageRectWithPaintFlags
static constexpr DisplayListAttributeFlags kSaveLayerFlags
static constexpr DisplayListAttributeFlags kDrawOvalFlags
static constexpr DisplayListAttributeFlags kDrawPointsAsLinesFlags
static constexpr DisplayListAttributeFlags kDrawPointsAsPolygonFlags
static constexpr DisplayListAttributeFlags kDrawImageRectFlags
static constexpr DisplayListAttributeFlags kDrawCircleFlags
static constexpr DisplayListAttributeFlags kDrawDisplayListFlags
static constexpr DisplayListAttributeFlags kDrawPathFlags
static constexpr DisplayListAttributeFlags kDrawAtlasWithPaintFlags
static constexpr DisplayListAttributeFlags kDrawImageNineFlags
static constexpr DisplayListAttributeFlags kDrawLineFlags
static constexpr DisplayListAttributeFlags kSaveLayerWithPaintFlags
static constexpr DisplayListAttributeFlags kDrawPointsAsPointsFlags
static constexpr DisplayListAttributeFlags kDrawColorFlags
static constexpr DisplayListAttributeFlags kDrawImageWithPaintFlags
static constexpr DisplayListAttributeFlags kDrawImageNineWithPaintFlags
static constexpr DisplayListAttributeFlags kDrawTextFlags
static constexpr DisplayListAttributeFlags kDrawShadowFlags
static constexpr DisplayListAttributeFlags kDrawRSuperellipseFlags
static constexpr DisplayListAttributeFlags kDrawImageFlags
static constexpr DisplayListAttributeFlags kDrawHVLineFlags
static constexpr DisplayListAttributeFlags kDrawRRectFlags
static constexpr DisplayListAttributeFlags kDrawDRRectFlags
static constexpr DisplayListAttributeFlags kDrawRectFlags
constexpr bool may_have_diagonal_caps() const
constexpr bool may_have_joins() const
The geometry may have segments connect non-continuously.
constexpr bool may_have_end_caps() const
The geometry may have segments that end without closing the path.
constexpr bool may_have_acute_joins() const
constexpr bool butt_cap_becomes_square() const
Mainly for drawPoints(PointMode) where Butt caps are rendered as squares.
#define FML_DCHECK(condition)
Definition logging.h:122
DlDrawStyle
Definition dl_paint.h:19
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes