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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 template <typename T> | 205 template <typename T> |
206 const M* GetArrayForThis(const T* op) const { | 206 const M* GetArrayForThis(const T* op) const { |
207 static_assert(std::is_convertible<T, PaintOpWithArrayBase>::value, | 207 static_assert(std::is_convertible<T, PaintOpWithArrayBase>::value, |
208 "T is not a PaintOpWithData"); | 208 "T is not a PaintOpWithData"); |
209 // As an optimization to not have to store an additional offset, | 209 // As an optimization to not have to store an additional offset, |
210 // assert that T has the same or more alignment requirements than M. Thus, | 210 // assert that T has the same or more alignment requirements than M. Thus, |
211 // if T is aligned, and M's alignment needs are a multiple of T's size, then | 211 // if T is aligned, and M's alignment needs are a multiple of T's size, then |
212 // M will also be aligned when placed immediately after T. | 212 // M will also be aligned when placed immediately after T. |
213 static_assert( | 213 static_assert( |
214 sizeof(T) % ALIGNOF(M) == 0, | 214 sizeof(T) % alignof(M) == 0, |
215 "T must be padded such that an array of M is aligned after it"); | 215 "T must be padded such that an array of M is aligned after it"); |
216 static_assert( | 216 static_assert( |
217 ALIGNOF(T) >= ALIGNOF(M), | 217 alignof(T) >= alignof(M), |
218 "T must have not have less alignment requirements than the array data"); | 218 "T must have not have less alignment requirements than the array data"); |
219 return reinterpret_cast<const M*>(op + 1); | 219 return reinterpret_cast<const M*>(op + 1); |
220 } | 220 } |
221 | 221 |
222 template <typename T> | 222 template <typename T> |
223 M* GetArrayForThis(T* op) { | 223 M* GetArrayForThis(T* op) { |
224 return const_cast<M*>( | 224 return const_cast<M*>( |
225 const_cast<const PaintOpWithArray*>(this)->GetArrayForThis( | 225 const_cast<const PaintOpWithArray*>(this)->GetArrayForThis( |
226 const_cast<T*>(op))); | 226 const_cast<T*>(op))); |
227 } | 227 } |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 SkScalar dy; | 771 SkScalar dy; |
772 }; | 772 }; |
773 | 773 |
774 using LargestPaintOp = DrawDRRectOp; | 774 using LargestPaintOp = DrawDRRectOp; |
775 | 775 |
776 class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { | 776 class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
777 public: | 777 public: |
778 enum { kInitialBufferSize = 4096 }; | 778 enum { kInitialBufferSize = 4096 }; |
779 // It's not necessarily the case that the op with the maximum alignment | 779 // It's not necessarily the case that the op with the maximum alignment |
780 // requirements is also the biggest op, but for now that's true. | 780 // requirements is also the biggest op, but for now that's true. |
781 static constexpr size_t PaintOpAlign = ALIGNOF(DrawDRRectOp); | 781 static constexpr size_t PaintOpAlign = alignof(DrawDRRectOp); |
782 | 782 |
783 PaintOpBuffer(); | 783 PaintOpBuffer(); |
784 ~PaintOpBuffer() override; | 784 ~PaintOpBuffer() override; |
785 | 785 |
786 void Reset(); | 786 void Reset(); |
787 | 787 |
788 void playback(SkCanvas* canvas, | 788 void playback(SkCanvas* canvas, |
789 SkPicture::AbortCallback* callback = nullptr) const; | 789 SkPicture::AbortCallback* callback = nullptr) const; |
790 // This can be used to play back a subset of the PaintOpBuffer. | 790 // This can be used to play back a subset of the PaintOpBuffer. |
791 // The |range_starts| array is an increasing set of positions in the | 791 // The |range_starts| array is an increasing set of positions in the |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 }; | 928 }; |
929 | 929 |
930 private: | 930 private: |
931 void ReallocBuffer(size_t new_size); | 931 void ReallocBuffer(size_t new_size); |
932 // Returns the allocated op and the number of bytes to skip in |data_| to get | 932 // Returns the allocated op and the number of bytes to skip in |data_| to get |
933 // to the next op. | 933 // to the next op. |
934 std::pair<void*, size_t> AllocatePaintOp(size_t sizeof_op, size_t bytes); | 934 std::pair<void*, size_t> AllocatePaintOp(size_t sizeof_op, size_t bytes); |
935 | 935 |
936 template <typename T, typename... Args> | 936 template <typename T, typename... Args> |
937 T* push_internal(size_t bytes, Args&&... args) { | 937 T* push_internal(size_t bytes, Args&&... args) { |
938 static_assert(ALIGNOF(T) <= PaintOpAlign, ""); | 938 static_assert(alignof(T) <= PaintOpAlign, ""); |
939 | 939 |
940 auto pair = AllocatePaintOp(sizeof(T), bytes); | 940 auto pair = AllocatePaintOp(sizeof(T), bytes); |
941 T* op = reinterpret_cast<T*>(pair.first); | 941 T* op = reinterpret_cast<T*>(pair.first); |
942 size_t skip = pair.second; | 942 size_t skip = pair.second; |
943 | 943 |
944 new (op) T{std::forward<Args>(args)...}; | 944 new (op) T{std::forward<Args>(args)...}; |
945 op->type = static_cast<uint32_t>(T::kType); | 945 op->type = static_cast<uint32_t>(T::kType); |
946 op->skip = skip; | 946 op->skip = skip; |
947 AnalyzeAddedOp(op); | 947 AnalyzeAddedOp(op); |
948 return op; | 948 return op; |
(...skipping 20 matching lines...) Expand all Loading... |
969 // Record additional bytes used by referenced sub-records and display lists. | 969 // Record additional bytes used by referenced sub-records and display lists. |
970 size_t subrecord_bytes_used_ = 0; | 970 size_t subrecord_bytes_used_ = 0; |
971 bool has_discardable_images_ = false; | 971 bool has_discardable_images_ = false; |
972 | 972 |
973 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); | 973 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); |
974 }; | 974 }; |
975 | 975 |
976 } // namespace cc | 976 } // namespace cc |
977 | 977 |
978 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ | 978 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ |
OLD | NEW |