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

Side by Side Diff: src/core/SkValidatingReadBuffer.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/SkShader.cpp ('k') | src/core/SkXfermode.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 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return nullptr; 236 return nullptr;
237 } 237 }
238 238
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 sk_sp<SkFlattenable> obj;
247 uint32_t sizeRecorded = this->readUInt(); 247 uint32_t sizeRecorded = this->readUInt();
248 if (factory) { 248 if (factory) {
249 size_t offset = fReader.offset(); 249 size_t offset = fReader.offset();
250 obj = (*factory)(*this); 250 obj = (*factory)(*this);
251 // check that we read the amount we expected 251 // check that we read the amount we expected
252 size_t sizeRead = fReader.offset() - offset; 252 size_t sizeRead = fReader.offset() - offset;
253 this->validate(sizeRecorded == sizeRead); 253 this->validate(sizeRecorded == sizeRead);
254 if (fError) { 254 if (fError) {
255 // we could try to fix up the offset...
256 SkSafeUnref(obj);
257 obj = nullptr; 255 obj = nullptr;
258 } 256 }
259 } else { 257 } else {
260 // we must skip the remaining data 258 // we must skip the remaining data
261 this->skip(sizeRecorded); 259 this->skip(sizeRecorded);
262 SkASSERT(false); 260 SkASSERT(false);
263 } 261 }
264 return obj; 262 return obj.release();
265 } 263 }
266 264
267 void SkValidatingReadBuffer::skipFlattenable() { 265 void SkValidatingReadBuffer::skipFlattenable() {
268 SkString name; 266 SkString name;
269 this->readString(&name); 267 this->readString(&name);
270 if (fError) { 268 if (fError) {
271 return; 269 return;
272 } 270 }
273 uint32_t sizeRecorded = this->readUInt(); 271 uint32_t sizeRecorded = this->readUInt();
274 this->skip(sizeRecorded); 272 this->skip(sizeRecorded);
275 } 273 }
OLDNEW
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698