OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkReader32.h" | 8 #include "SkReader32.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 #include "SkWriter32.h" | 10 #include "SkWriter32.h" |
11 | 11 |
12 /* | 12 /* |
13 * Strings are stored as: length[4-bytes] + string_data + '\0' + pad_to_mul_4 | 13 * Strings are stored as: length[4-bytes] + string_data + '\0' + pad_to_mul_4 |
14 */ | 14 */ |
15 | 15 |
16 const char* SkReader32::readString(size_t* outLen) { | 16 const char* SkReader32::readString(size_t* outLen) { |
17 size_t len = this->readInt(); | 17 size_t len = this->readU32(); |
18 const void* ptr = this->peek(); | 18 const void* ptr = this->peek(); |
19 | 19 |
20 // skip over the string + '\0' and then pad to a multiple of 4 | 20 // skip over the string + '\0' and then pad to a multiple of 4 |
21 size_t alignedSize = SkAlign4(len + 1); | 21 size_t alignedSize = SkAlign4(len + 1); |
22 this->skip(alignedSize); | 22 this->skip(alignedSize); |
23 | 23 |
24 if (outLen) { | 24 if (outLen) { |
25 *outLen = len; | 25 *outLen = len; |
26 } | 26 } |
27 return (const char*)ptr; | 27 return (const char*)ptr; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // prepare us to do copy on write, by pretending the data buffer | 96 // prepare us to do copy on write, by pretending the data buffer |
97 // is external and size limited | 97 // is external and size limited |
98 mutable_this.fData = buffer; | 98 mutable_this.fData = buffer; |
99 mutable_this.fCapacity = fUsed; | 99 mutable_this.fCapacity = fUsed; |
100 mutable_this.fExternal = buffer; | 100 mutable_this.fExternal = buffer; |
101 } | 101 } |
102 mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed)); | 102 mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed)); |
103 } | 103 } |
104 return SkRef(fSnapshot.get()); // Take an extra ref for the caller. | 104 return SkRef(fSnapshot.get()); // Take an extra ref for the caller. |
105 } | 105 } |
OLD | NEW |