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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void reset(void* external = NULL, size_t externalBytes = 0) { | 44 void reset(void* external = NULL, size_t externalBytes = 0) { |
45 SkASSERT(SkIsAlign4((uintptr_t)external)); | 45 SkASSERT(SkIsAlign4((uintptr_t)external)); |
46 SkASSERT(SkIsAlign4(externalBytes)); | 46 SkASSERT(SkIsAlign4(externalBytes)); |
47 | 47 |
48 fData = (uint8_t*)external; | 48 fData = (uint8_t*)external; |
49 fCapacity = externalBytes; | 49 fCapacity = externalBytes; |
50 fUsed = 0; | 50 fUsed = 0; |
51 fExternal = external; | 51 fExternal = external; |
52 } | 52 } |
53 | 53 |
54 // Returns the current buffer. | |
55 // The pointer may be invalidated by any future write calls. | |
56 const uint32_t* contiguousArray() const { | |
57 return (uint32_t*)fData; | |
58 } | |
59 | |
60 // size MUST be multiple of 4 | 54 // size MUST be multiple of 4 |
61 uint32_t* reserve(size_t size) { | 55 uint32_t* reserve(size_t size) { |
62 SkASSERT(SkAlign4(size) == size); | 56 SkASSERT(SkAlign4(size) == size); |
63 size_t offset = fUsed; | 57 size_t offset = fUsed; |
64 size_t totalRequired = fUsed + size; | 58 size_t totalRequired = fUsed + size; |
65 if (totalRequired > fCapacity) { | 59 if (totalRequired > fCapacity) { |
66 this->growToAtLeast(totalRequired); | 60 this->growToAtLeast(totalRequired); |
67 } | 61 } |
68 fUsed = totalRequired; | 62 fUsed = totalRequired; |
69 return (uint32_t*)(fData + offset); | 63 return (uint32_t*)(fData + offset); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 union { | 267 union { |
274 void* fPtrAlignment; | 268 void* fPtrAlignment; |
275 double fDoubleAlignment; | 269 double fDoubleAlignment; |
276 char fStorage[SIZE]; | 270 char fStorage[SIZE]; |
277 } fData; | 271 } fData; |
278 | 272 |
279 typedef SkWriter32 INHERITED; | 273 typedef SkWriter32 INHERITED; |
280 }; | 274 }; |
281 | 275 |
282 #endif | 276 #endif |
OLD | NEW |