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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname); | 239 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname); |
240 if (nullptr == factory) { | 240 if (nullptr == factory) { |
241 return nullptr; // writer failed to give us the flattenable | 241 return nullptr; // writer failed to give us the flattenable |
242 } | 242 } |
243 | 243 |
244 // if we get here, factory may still be null, but if that is the case, the | 244 // if we get here, factory may still be null, but if that is the case, the |
245 // failure was ours, not the writer. | 245 // failure was ours, not the writer. |
246 SkFlattenable* obj = nullptr; | 246 SkFlattenable* obj = nullptr; |
247 uint32_t sizeRecorded = this->readUInt(); | 247 uint32_t sizeRecorded = this->readUInt(); |
248 if (factory) { | 248 if (factory) { |
| 249 // Check if a custom Factory has been specified for this flattenable. |
| 250 SkFlattenable::Factory* customFactoryPtr = getCustomFactory(factory); |
| 251 if (customFactoryPtr) { |
| 252 factory = *customFactoryPtr; |
| 253 } |
| 254 |
249 size_t offset = fReader.offset(); | 255 size_t offset = fReader.offset(); |
250 obj = (*factory)(*this); | 256 obj = (*factory)(*this); |
251 // check that we read the amount we expected | 257 // check that we read the amount we expected |
252 size_t sizeRead = fReader.offset() - offset; | 258 size_t sizeRead = fReader.offset() - offset; |
253 this->validate(sizeRecorded == sizeRead); | 259 this->validate(sizeRecorded == sizeRead); |
254 if (fError) { | 260 if (fError) { |
255 // we could try to fix up the offset... | 261 // we could try to fix up the offset... |
256 SkSafeUnref(obj); | 262 SkSafeUnref(obj); |
257 obj = nullptr; | 263 obj = nullptr; |
258 } | 264 } |
259 } else { | 265 } else { |
260 // we must skip the remaining data | 266 // we must skip the remaining data |
261 this->skip(sizeRecorded); | 267 this->skip(sizeRecorded); |
262 SkASSERT(false); | 268 SkASSERT(false); |
263 } | 269 } |
264 return obj; | 270 return obj; |
265 } | 271 } |
266 | 272 |
267 void SkValidatingReadBuffer::skipFlattenable() { | 273 void SkValidatingReadBuffer::skipFlattenable() { |
268 SkString name; | 274 SkString name; |
269 this->readString(&name); | 275 this->readString(&name); |
270 if (fError) { | 276 if (fError) { |
271 return; | 277 return; |
272 } | 278 } |
273 uint32_t sizeRecorded = this->readUInt(); | 279 uint32_t sizeRecorded = this->readUInt(); |
274 this->skip(sizeRecorded); | 280 this->skip(sizeRecorded); |
275 } | 281 } |
OLD | NEW |