Flutter Engine
The Flutter Engine
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
8#include "flutter/display_list/dl_paint.h"
9#include "flutter/fml/logging.h"
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)
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)
224 special_flags_(flags & kAnySpecialGeometryMask) {
230 ((flags & kIgnoresPaint) == 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 {
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:
279 };
281 kIsNonGeometric | //
282 kUsesAlpha | //
283 kUsesBlend | //
286 };
288 kFloodsSurface | //
290 };
292 kBasePaintFlags | //
294 };
295 // Special case flags for horizonal and vertical lines
297 kBasePaintFlags | //
298 kBaseStrokeFlags | //
299 kMayHaveCaps //
300 };
304 };
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 kMayHaveCaps | //
331 kMayHaveJoins | //
333 };
335 kBasePaintFlags | //
336 kBaseStrokeOrFillFlags | //
337 kMayHaveCaps | //
339 };
341 kBasePaintFlags | //
342 kBaseStrokeOrFillFlags | //
343 kMayHaveJoins | //
345 };
347 kBasePaintFlags | //
348 kBaseStrokeFlags | //
349 kMayHaveCaps | //
351 };
353 kBasePaintFlags | //
354 kBaseStrokeFlags | //
355 kMayHaveCaps | //
357 };
358 // Polygon mode just draws (count-1) separate lines, no joins
360 kBasePaintFlags | //
361 kBaseStrokeFlags | //
362 kMayHaveCaps | //
364 };
366 kIsNonGeometric | //
367 kUsesAlpha | //
368 kUsesShader | //
369 kUsesBlend | //
372 };
375 };
377 kBaseImageFlags | //
378 kUsesAntiAlias | //
380 };
383 };
385 kBaseImageFlags | //
386 kUsesAntiAlias | //
388 };
391 };
393 kBaseImageFlags //
394 };
397 };
399 kBaseImageFlags //
400 };
403 };
405 DisplayListAttributeFlags(kBasePaintFlags | //
406 kBaseStrokeOrFillFlags | //
407 kMayHaveJoins) //
408 - kUsesAntiAlias //
409 };
412 };
413};
414
415} // namespace flutter
416
417#endif // FLUTTER_DISPLAY_LIST_DL_OP_FLAGS_H_
constexpr bool applies_color() const
Definition: dl_op_flags.h:172
constexpr bool is_stroked(DlDrawStyle style=DlDrawStyle::kStroke) const
Definition: dl_op_flags.h:210
constexpr bool applies_alpha() const
Definition: dl_op_flags.h:173
constexpr bool applies_color_filter() const
Definition: dl_op_flags.h:194
constexpr bool ignores_paint() const
Definition: dl_op_flags.h:169
constexpr bool is_geometric() const
Definition: dl_op_flags.h:208
constexpr bool applies_alpha_or_color() const
Definition: dl_op_flags.h:174
constexpr bool applies_image_filter() const
Definition: dl_op_flags.h:204
constexpr bool applies_shader() const
Definition: dl_op_flags.h:191
const DisplayListSpecialGeometryFlags GeometryFlags(bool is_stroked) const
Definition: dl_op_flags.h:165
constexpr bool applies_anti_alias() const
Definition: dl_op_flags.h:171
constexpr bool always_stroked() const
Definition: dl_op_flags.h:209
constexpr bool operator==(DisplayListAttributeFlags const &other) const
Definition: dl_op_flags.h:217
constexpr bool applies_mask_filter() const
Definition: dl_op_flags.h:201
constexpr bool applies_blend() const
The primitive honors the DlBlendMode.
Definition: dl_op_flags.h:198
constexpr bool applies_style() const
Definition: dl_op_flags.h:180
constexpr bool is_flood() const
Definition: dl_op_flags.h:215
constexpr DisplayListFlagsBase(int flags)
Definition: dl_op_flags.h:108
constexpr bool has_none(int qFlags) const
Definition: dl_op_flags.h:116
constexpr bool has_any(int qFlags) const
Definition: dl_op_flags.h:112
constexpr bool has_all(int qFlags) const
Definition: dl_op_flags.h:113
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
Definition: dl_op_flags.h:101
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 kDrawAtlasFlags
Definition: dl_op_flags.h:395
static constexpr DisplayListAttributeFlags kDrawVerticesFlags
Definition: dl_op_flags.h:365
static constexpr DisplayListAttributeFlags kDrawArcWithCenterFlags
Definition: dl_op_flags.h:340
static constexpr DisplayListAttributeFlags kDrawPaintFlags
Definition: dl_op_flags.h:291
static constexpr DisplayListAttributeFlags kDrawArcNoCenterFlags
Definition: dl_op_flags.h:334
static constexpr DisplayListAttributeFlags kDrawImageRectWithPaintFlags
Definition: dl_op_flags.h:384
static constexpr DisplayListAttributeFlags kSaveLayerFlags
Definition: dl_op_flags.h:277
static constexpr DisplayListAttributeFlags kDrawOvalFlags
Definition: dl_op_flags.h:310
static constexpr DisplayListAttributeFlags kDrawTextBlobFlags
Definition: dl_op_flags.h:404
static constexpr DisplayListAttributeFlags kDrawPointsAsLinesFlags
Definition: dl_op_flags.h:352
static constexpr DisplayListAttributeFlags kDrawPointsAsPolygonFlags
Definition: dl_op_flags.h:359
static constexpr DisplayListAttributeFlags kDrawImageRectFlags
Definition: dl_op_flags.h:381
static constexpr DisplayListAttributeFlags kDrawCircleFlags
Definition: dl_op_flags.h:314
static constexpr DisplayListAttributeFlags kDrawDisplayListFlags
Definition: dl_op_flags.h:401
static constexpr DisplayListAttributeFlags kDrawPathFlags
Definition: dl_op_flags.h:326
static constexpr DisplayListAttributeFlags kDrawAtlasWithPaintFlags
Definition: dl_op_flags.h:398
static constexpr DisplayListAttributeFlags kDrawImageNineFlags
Definition: dl_op_flags.h:389
static constexpr DisplayListAttributeFlags kDrawLineFlags
Definition: dl_op_flags.h:301
static constexpr DisplayListAttributeFlags kSaveLayerWithPaintFlags
Definition: dl_op_flags.h:280
static constexpr DisplayListAttributeFlags kDrawPointsAsPointsFlags
Definition: dl_op_flags.h:346
static constexpr DisplayListAttributeFlags kDrawColorFlags
Definition: dl_op_flags.h:287
static constexpr DisplayListAttributeFlags kDrawImageWithPaintFlags
Definition: dl_op_flags.h:376
static constexpr DisplayListAttributeFlags kDrawImageNineWithPaintFlags
Definition: dl_op_flags.h:392
static constexpr DisplayListAttributeFlags kDrawShadowFlags
Definition: dl_op_flags.h:410
static constexpr DisplayListAttributeFlags kDrawImageFlags
Definition: dl_op_flags.h:373
static constexpr DisplayListAttributeFlags kDrawHVLineFlags
Definition: dl_op_flags.h:296
static constexpr DisplayListAttributeFlags kDrawRRectFlags
Definition: dl_op_flags.h:318
static constexpr DisplayListAttributeFlags kDrawDRRectFlags
Definition: dl_op_flags.h:322
static constexpr DisplayListAttributeFlags kDrawRectFlags
Definition: dl_op_flags.h:305
constexpr bool may_have_diagonal_caps() const
Definition: dl_op_flags.h:138
constexpr bool may_have_joins() const
The geometry may have segments connect non-continuously.
Definition: dl_op_flags.h:128
constexpr bool may_have_end_caps() const
The geometry may have segments that end without closing the path.
Definition: dl_op_flags.h:125
constexpr bool may_have_acute_joins() const
Definition: dl_op_flags.h:146
constexpr bool butt_cap_becomes_square() const
Mainly for drawPoints(PointMode) where Butt caps are rendered as squares.
Definition: dl_op_flags.h:131
FlutterSemanticsFlag flags
#define FML_DCHECK(condition)
Definition: logging.h:103
DlDrawStyle
Definition: dl_paint.h:19
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes
def remove(*paths)