Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: cc/paint/paint_op_buffer.h

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

Powered by Google App Engine
This is Rietveld 408576698