| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkImage.h" | 10 #include "SkImage.h" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 factory = fFactoryArray[index]; | 349 factory = fFactoryArray[index]; |
| 350 } else { | 350 } else { |
| 351 factory = (SkFlattenable::Factory)readFunctionPtr(); | 351 factory = (SkFlattenable::Factory)readFunctionPtr(); |
| 352 if (nullptr == factory) { | 352 if (nullptr == factory) { |
| 353 return nullptr; // writer failed to give us the flattenable | 353 return nullptr; // writer failed to give us the flattenable |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 // if we get here, factory may still be null, but if that is the case, the | 357 // if we get here, factory may still be null, but if that is the case, the |
| 358 // failure was ours, not the writer. | 358 // failure was ours, not the writer. |
| 359 SkFlattenable* obj = nullptr; | 359 sk_sp<SkFlattenable> obj; |
| 360 uint32_t sizeRecorded = fReader.readU32(); | 360 uint32_t sizeRecorded = fReader.readU32(); |
| 361 if (factory) { | 361 if (factory) { |
| 362 size_t offset = fReader.offset(); | 362 size_t offset = fReader.offset(); |
| 363 obj = (*factory)(*this); | 363 obj = (*factory)(*this); |
| 364 // check that we read the amount we expected | 364 // check that we read the amount we expected |
| 365 size_t sizeRead = fReader.offset() - offset; | 365 size_t sizeRead = fReader.offset() - offset; |
| 366 if (sizeRecorded != sizeRead) { | 366 if (sizeRecorded != sizeRead) { |
| 367 this->validate(false); | 367 this->validate(false); |
| 368 return nullptr; | 368 return nullptr; |
| 369 } | 369 } |
| 370 } else { | 370 } else { |
| 371 // we must skip the remaining data | 371 // we must skip the remaining data |
| 372 fReader.skip(sizeRecorded); | 372 fReader.skip(sizeRecorded); |
| 373 } | 373 } |
| 374 return obj; | 374 return obj.release(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 /** | 377 /** |
| 378 * Needs to follow the same pattern as readFlattenable(), but explicitly skip w
hatever data | 378 * Needs to follow the same pattern as readFlattenable(), but explicitly skip w
hatever data |
| 379 * has been written. | 379 * has been written. |
| 380 */ | 380 */ |
| 381 void SkReadBuffer::skipFlattenable() { | 381 void SkReadBuffer::skipFlattenable() { |
| 382 if (fFactoryCount > 0) { | 382 if (fFactoryCount > 0) { |
| 383 if (0 == fReader.readU32()) { | 383 if (0 == fReader.readU32()) { |
| 384 return; | 384 return; |
| 385 } | 385 } |
| 386 } else { | 386 } else { |
| 387 if (nullptr == this->readFunctionPtr()) { | 387 if (nullptr == this->readFunctionPtr()) { |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 uint32_t sizeRecorded = fReader.readU32(); | 391 uint32_t sizeRecorded = fReader.readU32(); |
| 392 fReader.skip(sizeRecorded); | 392 fReader.skip(sizeRecorded); |
| 393 } | 393 } |
| OLD | NEW |