Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/core/SkReadBuffer.cpp

Issue 1855733002: change flattenable factory to return sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | src/core/SkShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | src/core/SkShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698