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