OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkValidatingReadBuffer.h" | 10 #include "SkValidatingReadBuffer.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 return nullptr; | 225 return nullptr; |
226 } | 226 } |
227 | 227 |
228 // Is this the type we wanted ? | 228 // Is this the type we wanted ? |
229 const char* cname = name.c_str(); | 229 const char* cname = name.c_str(); |
230 SkFlattenable::Type baseType; | 230 SkFlattenable::Type baseType; |
231 if (!SkFlattenable::NameToType(cname, &baseType) || (baseType != type)) { | 231 if (!SkFlattenable::NameToType(cname, &baseType) || (baseType != type)) { |
232 return nullptr; | 232 return nullptr; |
233 } | 233 } |
234 | 234 |
235 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname); | 235 // Get the factory for this flattenable. |
236 if (nullptr == factory) { | 236 SkFlattenable::Factory factory = this->getCustomFactory(name); |
237 return nullptr; // writer failed to give us the flattenable | 237 if (!factory) { |
| 238 factory = SkFlattenable::NameToFactory(cname); |
| 239 if (!factory) { |
| 240 return nullptr; // writer failed to give us the flattenable |
| 241 } |
238 } | 242 } |
239 | 243 |
240 // if we get here, factory may still be null, but if that is the case, the | 244 // If we get here, the factory is non-null. |
241 // failure was ours, not the writer. | |
242 sk_sp<SkFlattenable> obj; | 245 sk_sp<SkFlattenable> obj; |
243 uint32_t sizeRecorded = this->readUInt(); | 246 uint32_t sizeRecorded = this->readUInt(); |
244 if (factory) { | 247 size_t offset = fReader.offset(); |
245 size_t offset = fReader.offset(); | 248 obj = (*factory)(*this); |
246 obj = (*factory)(*this); | 249 // check that we read the amount we expected |
247 // check that we read the amount we expected | 250 size_t sizeRead = fReader.offset() - offset; |
248 size_t sizeRead = fReader.offset() - offset; | 251 this->validate(sizeRecorded == sizeRead); |
249 this->validate(sizeRecorded == sizeRead); | 252 if (fError) { |
250 if (fError) { | 253 obj = nullptr; |
251 obj = nullptr; | |
252 } | |
253 } else { | |
254 // we must skip the remaining data | |
255 this->skip(sizeRecorded); | |
256 SkASSERT(false); | |
257 } | 254 } |
258 return obj.release(); | 255 return obj.release(); |
259 } | 256 } |
260 | 257 |
261 void SkValidatingReadBuffer::skipFlattenable() { | 258 void SkValidatingReadBuffer::skipFlattenable() { |
262 SkString name; | 259 SkString name; |
263 this->readString(&name); | 260 this->readString(&name); |
264 if (fError) { | 261 if (fError) { |
265 return; | 262 return; |
266 } | 263 } |
267 uint32_t sizeRecorded = this->readUInt(); | 264 uint32_t sizeRecorded = this->readUInt(); |
268 this->skip(sizeRecorded); | 265 this->skip(sizeRecorded); |
269 } | 266 } |
OLD | NEW |