OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkWriter32_DEFINED | 10 #ifndef SkWriter32_DEFINED |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const uint32_t* contiguousArray() const { | 60 const uint32_t* contiguousArray() const { |
61 return (uint32_t*)fData; | 61 return (uint32_t*)fData; |
62 } | 62 } |
63 | 63 |
64 // size MUST be multiple of 4 | 64 // size MUST be multiple of 4 |
65 uint32_t* reserve(size_t size) { | 65 uint32_t* reserve(size_t size) { |
66 SkASSERT(SkAlign4(size) == size); | 66 SkASSERT(SkAlign4(size) == size); |
67 size_t offset = fUsed; | 67 size_t offset = fUsed; |
68 size_t totalRequired = fUsed + size; | 68 size_t totalRequired = fUsed + size; |
69 if (totalRequired > fCapacity) { | 69 if (totalRequired > fCapacity) { |
70 growToAtLeast(totalRequired); | 70 this->growToAtLeast(totalRequired); |
71 } | 71 } |
72 fUsed = totalRequired; | 72 fUsed = totalRequired; |
73 return (uint32_t*)(fData + offset); | 73 return (uint32_t*)(fData + offset); |
74 } | 74 } |
75 | 75 |
76 // Read or write 4 bytes at offset, which must be a multiple of 4 <= size(). | 76 // Read or write 4 bytes at offset, which must be a multiple of 4 <= size(). |
77 uint32_t read32At(size_t offset) { | 77 uint32_t read32At(size_t offset) { |
78 SkASSERT(SkAlign4(offset) == offset); | 78 SkASSERT(SkAlign4(offset) == offset); |
79 SkASSERT(offset < fUsed); | 79 SkASSERT(offset < fUsed); |
80 return *(uint32_t*)(fData + offset); | 80 return *(uint32_t*)(fData + offset); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 }; | 240 }; |
241 | 241 |
242 /** | 242 /** |
243 * Helper class to allocated SIZE bytes as part of the writer, and to provide | 243 * Helper class to allocated SIZE bytes as part of the writer, and to provide |
244 * that storage to the constructor as its initial storage buffer. | 244 * that storage to the constructor as its initial storage buffer. |
245 * | 245 * |
246 * This wrapper ensures proper alignment rules are met for the storage. | 246 * This wrapper ensures proper alignment rules are met for the storage. |
247 */ | 247 */ |
248 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { | 248 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { |
249 public: | 249 public: |
250 SkSWriter32() : SkWriter32(fData.fStorage, SIZE) {} | 250 SkSWriter32() { this->reset(); } |
| 251 |
| 252 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); } |
251 | 253 |
252 private: | 254 private: |
253 union { | 255 union { |
254 void* fPtrAlignment; | 256 void* fPtrAlignment; |
255 double fDoubleAlignment; | 257 double fDoubleAlignment; |
256 char fStorage[SIZE]; | 258 char fStorage[SIZE]; |
257 } fData; | 259 } fData; |
| 260 |
| 261 typedef SkWriter32 INHERITED; |
258 }; | 262 }; |
259 | 263 |
260 #endif | 264 #endif |
OLD | NEW |