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

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

Issue 2884563004: cc: Renamed approximate{BytesUsed,OpCount} in paint op buffer. (Closed)
Patch Set: winfix 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
« no previous file with comments | « cc/paint/float_clip_display_item.h ('k') | cc/paint/paint_op_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 773
774 PaintOpBuffer(); 774 PaintOpBuffer();
775 explicit PaintOpBuffer(const SkRect& cull_rect); 775 explicit PaintOpBuffer(const SkRect& cull_rect);
776 ~PaintOpBuffer() override; 776 ~PaintOpBuffer() override;
777 777
778 void Reset(); 778 void Reset();
779 779
780 void playback(SkCanvas* canvas) const; 780 void playback(SkCanvas* canvas) const;
781 void playback(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; 781 void playback(SkCanvas* canvas, SkPicture::AbortCallback* callback) const;
782 782
783 // TODO(enne): These are no longer approximate. Rename these. 783 // Returns the size of the paint op buffer. That is, the number of ops
784 int approximateOpCount() const { return op_count_; } 784 // contained in it.
785 size_t approximateBytesUsed() const { 785 size_t size() const { return op_count_; }
786 // Returns the number of bytes used by the paint op buffer.
787 size_t bytes_used() const {
786 return sizeof(*this) + reserved_ + subrecord_bytes_used_; 788 return sizeof(*this) + reserved_ + subrecord_bytes_used_;
787 } 789 }
788 int numSlowPaths() const { return num_slow_paths_; } 790 int numSlowPaths() const { return num_slow_paths_; }
789 bool HasDiscardableImages() const { return has_discardable_images_; } 791 bool HasDiscardableImages() const { return has_discardable_images_; }
790 792
791 // Resize the PaintOpBuffer to exactly fit the current amount of used space. 793 // Resize the PaintOpBuffer to exactly fit the current amount of used space.
792 void ShrinkToFit(); 794 void ShrinkToFit();
793 795
794 const SkRect& cullRect() const { return cull_rect_; } 796 const SkRect& cullRect() const { return cull_rect_; }
795 797
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 explicit Iterator(const PaintOpBuffer* buffer) 868 explicit Iterator(const PaintOpBuffer* buffer)
867 : buffer_(buffer), ptr_(buffer_->data_.get()) {} 869 : buffer_(buffer), ptr_(buffer_->data_.get()) {}
868 870
869 PaintOp* operator->() const { 871 PaintOp* operator->() const {
870 return op_idx_ ? reinterpret_cast<PaintOp*>(ptr_) : buffer_->GetFirstOp(); 872 return op_idx_ ? reinterpret_cast<PaintOp*>(ptr_) : buffer_->GetFirstOp();
871 } 873 }
872 PaintOp* operator*() const { return operator->(); } 874 PaintOp* operator*() const { return operator->(); }
873 Iterator begin() { return Iterator(buffer_, buffer_->data_.get(), 0); } 875 Iterator begin() { return Iterator(buffer_, buffer_->data_.get(), 0); }
874 Iterator end() { 876 Iterator end() {
875 return Iterator(buffer_, buffer_->data_.get() + buffer_->used_, 877 return Iterator(buffer_, buffer_->data_.get() + buffer_->used_,
876 buffer_->approximateOpCount()); 878 buffer_->size());
877 } 879 }
878 bool operator!=(const Iterator& other) { 880 bool operator!=(const Iterator& other) {
879 // Not valid to compare iterators on different buffers. 881 // Not valid to compare iterators on different buffers.
880 DCHECK_EQ(other.buffer_, buffer_); 882 DCHECK_EQ(other.buffer_, buffer_);
881 return other.op_idx_ != op_idx_; 883 return other.op_idx_ != op_idx_;
882 } 884 }
883 Iterator& operator++() { 885 Iterator& operator++() {
884 if (!op_idx_++) 886 if (!op_idx_++)
885 return *this; 887 return *this;
886 PaintOp* op = **this; 888 PaintOp* op = **this;
887 uint32_t type = op->type; 889 uint32_t type = op->type;
888 CHECK_LE(type, static_cast<uint32_t>(PaintOpType::LastPaintOpType)); 890 CHECK_LE(type, static_cast<uint32_t>(PaintOpType::LastPaintOpType));
889 ptr_ += op->skip; 891 ptr_ += op->skip;
890 return *this; 892 return *this;
891 } 893 }
892 operator bool() const { return op_idx_ < buffer_->approximateOpCount(); } 894 operator bool() const { return op_idx_ < buffer_->size(); }
893 895
894 int op_idx() const { return op_idx_; } 896 size_t op_idx() const { return op_idx_; }
895 897
896 // Return the next op without advancing the iterator, or nullptr if none. 898 // Return the next op without advancing the iterator, or nullptr if none.
897 PaintOp* peek1() const { 899 PaintOp* peek1() const {
898 if (op_idx_ + 1 >= buffer_->approximateOpCount()) 900 if (op_idx_ + 1 >= buffer_->size())
899 return nullptr; 901 return nullptr;
900 if (!op_idx_) 902 if (!op_idx_)
901 return reinterpret_cast<PaintOp*>(ptr_); 903 return reinterpret_cast<PaintOp*>(ptr_);
902 return reinterpret_cast<PaintOp*>(ptr_ + (*this)->skip); 904 return reinterpret_cast<PaintOp*>(ptr_ + (*this)->skip);
903 } 905 }
904 906
905 // Return the op two ops ahead without advancing the iterator, or nullptr if 907 // Return the op two ops ahead without advancing the iterator, or nullptr if
906 // none. 908 // none.
907 PaintOp* peek2() const { 909 PaintOp* peek2() const {
908 if (op_idx_ + 2 >= buffer_->approximateOpCount()) 910 if (op_idx_ + 2 >= buffer_->size())
909 return nullptr; 911 return nullptr;
910 char* next = ptr_ + reinterpret_cast<PaintOp*>(ptr_)->skip; 912 char* next = ptr_ + reinterpret_cast<PaintOp*>(ptr_)->skip;
911 PaintOp* next_op = reinterpret_cast<PaintOp*>(next); 913 PaintOp* next_op = reinterpret_cast<PaintOp*>(next);
912 if (!op_idx_) 914 if (!op_idx_)
913 return next_op; 915 return next_op;
914 return reinterpret_cast<PaintOp*>(next + next_op->skip); 916 return reinterpret_cast<PaintOp*>(next + next_op->skip);
915 } 917 }
916 918
917 private: 919 private:
918 Iterator(const PaintOpBuffer* buffer, char* ptr, int op_idx) 920 Iterator(const PaintOpBuffer* buffer, char* ptr, size_t op_idx)
919 : buffer_(buffer), ptr_(ptr), op_idx_(op_idx) {} 921 : buffer_(buffer), ptr_(ptr), op_idx_(op_idx) {}
920 922
921 const PaintOpBuffer* buffer_ = nullptr; 923 const PaintOpBuffer* buffer_ = nullptr;
922 char* ptr_ = nullptr; 924 char* ptr_ = nullptr;
923 int op_idx_ = 0; 925 size_t op_idx_ = 0;
924 }; 926 };
925 927
926 private: 928 private:
927 void ReallocBuffer(size_t new_size); 929 void ReallocBuffer(size_t new_size);
928 // Returns the allocated op and the number of bytes to skip in |data_| to get 930 // Returns the allocated op and the number of bytes to skip in |data_| to get
929 // to the next op. 931 // to the next op.
930 std::pair<void*, size_t> AllocatePaintOp(size_t sizeof_op, size_t bytes); 932 std::pair<void*, size_t> AllocatePaintOp(size_t sizeof_op, size_t bytes);
931 933
932 template <typename T, typename... Args> 934 template <typename T, typename... Args>
933 T* push_internal(size_t bytes, Args&&... args) { 935 T* push_internal(size_t bytes, Args&&... args) {
(...skipping 20 matching lines...) Expand all
954 956
955 subrecord_bytes_used_ += op->AdditionalBytesUsed(); 957 subrecord_bytes_used_ += op->AdditionalBytesUsed();
956 } 958 }
957 959
958 // As a performance optimization because n=1 is an extremely common case just 960 // As a performance optimization because n=1 is an extremely common case just
959 // store the first op in the PaintOpBuffer itself to avoid an extra alloc. 961 // store the first op in the PaintOpBuffer itself to avoid an extra alloc.
960 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_; 962 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_;
961 std::unique_ptr<char, base::AlignedFreeDeleter> data_; 963 std::unique_ptr<char, base::AlignedFreeDeleter> data_;
962 size_t used_ = 0; 964 size_t used_ = 0;
963 size_t reserved_ = 0; 965 size_t reserved_ = 0;
964 int op_count_ = 0; 966 size_t op_count_ = 0;
965 967
966 // Record paths for veto-to-msaa for gpu raster. 968 // Record paths for veto-to-msaa for gpu raster.
967 int num_slow_paths_ = 0; 969 int num_slow_paths_ = 0;
968 // Record additional bytes used by referenced sub-records and display lists. 970 // Record additional bytes used by referenced sub-records and display lists.
969 size_t subrecord_bytes_used_ = 0; 971 size_t subrecord_bytes_used_ = 0;
970 bool has_discardable_images_ = false; 972 bool has_discardable_images_ = false;
971 SkRect cull_rect_; 973 SkRect cull_rect_;
972 974
973 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); 975 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer);
974 }; 976 };
975 977
976 } // namespace cc 978 } // namespace cc
977 979
978 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ 980 #endif // CC_PAINT_PAINT_OP_BUFFER_H_
OLDNEW
« no previous file with comments | « cc/paint/float_clip_display_item.h ('k') | cc/paint/paint_op_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698