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 28 matching lines...) Expand all Loading... |
39 , fTail(NULL) | 39 , fTail(NULL) |
40 , fMinSize(minSize) | 40 , fMinSize(minSize) |
41 , fSize(0) | 41 , fSize(0) |
42 , fWrittenBeforeLastBlock(0) | 42 , fWrittenBeforeLastBlock(0) |
43 {} | 43 {} |
44 | 44 |
45 ~SkWriter32(); | 45 ~SkWriter32(); |
46 | 46 |
47 // return the current offset (will always be a multiple of 4) | 47 // return the current offset (will always be a multiple of 4) |
48 uint32_t bytesWritten() const { return fSize; } | 48 uint32_t bytesWritten() const { return fSize; } |
49 // DEPRECATED: use byetsWritten instead | 49 // DEPRECATED: use bytesWritten instead TODO(mtklein): clean up |
50 uint32_t size() const { return this->bytesWritten(); } | 50 uint32_t size() const { return this->bytesWritten(); } |
51 | 51 |
52 void reset(); | 52 // Returns true if we've written only into the storage passed into construct
or or reset. |
| 53 // (You may be able to use this to avoid a call to flatten.) |
| 54 bool wroteOnlyToStorage() const { |
| 55 return fHead == &fExternalBlock && this->bytesWritten() <= fExternalBloc
k.fSizeOfBlock; |
| 56 } |
| 57 |
| 58 void reset(); |
| 59 void reset(void* storage, size_t size); |
53 | 60 |
54 // size MUST be multiple of 4 | 61 // size MUST be multiple of 4 |
55 uint32_t* reserve(size_t size) { | 62 uint32_t* reserve(size_t size) { |
56 SkASSERT(SkAlign4(size) == size); | 63 SkASSERT(SkAlign4(size) == size); |
57 | 64 |
58 Block* block = fTail; | 65 Block* block = fTail; |
59 if (NULL == block || block->available() < size) { | 66 if (NULL == block || block->available() < size) { |
60 block = this->doReserve(size); | 67 block = this->doReserve(size); |
61 } | 68 } |
62 fSize += size; | 69 fSize += size; |
63 return block->alloc(size); | 70 return block->alloc(size); |
64 } | 71 } |
65 | 72 |
66 void reset(void* storage, size_t size); | |
67 | |
68 bool writeBool(bool value) { | 73 bool writeBool(bool value) { |
69 this->writeInt(value); | 74 this->writeInt(value); |
70 return value; | 75 return value; |
71 } | 76 } |
72 | 77 |
73 void writeInt(int32_t value) { | 78 void writeInt(int32_t value) { |
74 *(int32_t*)this->reserve(sizeof(value)) = value; | 79 *(int32_t*)this->reserve(sizeof(value)) = value; |
75 } | 80 } |
76 | 81 |
77 void write8(int32_t value) { | 82 void write8(int32_t value) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 290 |
286 private: | 291 private: |
287 union { | 292 union { |
288 void* fPtrAlignment; | 293 void* fPtrAlignment; |
289 double fDoubleAlignment; | 294 double fDoubleAlignment; |
290 char fStorage[SIZE]; | 295 char fStorage[SIZE]; |
291 } fData; | 296 } fData; |
292 }; | 297 }; |
293 | 298 |
294 #endif | 299 #endif |
OLD | NEW |