| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 int CountSlowPathsFromFlags() const { return 0; } |
| 90 | 90 |
| 91 bool HasDiscardableImages() const { return false; } |
| 92 bool HasDiscardableImagesFromFlags() const { return false; } |
| 93 |
| 91 // Returns the number of bytes used by this op in referenced sub records | 94 // Returns the number of bytes used by this op in referenced sub records |
| 92 // and display lists. This doesn't count other objects like paths or blobs. | 95 // and display lists. This doesn't count other objects like paths or blobs. |
| 93 size_t AdditionalBytesUsed() const { return 0; } | 96 size_t AdditionalBytesUsed() const { return 0; } |
| 94 | 97 |
| 95 static constexpr bool kIsDrawOp = false; | 98 static constexpr bool kIsDrawOp = false; |
| 96 static constexpr bool kHasPaintFlags = false; | 99 static constexpr bool kHasPaintFlags = false; |
| 97 static SkRect kUnsetRect; | 100 static SkRect kUnsetRect; |
| 98 }; | 101 }; |
| 99 | 102 |
| 100 struct CC_PAINT_EXPORT PaintOpWithFlags : PaintOp { | 103 struct CC_PAINT_EXPORT PaintOpWithFlags : PaintOp { |
| 101 static constexpr bool kHasPaintFlags = true; | 104 static constexpr bool kHasPaintFlags = true; |
| 102 | 105 |
| 103 explicit PaintOpWithFlags(const PaintFlags& flags) : flags(flags) {} | 106 explicit PaintOpWithFlags(const PaintFlags& flags) : flags(flags) {} |
| 104 | 107 |
| 105 int CountSlowPathsFromFlags() const { return flags.getPathEffect() ? 1 : 0; } | 108 int CountSlowPathsFromFlags() const { return flags.getPathEffect() ? 1 : 0; } |
| 109 bool HasDiscardableImagesFromFlags() const { |
| 110 if (!IsDrawOp()) |
| 111 return false; |
| 112 |
| 113 SkShader* shader = flags.getShader(); |
| 114 SkImage* image = shader ? shader->isAImage(nullptr, nullptr) : nullptr; |
| 115 return image && image->isLazyGenerated(); |
| 116 } |
| 106 | 117 |
| 107 PaintFlags flags; | 118 PaintFlags flags; |
| 108 }; | 119 }; |
| 109 | 120 |
| 110 struct CC_PAINT_EXPORT PaintOpWithData : PaintOpWithFlags { | 121 struct CC_PAINT_EXPORT PaintOpWithData : PaintOpWithFlags { |
| 111 // Having data is just a helper for ops that have a varying amount of data and | 122 // Having data is just a helper for ops that have a varying amount of data and |
| 112 // want a way to store that inline. This is for ops that pass in a | 123 // want a way to store that inline. This is for ops that pass in a |
| 113 // void* and a length. The void* data is assumed to not have any alignment | 124 // void* and a length. The void* data is assumed to not have any alignment |
| 114 // requirements. | 125 // requirements. |
| 115 PaintOpWithData(const PaintFlags& flags, size_t bytes) | 126 PaintOpWithData(const PaintFlags& flags, size_t bytes) |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // Windows wants to generate these when types are exported, so | 344 // Windows wants to generate these when types are exported, so |
| 334 // provide them here explicitly so that DisplayItemList doesn't have | 345 // provide them here explicitly so that DisplayItemList doesn't have |
| 335 // to be defined in this header. | 346 // to be defined in this header. |
| 336 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); | 347 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); |
| 337 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); | 348 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); |
| 338 ~DrawDisplayItemListOp(); | 349 ~DrawDisplayItemListOp(); |
| 339 static void Raster(const PaintOp* op, | 350 static void Raster(const PaintOp* op, |
| 340 SkCanvas* canvas, | 351 SkCanvas* canvas, |
| 341 const SkMatrix& original_ctm); | 352 const SkMatrix& original_ctm); |
| 342 size_t AdditionalBytesUsed() const; | 353 size_t AdditionalBytesUsed() const; |
| 354 bool HasDiscardableImages() const; |
| 343 // TODO(enne): DisplayItemList should know number of slow paths. | 355 // TODO(enne): DisplayItemList should know number of slow paths. |
| 344 | 356 |
| 345 scoped_refptr<DisplayItemList> list; | 357 scoped_refptr<DisplayItemList> list; |
| 346 }; | 358 }; |
| 347 | 359 |
| 348 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags { | 360 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags { |
| 349 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; | 361 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; |
| 350 static constexpr bool kIsDrawOp = true; | 362 static constexpr bool kIsDrawOp = true; |
| 351 DrawDRRectOp(const SkRRect& outer, | 363 DrawDRRectOp(const SkRRect& outer, |
| 352 const SkRRect& inner, | 364 const SkRRect& inner, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 364 static constexpr PaintOpType kType = PaintOpType::DrawImage; | 376 static constexpr PaintOpType kType = PaintOpType::DrawImage; |
| 365 static constexpr bool kIsDrawOp = true; | 377 static constexpr bool kIsDrawOp = true; |
| 366 DrawImageOp(const PaintImage& image, | 378 DrawImageOp(const PaintImage& image, |
| 367 SkScalar left, | 379 SkScalar left, |
| 368 SkScalar top, | 380 SkScalar top, |
| 369 const PaintFlags* flags); | 381 const PaintFlags* flags); |
| 370 ~DrawImageOp(); | 382 ~DrawImageOp(); |
| 371 static void Raster(const PaintOp* op, | 383 static void Raster(const PaintOp* op, |
| 372 SkCanvas* canvas, | 384 SkCanvas* canvas, |
| 373 const SkMatrix& original_ctm); | 385 const SkMatrix& original_ctm); |
| 386 bool HasDiscardableImages() const; |
| 374 | 387 |
| 375 PaintImage image; | 388 PaintImage image; |
| 376 SkScalar left; | 389 SkScalar left; |
| 377 SkScalar top; | 390 SkScalar top; |
| 378 }; | 391 }; |
| 379 | 392 |
| 380 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags { | 393 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags { |
| 381 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; | 394 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; |
| 382 static constexpr bool kIsDrawOp = true; | 395 static constexpr bool kIsDrawOp = true; |
| 383 DrawImageRectOp(const PaintImage& image, | 396 DrawImageRectOp(const PaintImage& image, |
| 384 const SkRect& src, | 397 const SkRect& src, |
| 385 const SkRect& dst, | 398 const SkRect& dst, |
| 386 const PaintFlags* flags, | 399 const PaintFlags* flags, |
| 387 PaintCanvas::SrcRectConstraint constraint); | 400 PaintCanvas::SrcRectConstraint constraint); |
| 388 ~DrawImageRectOp(); | 401 ~DrawImageRectOp(); |
| 389 static void Raster(const PaintOp* op, | 402 static void Raster(const PaintOp* op, |
| 390 SkCanvas* canvas, | 403 SkCanvas* canvas, |
| 391 const SkMatrix& original_ctm); | 404 const SkMatrix& original_ctm); |
| 405 bool HasDiscardableImages() const; |
| 392 | 406 |
| 393 PaintImage image; | 407 PaintImage image; |
| 394 SkRect src; | 408 SkRect src; |
| 395 SkRect dst; | 409 SkRect dst; |
| 396 PaintCanvas::SrcRectConstraint constraint; | 410 PaintCanvas::SrcRectConstraint constraint; |
| 397 }; | 411 }; |
| 398 | 412 |
| 399 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags { | 413 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags { |
| 400 static constexpr PaintOpType kType = PaintOpType::DrawIRect; | 414 static constexpr PaintOpType kType = PaintOpType::DrawIRect; |
| 401 static constexpr bool kIsDrawOp = true; | 415 static constexpr bool kIsDrawOp = true; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 483 |
| 470 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { | 484 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { |
| 471 static constexpr PaintOpType kType = PaintOpType::DrawRecord; | 485 static constexpr PaintOpType kType = PaintOpType::DrawRecord; |
| 472 static constexpr bool kIsDrawOp = true; | 486 static constexpr bool kIsDrawOp = true; |
| 473 explicit DrawRecordOp(sk_sp<const PaintRecord> record); | 487 explicit DrawRecordOp(sk_sp<const PaintRecord> record); |
| 474 ~DrawRecordOp(); | 488 ~DrawRecordOp(); |
| 475 static void Raster(const PaintOp* op, | 489 static void Raster(const PaintOp* op, |
| 476 SkCanvas* canvas, | 490 SkCanvas* canvas, |
| 477 const SkMatrix& original_ctm); | 491 const SkMatrix& original_ctm); |
| 478 size_t AdditionalBytesUsed() const; | 492 size_t AdditionalBytesUsed() const; |
| 493 bool HasDiscardableImages() const; |
| 479 | 494 |
| 480 sk_sp<const PaintRecord> record; | 495 sk_sp<const PaintRecord> record; |
| 481 }; | 496 }; |
| 482 | 497 |
| 483 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags { | 498 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags { |
| 484 static constexpr PaintOpType kType = PaintOpType::DrawRect; | 499 static constexpr PaintOpType kType = PaintOpType::DrawRect; |
| 485 static constexpr bool kIsDrawOp = true; | 500 static constexpr bool kIsDrawOp = true; |
| 486 DrawRectOp(const SkRect& rect, const PaintFlags& flags) | 501 DrawRectOp(const SkRect& rect, const PaintFlags& flags) |
| 487 : PaintOpWithFlags(flags), rect(rect) {} | 502 : PaintOpWithFlags(flags), rect(rect) {} |
| 488 static void Raster(const PaintOp* op, | 503 static void Raster(const PaintOp* op, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 662 |
| 648 void playback(SkCanvas* canvas) const; | 663 void playback(SkCanvas* canvas) const; |
| 649 void playback(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; | 664 void playback(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; |
| 650 | 665 |
| 651 // TODO(enne): These are no longer approximate. Rename these. | 666 // TODO(enne): These are no longer approximate. Rename these. |
| 652 int approximateOpCount() const { return op_count_; } | 667 int approximateOpCount() const { return op_count_; } |
| 653 size_t approximateBytesUsed() const { | 668 size_t approximateBytesUsed() const { |
| 654 return sizeof(*this) + reserved_ + subrecord_bytes_used_; | 669 return sizeof(*this) + reserved_ + subrecord_bytes_used_; |
| 655 } | 670 } |
| 656 int numSlowPaths() const { return num_slow_paths_; } | 671 int numSlowPaths() const { return num_slow_paths_; } |
| 672 bool HasDiscardableImages() const { return has_discardable_images_; } |
| 657 | 673 |
| 658 // Resize the PaintOpBuffer to exactly fit the current amount of used space. | 674 // Resize the PaintOpBuffer to exactly fit the current amount of used space. |
| 659 void ShrinkToFit(); | 675 void ShrinkToFit(); |
| 660 | 676 |
| 661 const SkRect& cullRect() const { return cull_rect_; } | 677 const SkRect& cullRect() const { return cull_rect_; } |
| 662 | 678 |
| 663 PaintOp* GetFirstOp() const { | 679 PaintOp* GetFirstOp() const { |
| 664 return const_cast<PaintOp*>(first_op_.data_as<PaintOp>()); | 680 return const_cast<PaintOp*>(first_op_.data_as<PaintOp>()); |
| 665 } | 681 } |
| 666 | 682 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 op->skip = skip; | 825 op->skip = skip; |
| 810 AnalyzeAddedOp(op); | 826 AnalyzeAddedOp(op); |
| 811 return op; | 827 return op; |
| 812 } | 828 } |
| 813 | 829 |
| 814 template <typename T> | 830 template <typename T> |
| 815 void AnalyzeAddedOp(const T* op) { | 831 void AnalyzeAddedOp(const T* op) { |
| 816 num_slow_paths_ += op->CountSlowPathsFromFlags(); | 832 num_slow_paths_ += op->CountSlowPathsFromFlags(); |
| 817 num_slow_paths_ += op->CountSlowPaths(); | 833 num_slow_paths_ += op->CountSlowPaths(); |
| 818 | 834 |
| 835 has_discardable_images_ |= op->HasDiscardableImages(); |
| 836 has_discardable_images_ |= op->HasDiscardableImagesFromFlags(); |
| 837 |
| 819 subrecord_bytes_used_ += op->AdditionalBytesUsed(); | 838 subrecord_bytes_used_ += op->AdditionalBytesUsed(); |
| 820 } | 839 } |
| 821 | 840 |
| 822 // As a performance optimization because n=1 is an extremely common case just | 841 // As a performance optimization because n=1 is an extremely common case just |
| 823 // store the first op in the PaintOpBuffer itself to avoid an extra alloc. | 842 // store the first op in the PaintOpBuffer itself to avoid an extra alloc. |
| 824 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_; | 843 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_; |
| 825 std::unique_ptr<char, base::AlignedFreeDeleter> data_; | 844 std::unique_ptr<char, base::AlignedFreeDeleter> data_; |
| 826 size_t used_ = 0; | 845 size_t used_ = 0; |
| 827 size_t reserved_ = 0; | 846 size_t reserved_ = 0; |
| 828 int op_count_ = 0; | 847 int op_count_ = 0; |
| 829 | 848 |
| 830 // Record paths for veto-to-msaa for gpu raster. | 849 // Record paths for veto-to-msaa for gpu raster. |
| 831 int num_slow_paths_ = 0; | 850 int num_slow_paths_ = 0; |
| 832 // Record additional bytes used by referenced sub-records and display lists. | 851 // Record additional bytes used by referenced sub-records and display lists. |
| 833 size_t subrecord_bytes_used_ = 0; | 852 size_t subrecord_bytes_used_ = 0; |
| 853 bool has_discardable_images_ = false; |
| 834 SkRect cull_rect_; | 854 SkRect cull_rect_; |
| 835 | 855 |
| 836 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); | 856 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); |
| 837 }; | 857 }; |
| 838 | 858 |
| 839 } // namespace cc | 859 } // namespace cc |
| 840 | 860 |
| 841 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ | 861 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ |
| OLD | NEW |