OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_PAINT_PAINT_OP_BUFFER_H_ | 5 #ifndef CC_PAINT_PAINT_OP_BUFFER_H_ |
6 #define CC_PAINT_PAINT_OP_BUFFER_H_ | 6 #define CC_PAINT_PAINT_OP_BUFFER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 Rotate, | 65 Rotate, |
66 Save, | 66 Save, |
67 SaveLayer, | 67 SaveLayer, |
68 SaveLayerAlpha, | 68 SaveLayerAlpha, |
69 Scale, | 69 Scale, |
70 SetMatrix, | 70 SetMatrix, |
71 Translate, | 71 Translate, |
72 LastPaintOpType = Translate, | 72 LastPaintOpType = Translate, |
73 }; | 73 }; |
74 | 74 |
75 // It is a requirement for every field in a PaintOp that we can memcpy it to | |
76 // another place in memory and free the only one (without calling any | |
77 // constructors or destructors). Specializations of this template are for | |
78 // types that we know to be safe for memcpy+free, with static asserts if | |
79 // possible, and explanations if not. | |
80 template <typename T> | |
81 struct SafePaintOpData; | |
vmpstr
2017/06/01 22:00:55
Don't need the forward declare anymore
| |
82 | |
83 template <typename T> | |
84 struct SafePaintOpData { | |
85 using type = T; | |
86 | |
87 // TODO(danakj): This could use std::is_trivially_move_constructible once that | |
88 // is available on all our toolchains. | |
89 static_assert(base::is_trivially_copyable<type>::value, | |
90 "This type is not trivially copyable, which means it may not be" | |
91 " okay to change its memory address via memcpy+free. A template" | |
92 " specialization should be provided for this type that verifies" | |
93 " or explains why it is valid to memcpy+free this type."); | |
94 }; | |
95 | |
96 // sk_sp<T> pointers behave if their memory address is changed because there | |
97 // is never a pointer back to the sk_sp<T> itself from inside the T. This is | |
98 // true because multiple sk_sp<> may point to the same T and they are | |
99 // transient compared to the lifetime of any T. Additionally, the move | |
100 // constructor doesn't change any state that needs to be reflected in the new | |
101 // object. | |
102 template <typename U> | |
103 struct SafePaintOpData<sk_sp<U>> { | |
104 using type = sk_sp<U>; | |
105 }; | |
106 // scoped_refptr<> is able to be moved in memory for the same reasons as | |
107 // sk_sp<>. | |
108 template <typename U> | |
109 struct SafePaintOpData<scoped_refptr<U>> { | |
110 using type = scoped_refptr<U>; | |
111 }; | |
112 | |
113 // PaintFlags is a collection of trivial data types and sk_sp<> ref pointers. | |
114 // The trivial data types satisfy std::is_trivially_copyable, and sk_sp<> is | |
115 // valid to have its memory address changed for reasons decribed on | |
116 // SafePaintOpData<sk_sp>. | |
117 template <> | |
118 struct SafePaintOpData<PaintFlags> { | |
119 using type = PaintFlags; | |
120 }; | |
121 | |
122 // PaintImage is a set of trivial types and an sk_sp<> which is able to be | |
123 // moved in memory as described on SafePaintOpData<sk_sp>. PaintImage does not | |
124 // hold any pointers back to itself directly or indirectly. | |
125 template <> | |
126 struct SafePaintOpData<PaintImage> { | |
127 using type = PaintImage; | |
128 }; | |
129 | |
130 // ThreadsafePath is an SkPath which contains trivial types, sk_sp<>, and | |
131 // SkAtomic<uint8_t>. sk_sp<> is valid as described on SafePaintOpData<sk_sp>. | |
132 // SkAtomic<uint8_t> stores a trivial type internally, and takes its address | |
133 // but does not store it. | |
134 template <> | |
135 struct SafePaintOpData<ThreadsafePath> { | |
136 using type = ThreadsafePath; | |
137 }; | |
138 | |
139 // WARNING: It is a requirement for every field in a PaintOp that we can memcpy | |
140 // it to another place in memory and free the only one (without calling any | |
141 // constructors or destructors). We think of this as moving the memory address | |
142 // of the data type. This is required because PaintOpBuffer stores PaintOps in | |
143 // a memory buffer that is realloced when it grows, changing the address of | |
144 // everything inside the buffer. | |
145 // std::is_trivially_copyable<> would guarantee this, but is a superset of the | |
146 // guarantees that we need. For instance sk_sp<> works correctly when we | |
147 // memcpy+free it, but it has a non-trivial move constructor and destructor, | |
148 // which would make it fail a check for std::is_trivially_copyable<>. | |
149 // std::is_trivially_move_constructible<> also provides enough as we are moving | |
150 // the objects from one address to another conceptually, but also is not | |
151 // satisfied by sk_sp<> since it modifies the moved-from type. | |
152 // | |
153 // THEREFORE: For each field in a PaintOp, declare it as a | |
154 // SafePaintOpData<T>::type, which provides us with an explanation of safety for | |
155 // each type. | |
156 // | |
157 // BEWARE: std::vector does *not* work if its memory address is changed, as | |
158 // implementations can (and do) sometimes have a pointer back to the vector from | |
159 // its internals, so running its move-assignment operator is required. | |
75 struct CC_PAINT_EXPORT PaintOp { | 160 struct CC_PAINT_EXPORT PaintOp { |
vmpstr
2017/06/01 22:00:55
maybe we can add something like
template <typenam
| |
76 uint32_t type : 8; | 161 uint32_t type : 8; |
77 uint32_t skip : 24; | 162 uint32_t skip : 24; |
78 | 163 |
79 PaintOpType GetType() const { return static_cast<PaintOpType>(type); } | 164 PaintOpType GetType() const { return static_cast<PaintOpType>(type); } |
80 | 165 |
81 // Subclasses should provide a static Raster() method which is called from | 166 // Subclasses should provide a static Raster() method which is called from |
82 // here. The Raster method should take a const PaintOp* parameter. It is | 167 // here. The Raster method should take a const PaintOp* parameter. It is |
83 // static with a pointer to the base type so that we can use it as a function | 168 // static with a pointer to the base type so that we can use it as a function |
84 // pointer. | 169 // pointer. |
85 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; | 170 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 SkImage* image = shader ? shader->isAImage(nullptr, nullptr) : nullptr; | 204 SkImage* image = shader ? shader->isAImage(nullptr, nullptr) : nullptr; |
120 return image && image->isLazyGenerated(); | 205 return image && image->isLazyGenerated(); |
121 } | 206 } |
122 | 207 |
123 // Subclasses should provide a static RasterWithFlags() method which is called | 208 // Subclasses should provide a static RasterWithFlags() method which is called |
124 // from the Raster() method. The RasterWithFlags() should use the PaintFlags | 209 // from the Raster() method. The RasterWithFlags() should use the PaintFlags |
125 // passed to it, instead of the |flags| member directly, as some callers may | 210 // passed to it, instead of the |flags| member directly, as some callers may |
126 // provide a modified PaintFlags. The RasterWithFlags() method is static with | 211 // provide a modified PaintFlags. The RasterWithFlags() method is static with |
127 // a const PaintOpWithFlags* parameter so that it can be used as a function | 212 // a const PaintOpWithFlags* parameter so that it can be used as a function |
128 // pointer. | 213 // pointer. |
129 PaintFlags flags; | 214 SafePaintOpData<PaintFlags>::type flags; |
130 }; | 215 }; |
131 | 216 |
217 // A PaintOp with an additional block of memory with variable size. The | |
218 // additional data held in the PaintOpWithData must be able to be moved in | |
219 // memory without consequences. As such it must not (directly or indirectly) | |
220 // contain any pointers back to itself or to the PaintOp. | |
132 struct CC_PAINT_EXPORT PaintOpWithData : PaintOpWithFlags { | 221 struct CC_PAINT_EXPORT PaintOpWithData : PaintOpWithFlags { |
133 // Having data is just a helper for ops that have a varying amount of data and | 222 // Having data is just a helper for ops that have a varying amount of data and |
134 // want a way to store that inline. This is for ops that pass in a | 223 // want a way to store that inline. This is for ops that pass in a |
135 // void* and a length. The void* data is assumed to not have any alignment | 224 // void* and a length. The void* data is assumed to not have any alignment |
136 // requirements. | 225 // requirements. |
137 PaintOpWithData(const PaintFlags& flags, size_t bytes) | 226 PaintOpWithData(const PaintFlags& flags, size_t bytes) |
138 : PaintOpWithFlags(flags), bytes(bytes) {} | 227 : PaintOpWithFlags(flags), bytes(bytes) {} |
139 | 228 |
140 // Get data out by calling paint_op_data. This can't be part of the class | 229 // Get data out by calling paint_op_data. This can't be part of the class |
141 // because it needs to know the size of the derived type. | 230 // because it needs to know the size of the derived type. |
142 size_t bytes; | 231 SafePaintOpData<size_t>::type bytes; |
143 | 232 |
144 protected: | 233 protected: |
145 // For some derived object T, return the internally stored data. | 234 // For some derived object T, return the internally stored data. |
146 // This needs the fully derived type to know how much to offset | 235 // This needs the fully derived type to know how much to offset |
147 // from the start of the top to the data. | 236 // from the start of the top to the data. |
148 template <typename T> | 237 template <typename T> |
149 const void* GetDataForThis(const T* op) const { | 238 const void* GetDataForThis(const T* op) const { |
150 static_assert(std::is_convertible<T, PaintOpWithData>::value, | 239 static_assert(std::is_convertible<T, PaintOpWithData>::value, |
151 "T is not a PaintOpWithData"); | 240 "T is not a PaintOpWithData"); |
152 // Arbitrary data for a PaintOp is stored after the PaintOp itself | 241 // Arbitrary data for a PaintOp is stored after the PaintOp itself |
(...skipping 10 matching lines...) Expand all Loading... | |
163 const_cast<const PaintOpWithData*>(this)->GetDataForThis( | 252 const_cast<const PaintOpWithData*>(this)->GetDataForThis( |
164 const_cast<const T*>(op))); | 253 const_cast<const T*>(op))); |
165 } | 254 } |
166 }; | 255 }; |
167 | 256 |
168 struct CC_PAINT_EXPORT PaintOpWithArrayBase : PaintOpWithFlags { | 257 struct CC_PAINT_EXPORT PaintOpWithArrayBase : PaintOpWithFlags { |
169 explicit PaintOpWithArrayBase(const PaintFlags& flags) | 258 explicit PaintOpWithArrayBase(const PaintFlags& flags) |
170 : PaintOpWithFlags(flags) {} | 259 : PaintOpWithFlags(flags) {} |
171 }; | 260 }; |
172 | 261 |
262 // A PaintOp with an additional block of memory with variable size that is | |
263 // an array of a known type. The types held in the array must be able to be | |
264 // moved in memory without consequences. As such it must not (directly or | |
265 // indirectly) contain any pointers back to itself or to the PaintOp. We use | |
266 // std::is_trivially_copyable() to verify this (it is more strict but satisfies | |
267 // our needs). | |
173 template <typename M> | 268 template <typename M> |
174 struct CC_PAINT_EXPORT PaintOpWithArray : PaintOpWithArrayBase { | 269 struct CC_PAINT_EXPORT PaintOpWithArray : PaintOpWithArrayBase { |
270 static_assert(base::is_trivially_copyable<M>::value, ""); | |
271 | |
175 // Paint op that has a M[count] and a char[bytes]. | 272 // Paint op that has a M[count] and a char[bytes]. |
176 // Array data is stored first so that it can be aligned with T's alignment | 273 // Array data is stored first so that it can be aligned with T's alignment |
177 // with the arbitrary unaligned char data after it. | 274 // with the arbitrary unaligned char data after it. |
178 // Memory layout here is: | op | M[count] | char[bytes] | padding | next op | | 275 // Memory layout here is: | op | M[count] | char[bytes] | padding | next op | |
179 // Next op is located at (char*)(op) + op->skip. | 276 // Next op is located at (char*)(op) + op->skip. |
180 PaintOpWithArray(const PaintFlags& flags, size_t bytes, size_t count) | 277 PaintOpWithArray(const PaintFlags& flags, size_t bytes, size_t count) |
181 : PaintOpWithArrayBase(flags), bytes(bytes), count(count) {} | 278 : PaintOpWithArrayBase(flags), bytes(bytes), count(count) {} |
182 | 279 |
183 size_t bytes; | 280 SafePaintOpData<size_t>::type bytes; |
184 size_t count; | 281 SafePaintOpData<size_t>::type count; |
185 | 282 |
186 protected: | 283 protected: |
187 template <typename T> | 284 template <typename T> |
188 const void* GetDataForThis(const T* op) const { | 285 const void* GetDataForThis(const T* op) const { |
189 static_assert(std::is_convertible<T, PaintOpWithArrayBase>::value, | 286 static_assert(std::is_convertible<T, PaintOpWithArrayBase>::value, |
190 "T is not a PaintOpWithData"); | 287 "T is not a PaintOpWithData"); |
191 const char* start_array = | 288 const char* start_array = |
192 reinterpret_cast<const char*>(GetArrayForThis(op)); | 289 reinterpret_cast<const char*>(GetArrayForThis(op)); |
193 return start_array + sizeof(M) * count; | 290 return start_array + sizeof(M) * count; |
194 } | 291 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 331 |
235 static constexpr PaintOpType kType = PaintOpType::Annotate; | 332 static constexpr PaintOpType kType = PaintOpType::Annotate; |
236 AnnotateOp(PaintCanvas::AnnotationType annotation_type, | 333 AnnotateOp(PaintCanvas::AnnotationType annotation_type, |
237 const SkRect& rect, | 334 const SkRect& rect, |
238 sk_sp<SkData> data); | 335 sk_sp<SkData> data); |
239 ~AnnotateOp(); | 336 ~AnnotateOp(); |
240 static void Raster(const PaintOp* op, | 337 static void Raster(const PaintOp* op, |
241 SkCanvas* canvas, | 338 SkCanvas* canvas, |
242 const SkMatrix& original_ctm); | 339 const SkMatrix& original_ctm); |
243 | 340 |
244 PaintCanvas::AnnotationType annotation_type; | 341 SafePaintOpData<PaintCanvas::AnnotationType>::type annotation_type; |
245 SkRect rect; | 342 SafePaintOpData<SkRect>::type rect; |
246 sk_sp<SkData> data; | 343 SafePaintOpData<sk_sp<SkData>>::type data; |
247 }; | 344 }; |
248 | 345 |
249 struct CC_PAINT_EXPORT ClipPathOp final : PaintOp { | 346 struct CC_PAINT_EXPORT ClipPathOp final : PaintOp { |
250 static constexpr PaintOpType kType = PaintOpType::ClipPath; | 347 static constexpr PaintOpType kType = PaintOpType::ClipPath; |
251 ClipPathOp(SkPath path, SkClipOp op, bool antialias) | 348 ClipPathOp(SkPath path, SkClipOp op, bool antialias) |
252 : path(path), op(op), antialias(antialias) {} | 349 : path(path), op(op), antialias(antialias) {} |
253 static void Raster(const PaintOp* op, | 350 static void Raster(const PaintOp* op, |
254 SkCanvas* canvas, | 351 SkCanvas* canvas, |
255 const SkMatrix& original_ctm); | 352 const SkMatrix& original_ctm); |
256 int CountSlowPaths() const; | 353 int CountSlowPaths() const; |
257 | 354 |
258 ThreadsafePath path; | 355 SafePaintOpData<ThreadsafePath>::type path; |
259 SkClipOp op; | 356 SafePaintOpData<SkClipOp>::type op; |
260 bool antialias; | 357 SafePaintOpData<bool>::type antialias; |
261 }; | 358 }; |
262 | 359 |
263 struct CC_PAINT_EXPORT ClipRectOp final : PaintOp { | 360 struct CC_PAINT_EXPORT ClipRectOp final : PaintOp { |
264 static constexpr PaintOpType kType = PaintOpType::ClipRect; | 361 static constexpr PaintOpType kType = PaintOpType::ClipRect; |
265 ClipRectOp(const SkRect& rect, SkClipOp op, bool antialias) | 362 ClipRectOp(const SkRect& rect, SkClipOp op, bool antialias) |
266 : rect(rect), op(op), antialias(antialias) {} | 363 : rect(rect), op(op), antialias(antialias) {} |
267 static void Raster(const PaintOp* op, | 364 static void Raster(const PaintOp* op, |
268 SkCanvas* canvas, | 365 SkCanvas* canvas, |
269 const SkMatrix& original_ctm); | 366 const SkMatrix& original_ctm); |
270 | 367 |
271 SkRect rect; | 368 SafePaintOpData<SkRect>::type rect; |
272 SkClipOp op; | 369 SafePaintOpData<SkClipOp>::type op; |
273 bool antialias; | 370 SafePaintOpData<bool>::type antialias; |
274 }; | 371 }; |
275 | 372 |
276 struct CC_PAINT_EXPORT ClipRRectOp final : PaintOp { | 373 struct CC_PAINT_EXPORT ClipRRectOp final : PaintOp { |
277 static constexpr PaintOpType kType = PaintOpType::ClipRRect; | 374 static constexpr PaintOpType kType = PaintOpType::ClipRRect; |
278 ClipRRectOp(const SkRRect& rrect, SkClipOp op, bool antialias) | 375 ClipRRectOp(const SkRRect& rrect, SkClipOp op, bool antialias) |
279 : rrect(rrect), op(op), antialias(antialias) {} | 376 : rrect(rrect), op(op), antialias(antialias) {} |
280 static void Raster(const PaintOp* op, | 377 static void Raster(const PaintOp* op, |
281 SkCanvas* canvas, | 378 SkCanvas* canvas, |
282 const SkMatrix& original_ctm); | 379 const SkMatrix& original_ctm); |
283 | 380 |
284 SkRRect rrect; | 381 SafePaintOpData<SkRRect>::type rrect; |
285 SkClipOp op; | 382 SafePaintOpData<SkClipOp>::type op; |
286 bool antialias; | 383 SafePaintOpData<bool>::type antialias; |
287 }; | 384 }; |
288 | 385 |
289 struct CC_PAINT_EXPORT ConcatOp final : PaintOp { | 386 struct CC_PAINT_EXPORT ConcatOp final : PaintOp { |
290 static constexpr PaintOpType kType = PaintOpType::Concat; | 387 static constexpr PaintOpType kType = PaintOpType::Concat; |
291 explicit ConcatOp(const SkMatrix& matrix) : matrix(matrix) {} | 388 explicit ConcatOp(const SkMatrix& matrix) : matrix(matrix) {} |
292 static void Raster(const PaintOp* op, | 389 static void Raster(const PaintOp* op, |
293 SkCanvas* canvas, | 390 SkCanvas* canvas, |
294 const SkMatrix& original_ctm); | 391 const SkMatrix& original_ctm); |
295 | 392 |
296 ThreadsafeMatrix matrix; | 393 SafePaintOpData<ThreadsafeMatrix>::type matrix; |
297 }; | 394 }; |
298 | 395 |
299 struct CC_PAINT_EXPORT DrawArcOp final : PaintOpWithFlags { | 396 struct CC_PAINT_EXPORT DrawArcOp final : PaintOpWithFlags { |
300 static constexpr PaintOpType kType = PaintOpType::DrawArc; | 397 static constexpr PaintOpType kType = PaintOpType::DrawArc; |
301 static constexpr bool kIsDrawOp = true; | 398 static constexpr bool kIsDrawOp = true; |
302 DrawArcOp(const SkRect& oval, | 399 DrawArcOp(const SkRect& oval, |
303 SkScalar start_angle, | 400 SkScalar start_angle, |
304 SkScalar sweep_angle, | 401 SkScalar sweep_angle, |
305 bool use_center, | 402 bool use_center, |
306 const PaintFlags& flags) | 403 const PaintFlags& flags) |
307 : PaintOpWithFlags(flags), | 404 : PaintOpWithFlags(flags), |
308 oval(oval), | 405 oval(oval), |
309 start_angle(start_angle), | 406 start_angle(start_angle), |
310 sweep_angle(sweep_angle), | 407 sweep_angle(sweep_angle), |
311 use_center(use_center) {} | 408 use_center(use_center) {} |
312 static void Raster(const PaintOp* op, | 409 static void Raster(const PaintOp* op, |
313 SkCanvas* canvas, | 410 SkCanvas* canvas, |
314 const SkMatrix& original_ctm) { | 411 const SkMatrix& original_ctm) { |
315 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 412 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
316 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 413 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
317 } | 414 } |
318 static void RasterWithFlags(const PaintOpWithFlags* op, | 415 static void RasterWithFlags(const PaintOpWithFlags* op, |
319 const PaintFlags* flags, | 416 const PaintFlags* flags, |
320 SkCanvas* canvas, | 417 SkCanvas* canvas, |
321 const SkMatrix& original_ctm); | 418 const SkMatrix& original_ctm); |
322 | 419 |
323 SkRect oval; | 420 SafePaintOpData<SkRect>::type oval; |
324 SkScalar start_angle; | 421 SafePaintOpData<SkScalar>::type start_angle; |
325 SkScalar sweep_angle; | 422 SafePaintOpData<SkScalar>::type sweep_angle; |
326 bool use_center; | 423 SafePaintOpData<bool>::type use_center; |
327 }; | 424 }; |
328 | 425 |
329 struct CC_PAINT_EXPORT DrawCircleOp final : PaintOpWithFlags { | 426 struct CC_PAINT_EXPORT DrawCircleOp final : PaintOpWithFlags { |
330 static constexpr PaintOpType kType = PaintOpType::DrawCircle; | 427 static constexpr PaintOpType kType = PaintOpType::DrawCircle; |
331 static constexpr bool kIsDrawOp = true; | 428 static constexpr bool kIsDrawOp = true; |
332 DrawCircleOp(SkScalar cx, | 429 DrawCircleOp(SkScalar cx, |
333 SkScalar cy, | 430 SkScalar cy, |
334 SkScalar radius, | 431 SkScalar radius, |
335 const PaintFlags& flags) | 432 const PaintFlags& flags) |
336 : PaintOpWithFlags(flags), cx(cx), cy(cy), radius(radius) {} | 433 : PaintOpWithFlags(flags), cx(cx), cy(cy), radius(radius) {} |
337 static void Raster(const PaintOp* op, | 434 static void Raster(const PaintOp* op, |
338 SkCanvas* canvas, | 435 SkCanvas* canvas, |
339 const SkMatrix& original_ctm) { | 436 const SkMatrix& original_ctm) { |
340 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 437 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
341 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 438 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
342 } | 439 } |
343 static void RasterWithFlags(const PaintOpWithFlags* op, | 440 static void RasterWithFlags(const PaintOpWithFlags* op, |
344 const PaintFlags* flags, | 441 const PaintFlags* flags, |
345 SkCanvas* canvas, | 442 SkCanvas* canvas, |
346 const SkMatrix& original_ctm); | 443 const SkMatrix& original_ctm); |
347 | 444 |
348 SkScalar cx; | 445 SafePaintOpData<SkScalar>::type cx; |
349 SkScalar cy; | 446 SafePaintOpData<SkScalar>::type cy; |
350 SkScalar radius; | 447 SafePaintOpData<SkScalar>::type radius; |
351 }; | 448 }; |
352 | 449 |
353 struct CC_PAINT_EXPORT DrawColorOp final : PaintOp { | 450 struct CC_PAINT_EXPORT DrawColorOp final : PaintOp { |
354 static constexpr PaintOpType kType = PaintOpType::DrawColor; | 451 static constexpr PaintOpType kType = PaintOpType::DrawColor; |
355 static constexpr bool kIsDrawOp = true; | 452 static constexpr bool kIsDrawOp = true; |
356 DrawColorOp(SkColor color, SkBlendMode mode) : color(color), mode(mode) {} | 453 DrawColorOp(SkColor color, SkBlendMode mode) : color(color), mode(mode) {} |
357 static void Raster(const PaintOp* op, | 454 static void Raster(const PaintOp* op, |
358 SkCanvas* canvas, | 455 SkCanvas* canvas, |
359 const SkMatrix& original_ctm); | 456 const SkMatrix& original_ctm); |
360 | 457 |
361 SkColor color; | 458 SafePaintOpData<SkColor>::type color; |
362 SkBlendMode mode; | 459 SafePaintOpData<SkBlendMode>::type mode; |
363 }; | 460 }; |
364 | 461 |
365 struct CC_PAINT_EXPORT DrawDisplayItemListOp final : PaintOp { | 462 struct CC_PAINT_EXPORT DrawDisplayItemListOp final : PaintOp { |
366 static constexpr PaintOpType kType = PaintOpType::DrawDisplayItemList; | 463 static constexpr PaintOpType kType = PaintOpType::DrawDisplayItemList; |
367 static constexpr bool kIsDrawOp = true; | 464 static constexpr bool kIsDrawOp = true; |
368 explicit DrawDisplayItemListOp(scoped_refptr<DisplayItemList> list); | 465 explicit DrawDisplayItemListOp(scoped_refptr<DisplayItemList> list); |
369 // Windows wants to generate these when types are exported, so | 466 // Windows wants to generate these when types are exported, so |
370 // provide them here explicitly so that DisplayItemList doesn't have | 467 // provide them here explicitly so that DisplayItemList doesn't have |
371 // to be defined in this header. | 468 // to be defined in this header. |
372 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); | 469 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); |
373 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); | 470 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); |
374 ~DrawDisplayItemListOp(); | 471 ~DrawDisplayItemListOp(); |
375 static void Raster(const PaintOp* op, | 472 static void Raster(const PaintOp* op, |
376 SkCanvas* canvas, | 473 SkCanvas* canvas, |
377 const SkMatrix& original_ctm); | 474 const SkMatrix& original_ctm); |
378 size_t AdditionalBytesUsed() const; | 475 size_t AdditionalBytesUsed() const; |
379 bool HasDiscardableImages() const; | 476 bool HasDiscardableImages() const; |
380 int CountSlowPaths() const; | 477 int CountSlowPaths() const; |
381 | 478 |
382 scoped_refptr<DisplayItemList> list; | 479 SafePaintOpData<scoped_refptr<DisplayItemList>>::type list; |
383 }; | 480 }; |
384 | 481 |
385 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags { | 482 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags { |
386 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; | 483 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; |
387 static constexpr bool kIsDrawOp = true; | 484 static constexpr bool kIsDrawOp = true; |
388 DrawDRRectOp(const SkRRect& outer, | 485 DrawDRRectOp(const SkRRect& outer, |
389 const SkRRect& inner, | 486 const SkRRect& inner, |
390 const PaintFlags& flags) | 487 const PaintFlags& flags) |
391 : PaintOpWithFlags(flags), outer(outer), inner(inner) {} | 488 : PaintOpWithFlags(flags), outer(outer), inner(inner) {} |
392 static void Raster(const PaintOp* op, | 489 static void Raster(const PaintOp* op, |
393 SkCanvas* canvas, | 490 SkCanvas* canvas, |
394 const SkMatrix& original_ctm) { | 491 const SkMatrix& original_ctm) { |
395 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 492 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
396 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 493 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
397 } | 494 } |
398 static void RasterWithFlags(const PaintOpWithFlags* op, | 495 static void RasterWithFlags(const PaintOpWithFlags* op, |
399 const PaintFlags* flags, | 496 const PaintFlags* flags, |
400 SkCanvas* canvas, | 497 SkCanvas* canvas, |
401 const SkMatrix& original_ctm); | 498 const SkMatrix& original_ctm); |
402 | 499 |
403 SkRRect outer; | 500 SafePaintOpData<SkRRect>::type outer; |
404 SkRRect inner; | 501 SafePaintOpData<SkRRect>::type inner; |
405 }; | 502 }; |
406 | 503 |
407 struct CC_PAINT_EXPORT DrawImageOp final : PaintOpWithFlags { | 504 struct CC_PAINT_EXPORT DrawImageOp final : PaintOpWithFlags { |
408 static constexpr PaintOpType kType = PaintOpType::DrawImage; | 505 static constexpr PaintOpType kType = PaintOpType::DrawImage; |
409 static constexpr bool kIsDrawOp = true; | 506 static constexpr bool kIsDrawOp = true; |
410 DrawImageOp(const PaintImage& image, | 507 DrawImageOp(const PaintImage& image, |
411 SkScalar left, | 508 SkScalar left, |
412 SkScalar top, | 509 SkScalar top, |
413 const PaintFlags* flags); | 510 const PaintFlags* flags); |
414 ~DrawImageOp(); | 511 ~DrawImageOp(); |
415 static void Raster(const PaintOp* op, | 512 static void Raster(const PaintOp* op, |
416 SkCanvas* canvas, | 513 SkCanvas* canvas, |
417 const SkMatrix& original_ctm) { | 514 const SkMatrix& original_ctm) { |
418 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 515 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
419 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 516 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
420 } | 517 } |
421 static void RasterWithFlags(const PaintOpWithFlags* op, | 518 static void RasterWithFlags(const PaintOpWithFlags* op, |
422 const PaintFlags* flags, | 519 const PaintFlags* flags, |
423 SkCanvas* canvas, | 520 SkCanvas* canvas, |
424 const SkMatrix& original_ctm); | 521 const SkMatrix& original_ctm); |
425 bool HasDiscardableImages() const; | 522 bool HasDiscardableImages() const; |
426 | 523 |
427 PaintImage image; | 524 SafePaintOpData<PaintImage>::type image; |
428 SkScalar left; | 525 SafePaintOpData<SkScalar>::type left; |
429 SkScalar top; | 526 SafePaintOpData<SkScalar>::type top; |
430 }; | 527 }; |
431 | 528 |
432 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags { | 529 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags { |
433 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; | 530 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; |
434 static constexpr bool kIsDrawOp = true; | 531 static constexpr bool kIsDrawOp = true; |
435 DrawImageRectOp(const PaintImage& image, | 532 DrawImageRectOp(const PaintImage& image, |
436 const SkRect& src, | 533 const SkRect& src, |
437 const SkRect& dst, | 534 const SkRect& dst, |
438 const PaintFlags* flags, | 535 const PaintFlags* flags, |
439 PaintCanvas::SrcRectConstraint constraint); | 536 PaintCanvas::SrcRectConstraint constraint); |
440 ~DrawImageRectOp(); | 537 ~DrawImageRectOp(); |
441 static void Raster(const PaintOp* op, | 538 static void Raster(const PaintOp* op, |
442 SkCanvas* canvas, | 539 SkCanvas* canvas, |
443 const SkMatrix& original_ctm) { | 540 const SkMatrix& original_ctm) { |
444 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 541 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
445 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 542 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
446 } | 543 } |
447 static void RasterWithFlags(const PaintOpWithFlags* op, | 544 static void RasterWithFlags(const PaintOpWithFlags* op, |
448 const PaintFlags* flags, | 545 const PaintFlags* flags, |
449 SkCanvas* canvas, | 546 SkCanvas* canvas, |
450 const SkMatrix& original_ctm); | 547 const SkMatrix& original_ctm); |
451 bool HasDiscardableImages() const; | 548 bool HasDiscardableImages() const; |
452 | 549 |
453 PaintImage image; | 550 SafePaintOpData<PaintImage>::type image; |
454 SkRect src; | 551 SafePaintOpData<SkRect>::type src; |
455 SkRect dst; | 552 SafePaintOpData<SkRect>::type dst; |
456 PaintCanvas::SrcRectConstraint constraint; | 553 SafePaintOpData<PaintCanvas::SrcRectConstraint>::type constraint; |
457 }; | 554 }; |
458 | 555 |
459 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags { | 556 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags { |
460 static constexpr PaintOpType kType = PaintOpType::DrawIRect; | 557 static constexpr PaintOpType kType = PaintOpType::DrawIRect; |
461 static constexpr bool kIsDrawOp = true; | 558 static constexpr bool kIsDrawOp = true; |
462 DrawIRectOp(const SkIRect& rect, const PaintFlags& flags) | 559 DrawIRectOp(const SkIRect& rect, const PaintFlags& flags) |
463 : PaintOpWithFlags(flags), rect(rect) {} | 560 : PaintOpWithFlags(flags), rect(rect) {} |
464 static void Raster(const PaintOp* op, | 561 static void Raster(const PaintOp* op, |
465 SkCanvas* canvas, | 562 SkCanvas* canvas, |
466 const SkMatrix& original_ctm) { | 563 const SkMatrix& original_ctm) { |
467 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 564 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
468 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 565 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
469 } | 566 } |
470 static void RasterWithFlags(const PaintOpWithFlags* op, | 567 static void RasterWithFlags(const PaintOpWithFlags* op, |
471 const PaintFlags* flags, | 568 const PaintFlags* flags, |
472 SkCanvas* canvas, | 569 SkCanvas* canvas, |
473 const SkMatrix& original_ctm); | 570 const SkMatrix& original_ctm); |
474 | 571 |
475 SkIRect rect; | 572 SafePaintOpData<SkIRect>::type rect; |
476 }; | 573 }; |
477 | 574 |
478 struct CC_PAINT_EXPORT DrawLineOp final : PaintOpWithFlags { | 575 struct CC_PAINT_EXPORT DrawLineOp final : PaintOpWithFlags { |
479 static constexpr PaintOpType kType = PaintOpType::DrawLine; | 576 static constexpr PaintOpType kType = PaintOpType::DrawLine; |
480 static constexpr bool kIsDrawOp = true; | 577 static constexpr bool kIsDrawOp = true; |
481 DrawLineOp(SkScalar x0, | 578 DrawLineOp(SkScalar x0, |
482 SkScalar y0, | 579 SkScalar y0, |
483 SkScalar x1, | 580 SkScalar x1, |
484 SkScalar y1, | 581 SkScalar y1, |
485 const PaintFlags& flags) | 582 const PaintFlags& flags) |
486 : PaintOpWithFlags(flags), x0(x0), y0(y0), x1(x1), y1(y1) {} | 583 : PaintOpWithFlags(flags), x0(x0), y0(y0), x1(x1), y1(y1) {} |
487 static void Raster(const PaintOp* op, | 584 static void Raster(const PaintOp* op, |
488 SkCanvas* canvas, | 585 SkCanvas* canvas, |
489 const SkMatrix& original_ctm) { | 586 const SkMatrix& original_ctm) { |
490 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 587 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
491 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 588 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
492 } | 589 } |
493 static void RasterWithFlags(const PaintOpWithFlags* op, | 590 static void RasterWithFlags(const PaintOpWithFlags* op, |
494 const PaintFlags* flags, | 591 const PaintFlags* flags, |
495 SkCanvas* canvas, | 592 SkCanvas* canvas, |
496 const SkMatrix& original_ctm); | 593 const SkMatrix& original_ctm); |
497 | 594 |
498 int CountSlowPaths() const; | 595 int CountSlowPaths() const; |
499 | 596 |
500 SkScalar x0; | 597 SafePaintOpData<SkScalar>::type x0; |
501 SkScalar y0; | 598 SafePaintOpData<SkScalar>::type y0; |
502 SkScalar x1; | 599 SafePaintOpData<SkScalar>::type x1; |
503 SkScalar y1; | 600 SafePaintOpData<SkScalar>::type y1; |
504 }; | 601 }; |
505 | 602 |
506 struct CC_PAINT_EXPORT DrawOvalOp final : PaintOpWithFlags { | 603 struct CC_PAINT_EXPORT DrawOvalOp final : PaintOpWithFlags { |
507 static constexpr PaintOpType kType = PaintOpType::DrawOval; | 604 static constexpr PaintOpType kType = PaintOpType::DrawOval; |
508 static constexpr bool kIsDrawOp = true; | 605 static constexpr bool kIsDrawOp = true; |
509 DrawOvalOp(const SkRect& oval, const PaintFlags& flags) | 606 DrawOvalOp(const SkRect& oval, const PaintFlags& flags) |
510 : PaintOpWithFlags(flags), oval(oval) {} | 607 : PaintOpWithFlags(flags), oval(oval) {} |
511 static void Raster(const PaintOp* op, | 608 static void Raster(const PaintOp* op, |
512 SkCanvas* canvas, | 609 SkCanvas* canvas, |
513 const SkMatrix& original_ctm) { | 610 const SkMatrix& original_ctm) { |
514 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 611 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
515 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 612 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
516 } | 613 } |
517 static void RasterWithFlags(const PaintOpWithFlags* op, | 614 static void RasterWithFlags(const PaintOpWithFlags* op, |
518 const PaintFlags* flags, | 615 const PaintFlags* flags, |
519 SkCanvas* canvas, | 616 SkCanvas* canvas, |
520 const SkMatrix& original_ctm); | 617 const SkMatrix& original_ctm); |
521 | 618 |
522 SkRect oval; | 619 SafePaintOpData<SkRect>::type oval; |
523 }; | 620 }; |
524 | 621 |
525 struct CC_PAINT_EXPORT DrawPathOp final : PaintOpWithFlags { | 622 struct CC_PAINT_EXPORT DrawPathOp final : PaintOpWithFlags { |
526 static constexpr PaintOpType kType = PaintOpType::DrawPath; | 623 static constexpr PaintOpType kType = PaintOpType::DrawPath; |
527 static constexpr bool kIsDrawOp = true; | 624 static constexpr bool kIsDrawOp = true; |
528 DrawPathOp(const SkPath& path, const PaintFlags& flags) | 625 DrawPathOp(const SkPath& path, const PaintFlags& flags) |
529 : PaintOpWithFlags(flags), path(path) {} | 626 : PaintOpWithFlags(flags), path(path) {} |
530 static void Raster(const PaintOp* op, | 627 static void Raster(const PaintOp* op, |
531 SkCanvas* canvas, | 628 SkCanvas* canvas, |
532 const SkMatrix& original_ctm) { | 629 const SkMatrix& original_ctm) { |
533 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 630 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
534 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 631 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
535 } | 632 } |
536 static void RasterWithFlags(const PaintOpWithFlags* op, | 633 static void RasterWithFlags(const PaintOpWithFlags* op, |
537 const PaintFlags* flags, | 634 const PaintFlags* flags, |
538 SkCanvas* canvas, | 635 SkCanvas* canvas, |
539 const SkMatrix& original_ctm); | 636 const SkMatrix& original_ctm); |
540 int CountSlowPaths() const; | 637 int CountSlowPaths() const; |
541 | 638 |
542 ThreadsafePath path; | 639 SafePaintOpData<ThreadsafePath>::type path; |
543 }; | 640 }; |
544 | 641 |
545 struct CC_PAINT_EXPORT DrawPosTextOp final : PaintOpWithArray<SkPoint> { | 642 struct CC_PAINT_EXPORT DrawPosTextOp final : PaintOpWithArray<SkPoint> { |
546 static constexpr PaintOpType kType = PaintOpType::DrawPosText; | 643 static constexpr PaintOpType kType = PaintOpType::DrawPosText; |
547 static constexpr bool kIsDrawOp = true; | 644 static constexpr bool kIsDrawOp = true; |
548 DrawPosTextOp(size_t bytes, size_t count, const PaintFlags& flags); | 645 DrawPosTextOp(size_t bytes, size_t count, const PaintFlags& flags); |
549 ~DrawPosTextOp(); | 646 ~DrawPosTextOp(); |
550 static void Raster(const PaintOp* op, | 647 static void Raster(const PaintOp* op, |
551 SkCanvas* canvas, | 648 SkCanvas* canvas, |
552 const SkMatrix& original_ctm) { | 649 const SkMatrix& original_ctm) { |
(...skipping 16 matching lines...) Expand all Loading... | |
569 static constexpr bool kIsDrawOp = true; | 666 static constexpr bool kIsDrawOp = true; |
570 explicit DrawRecordOp(sk_sp<const PaintRecord> record); | 667 explicit DrawRecordOp(sk_sp<const PaintRecord> record); |
571 ~DrawRecordOp(); | 668 ~DrawRecordOp(); |
572 static void Raster(const PaintOp* op, | 669 static void Raster(const PaintOp* op, |
573 SkCanvas* canvas, | 670 SkCanvas* canvas, |
574 const SkMatrix& original_ctm); | 671 const SkMatrix& original_ctm); |
575 size_t AdditionalBytesUsed() const; | 672 size_t AdditionalBytesUsed() const; |
576 bool HasDiscardableImages() const; | 673 bool HasDiscardableImages() const; |
577 int CountSlowPaths() const; | 674 int CountSlowPaths() const; |
578 | 675 |
579 sk_sp<const PaintRecord> record; | 676 SafePaintOpData<sk_sp<const PaintRecord>>::type record; |
580 }; | 677 }; |
581 | 678 |
582 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags { | 679 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags { |
583 static constexpr PaintOpType kType = PaintOpType::DrawRect; | 680 static constexpr PaintOpType kType = PaintOpType::DrawRect; |
584 static constexpr bool kIsDrawOp = true; | 681 static constexpr bool kIsDrawOp = true; |
585 DrawRectOp(const SkRect& rect, const PaintFlags& flags) | 682 DrawRectOp(const SkRect& rect, const PaintFlags& flags) |
586 : PaintOpWithFlags(flags), rect(rect) {} | 683 : PaintOpWithFlags(flags), rect(rect) {} |
587 static void Raster(const PaintOp* op, | 684 static void Raster(const PaintOp* op, |
588 SkCanvas* canvas, | 685 SkCanvas* canvas, |
589 const SkMatrix& original_ctm) { | 686 const SkMatrix& original_ctm) { |
590 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 687 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
591 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 688 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
592 } | 689 } |
593 static void RasterWithFlags(const PaintOpWithFlags* op, | 690 static void RasterWithFlags(const PaintOpWithFlags* op, |
594 const PaintFlags* flags, | 691 const PaintFlags* flags, |
595 SkCanvas* canvas, | 692 SkCanvas* canvas, |
596 const SkMatrix& original_ctm); | 693 const SkMatrix& original_ctm); |
597 | 694 |
598 SkRect rect; | 695 SafePaintOpData<SkRect>::type rect; |
599 }; | 696 }; |
600 | 697 |
601 struct CC_PAINT_EXPORT DrawRRectOp final : PaintOpWithFlags { | 698 struct CC_PAINT_EXPORT DrawRRectOp final : PaintOpWithFlags { |
602 static constexpr PaintOpType kType = PaintOpType::DrawRRect; | 699 static constexpr PaintOpType kType = PaintOpType::DrawRRect; |
603 static constexpr bool kIsDrawOp = true; | 700 static constexpr bool kIsDrawOp = true; |
604 DrawRRectOp(const SkRRect& rrect, const PaintFlags& flags) | 701 DrawRRectOp(const SkRRect& rrect, const PaintFlags& flags) |
605 : PaintOpWithFlags(flags), rrect(rrect) {} | 702 : PaintOpWithFlags(flags), rrect(rrect) {} |
606 static void Raster(const PaintOp* op, | 703 static void Raster(const PaintOp* op, |
607 SkCanvas* canvas, | 704 SkCanvas* canvas, |
608 const SkMatrix& original_ctm) { | 705 const SkMatrix& original_ctm) { |
609 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 706 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
610 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 707 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
611 } | 708 } |
612 static void RasterWithFlags(const PaintOpWithFlags* op, | 709 static void RasterWithFlags(const PaintOpWithFlags* op, |
613 const PaintFlags* flags, | 710 const PaintFlags* flags, |
614 SkCanvas* canvas, | 711 SkCanvas* canvas, |
615 const SkMatrix& original_ctm); | 712 const SkMatrix& original_ctm); |
616 | 713 |
617 SkRRect rrect; | 714 SafePaintOpData<SkRRect>::type rrect; |
618 }; | 715 }; |
619 | 716 |
620 struct CC_PAINT_EXPORT DrawTextOp final : PaintOpWithData { | 717 struct CC_PAINT_EXPORT DrawTextOp final : PaintOpWithData { |
621 static constexpr PaintOpType kType = PaintOpType::DrawText; | 718 static constexpr PaintOpType kType = PaintOpType::DrawText; |
622 static constexpr bool kIsDrawOp = true; | 719 static constexpr bool kIsDrawOp = true; |
623 DrawTextOp(size_t bytes, SkScalar x, SkScalar y, const PaintFlags& flags) | 720 DrawTextOp(size_t bytes, SkScalar x, SkScalar y, const PaintFlags& flags) |
624 : PaintOpWithData(flags, bytes), x(x), y(y) {} | 721 : PaintOpWithData(flags, bytes), x(x), y(y) {} |
625 static void Raster(const PaintOp* op, | 722 static void Raster(const PaintOp* op, |
626 SkCanvas* canvas, | 723 SkCanvas* canvas, |
627 const SkMatrix& original_ctm) { | 724 const SkMatrix& original_ctm) { |
628 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 725 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
629 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 726 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
630 } | 727 } |
631 static void RasterWithFlags(const PaintOpWithFlags* op, | 728 static void RasterWithFlags(const PaintOpWithFlags* op, |
632 const PaintFlags* flags, | 729 const PaintFlags* flags, |
633 SkCanvas* canvas, | 730 SkCanvas* canvas, |
634 const SkMatrix& original_ctm); | 731 const SkMatrix& original_ctm); |
635 | 732 |
636 void* GetData() { return GetDataForThis(this); } | 733 void* GetData() { return GetDataForThis(this); } |
637 const void* GetData() const { return GetDataForThis(this); } | 734 const void* GetData() const { return GetDataForThis(this); } |
638 | 735 |
639 SkScalar x; | 736 SafePaintOpData<SkScalar>::type x; |
640 SkScalar y; | 737 SafePaintOpData<SkScalar>::type y; |
641 }; | 738 }; |
642 | 739 |
643 struct CC_PAINT_EXPORT DrawTextBlobOp final : PaintOpWithFlags { | 740 struct CC_PAINT_EXPORT DrawTextBlobOp final : PaintOpWithFlags { |
644 static constexpr PaintOpType kType = PaintOpType::DrawTextBlob; | 741 static constexpr PaintOpType kType = PaintOpType::DrawTextBlob; |
645 static constexpr bool kIsDrawOp = true; | 742 static constexpr bool kIsDrawOp = true; |
646 DrawTextBlobOp(sk_sp<SkTextBlob> blob, | 743 DrawTextBlobOp(sk_sp<SkTextBlob> blob, |
647 SkScalar x, | 744 SkScalar x, |
648 SkScalar y, | 745 SkScalar y, |
649 const PaintFlags& flags); | 746 const PaintFlags& flags); |
650 ~DrawTextBlobOp(); | 747 ~DrawTextBlobOp(); |
651 static void Raster(const PaintOp* op, | 748 static void Raster(const PaintOp* op, |
652 SkCanvas* canvas, | 749 SkCanvas* canvas, |
653 const SkMatrix& original_ctm) { | 750 const SkMatrix& original_ctm) { |
654 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 751 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
655 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 752 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
656 } | 753 } |
657 static void RasterWithFlags(const PaintOpWithFlags* op, | 754 static void RasterWithFlags(const PaintOpWithFlags* op, |
658 const PaintFlags* flags, | 755 const PaintFlags* flags, |
659 SkCanvas* canvas, | 756 SkCanvas* canvas, |
660 const SkMatrix& original_ctm); | 757 const SkMatrix& original_ctm); |
661 | 758 |
662 sk_sp<SkTextBlob> blob; | 759 SafePaintOpData<sk_sp<SkTextBlob>>::type blob; |
663 SkScalar x; | 760 SafePaintOpData<SkScalar>::type x; |
664 SkScalar y; | 761 SafePaintOpData<SkScalar>::type y; |
665 }; | 762 }; |
666 | 763 |
667 struct CC_PAINT_EXPORT NoopOp final : PaintOp { | 764 struct CC_PAINT_EXPORT NoopOp final : PaintOp { |
668 static constexpr PaintOpType kType = PaintOpType::Noop; | 765 static constexpr PaintOpType kType = PaintOpType::Noop; |
669 static void Raster(const PaintOp* op, | 766 static void Raster(const PaintOp* op, |
670 SkCanvas* canvas, | 767 SkCanvas* canvas, |
671 const SkMatrix& original_ctm) {} | 768 const SkMatrix& original_ctm) {} |
672 }; | 769 }; |
673 | 770 |
674 struct CC_PAINT_EXPORT RestoreOp final : PaintOp { | 771 struct CC_PAINT_EXPORT RestoreOp final : PaintOp { |
675 static constexpr PaintOpType kType = PaintOpType::Restore; | 772 static constexpr PaintOpType kType = PaintOpType::Restore; |
676 static void Raster(const PaintOp* op, | 773 static void Raster(const PaintOp* op, |
677 SkCanvas* canvas, | 774 SkCanvas* canvas, |
678 const SkMatrix& original_ctm); | 775 const SkMatrix& original_ctm); |
679 }; | 776 }; |
680 | 777 |
681 struct CC_PAINT_EXPORT RotateOp final : PaintOp { | 778 struct CC_PAINT_EXPORT RotateOp final : PaintOp { |
682 static constexpr PaintOpType kType = PaintOpType::Rotate; | 779 static constexpr PaintOpType kType = PaintOpType::Rotate; |
683 explicit RotateOp(SkScalar degrees) : degrees(degrees) {} | 780 explicit RotateOp(SkScalar degrees) : degrees(degrees) {} |
684 static void Raster(const PaintOp* op, | 781 static void Raster(const PaintOp* op, |
685 SkCanvas* canvas, | 782 SkCanvas* canvas, |
686 const SkMatrix& original_ctm); | 783 const SkMatrix& original_ctm); |
687 | 784 |
688 SkScalar degrees; | 785 SafePaintOpData<SkScalar>::type degrees; |
689 }; | 786 }; |
690 | 787 |
691 struct CC_PAINT_EXPORT SaveOp final : PaintOp { | 788 struct CC_PAINT_EXPORT SaveOp final : PaintOp { |
692 static constexpr PaintOpType kType = PaintOpType::Save; | 789 static constexpr PaintOpType kType = PaintOpType::Save; |
693 static void Raster(const PaintOp* op, | 790 static void Raster(const PaintOp* op, |
694 SkCanvas* canvas, | 791 SkCanvas* canvas, |
695 const SkMatrix& original_ctm); | 792 const SkMatrix& original_ctm); |
696 }; | 793 }; |
697 | 794 |
698 struct CC_PAINT_EXPORT SaveLayerOp final : PaintOpWithFlags { | 795 struct CC_PAINT_EXPORT SaveLayerOp final : PaintOpWithFlags { |
699 static constexpr PaintOpType kType = PaintOpType::SaveLayer; | 796 static constexpr PaintOpType kType = PaintOpType::SaveLayer; |
700 SaveLayerOp(const SkRect* bounds, const PaintFlags* flags) | 797 SaveLayerOp(const SkRect* bounds, const PaintFlags* flags) |
701 : PaintOpWithFlags(flags ? *flags : PaintFlags()), | 798 : PaintOpWithFlags(flags ? *flags : PaintFlags()), |
702 bounds(bounds ? *bounds : kUnsetRect) {} | 799 bounds(bounds ? *bounds : kUnsetRect) {} |
703 static void Raster(const PaintOp* op, | 800 static void Raster(const PaintOp* op, |
704 SkCanvas* canvas, | 801 SkCanvas* canvas, |
705 const SkMatrix& original_ctm) { | 802 const SkMatrix& original_ctm) { |
706 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); | 803 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); |
707 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); | 804 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); |
708 } | 805 } |
709 static void RasterWithFlags(const PaintOpWithFlags* op, | 806 static void RasterWithFlags(const PaintOpWithFlags* op, |
710 const PaintFlags* flags, | 807 const PaintFlags* flags, |
711 SkCanvas* canvas, | 808 SkCanvas* canvas, |
712 const SkMatrix& original_ctm); | 809 const SkMatrix& original_ctm); |
713 | 810 |
714 SkRect bounds; | 811 SafePaintOpData<SkRect>::type bounds; |
715 }; | 812 }; |
716 | 813 |
717 struct CC_PAINT_EXPORT SaveLayerAlphaOp final : PaintOp { | 814 struct CC_PAINT_EXPORT SaveLayerAlphaOp final : PaintOp { |
718 static constexpr PaintOpType kType = PaintOpType::SaveLayerAlpha; | 815 static constexpr PaintOpType kType = PaintOpType::SaveLayerAlpha; |
719 SaveLayerAlphaOp(const SkRect* bounds, uint8_t alpha) | 816 SaveLayerAlphaOp(const SkRect* bounds, uint8_t alpha) |
720 : bounds(bounds ? *bounds : kUnsetRect), alpha(alpha) {} | 817 : bounds(bounds ? *bounds : kUnsetRect), alpha(alpha) {} |
721 static void Raster(const PaintOp* op, | 818 static void Raster(const PaintOp* op, |
722 SkCanvas* canvas, | 819 SkCanvas* canvas, |
723 const SkMatrix& original_ctm); | 820 const SkMatrix& original_ctm); |
724 | 821 |
725 SkRect bounds; | 822 SafePaintOpData<SkRect>::type bounds; |
726 uint8_t alpha; | 823 SafePaintOpData<uint8_t>::type alpha; |
727 }; | 824 }; |
728 | 825 |
729 struct CC_PAINT_EXPORT ScaleOp final : PaintOp { | 826 struct CC_PAINT_EXPORT ScaleOp final : PaintOp { |
730 static constexpr PaintOpType kType = PaintOpType::Scale; | 827 static constexpr PaintOpType kType = PaintOpType::Scale; |
731 ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} | 828 ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} |
732 static void Raster(const PaintOp* op, | 829 static void Raster(const PaintOp* op, |
733 SkCanvas* canvas, | 830 SkCanvas* canvas, |
734 const SkMatrix& original_ctm); | 831 const SkMatrix& original_ctm); |
735 | 832 |
736 SkScalar sx; | 833 SafePaintOpData<SkScalar>::type sx; |
737 SkScalar sy; | 834 SafePaintOpData<SkScalar>::type sy; |
738 }; | 835 }; |
739 | 836 |
740 struct CC_PAINT_EXPORT SetMatrixOp final : PaintOp { | 837 struct CC_PAINT_EXPORT SetMatrixOp final : PaintOp { |
741 static constexpr PaintOpType kType = PaintOpType::SetMatrix; | 838 static constexpr PaintOpType kType = PaintOpType::SetMatrix; |
742 explicit SetMatrixOp(const SkMatrix& matrix) : matrix(matrix) {} | 839 explicit SetMatrixOp(const SkMatrix& matrix) : matrix(matrix) {} |
743 // This is the only op that needs the original ctm of the SkCanvas | 840 // This is the only op that needs the original ctm of the SkCanvas |
744 // used for raster (since SetMatrix is relative to the recording origin and | 841 // used for raster (since SetMatrix is relative to the recording origin and |
745 // shouldn't clobber the SkCanvas raster origin). | 842 // shouldn't clobber the SkCanvas raster origin). |
746 // | 843 // |
747 // TODO(enne): Find some cleaner way to do this, possibly by making | 844 // TODO(enne): Find some cleaner way to do this, possibly by making |
748 // all SetMatrix calls Concat?? | 845 // all SetMatrix calls Concat?? |
749 static void Raster(const PaintOp* op, | 846 static void Raster(const PaintOp* op, |
750 SkCanvas* canvas, | 847 SkCanvas* canvas, |
751 const SkMatrix& original_ctm); | 848 const SkMatrix& original_ctm); |
752 | 849 |
753 ThreadsafeMatrix matrix; | 850 SafePaintOpData<ThreadsafeMatrix>::type matrix; |
754 }; | 851 }; |
755 | 852 |
756 struct CC_PAINT_EXPORT TranslateOp final : PaintOp { | 853 struct CC_PAINT_EXPORT TranslateOp final : PaintOp { |
757 static constexpr PaintOpType kType = PaintOpType::Translate; | 854 static constexpr PaintOpType kType = PaintOpType::Translate; |
758 TranslateOp(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {} | 855 TranslateOp(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {} |
759 static void Raster(const PaintOp* op, | 856 static void Raster(const PaintOp* op, |
760 SkCanvas* canvas, | 857 SkCanvas* canvas, |
761 const SkMatrix& original_ctm); | 858 const SkMatrix& original_ctm); |
762 | 859 |
763 SkScalar dx; | 860 SafePaintOpData<SkScalar>::type dx; |
764 SkScalar dy; | 861 SafePaintOpData<SkScalar>::type dy; |
765 }; | 862 }; |
766 | 863 |
767 using LargestPaintOp = DrawDRRectOp; | 864 using LargestPaintOp = DrawDRRectOp; |
768 | 865 |
769 class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { | 866 class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
770 public: | 867 public: |
771 enum { kInitialBufferSize = 4096 }; | 868 enum { kInitialBufferSize = 4096 }; |
772 // It's not necessarily the case that the op with the maximum alignment | 869 // It's not necessarily the case that the op with the maximum alignment |
773 // requirements is also the biggest op, but for now that's true. | 870 // requirements is also the biggest op, but for now that's true. |
774 static constexpr size_t PaintOpAlign = ALIGNOF(DrawDRRectOp); | 871 static constexpr size_t PaintOpAlign = ALIGNOF(DrawDRRectOp); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
968 // Record additional bytes used by referenced sub-records and display lists. | 1065 // Record additional bytes used by referenced sub-records and display lists. |
969 size_t subrecord_bytes_used_ = 0; | 1066 size_t subrecord_bytes_used_ = 0; |
970 bool has_discardable_images_ = false; | 1067 bool has_discardable_images_ = false; |
971 | 1068 |
972 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); | 1069 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); |
973 }; | 1070 }; |
974 | 1071 |
975 } // namespace cc | 1072 } // namespace cc |
976 | 1073 |
977 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ | 1074 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ |
OLD | NEW |