Flutter Engine
The 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
8#include "flutter/display_list/dl_paint.h"
9#include "flutter/fml/logging.h"
10
11namespace flutter {
12
13class DlPathEffect;
14/// The base class for the classes that maintain a list of
15/// attributes that might be important for a number of operations
16/// including which rendering attributes need to be set before
17/// calling a rendering method (all |drawSomething| calls),
18/// or for determining which exceptional conditions may need
19/// to be accounted for in bounds calculations.
20/// This class contains only protected definitions and helper methods
21/// for the public classes |DisplayListAttributeFlags| and
22/// |DisplayListSpecialGeometryFlags|.
24 protected:
25 // A drawing operation that is not geometric in nature (but which
26 // may still apply a MaskFilter - see |kUsesMaskFilter| below).
27 static constexpr int kIsNonGeometric = 0;
28
29 // A geometric operation that is defined as a fill operation
30 // regardless of what the current paint Style is set to.
31 // This flag will automatically assume |kUsesMaskFilter|.
32 static constexpr int kIsFilledGeometry = 1 << 0;
33
34 // A geometric operation that is defined as a stroke operation
35 // regardless of what the current paint Style is set to.
36 // This flag will automatically assume |kUsesMaskFilter|.
37 static constexpr int kIsStrokedGeometry = 1 << 1;
38
39 // A geometric operation that may be a stroke or fill operation
40 // depending on the current state of the paint Style attribute.
41 // This flag will automatically assume |kUsesMaskFilter|.
42 static constexpr int kIsDrawnGeometry = 1 << 2;
43
44 static constexpr int kIsAnyGeometryMask = //
48
49 // A primitive that floods the surface (or clip) with no
50 // natural bounds, such as |drawColor| or |drawPaint|.
51 static constexpr int kFloodsSurface = 1 << 3;
52
53 static constexpr int kMayHaveCaps = 1 << 4;
54 static constexpr int kMayHaveJoins = 1 << 5;
55 static constexpr int kButtCapIsSquare = 1 << 6;
56
57 // A geometric operation which has a path that might have
58 // end caps that are not rectilinear which means that square
59 // end caps might project further than half the stroke width
60 // from the geometry bounds.
61 // A rectilinear path such as |drawRect| will not have
62 // diagonal end caps. |drawLine| might have diagonal end
63 // caps depending on the angle of the line, and more likely
64 // |drawPath| will often have such end caps.
65 static constexpr int kMayHaveDiagonalCaps = 1 << 7;
66
67 // A geometric operation which has joined vertices that are
68 // not guaranteed to be smooth (angles of incoming and outgoing)
69 // segments at some joins may not have the same angle) or
70 // rectilinear (squares have right angles at the corners, but
71 // those corners will never extend past the bounding box of
72 // the geometry pre-transform).
73 // |drawRect|, |drawOval| and |drawRRect| all have well
74 // behaved joins, but |drawPath| might have joins that cause
75 // mitered extensions outside the pre-transformed bounding box.
76 static constexpr int kMayHaveAcuteJoins = 1 << 8;
77
78 static constexpr int kAnySpecialGeometryMask = //
81
82 // clang-format off
83 static constexpr int kUsesAntiAlias = 1 << 10;
84 static constexpr int kUsesAlpha = 1 << 11;
85 static constexpr int kUsesColor = 1 << 12;
86 static constexpr int kUsesBlend = 1 << 13;
87 static constexpr int kUsesShader = 1 << 14;
88 static constexpr int kUsesColorFilter = 1 << 15;
89 static constexpr int kUsesPathEffect = 1 << 16;
90 static constexpr int kUsesMaskFilter = 1 << 17;
91 static constexpr int kUsesImageFilter = 1 << 18;
92
93 // Some ops have an optional paint argument. If the version
94 // stored in the DisplayList ignores the paint, but there
95 // is an option to render the same op with a paint then
96 // both of the following flags are set to indicate that
97 // a default paint object can be constructed when rendering
98 // the op to carry information imposed from outside the
99 // DisplayList (for example, the opacity override).
100 static constexpr int kIgnoresPaint = 1 << 30;
101 // clang-format on
102
103 static constexpr int kAnyAttributeMask = //
106};
107
109 protected:
110 explicit constexpr DisplayListFlagsBase(int flags) : flags_(flags) {}
111
112 const int flags_;
113
114 constexpr bool has_any(int qFlags) const { return (flags_ & qFlags) != 0; }
115 constexpr bool has_all(int qFlags) const {
116 return (flags_ & qFlags) == qFlags;
117 }
118 constexpr bool has_none(int qFlags) const { return (flags_ & qFlags) == 0; }
119};
120
121/// An attribute class for advertising specific properties of
122/// a geometric attribute that can affect the computation of
123/// the bounds of the primitive.
125 public:
126 /// The geometry may have segments that end without closing the path.
127 constexpr bool may_have_end_caps() const { return has_any(kMayHaveCaps); }
128
129 /// The geometry may have segments connect non-continuously.
130 constexpr bool may_have_joins() const { return has_any(kMayHaveJoins); }
131
132 /// Mainly for drawPoints(PointMode) where Butt caps are rendered as squares.
133 constexpr bool butt_cap_becomes_square() const {
135 }
136
137 /// The geometry may have segments that end on a diagonal
138 /// such that their end caps extend further than the default
139 /// |strokeWidth * 0.5| margin around the geometry.
140 constexpr bool may_have_diagonal_caps() const {
142 }
143
144 /// The geometry may have segments that meet at vertices at
145 /// an acute angle such that the miter joins will extend
146 /// further than the default |strokeWidth * 0.5| margin around
147 /// the geometry.
148 constexpr bool may_have_acute_joins() const {
150 }
151
152 private:
153 explicit constexpr DisplayListSpecialGeometryFlags(int flags)
156 }
157
158 const DisplayListSpecialGeometryFlags with(int extra) const {
159 return extra == 0 ? *this : DisplayListSpecialGeometryFlags(flags_ | extra);
160 }
161
163};
164
166 public:
168 const DlPathEffect* effect,
169 bool is_stroked) const;
170
171 constexpr bool ignores_paint() const { return has_any(kIgnoresPaint); }
172
173 constexpr bool applies_anti_alias() const { return has_any(kUsesAntiAlias); }
174 constexpr bool applies_color() const { return has_any(kUsesColor); }
175 constexpr bool applies_alpha() const { return has_any(kUsesAlpha); }
176 constexpr bool applies_alpha_or_color() const {
177 return has_any(kUsesAlpha | kUsesColor);
178 }
179
180 /// The primitive dynamically determines whether it is a stroke or fill
181 /// operation (or both) based on the setting of the |Style| attribute.
182 constexpr bool applies_style() const { return has_any(kIsDrawnGeometry); }
183 /// The primitive can use any of the stroke attributes, such as
184 /// StrokeWidth, StrokeMiter, StrokeCap, or StrokeJoin. This
185 /// method will return if the primitive is defined as one that
186 /// strokes its geometry (such as |drawLine|) or if it is defined
187 /// as one that honors the Style attribute. If the Style attribute
188 /// is known then a more accurate answer can be returned from
189 /// the |is_stroked| method by supplying the actual setting of
190 /// the style.
191 // bool applies_stroke_attributes() const { return is_stroked(); }
192
193 constexpr bool applies_shader() const { return has_any(kUsesShader); }
194 /// The primitive honors the current DlColorFilter, including
195 /// the related attribute InvertColors
196 constexpr bool applies_color_filter() const {
198 }
199 /// The primitive honors the DlBlendMode
200 constexpr bool applies_blend() const { return has_any(kUsesBlend); }
201 constexpr bool applies_path_effect() const {
202 return has_any(kUsesPathEffect);
203 }
204 /// The primitive honors the DlMaskFilter whether set using the
205 /// filter object or using the convenience method |setMaskBlurFilter|
206 constexpr bool applies_mask_filter() const {
207 return has_any(kUsesMaskFilter);
208 }
209 constexpr bool applies_image_filter() const {
211 }
212
213 constexpr bool is_geometric() const { return has_any(kIsAnyGeometryMask); }
214 constexpr bool always_stroked() const { return has_any(kIsStrokedGeometry); }
215 constexpr bool is_stroked(DlDrawStyle style = DlDrawStyle::kStroke) const {
216 return (has_any(kIsStrokedGeometry) ||
218 }
219
220 constexpr bool is_flood() const { return has_any(kFloodsSurface); }
221
222 constexpr bool operator==(DisplayListAttributeFlags const& other) const {
223 return flags_ == other.flags_;
224 }
225
226 private:
227 explicit constexpr DisplayListAttributeFlags(int flags)
229 special_flags_(flags & kAnySpecialGeometryMask) {
235 ((flags & kIgnoresPaint) == 0));
238 }
239
240 constexpr DisplayListAttributeFlags operator+(int extra) const {
241 return extra == 0 ? *this : DisplayListAttributeFlags(flags_ | extra);
242 }
243
244 constexpr DisplayListAttributeFlags operator-(int remove) const {
245 FML_DCHECK(has_all(remove));
246 return DisplayListAttributeFlags(flags_ & ~remove);
247 }
248
249 const DisplayListSpecialGeometryFlags special_flags_;
250
251 friend class DisplayListOpFlags;
252};
253
255 private:
256 // Flags common to all primitives that apply colors
257 static constexpr int kBasePaintFlags = (kUsesColor | //
258 kUsesAlpha | //
259 kUsesBlend | //
260 kUsesShader | //
263
264 // Flags common to all primitives that stroke or fill
265 static constexpr int kBaseStrokeOrFillFlags = (kIsDrawnGeometry | //
266 kUsesAntiAlias | //
267 kUsesMaskFilter | //
269
270 // Flags common to primitives that stroke geometry
271 static constexpr int kBaseStrokeFlags = (kIsStrokedGeometry | //
272 kUsesAntiAlias | //
273 kUsesMaskFilter | //
275
276 // Flags common to primitives that render an image with paint attributes
277 static constexpr int kBaseImageFlags = (kIsNonGeometric | //
278 kUsesAlpha | //
279 kUsesBlend | //
282
283 public:
299 kBasePaintFlags | //
301 };
302 // Special case flags for horizonal and vertical lines
304 kBasePaintFlags | //
305 kBaseStrokeFlags | //
306 kMayHaveCaps //
307 };
313 kBasePaintFlags | //
314 kBaseStrokeOrFillFlags | //
316 };
318 kBasePaintFlags | //
319 kBaseStrokeOrFillFlags //
320 };
322 kBasePaintFlags | //
323 kBaseStrokeOrFillFlags //
324 };
326 kBasePaintFlags | //
327 kBaseStrokeOrFillFlags //
328 };
330 kBasePaintFlags | //
331 kBaseStrokeOrFillFlags //
332 };
334 kBasePaintFlags | //
335 kBaseStrokeOrFillFlags | //
336 kMayHaveCaps | //
338 kMayHaveJoins | //
340 };
342 kBasePaintFlags | //
343 kBaseStrokeOrFillFlags | //
344 kMayHaveCaps | //
346 };
348 kBasePaintFlags | //
349 kBaseStrokeOrFillFlags | //
350 kMayHaveJoins | //
352 };
354 kBasePaintFlags | //
355 kBaseStrokeFlags | //
356 kMayHaveCaps | //
358 };
360 kBasePaintFlags | //
361 kBaseStrokeFlags | //
362 kMayHaveCaps | //
364 };
365 // Polygon mode just draws (count-1) separate lines, no joins
367 kBasePaintFlags | //
368 kBaseStrokeFlags | //
369 kMayHaveCaps | //
371 };
373 kIsNonGeometric | //
374 kUsesAlpha | //
375 kUsesShader | //
376 kUsesBlend | //
379 };
384 kBaseImageFlags | //
385 kUsesAntiAlias | //
387 };
392 kBaseImageFlags | //
393 kUsesAntiAlias | //
395 };
400 kBaseImageFlags //
401 };
406 kBaseImageFlags //
407 };
412 DisplayListAttributeFlags(kBasePaintFlags | //
413 kBaseStrokeOrFillFlags | //
414 kMayHaveJoins) //
415 - kUsesAntiAlias //
416 };
420};
421
422} // namespace flutter
423
424#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
const DisplayListSpecialGeometryFlags WithPathEffect(const DlPathEffect *effect, bool is_stroked) const
constexpr bool applies_image_filter() const
constexpr bool applies_path_effect() const
constexpr bool applies_shader() 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:87
static constexpr int kIsStrokedGeometry
Definition dl_op_flags.h:37
static constexpr int kUsesAlpha
Definition dl_op_flags.h:84
static constexpr int kUsesPathEffect
Definition dl_op_flags.h:89
static constexpr int kUsesColorFilter
Definition dl_op_flags.h:88
static constexpr int kAnyAttributeMask
static constexpr int kMayHaveDiagonalCaps
Definition dl_op_flags.h:65
static constexpr int kIsFilledGeometry
Definition dl_op_flags.h:32
static constexpr int kMayHaveAcuteJoins
Definition dl_op_flags.h:76
static constexpr int kMayHaveCaps
Definition dl_op_flags.h:53
static constexpr int kButtCapIsSquare
Definition dl_op_flags.h:55
static constexpr int kIsDrawnGeometry
Definition dl_op_flags.h:42
static constexpr int kIsAnyGeometryMask
Definition dl_op_flags.h:44
static constexpr int kAnySpecialGeometryMask
Definition dl_op_flags.h:78
static constexpr int kMayHaveJoins
Definition dl_op_flags.h:54
static constexpr int kIsNonGeometric
Definition dl_op_flags.h:27
static constexpr int kFloodsSurface
Definition dl_op_flags.h:51
static constexpr int kUsesMaskFilter
Definition dl_op_flags.h:90
static constexpr int kUsesColor
Definition dl_op_flags.h:85
static constexpr int kUsesBlend
Definition dl_op_flags.h:86
static constexpr int kUsesImageFilter
Definition dl_op_flags.h:91
static constexpr int kIgnoresPaint
static constexpr int kUsesAntiAlias
Definition dl_op_flags.h:83
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 kDrawTextBlobFlags
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 kDrawShadowFlags
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.
FlutterSemanticsFlag flags
#define FML_DCHECK(condition)
Definition logging.h:103
DlDrawStyle
Definition dl_paint.h:20
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes