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

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

Issue 1858323002: Enable flattening/unflattening with custom unflatten procs (Closed) Base URL: https://skia.googlesource.com/skia.git@flattenable
Patch Set: Avoid duping strings 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 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 } 326 }
327 327
328 SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) { 328 SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
329 // 329 //
330 // TODO: confirm that ft matches the factory we decide to use 330 // TODO: confirm that ft matches the factory we decide to use
331 // 331 //
332 332
333 SkFlattenable::Factory factory = nullptr; 333 SkFlattenable::Factory factory = nullptr;
334 334
335 uint32_t index = fReader.readU32();
336 if (0 == index) {
337 return nullptr; // writer failed to give us the flattenable
338 }
339
335 if (fFactoryCount > 0) { 340 if (fFactoryCount > 0) {
336 int32_t index = fReader.readU32();
337 if (0 == index) {
338 return nullptr; // writer failed to give us the flattenable
339 }
340 index -= 1; // we stored the index-base-1 341 index -= 1; // we stored the index-base-1
341 if ((unsigned)index >= (unsigned)fFactoryCount) { 342 if (index >= (uint32_t) fFactoryCount) {
342 this->validate(false); 343 this->validate(false);
343 return nullptr; 344 return nullptr;
344 } 345 }
345 factory = fFactoryArray[index]; 346 factory = fFactoryArray[index];
346 } else { 347 } else {
347 factory = (SkFlattenable::Factory)readFunctionPtr(); 348 SkString name;
348 if (nullptr == factory) { 349 SkString* namePtr = fFlattenableDict.find(index);
349 return nullptr; // writer failed to give us the flattenable 350 if (namePtr) {
351 // Assume we have already seen this name and saved it to the dict.
352 name = *namePtr;
353 } else {
354 // The string must be passed after the index.
355 this->readString(&name);
356
357 // Add the string to the dictionary.
358 fFlattenableDict.set(index, name);
359 }
360
361 // Check if a custom Factory has been specified for this flattenable.
362 factory = getCustomFactory(name);
mtklein 2016/04/19 18:14:55 this->
msarett 2016/04/19 18:55:51 Done.
363 if (!factory) {
364 // If there is no custom Factory, check for a default.
365 factory = SkFlattenable::NameToFactory(name.c_str());
366 if (!factory) {
367 return nullptr; // writer failed to give us the flattenable
368 }
350 } 369 }
351 } 370 }
352 371
353 // if we get here, factory may still be null, but if that is the case, the 372 // if we get here, factory may still be null, but if that is the case, the
354 // failure was ours, not the writer. 373 // failure was ours, not the writer.
355 sk_sp<SkFlattenable> obj; 374 sk_sp<SkFlattenable> obj;
356 uint32_t sizeRecorded = fReader.readU32(); 375 uint32_t sizeRecorded = fReader.readU32();
357 if (factory) { 376 if (factory) {
358 size_t offset = fReader.offset(); 377 size_t offset = fReader.offset();
359 obj = (*factory)(*this); 378 obj = (*factory)(*this);
(...skipping 20 matching lines...) Expand all
380 return; 399 return;
381 } 400 }
382 } else { 401 } else {
383 if (nullptr == this->readFunctionPtr()) { 402 if (nullptr == this->readFunctionPtr()) {
384 return; 403 return;
385 } 404 }
386 } 405 }
387 uint32_t sizeRecorded = fReader.readU32(); 406 uint32_t sizeRecorded = fReader.readU32();
388 fReader.skip(sizeRecorded); 407 fReader.skip(sizeRecorded);
389 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698