OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
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 | 8 |
9 #ifndef SkReader32_DEFINED | 9 #ifndef SkReader32_DEFINED |
10 #define SkReader32_DEFINED | 10 #define SkReader32_DEFINED |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 * string within the reader's buffer. | 128 * string within the reader's buffer. |
129 */ | 129 */ |
130 const char* readString(size_t* len = nullptr); | 130 const char* readString(size_t* len = nullptr); |
131 | 131 |
132 /** | 132 /** |
133 * Read the string (written by SkWriter32::writeString) and return it in | 133 * Read the string (written by SkWriter32::writeString) and return it in |
134 * copy (if copy is not null). Return the length of the string. | 134 * copy (if copy is not null). Return the length of the string. |
135 */ | 135 */ |
136 size_t readIntoString(SkString* copy); | 136 size_t readIntoString(SkString* copy); |
137 | 137 |
138 SkData* readData() { | 138 sk_sp<SkData> readData() { |
139 uint32_t byteLength = this->readU32(); | 139 uint32_t byteLength = this->readU32(); |
140 if (0 == byteLength) { | 140 if (0 == byteLength) { |
141 return SkData::NewEmpty(); | 141 return SkData::MakeEmpty(); |
142 } | 142 } |
143 return SkData::NewWithCopy(this->skip(byteLength), byteLength); | 143 return SkData::MakeWithCopy(this->skip(byteLength), byteLength); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 template <typename T> bool readObjectFromMemory(T* obj) { | 147 template <typename T> bool readObjectFromMemory(T* obj) { |
148 size_t size = obj->readFromMemory(this->peek(), this->available()); | 148 size_t size = obj->readFromMemory(this->peek(), this->available()); |
149 // If readFromMemory() fails (which means that available() was too small
), it returns 0 | 149 // If readFromMemory() fails (which means that available() was too small
), it returns 0 |
150 bool success = (size > 0) && (size <= this->available()) && (SkAlign4(si
ze) == size); | 150 bool success = (size > 0) && (size <= this->available()) && (SkAlign4(si
ze) == size); |
151 // In case of failure, we want to skip to the end | 151 // In case of failure, we want to skip to the end |
152 (void)this->skip(success ? size : this->available()); | 152 (void)this->skip(success ? size : this->available()); |
153 return success; | 153 return success; |
154 } | 154 } |
155 | 155 |
156 // these are always 4-byte aligned | 156 // these are always 4-byte aligned |
157 const char* fCurr; // current position within buffer | 157 const char* fCurr; // current position within buffer |
158 const char* fStop; // end of buffer | 158 const char* fStop; // end of buffer |
159 const char* fBase; // beginning of buffer | 159 const char* fBase; // beginning of buffer |
160 | 160 |
161 #ifdef SK_DEBUG | 161 #ifdef SK_DEBUG |
162 static bool ptr_align_4(const void* ptr) { | 162 static bool ptr_align_4(const void* ptr) { |
163 return (((const char*)ptr - (const char*)nullptr) & 3) == 0; | 163 return (((const char*)ptr - (const char*)nullptr) & 3) == 0; |
164 } | 164 } |
165 #endif | 165 #endif |
166 }; | 166 }; |
167 | 167 |
168 #endif | 168 #endif |
OLD | NEW |