| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 PaintOpType GetType() const { return static_cast<PaintOpType>(type); } | 80 PaintOpType GetType() const { return static_cast<PaintOpType>(type); } |
| 81 | 81 |
| 82 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; | 82 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; |
| 83 bool IsDrawOp() const; | 83 bool IsDrawOp() const; |
| 84 | 84 |
| 85 // Only valid for draw ops. | 85 // Only valid for draw ops. |
| 86 void RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const; | 86 void RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const; |
| 87 | 87 |
| 88 int CountSlowPaths() const { return 0; } | 88 int CountSlowPaths() const { return 0; } |
| 89 int CountSlowPathsFromFlags() const { return 0; } |
| 89 | 90 |
| 90 // Returns the number of bytes used by this op in referenced sub records | 91 // Returns the number of bytes used by this op in referenced sub records |
| 91 // and display lists. This doesn't count other objects like paths or blobs. | 92 // and display lists. This doesn't count other objects like paths or blobs. |
| 92 size_t AdditionalBytesUsed() const { return 0; } | 93 size_t AdditionalBytesUsed() const { return 0; } |
| 93 | 94 |
| 94 static constexpr bool kIsDrawOp = false; | 95 static constexpr bool kIsDrawOp = false; |
| 95 // If an op has |kHasPaintFlags| set to true, it must: | |
| 96 // (1) Provide a PaintFlags member called |flags| | |
| 97 // (2) Provide a RasterWithFlags function instead of a Raster function. | |
| 98 static constexpr bool kHasPaintFlags = false; | 96 static constexpr bool kHasPaintFlags = false; |
| 99 static SkRect kUnsetRect; | 97 static SkRect kUnsetRect; |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 struct CC_PAINT_EXPORT PaintOpWithData : PaintOp { | 100 struct CC_PAINT_EXPORT PaintOpWithFlags : PaintOp { |
| 101 static constexpr bool kHasPaintFlags = true; |
| 102 |
| 103 explicit PaintOpWithFlags(const PaintFlags& flags) : flags(flags) {} |
| 104 |
| 105 int CountSlowPathsFromFlags() const { return flags.getPathEffect() ? 1 : 0; } |
| 106 |
| 107 PaintFlags flags; |
| 108 }; |
| 109 |
| 110 struct CC_PAINT_EXPORT PaintOpWithData : PaintOpWithFlags { |
| 103 // Having data is just a helper for ops that have a varying amount of data and | 111 // Having data is just a helper for ops that have a varying amount of data and |
| 104 // want a way to store that inline. This is for ops that pass in a | 112 // want a way to store that inline. This is for ops that pass in a |
| 105 // void* and a length. The void* data is assumed to not have any alignment | 113 // void* and a length. The void* data is assumed to not have any alignment |
| 106 // requirements. | 114 // requirements. |
| 107 explicit PaintOpWithData(size_t bytes) : bytes(bytes) {} | 115 PaintOpWithData(const PaintFlags& flags, size_t bytes) |
| 116 : PaintOpWithFlags(flags), bytes(bytes) {} |
| 108 | 117 |
| 109 // Get data out by calling paint_op_data. This can't be part of the class | 118 // Get data out by calling paint_op_data. This can't be part of the class |
| 110 // because it needs to know the size of the derived type. | 119 // because it needs to know the size of the derived type. |
| 111 size_t bytes; | 120 size_t bytes; |
| 112 | 121 |
| 113 protected: | 122 protected: |
| 114 // For some derived object T, return the internally stored data. | 123 // For some derived object T, return the internally stored data. |
| 115 // This needs the fully derived type to know how much to offset | 124 // This needs the fully derived type to know how much to offset |
| 116 // from the start of the top to the data. | 125 // from the start of the top to the data. |
| 117 template <typename T> | 126 template <typename T> |
| 118 const void* GetDataForThis(const T* op) const { | 127 const void* GetDataForThis(const T* op) const { |
| 119 static_assert(std::is_convertible<T, PaintOpWithData>::value, | 128 static_assert(std::is_convertible<T, PaintOpWithData>::value, |
| 120 "T is not a PaintOpWithData"); | 129 "T is not a PaintOpWithData"); |
| 121 // Arbitrary data for a PaintOp is stored after the PaintOp itself | 130 // Arbitrary data for a PaintOp is stored after the PaintOp itself |
| 122 // in the PaintOpBuffer. Therefore, to access this data, it's | 131 // in the PaintOpBuffer. Therefore, to access this data, it's |
| 123 // pointer math to increment past the size of T. Accessing the | 132 // pointer math to increment past the size of T. Accessing the |
| 124 // next op in the buffer is ((char*)op) + op->skip, with the data | 133 // next op in the buffer is ((char*)op) + op->skip, with the data |
| 125 // fitting between. | 134 // fitting between. |
| 126 return op + 1; | 135 return op + 1; |
| 127 } | 136 } |
| 128 | 137 |
| 129 template <typename T> | 138 template <typename T> |
| 130 void* GetDataForThis(T* op) { | 139 void* GetDataForThis(T* op) { |
| 131 return const_cast<void*>( | 140 return const_cast<void*>( |
| 132 const_cast<const PaintOpWithData*>(this)->GetDataForThis( | 141 const_cast<const PaintOpWithData*>(this)->GetDataForThis( |
| 133 const_cast<const T*>(op))); | 142 const_cast<const T*>(op))); |
| 134 } | 143 } |
| 135 }; | 144 }; |
| 136 | 145 |
| 137 struct CC_PAINT_EXPORT PaintOpWithArrayBase : PaintOp {}; | 146 struct CC_PAINT_EXPORT PaintOpWithArrayBase : PaintOpWithFlags { |
| 147 explicit PaintOpWithArrayBase(const PaintFlags& flags) |
| 148 : PaintOpWithFlags(flags) {} |
| 149 }; |
| 138 | 150 |
| 139 template <typename M> | 151 template <typename M> |
| 140 struct CC_PAINT_EXPORT PaintOpWithArray : PaintOpWithArrayBase { | 152 struct CC_PAINT_EXPORT PaintOpWithArray : PaintOpWithArrayBase { |
| 141 // Paint op that has a M[count] and a char[bytes]. | 153 // Paint op that has a M[count] and a char[bytes]. |
| 142 // Array data is stored first so that it can be aligned with T's alignment | 154 // Array data is stored first so that it can be aligned with T's alignment |
| 143 // with the arbitrary unaligned char data after it. | 155 // with the arbitrary unaligned char data after it. |
| 144 // Memory layout here is: | op | M[count] | char[bytes] | padding | next op | | 156 // Memory layout here is: | op | M[count] | char[bytes] | padding | next op | |
| 145 // Next op is located at (char*)(op) + op->skip. | 157 // Next op is located at (char*)(op) + op->skip. |
| 146 PaintOpWithArray(size_t bytes, size_t count) : bytes(bytes), count(count) {} | 158 PaintOpWithArray(const PaintFlags& flags, size_t bytes, size_t count) |
| 159 : PaintOpWithArrayBase(flags), bytes(bytes), count(count) {} |
| 147 | 160 |
| 148 size_t bytes; | 161 size_t bytes; |
| 149 size_t count; | 162 size_t count; |
| 150 | 163 |
| 151 protected: | 164 protected: |
| 152 template <typename T> | 165 template <typename T> |
| 153 const void* GetDataForThis(const T* op) const { | 166 const void* GetDataForThis(const T* op) const { |
| 154 static_assert(std::is_convertible<T, PaintOpWithArrayBase>::value, | 167 static_assert(std::is_convertible<T, PaintOpWithArrayBase>::value, |
| 155 "T is not a PaintOpWithData"); | 168 "T is not a PaintOpWithData"); |
| 156 const char* start_array = | 169 const char* start_array = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 URL, | 208 URL, |
| 196 LinkToDestination, | 209 LinkToDestination, |
| 197 NamedDestination, | 210 NamedDestination, |
| 198 }; | 211 }; |
| 199 | 212 |
| 200 static constexpr PaintOpType kType = PaintOpType::Annotate; | 213 static constexpr PaintOpType kType = PaintOpType::Annotate; |
| 201 AnnotateOp(PaintCanvas::AnnotationType annotation_type, | 214 AnnotateOp(PaintCanvas::AnnotationType annotation_type, |
| 202 const SkRect& rect, | 215 const SkRect& rect, |
| 203 sk_sp<SkData> data); | 216 sk_sp<SkData> data); |
| 204 ~AnnotateOp(); | 217 ~AnnotateOp(); |
| 205 void Raster(SkCanvas* canvas) const; | 218 static void Raster(const PaintOp* op, |
| 219 SkCanvas* canvas, |
| 220 const SkMatrix& original_ctm); |
| 206 | 221 |
| 207 PaintCanvas::AnnotationType annotation_type; | 222 PaintCanvas::AnnotationType annotation_type; |
| 208 SkRect rect; | 223 SkRect rect; |
| 209 sk_sp<SkData> data; | 224 sk_sp<SkData> data; |
| 210 }; | 225 }; |
| 211 | 226 |
| 212 struct CC_PAINT_EXPORT ClipPathOp final : PaintOp { | 227 struct CC_PAINT_EXPORT ClipPathOp final : PaintOp { |
| 213 static constexpr PaintOpType kType = PaintOpType::ClipPath; | 228 static constexpr PaintOpType kType = PaintOpType::ClipPath; |
| 214 ClipPathOp(SkPath path, SkClipOp op, bool antialias) | 229 ClipPathOp(SkPath path, SkClipOp op, bool antialias) |
| 215 : path(path), op(op), antialias(antialias) {} | 230 : path(path), op(op), antialias(antialias) {} |
| 216 void Raster(SkCanvas* canvas) const; | 231 static void Raster(const PaintOp* op, |
| 232 SkCanvas* canvas, |
| 233 const SkMatrix& original_ctm); |
| 217 int CountSlowPaths() const; | 234 int CountSlowPaths() const; |
| 218 | 235 |
| 219 ThreadsafePath path; | 236 ThreadsafePath path; |
| 220 SkClipOp op; | 237 SkClipOp op; |
| 221 bool antialias; | 238 bool antialias; |
| 222 }; | 239 }; |
| 223 | 240 |
| 224 struct CC_PAINT_EXPORT ClipRectOp final : PaintOp { | 241 struct CC_PAINT_EXPORT ClipRectOp final : PaintOp { |
| 225 static constexpr PaintOpType kType = PaintOpType::ClipRect; | 242 static constexpr PaintOpType kType = PaintOpType::ClipRect; |
| 226 ClipRectOp(const SkRect& rect, SkClipOp op, bool antialias) | 243 ClipRectOp(const SkRect& rect, SkClipOp op, bool antialias) |
| 227 : rect(rect), op(op), antialias(antialias) {} | 244 : rect(rect), op(op), antialias(antialias) {} |
| 228 void Raster(SkCanvas* canvas) const; | 245 static void Raster(const PaintOp* op, |
| 246 SkCanvas* canvas, |
| 247 const SkMatrix& original_ctm); |
| 229 | 248 |
| 230 SkRect rect; | 249 SkRect rect; |
| 231 SkClipOp op; | 250 SkClipOp op; |
| 232 bool antialias; | 251 bool antialias; |
| 233 }; | 252 }; |
| 234 | 253 |
| 235 struct CC_PAINT_EXPORT ClipRRectOp final : PaintOp { | 254 struct CC_PAINT_EXPORT ClipRRectOp final : PaintOp { |
| 236 static constexpr PaintOpType kType = PaintOpType::ClipRRect; | 255 static constexpr PaintOpType kType = PaintOpType::ClipRRect; |
| 237 ClipRRectOp(const SkRRect& rrect, SkClipOp op, bool antialias) | 256 ClipRRectOp(const SkRRect& rrect, SkClipOp op, bool antialias) |
| 238 : rrect(rrect), op(op), antialias(antialias) {} | 257 : rrect(rrect), op(op), antialias(antialias) {} |
| 239 void Raster(SkCanvas* canvas) const; | 258 static void Raster(const PaintOp* op, |
| 259 SkCanvas* canvas, |
| 260 const SkMatrix& original_ctm); |
| 240 | 261 |
| 241 SkRRect rrect; | 262 SkRRect rrect; |
| 242 SkClipOp op; | 263 SkClipOp op; |
| 243 bool antialias; | 264 bool antialias; |
| 244 }; | 265 }; |
| 245 | 266 |
| 246 struct CC_PAINT_EXPORT ConcatOp final : PaintOp { | 267 struct CC_PAINT_EXPORT ConcatOp final : PaintOp { |
| 247 static constexpr PaintOpType kType = PaintOpType::Concat; | 268 static constexpr PaintOpType kType = PaintOpType::Concat; |
| 248 explicit ConcatOp(const SkMatrix& matrix) : matrix(matrix) {} | 269 explicit ConcatOp(const SkMatrix& matrix) : matrix(matrix) {} |
| 249 void Raster(SkCanvas* canvas) const; | 270 static void Raster(const PaintOp* op, |
| 271 SkCanvas* canvas, |
| 272 const SkMatrix& original_ctm); |
| 250 | 273 |
| 251 ThreadsafeMatrix matrix; | 274 ThreadsafeMatrix matrix; |
| 252 }; | 275 }; |
| 253 | 276 |
| 254 struct CC_PAINT_EXPORT DrawArcOp final : PaintOp { | 277 struct CC_PAINT_EXPORT DrawArcOp final : PaintOpWithFlags { |
| 255 static constexpr PaintOpType kType = PaintOpType::DrawArc; | 278 static constexpr PaintOpType kType = PaintOpType::DrawArc; |
| 256 static constexpr bool kIsDrawOp = true; | 279 static constexpr bool kIsDrawOp = true; |
| 257 static constexpr bool kHasPaintFlags = true; | |
| 258 DrawArcOp(const SkRect& oval, | 280 DrawArcOp(const SkRect& oval, |
| 259 SkScalar start_angle, | 281 SkScalar start_angle, |
| 260 SkScalar sweep_angle, | 282 SkScalar sweep_angle, |
| 261 bool use_center, | 283 bool use_center, |
| 262 const PaintFlags& flags) | 284 const PaintFlags& flags) |
| 263 : oval(oval), | 285 : PaintOpWithFlags(flags), |
| 286 oval(oval), |
| 264 start_angle(start_angle), | 287 start_angle(start_angle), |
| 265 sweep_angle(sweep_angle), | 288 sweep_angle(sweep_angle), |
| 266 use_center(use_center), | 289 use_center(use_center) {} |
| 267 flags(flags) {} | 290 static void Raster(const PaintOp* op, |
| 268 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 291 SkCanvas* canvas, |
| 292 const SkMatrix& original_ctm); |
| 269 | 293 |
| 270 SkRect oval; | 294 SkRect oval; |
| 271 SkScalar start_angle; | 295 SkScalar start_angle; |
| 272 SkScalar sweep_angle; | 296 SkScalar sweep_angle; |
| 273 bool use_center; | 297 bool use_center; |
| 274 PaintFlags flags; | |
| 275 }; | 298 }; |
| 276 | 299 |
| 277 struct CC_PAINT_EXPORT DrawCircleOp final : PaintOp { | 300 struct CC_PAINT_EXPORT DrawCircleOp final : PaintOpWithFlags { |
| 278 static constexpr PaintOpType kType = PaintOpType::DrawCircle; | 301 static constexpr PaintOpType kType = PaintOpType::DrawCircle; |
| 279 static constexpr bool kIsDrawOp = true; | 302 static constexpr bool kIsDrawOp = true; |
| 280 static constexpr bool kHasPaintFlags = true; | |
| 281 DrawCircleOp(SkScalar cx, | 303 DrawCircleOp(SkScalar cx, |
| 282 SkScalar cy, | 304 SkScalar cy, |
| 283 SkScalar radius, | 305 SkScalar radius, |
| 284 const PaintFlags& flags) | 306 const PaintFlags& flags) |
| 285 : cx(cx), cy(cy), radius(radius), flags(flags) {} | 307 : PaintOpWithFlags(flags), cx(cx), cy(cy), radius(radius) {} |
| 286 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 308 static void Raster(const PaintOp* op, |
| 309 SkCanvas* canvas, |
| 310 const SkMatrix& original_ctm); |
| 287 | 311 |
| 288 SkScalar cx; | 312 SkScalar cx; |
| 289 SkScalar cy; | 313 SkScalar cy; |
| 290 SkScalar radius; | 314 SkScalar radius; |
| 291 PaintFlags flags; | |
| 292 }; | 315 }; |
| 293 | 316 |
| 294 struct CC_PAINT_EXPORT DrawColorOp final : PaintOp { | 317 struct CC_PAINT_EXPORT DrawColorOp final : PaintOp { |
| 295 static constexpr PaintOpType kType = PaintOpType::DrawColor; | 318 static constexpr PaintOpType kType = PaintOpType::DrawColor; |
| 296 static constexpr bool kIsDrawOp = true; | 319 static constexpr bool kIsDrawOp = true; |
| 297 DrawColorOp(SkColor color, SkBlendMode mode) : color(color), mode(mode) {} | 320 DrawColorOp(SkColor color, SkBlendMode mode) : color(color), mode(mode) {} |
| 298 void Raster(SkCanvas* canvas) const; | 321 static void Raster(const PaintOp* op, |
| 322 SkCanvas* canvas, |
| 323 const SkMatrix& original_ctm); |
| 299 | 324 |
| 300 SkColor color; | 325 SkColor color; |
| 301 SkBlendMode mode; | 326 SkBlendMode mode; |
| 302 }; | 327 }; |
| 303 | 328 |
| 304 struct CC_PAINT_EXPORT DrawDisplayItemListOp final : PaintOp { | 329 struct CC_PAINT_EXPORT DrawDisplayItemListOp final : PaintOp { |
| 305 static constexpr PaintOpType kType = PaintOpType::DrawDisplayItemList; | 330 static constexpr PaintOpType kType = PaintOpType::DrawDisplayItemList; |
| 306 static constexpr bool kIsDrawOp = true; | 331 static constexpr bool kIsDrawOp = true; |
| 307 explicit DrawDisplayItemListOp(scoped_refptr<DisplayItemList> list); | 332 explicit DrawDisplayItemListOp(scoped_refptr<DisplayItemList> list); |
| 308 // Windows wants to generate these when types are exported, so | 333 // Windows wants to generate these when types are exported, so |
| 309 // provide them here explicitly so that DisplayItemList doesn't have | 334 // provide them here explicitly so that DisplayItemList doesn't have |
| 310 // to be defined in this header. | 335 // to be defined in this header. |
| 311 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); | 336 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); |
| 312 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); | 337 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); |
| 313 ~DrawDisplayItemListOp(); | 338 ~DrawDisplayItemListOp(); |
| 314 void Raster(SkCanvas* canvas) const; | 339 static void Raster(const PaintOp* op, |
| 340 SkCanvas* canvas, |
| 341 const SkMatrix& original_ctm); |
| 315 size_t AdditionalBytesUsed() const; | 342 size_t AdditionalBytesUsed() const; |
| 316 // TODO(enne): DisplayItemList should know number of slow paths. | 343 // TODO(enne): DisplayItemList should know number of slow paths. |
| 317 | 344 |
| 318 scoped_refptr<DisplayItemList> list; | 345 scoped_refptr<DisplayItemList> list; |
| 319 }; | 346 }; |
| 320 | 347 |
| 321 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOp { | 348 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags { |
| 322 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; | 349 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; |
| 323 static constexpr bool kIsDrawOp = true; | 350 static constexpr bool kIsDrawOp = true; |
| 324 static constexpr bool kHasPaintFlags = true; | |
| 325 DrawDRRectOp(const SkRRect& outer, | 351 DrawDRRectOp(const SkRRect& outer, |
| 326 const SkRRect& inner, | 352 const SkRRect& inner, |
| 327 const PaintFlags& flags) | 353 const PaintFlags& flags) |
| 328 : outer(outer), inner(inner), flags(flags) {} | 354 : PaintOpWithFlags(flags), outer(outer), inner(inner) {} |
| 329 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 355 static void Raster(const PaintOp* op, |
| 356 SkCanvas* canvas, |
| 357 const SkMatrix& original_ctm); |
| 330 | 358 |
| 331 SkRRect outer; | 359 SkRRect outer; |
| 332 SkRRect inner; | 360 SkRRect inner; |
| 333 PaintFlags flags; | |
| 334 }; | 361 }; |
| 335 | 362 |
| 336 struct CC_PAINT_EXPORT DrawImageOp final : PaintOp { | 363 struct CC_PAINT_EXPORT DrawImageOp final : PaintOpWithFlags { |
| 337 static constexpr PaintOpType kType = PaintOpType::DrawImage; | 364 static constexpr PaintOpType kType = PaintOpType::DrawImage; |
| 338 static constexpr bool kIsDrawOp = true; | 365 static constexpr bool kIsDrawOp = true; |
| 339 static constexpr bool kHasPaintFlags = true; | |
| 340 DrawImageOp(const PaintImage& image, | 366 DrawImageOp(const PaintImage& image, |
| 341 SkScalar left, | 367 SkScalar left, |
| 342 SkScalar top, | 368 SkScalar top, |
| 343 const PaintFlags* flags); | 369 const PaintFlags* flags); |
| 344 ~DrawImageOp(); | 370 ~DrawImageOp(); |
| 345 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 371 static void Raster(const PaintOp* op, |
| 372 SkCanvas* canvas, |
| 373 const SkMatrix& original_ctm); |
| 346 | 374 |
| 347 PaintImage image; | 375 PaintImage image; |
| 348 SkScalar left; | 376 SkScalar left; |
| 349 SkScalar top; | 377 SkScalar top; |
| 350 PaintFlags flags; | |
| 351 }; | 378 }; |
| 352 | 379 |
| 353 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOp { | 380 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags { |
| 354 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; | 381 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; |
| 355 static constexpr bool kIsDrawOp = true; | 382 static constexpr bool kIsDrawOp = true; |
| 356 static constexpr bool kHasPaintFlags = true; | |
| 357 DrawImageRectOp(const PaintImage& image, | 383 DrawImageRectOp(const PaintImage& image, |
| 358 const SkRect& src, | 384 const SkRect& src, |
| 359 const SkRect& dst, | 385 const SkRect& dst, |
| 360 const PaintFlags* flags, | 386 const PaintFlags* flags, |
| 361 PaintCanvas::SrcRectConstraint constraint); | 387 PaintCanvas::SrcRectConstraint constraint); |
| 362 ~DrawImageRectOp(); | 388 ~DrawImageRectOp(); |
| 363 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 389 static void Raster(const PaintOp* op, |
| 390 SkCanvas* canvas, |
| 391 const SkMatrix& original_ctm); |
| 364 | 392 |
| 365 PaintImage image; | 393 PaintImage image; |
| 366 PaintFlags flags; | |
| 367 SkRect src; | 394 SkRect src; |
| 368 SkRect dst; | 395 SkRect dst; |
| 369 PaintCanvas::SrcRectConstraint constraint; | 396 PaintCanvas::SrcRectConstraint constraint; |
| 370 }; | 397 }; |
| 371 | 398 |
| 372 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOp { | 399 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags { |
| 373 static constexpr PaintOpType kType = PaintOpType::DrawIRect; | 400 static constexpr PaintOpType kType = PaintOpType::DrawIRect; |
| 374 static constexpr bool kIsDrawOp = true; | 401 static constexpr bool kIsDrawOp = true; |
| 375 static constexpr bool kHasPaintFlags = true; | |
| 376 DrawIRectOp(const SkIRect& rect, const PaintFlags& flags) | 402 DrawIRectOp(const SkIRect& rect, const PaintFlags& flags) |
| 377 : rect(rect), flags(flags) {} | 403 : PaintOpWithFlags(flags), rect(rect) {} |
| 378 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 404 static void Raster(const PaintOp* op, |
| 405 SkCanvas* canvas, |
| 406 const SkMatrix& original_ctm); |
| 379 | 407 |
| 380 SkIRect rect; | 408 SkIRect rect; |
| 381 PaintFlags flags; | |
| 382 }; | 409 }; |
| 383 | 410 |
| 384 struct CC_PAINT_EXPORT DrawLineOp final : PaintOp { | 411 struct CC_PAINT_EXPORT DrawLineOp final : PaintOpWithFlags { |
| 385 static constexpr PaintOpType kType = PaintOpType::DrawLine; | 412 static constexpr PaintOpType kType = PaintOpType::DrawLine; |
| 386 static constexpr bool kIsDrawOp = true; | 413 static constexpr bool kIsDrawOp = true; |
| 387 static constexpr bool kHasPaintFlags = true; | |
| 388 DrawLineOp(SkScalar x0, | 414 DrawLineOp(SkScalar x0, |
| 389 SkScalar y0, | 415 SkScalar y0, |
| 390 SkScalar x1, | 416 SkScalar x1, |
| 391 SkScalar y1, | 417 SkScalar y1, |
| 392 const PaintFlags& flags) | 418 const PaintFlags& flags) |
| 393 : x0(x0), y0(y0), x1(x1), y1(y1), flags(flags) {} | 419 : PaintOpWithFlags(flags), x0(x0), y0(y0), x1(x1), y1(y1) {} |
| 394 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 420 static void Raster(const PaintOp* op, |
| 421 SkCanvas* canvas, |
| 422 const SkMatrix& original_ctm); |
| 395 int CountSlowPaths() const; | 423 int CountSlowPaths() const; |
| 396 | 424 |
| 397 SkScalar x0; | 425 SkScalar x0; |
| 398 SkScalar y0; | 426 SkScalar y0; |
| 399 SkScalar x1; | 427 SkScalar x1; |
| 400 SkScalar y1; | 428 SkScalar y1; |
| 401 PaintFlags flags; | |
| 402 }; | 429 }; |
| 403 | 430 |
| 404 struct CC_PAINT_EXPORT DrawOvalOp final : PaintOp { | 431 struct CC_PAINT_EXPORT DrawOvalOp final : PaintOpWithFlags { |
| 405 static constexpr PaintOpType kType = PaintOpType::DrawOval; | 432 static constexpr PaintOpType kType = PaintOpType::DrawOval; |
| 406 static constexpr bool kIsDrawOp = true; | 433 static constexpr bool kIsDrawOp = true; |
| 407 static constexpr bool kHasPaintFlags = true; | |
| 408 DrawOvalOp(const SkRect& oval, const PaintFlags& flags) | 434 DrawOvalOp(const SkRect& oval, const PaintFlags& flags) |
| 409 : oval(oval), flags(flags) {} | 435 : PaintOpWithFlags(flags), oval(oval) {} |
| 410 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 436 static void Raster(const PaintOp* op, |
| 437 SkCanvas* canvas, |
| 438 const SkMatrix& original_ctm); |
| 411 | 439 |
| 412 SkRect oval; | 440 SkRect oval; |
| 413 PaintFlags flags; | |
| 414 }; | 441 }; |
| 415 | 442 |
| 416 struct CC_PAINT_EXPORT DrawPathOp final : PaintOp { | 443 struct CC_PAINT_EXPORT DrawPathOp final : PaintOpWithFlags { |
| 417 static constexpr PaintOpType kType = PaintOpType::DrawPath; | 444 static constexpr PaintOpType kType = PaintOpType::DrawPath; |
| 418 static constexpr bool kIsDrawOp = true; | 445 static constexpr bool kIsDrawOp = true; |
| 419 static constexpr bool kHasPaintFlags = true; | |
| 420 DrawPathOp(const SkPath& path, const PaintFlags& flags) | 446 DrawPathOp(const SkPath& path, const PaintFlags& flags) |
| 421 : path(path), flags(flags) {} | 447 : PaintOpWithFlags(flags), path(path) {} |
| 422 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 448 static void Raster(const PaintOp* op, |
| 449 SkCanvas* canvas, |
| 450 const SkMatrix& original_ctm); |
| 423 int CountSlowPaths() const; | 451 int CountSlowPaths() const; |
| 424 | 452 |
| 425 ThreadsafePath path; | 453 ThreadsafePath path; |
| 426 PaintFlags flags; | |
| 427 }; | 454 }; |
| 428 | 455 |
| 429 struct CC_PAINT_EXPORT DrawPosTextOp final : PaintOpWithArray<SkPoint> { | 456 struct CC_PAINT_EXPORT DrawPosTextOp final : PaintOpWithArray<SkPoint> { |
| 430 static constexpr PaintOpType kType = PaintOpType::DrawPosText; | 457 static constexpr PaintOpType kType = PaintOpType::DrawPosText; |
| 431 static constexpr bool kIsDrawOp = true; | 458 static constexpr bool kIsDrawOp = true; |
| 432 static constexpr bool kHasPaintFlags = true; | |
| 433 DrawPosTextOp(size_t bytes, size_t count, const PaintFlags& flags); | 459 DrawPosTextOp(size_t bytes, size_t count, const PaintFlags& flags); |
| 434 ~DrawPosTextOp(); | 460 ~DrawPosTextOp(); |
| 435 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 461 static void Raster(const PaintOp* op, |
| 436 | 462 SkCanvas* canvas, |
| 463 const SkMatrix& original_ctm); |
| 437 const void* GetData() const { return GetDataForThis(this); } | 464 const void* GetData() const { return GetDataForThis(this); } |
| 438 void* GetData() { return GetDataForThis(this); } | 465 void* GetData() { return GetDataForThis(this); } |
| 439 const SkPoint* GetArray() const { return GetArrayForThis(this); } | 466 const SkPoint* GetArray() const { return GetArrayForThis(this); } |
| 440 SkPoint* GetArray() { return GetArrayForThis(this); } | 467 SkPoint* GetArray() { return GetArrayForThis(this); } |
| 441 | |
| 442 PaintFlags flags; | |
| 443 }; | 468 }; |
| 444 | 469 |
| 445 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { | 470 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { |
| 446 static constexpr PaintOpType kType = PaintOpType::DrawRecord; | 471 static constexpr PaintOpType kType = PaintOpType::DrawRecord; |
| 447 static constexpr bool kIsDrawOp = true; | 472 static constexpr bool kIsDrawOp = true; |
| 448 explicit DrawRecordOp(sk_sp<const PaintRecord> record); | 473 explicit DrawRecordOp(sk_sp<const PaintRecord> record); |
| 449 ~DrawRecordOp(); | 474 ~DrawRecordOp(); |
| 450 void Raster(SkCanvas* canvas) const; | 475 static void Raster(const PaintOp* op, |
| 476 SkCanvas* canvas, |
| 477 const SkMatrix& original_ctm); |
| 451 size_t AdditionalBytesUsed() const; | 478 size_t AdditionalBytesUsed() const; |
| 452 | 479 |
| 453 sk_sp<const PaintRecord> record; | 480 sk_sp<const PaintRecord> record; |
| 454 }; | 481 }; |
| 455 | 482 |
| 456 struct CC_PAINT_EXPORT DrawRectOp final : PaintOp { | 483 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags { |
| 457 static constexpr PaintOpType kType = PaintOpType::DrawRect; | 484 static constexpr PaintOpType kType = PaintOpType::DrawRect; |
| 458 static constexpr bool kIsDrawOp = true; | 485 static constexpr bool kIsDrawOp = true; |
| 459 static constexpr bool kHasPaintFlags = true; | |
| 460 DrawRectOp(const SkRect& rect, const PaintFlags& flags) | 486 DrawRectOp(const SkRect& rect, const PaintFlags& flags) |
| 461 : rect(rect), flags(flags) {} | 487 : PaintOpWithFlags(flags), rect(rect) {} |
| 462 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 488 static void Raster(const PaintOp* op, |
| 489 SkCanvas* canvas, |
| 490 const SkMatrix& original_ctm); |
| 463 | 491 |
| 464 SkRect rect; | 492 SkRect rect; |
| 465 PaintFlags flags; | |
| 466 }; | 493 }; |
| 467 | 494 |
| 468 struct CC_PAINT_EXPORT DrawRRectOp final : PaintOp { | 495 struct CC_PAINT_EXPORT DrawRRectOp final : PaintOpWithFlags { |
| 469 static constexpr PaintOpType kType = PaintOpType::DrawRRect; | 496 static constexpr PaintOpType kType = PaintOpType::DrawRRect; |
| 470 static constexpr bool kIsDrawOp = true; | 497 static constexpr bool kIsDrawOp = true; |
| 471 static constexpr bool kHasPaintFlags = true; | |
| 472 DrawRRectOp(const SkRRect& rrect, const PaintFlags& flags) | 498 DrawRRectOp(const SkRRect& rrect, const PaintFlags& flags) |
| 473 : rrect(rrect), flags(flags) {} | 499 : PaintOpWithFlags(flags), rrect(rrect) {} |
| 474 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 500 static void Raster(const PaintOp* op, |
| 501 SkCanvas* canvas, |
| 502 const SkMatrix& original_ctm); |
| 475 | 503 |
| 476 SkRRect rrect; | 504 SkRRect rrect; |
| 477 PaintFlags flags; | |
| 478 }; | 505 }; |
| 479 | 506 |
| 480 struct CC_PAINT_EXPORT DrawTextOp final : PaintOpWithData { | 507 struct CC_PAINT_EXPORT DrawTextOp final : PaintOpWithData { |
| 481 static constexpr PaintOpType kType = PaintOpType::DrawText; | 508 static constexpr PaintOpType kType = PaintOpType::DrawText; |
| 482 static constexpr bool kIsDrawOp = true; | 509 static constexpr bool kIsDrawOp = true; |
| 483 static constexpr bool kHasPaintFlags = true; | |
| 484 DrawTextOp(size_t bytes, SkScalar x, SkScalar y, const PaintFlags& flags) | 510 DrawTextOp(size_t bytes, SkScalar x, SkScalar y, const PaintFlags& flags) |
| 485 : PaintOpWithData(bytes), x(x), y(y), flags(flags) {} | 511 : PaintOpWithData(flags, bytes), x(x), y(y) {} |
| 486 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 512 static void Raster(const PaintOp* op, |
| 513 SkCanvas* canvas, |
| 514 const SkMatrix& original_ctm); |
| 487 | 515 |
| 488 void* GetData() { return GetDataForThis(this); } | 516 void* GetData() { return GetDataForThis(this); } |
| 489 const void* GetData() const { return GetDataForThis(this); } | 517 const void* GetData() const { return GetDataForThis(this); } |
| 490 | 518 |
| 491 SkScalar x; | 519 SkScalar x; |
| 492 SkScalar y; | 520 SkScalar y; |
| 493 PaintFlags flags; | |
| 494 }; | 521 }; |
| 495 | 522 |
| 496 struct CC_PAINT_EXPORT DrawTextBlobOp final : PaintOp { | 523 struct CC_PAINT_EXPORT DrawTextBlobOp final : PaintOpWithFlags { |
| 497 static constexpr PaintOpType kType = PaintOpType::DrawTextBlob; | 524 static constexpr PaintOpType kType = PaintOpType::DrawTextBlob; |
| 498 static constexpr bool kIsDrawOp = true; | 525 static constexpr bool kIsDrawOp = true; |
| 499 static constexpr bool kHasPaintFlags = true; | |
| 500 DrawTextBlobOp(sk_sp<SkTextBlob> blob, | 526 DrawTextBlobOp(sk_sp<SkTextBlob> blob, |
| 501 SkScalar x, | 527 SkScalar x, |
| 502 SkScalar y, | 528 SkScalar y, |
| 503 const PaintFlags& flags); | 529 const PaintFlags& flags); |
| 504 ~DrawTextBlobOp(); | 530 ~DrawTextBlobOp(); |
| 505 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 531 static void Raster(const PaintOp* op, |
| 532 SkCanvas* canvas, |
| 533 const SkMatrix& original_ctm); |
| 506 | 534 |
| 507 sk_sp<SkTextBlob> blob; | 535 sk_sp<SkTextBlob> blob; |
| 508 SkScalar x; | 536 SkScalar x; |
| 509 SkScalar y; | 537 SkScalar y; |
| 510 PaintFlags flags; | |
| 511 }; | 538 }; |
| 512 | 539 |
| 513 struct CC_PAINT_EXPORT NoopOp final : PaintOp { | 540 struct CC_PAINT_EXPORT NoopOp final : PaintOp { |
| 514 static constexpr PaintOpType kType = PaintOpType::Noop; | 541 static constexpr PaintOpType kType = PaintOpType::Noop; |
| 515 void Raster(SkCanvas* canvas) const {} | 542 static void Raster(const PaintOp* op, |
| 543 SkCanvas* canvas, |
| 544 const SkMatrix& original_ctm) {} |
| 516 }; | 545 }; |
| 517 | 546 |
| 518 struct CC_PAINT_EXPORT RestoreOp final : PaintOp { | 547 struct CC_PAINT_EXPORT RestoreOp final : PaintOp { |
| 519 static constexpr PaintOpType kType = PaintOpType::Restore; | 548 static constexpr PaintOpType kType = PaintOpType::Restore; |
| 520 void Raster(SkCanvas* canvas) const; | 549 static void Raster(const PaintOp* op, |
| 550 SkCanvas* canvas, |
| 551 const SkMatrix& original_ctm); |
| 521 }; | 552 }; |
| 522 | 553 |
| 523 struct CC_PAINT_EXPORT RotateOp final : PaintOp { | 554 struct CC_PAINT_EXPORT RotateOp final : PaintOp { |
| 524 static constexpr PaintOpType kType = PaintOpType::Rotate; | 555 static constexpr PaintOpType kType = PaintOpType::Rotate; |
| 525 explicit RotateOp(SkScalar degrees) : degrees(degrees) {} | 556 explicit RotateOp(SkScalar degrees) : degrees(degrees) {} |
| 526 void Raster(SkCanvas* canvas) const; | 557 static void Raster(const PaintOp* op, |
| 558 SkCanvas* canvas, |
| 559 const SkMatrix& original_ctm); |
| 527 | 560 |
| 528 SkScalar degrees; | 561 SkScalar degrees; |
| 529 }; | 562 }; |
| 530 | 563 |
| 531 struct CC_PAINT_EXPORT SaveOp final : PaintOp { | 564 struct CC_PAINT_EXPORT SaveOp final : PaintOp { |
| 532 static constexpr PaintOpType kType = PaintOpType::Save; | 565 static constexpr PaintOpType kType = PaintOpType::Save; |
| 533 void Raster(SkCanvas* canvas) const; | 566 static void Raster(const PaintOp* op, |
| 567 SkCanvas* canvas, |
| 568 const SkMatrix& original_ctm); |
| 534 }; | 569 }; |
| 535 | 570 |
| 536 struct CC_PAINT_EXPORT SaveLayerOp final : PaintOp { | 571 struct CC_PAINT_EXPORT SaveLayerOp final : PaintOpWithFlags { |
| 537 static constexpr PaintOpType kType = PaintOpType::SaveLayer; | 572 static constexpr PaintOpType kType = PaintOpType::SaveLayer; |
| 538 static constexpr bool kHasPaintFlags = true; | |
| 539 SaveLayerOp(const SkRect* bounds, const PaintFlags* flags) | 573 SaveLayerOp(const SkRect* bounds, const PaintFlags* flags) |
| 540 : bounds(bounds ? *bounds : kUnsetRect) { | 574 : PaintOpWithFlags(flags ? *flags : PaintFlags()), |
| 541 if (flags) | 575 bounds(bounds ? *bounds : kUnsetRect) {} |
| 542 this->flags = *flags; | 576 static void Raster(const PaintOp* op, |
| 543 } | 577 SkCanvas* canvas, |
| 544 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 578 const SkMatrix& original_ctm); |
| 545 | 579 |
| 546 SkRect bounds; | 580 SkRect bounds; |
| 547 PaintFlags flags; | |
| 548 }; | 581 }; |
| 549 | 582 |
| 550 struct CC_PAINT_EXPORT SaveLayerAlphaOp final : PaintOp { | 583 struct CC_PAINT_EXPORT SaveLayerAlphaOp final : PaintOp { |
| 551 static constexpr PaintOpType kType = PaintOpType::SaveLayerAlpha; | 584 static constexpr PaintOpType kType = PaintOpType::SaveLayerAlpha; |
| 552 SaveLayerAlphaOp(const SkRect* bounds, uint8_t alpha) | 585 SaveLayerAlphaOp(const SkRect* bounds, uint8_t alpha) |
| 553 : bounds(bounds ? *bounds : kUnsetRect), alpha(alpha) {} | 586 : bounds(bounds ? *bounds : kUnsetRect), alpha(alpha) {} |
| 554 void Raster(SkCanvas* canvas) const; | 587 static void Raster(const PaintOp* op, |
| 588 SkCanvas* canvas, |
| 589 const SkMatrix& original_ctm); |
| 555 | 590 |
| 556 SkRect bounds; | 591 SkRect bounds; |
| 557 uint8_t alpha; | 592 uint8_t alpha; |
| 558 }; | 593 }; |
| 559 | 594 |
| 560 struct CC_PAINT_EXPORT ScaleOp final : PaintOp { | 595 struct CC_PAINT_EXPORT ScaleOp final : PaintOp { |
| 561 static constexpr PaintOpType kType = PaintOpType::Scale; | 596 static constexpr PaintOpType kType = PaintOpType::Scale; |
| 562 ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} | 597 ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} |
| 563 void Raster(SkCanvas* canvas) const; | 598 static void Raster(const PaintOp* op, |
| 599 SkCanvas* canvas, |
| 600 const SkMatrix& original_ctm); |
| 564 | 601 |
| 565 SkScalar sx; | 602 SkScalar sx; |
| 566 SkScalar sy; | 603 SkScalar sy; |
| 567 }; | 604 }; |
| 568 | 605 |
| 569 struct CC_PAINT_EXPORT SetMatrixOp final : PaintOp { | 606 struct CC_PAINT_EXPORT SetMatrixOp final : PaintOp { |
| 570 static constexpr PaintOpType kType = PaintOpType::SetMatrix; | 607 static constexpr PaintOpType kType = PaintOpType::SetMatrix; |
| 571 explicit SetMatrixOp(const SkMatrix& matrix) : matrix(matrix) {} | 608 explicit SetMatrixOp(const SkMatrix& matrix) : matrix(matrix) {} |
| 572 // This is the only op that needs the original ctm of the SkCanvas | 609 // This is the only op that needs the original ctm of the SkCanvas |
| 573 // used for raster (since SetMatrix is relative to the recording origin and | 610 // used for raster (since SetMatrix is relative to the recording origin and |
| 574 // shouldn't clobber the SkCanvas raster origin). | 611 // shouldn't clobber the SkCanvas raster origin). |
| 575 // | 612 // |
| 576 // TODO(enne): Find some cleaner way to do this, possibly by making | 613 // TODO(enne): Find some cleaner way to do this, possibly by making |
| 577 // all SetMatrix calls Concat?? | 614 // all SetMatrix calls Concat?? |
| 578 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; | 615 static void Raster(const PaintOp* op, |
| 616 SkCanvas* canvas, |
| 617 const SkMatrix& original_ctm); |
| 579 | 618 |
| 580 ThreadsafeMatrix matrix; | 619 ThreadsafeMatrix matrix; |
| 581 }; | 620 }; |
| 582 | 621 |
| 583 struct CC_PAINT_EXPORT TranslateOp final : PaintOp { | 622 struct CC_PAINT_EXPORT TranslateOp final : PaintOp { |
| 584 static constexpr PaintOpType kType = PaintOpType::Translate; | 623 static constexpr PaintOpType kType = PaintOpType::Translate; |
| 585 TranslateOp(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {} | 624 TranslateOp(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {} |
| 586 void Raster(SkCanvas* canvas) const; | 625 static void Raster(const PaintOp* op, |
| 626 SkCanvas* canvas, |
| 627 const SkMatrix& original_ctm); |
| 587 | 628 |
| 588 SkScalar dx; | 629 SkScalar dx; |
| 589 SkScalar dy; | 630 SkScalar dy; |
| 590 }; | 631 }; |
| 591 | 632 |
| 592 using LargestPaintOp = DrawDRRectOp; | 633 using LargestPaintOp = DrawDRRectOp; |
| 593 | 634 |
| 594 class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { | 635 class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
| 595 public: | 636 public: |
| 596 enum { kInitialBufferSize = 4096 }; | 637 enum { kInitialBufferSize = 4096 }; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 private: | 784 private: |
| 744 Iterator(const PaintOpBuffer* buffer, char* ptr, int op_idx) | 785 Iterator(const PaintOpBuffer* buffer, char* ptr, int op_idx) |
| 745 : buffer_(buffer), ptr_(ptr), op_idx_(op_idx) {} | 786 : buffer_(buffer), ptr_(ptr), op_idx_(op_idx) {} |
| 746 | 787 |
| 747 const PaintOpBuffer* buffer_ = nullptr; | 788 const PaintOpBuffer* buffer_ = nullptr; |
| 748 char* ptr_ = nullptr; | 789 char* ptr_ = nullptr; |
| 749 int op_idx_ = 0; | 790 int op_idx_ = 0; |
| 750 }; | 791 }; |
| 751 | 792 |
| 752 private: | 793 private: |
| 753 template <typename T, bool HasFlags> | |
| 754 struct CountSlowPathsFromFlags { | |
| 755 static int Count(const T* op) { return 0; } | |
| 756 }; | |
| 757 | |
| 758 template <typename T> | |
| 759 struct CountSlowPathsFromFlags<T, true> { | |
| 760 static int Count(const T* op) { return op->flags.getPathEffect() ? 1 : 0; } | |
| 761 }; | |
| 762 | |
| 763 void ReallocBuffer(size_t new_size); | 794 void ReallocBuffer(size_t new_size); |
| 795 // Returns the allocated op and the number of bytes to skip in |data_| to get |
| 796 // to the next op. |
| 797 std::pair<void*, size_t> AllocatePaintOp(size_t sizeof_op, size_t bytes); |
| 764 | 798 |
| 765 template <typename T, typename... Args> | 799 template <typename T, typename... Args> |
| 766 T* push_internal(size_t bytes, Args&&... args) { | 800 T* push_internal(size_t bytes, Args&&... args) { |
| 767 // Compute a skip such that all ops in the buffer are aligned to the | 801 static_assert(ALIGNOF(T) <= PaintOpAlign, ""); |
| 768 // maximum required alignment of all ops. | |
| 769 size_t skip = MathUtil::UncheckedRoundUp(sizeof(T) + bytes, PaintOpAlign); | |
| 770 DCHECK_LT(skip, static_cast<size_t>(1) << 24); | |
| 771 if (used_ + skip > reserved_ || !op_count_) { | |
| 772 if (!op_count_) { | |
| 773 if (bytes) { | |
| 774 // Internal first_op buffer doesn't have room for extra data. | |
| 775 // If the op wants extra bytes, then we'll just store a Noop | |
| 776 // in the first_op and proceed from there. This seems unlikely | |
| 777 // to be a common case. | |
| 778 push<NoopOp>(); | |
| 779 } else { | |
| 780 auto* op = reinterpret_cast<T*>(first_op_.data_as<T>()); | |
| 781 new (op) T{std::forward<Args>(args)...}; | |
| 782 op->type = static_cast<uint32_t>(T::kType); | |
| 783 op->skip = 0; | |
| 784 AnalyzeAddedOp(op); | |
| 785 op_count_++; | |
| 786 return op; | |
| 787 } | |
| 788 } | |
| 789 | 802 |
| 790 // Start reserved_ at kInitialBufferSize and then double. | 803 auto pair = AllocatePaintOp(sizeof(T), bytes); |
| 791 // ShrinkToFit can make this smaller afterwards. | 804 T* op = reinterpret_cast<T*>(pair.first); |
| 792 size_t new_size = reserved_ ? reserved_ : kInitialBufferSize; | 805 size_t skip = pair.second; |
| 793 while (used_ + skip > new_size) | |
| 794 new_size *= 2; | |
| 795 ReallocBuffer(new_size); | |
| 796 } | |
| 797 DCHECK_LE(used_ + skip, reserved_); | |
| 798 | 806 |
| 799 T* op = reinterpret_cast<T*>(data_.get() + used_); | 807 new (op) T{std::forward<Args>(args)...}; |
| 800 used_ += skip; | |
| 801 new (op) T(std::forward<Args>(args)...); | |
| 802 op->type = static_cast<uint32_t>(T::kType); | 808 op->type = static_cast<uint32_t>(T::kType); |
| 803 op->skip = skip; | 809 op->skip = skip; |
| 804 AnalyzeAddedOp(op); | 810 AnalyzeAddedOp(op); |
| 805 op_count_++; | |
| 806 return op; | 811 return op; |
| 807 } | 812 } |
| 808 | 813 |
| 809 template <typename T> | 814 template <typename T> |
| 810 void AnalyzeAddedOp(const T* op) { | 815 void AnalyzeAddedOp(const T* op) { |
| 811 num_slow_paths_ += CountSlowPathsFromFlags<T, T::kHasPaintFlags>::Count(op); | 816 num_slow_paths_ += op->CountSlowPathsFromFlags(); |
| 812 num_slow_paths_ += op->CountSlowPaths(); | 817 num_slow_paths_ += op->CountSlowPaths(); |
| 813 | 818 |
| 814 subrecord_bytes_used_ += op->AdditionalBytesUsed(); | 819 subrecord_bytes_used_ += op->AdditionalBytesUsed(); |
| 815 } | 820 } |
| 816 | 821 |
| 817 // As a performance optimization because n=1 is an extremely common case just | 822 // As a performance optimization because n=1 is an extremely common case just |
| 818 // store the first op in the PaintOpBuffer itself to avoid an extra alloc. | 823 // store the first op in the PaintOpBuffer itself to avoid an extra alloc. |
| 819 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_; | 824 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_; |
| 820 std::unique_ptr<char, base::AlignedFreeDeleter> data_; | 825 std::unique_ptr<char, base::AlignedFreeDeleter> data_; |
| 821 size_t used_ = 0; | 826 size_t used_ = 0; |
| 822 size_t reserved_ = 0; | 827 size_t reserved_ = 0; |
| 823 int op_count_ = 0; | 828 int op_count_ = 0; |
| 824 | 829 |
| 825 // Record paths for veto-to-msaa for gpu raster. | 830 // Record paths for veto-to-msaa for gpu raster. |
| 826 int num_slow_paths_ = 0; | 831 int num_slow_paths_ = 0; |
| 827 // Record additional bytes used by referenced sub-records and display lists. | 832 // Record additional bytes used by referenced sub-records and display lists. |
| 828 size_t subrecord_bytes_used_ = 0; | 833 size_t subrecord_bytes_used_ = 0; |
| 829 SkRect cull_rect_; | 834 SkRect cull_rect_; |
| 830 | 835 |
| 831 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); | 836 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); |
| 832 }; | 837 }; |
| 833 | 838 |
| 834 } // namespace cc | 839 } // namespace cc |
| 835 | 840 |
| 836 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ | 841 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ |
| OLD | NEW |