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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (fInternal.isEmpty() && this->externalCount() + count <= fExternalLim
it) { | 72 if (fInternal.isEmpty() && this->externalCount() + count <= fExternalLim
it) { |
73 p = fExternal + fCount; | 73 p = fExternal + fCount; |
74 } else { | 74 } else { |
75 p = fInternal.append(count); | 75 p = fInternal.append(count); |
76 } | 76 } |
77 | 77 |
78 fCount += count; | 78 fCount += count; |
79 return p; | 79 return p; |
80 } | 80 } |
81 | 81 |
82 // return the address of the 4byte int at the specified offset (which must | 82 // Return a reference to the 4 bytes at offset, which must be a multiple of
4. |
83 // be a multiple of 4. This does not allocate any new space, so the returned | 83 uint32_t& peek32(size_t offset) { |
84 // address is only valid for 1 int. | |
85 uint32_t* peek32(size_t offset) { | |
86 SkASSERT(SkAlign4(offset) == offset); | 84 SkASSERT(SkAlign4(offset) == offset); |
87 const int count = SkToInt(offset/4); | 85 const int count = SkToInt(offset/4); |
88 SkASSERT(count < fCount); | 86 SkASSERT(count < fCount); |
89 | 87 |
90 if (count < this->externalCount()) { | 88 if (count < this->externalCount()) { |
91 return fExternal + count; | 89 return fExternal[count]; |
92 } | 90 } |
93 return &fInternal[count - this->externalCount()]; | 91 return fInternal[count - this->externalCount()]; |
94 } | 92 } |
95 | 93 |
96 bool writeBool(bool value) { | 94 bool writeBool(bool value) { |
97 this->write32(value); | 95 this->write32(value); |
98 return value; | 96 return value; |
99 } | 97 } |
100 | 98 |
101 void writeInt(int32_t value) { | 99 void writeInt(int32_t value) { |
102 this->write32(value); | 100 this->write32(value); |
103 } | 101 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 206 |
209 /** | 207 /** |
210 * Computes the size (aligned to multiple of 4) need to write the string | 208 * Computes the size (aligned to multiple of 4) need to write the string |
211 * in a call to writeString(). If the length is not specified, it will be | 209 * in a call to writeString(). If the length is not specified, it will be |
212 * computed by calling strlen(). | 210 * computed by calling strlen(). |
213 */ | 211 */ |
214 static size_t WriteStringSize(const char* str, size_t len = (size_t)-1); | 212 static size_t WriteStringSize(const char* str, size_t len = (size_t)-1); |
215 | 213 |
216 /** | 214 /** |
217 * Move the cursor back to offset bytes from the beginning. | 215 * Move the cursor back to offset bytes from the beginning. |
218 * This has the same restrictions as peek32: offset must be <= size() and | 216 * offset must be a multiple of 4 no greater than size(). |
219 * offset must be a multiple of 4. | |
220 */ | 217 */ |
221 void rewindToOffset(size_t offset) { | 218 void rewindToOffset(size_t offset) { |
222 SkASSERT(SkAlign4(offset) == offset); | 219 SkASSERT(SkAlign4(offset) == offset); |
223 const int count = SkToInt(offset/4); | 220 const int count = SkToInt(offset/4); |
224 if (count < this->externalCount()) { | 221 if (count < this->externalCount()) { |
225 fInternal.setCount(0); | 222 fInternal.setCount(0); |
226 } else { | 223 } else { |
227 fInternal.setCount(count - this->externalCount()); | 224 fInternal.setCount(count - this->externalCount()); |
228 } | 225 } |
229 fCount = count; | 226 fCount = count; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 267 |
271 private: | 268 private: |
272 union { | 269 union { |
273 void* fPtrAlignment; | 270 void* fPtrAlignment; |
274 double fDoubleAlignment; | 271 double fDoubleAlignment; |
275 char fStorage[SIZE]; | 272 char fStorage[SIZE]; |
276 } fData; | 273 } fData; |
277 }; | 274 }; |
278 | 275 |
279 #endif | 276 #endif |
OLD | NEW |