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

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

Issue 1858323002: Enable flattening/unflattening with custom unflatten procs (Closed) Base URL: https://skia.googlesource.com/skia.git@flattenable
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
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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return nullptr; 229 return nullptr;
230 } 230 }
231 231
232 // Is this the type we wanted ? 232 // Is this the type we wanted ?
233 const char* cname = name.c_str(); 233 const char* cname = name.c_str();
234 SkFlattenable::Type baseType; 234 SkFlattenable::Type baseType;
235 if (!SkFlattenable::NameToType(cname, &baseType) || (baseType != type)) { 235 if (!SkFlattenable::NameToType(cname, &baseType) || (baseType != type)) {
236 return nullptr; 236 return nullptr;
237 } 237 }
238 238
239 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname); 239 // Get the factory for this flattenable.
240 if (nullptr == factory) { 240 SkFlattenable::Factory factory = getCustomFactory(cname);
241 return nullptr; // writer failed to give us the flattenable 241 if (!factory) {
242 factory = SkFlattenable::NameToFactory(cname);
243 if (!factory) {
244 return nullptr; // writer failed to give us the flattenable
245 }
242 } 246 }
243 247
244 // if we get here, factory may still be null, but if that is the case, the 248 // if we get here, factory may still be null, but if that is the case, the
245 // failure was ours, not the writer. 249 // failure was ours, not the writer.
246 sk_sp<SkFlattenable> obj; 250 sk_sp<SkFlattenable> obj;
247 uint32_t sizeRecorded = this->readUInt(); 251 uint32_t sizeRecorded = this->readUInt();
248 if (factory) { 252 size_t offset = fReader.offset();
249 size_t offset = fReader.offset(); 253 obj = (*factory)(*this);
250 obj = (*factory)(*this); 254 // check that we read the amount we expected
251 // check that we read the amount we expected 255 size_t sizeRead = fReader.offset() - offset;
252 size_t sizeRead = fReader.offset() - offset; 256 this->validate(sizeRecorded == sizeRead);
253 this->validate(sizeRecorded == sizeRead); 257 if (fError) {
254 if (fError) { 258 obj = nullptr;
255 obj = nullptr;
256 }
257 } else {
258 // we must skip the remaining data
259 this->skip(sizeRecorded);
260 SkASSERT(false);
261 } 259 }
262 return obj.release(); 260 return obj.release();
263 } 261 }
264 262
265 void SkValidatingReadBuffer::skipFlattenable() { 263 void SkValidatingReadBuffer::skipFlattenable() {
266 SkString name; 264 SkString name;
267 this->readString(&name); 265 this->readString(&name);
268 if (fError) { 266 if (fError) {
269 return; 267 return;
270 } 268 }
271 uint32_t sizeRecorded = this->readUInt(); 269 uint32_t sizeRecorded = this->readUInt();
272 this->skip(sizeRecorded); 270 this->skip(sizeRecorded);
273 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698