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

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: Fix test 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/SkValidatingReadBuffer.h » ('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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 100
101 uint32_t SkReadBuffer::readUInt() { 101 uint32_t SkReadBuffer::readUInt() {
102 return fReader.readU32(); 102 return fReader.readU32();
103 } 103 }
104 104
105 int32_t SkReadBuffer::read32() { 105 int32_t SkReadBuffer::read32() {
106 return fReader.readInt(); 106 return fReader.readInt();
107 } 107 }
108 108
109 uint8_t SkReadBuffer::peekByte() {
110 SkASSERT(fReader.available() > 0);
111 return *((uint8_t*) fReader.peek());
112 }
113
109 void SkReadBuffer::readString(SkString* string) { 114 void SkReadBuffer::readString(SkString* string) {
110 size_t len; 115 size_t len;
111 const char* strContents = fReader.readString(&len); 116 const char* strContents = fReader.readString(&len);
112 string->set(strContents, len); 117 string->set(strContents, len);
113 } 118 }
114 119
115 void* SkReadBuffer::readEncodedString(size_t* length, SkPaint::TextEncoding enco ding) { 120 void* SkReadBuffer::readEncodedString(size_t* length, SkPaint::TextEncoding enco ding) {
116 SkDEBUGCODE(int32_t encodingType = ) fReader.readInt(); 121 SkDEBUGCODE(int32_t encodingType = ) fReader.readInt();
117 SkASSERT(encodingType == encoding); 122 SkASSERT(encodingType == encoding);
118 *length = fReader.readInt(); 123 *length = fReader.readInt();
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (0 == index) { 342 if (0 == index) {
338 return nullptr; // writer failed to give us the flattenable 343 return nullptr; // writer failed to give us the flattenable
339 } 344 }
340 index -= 1; // we stored the index-base-1 345 index -= 1; // we stored the index-base-1
341 if ((unsigned)index >= (unsigned)fFactoryCount) { 346 if ((unsigned)index >= (unsigned)fFactoryCount) {
342 this->validate(false); 347 this->validate(false);
343 return nullptr; 348 return nullptr;
344 } 349 }
345 factory = fFactoryArray[index]; 350 factory = fFactoryArray[index];
346 } else { 351 } else {
347 factory = (SkFlattenable::Factory)readFunctionPtr(); 352 SkString name;
348 if (nullptr == factory) { 353 if (this->peekByte()) {
349 return nullptr; // writer failed to give us the flattenable 354 // If the first byte is non-zero, the flattenable is specified by a string.
355 this->readString(&name);
356
357 // Add the string to the dictionary.
358 fFlattenableDict.set(fFlattenableDict.count() + 1, name);
359 } else {
360 // Read the index. We are guaranteed that the first byte
361 // is zeroed, so we must shift down a byte.
362 uint32_t index = fReader.readU32() >> 8;
363 if (0 == index) {
364 return nullptr; // writer failed to give us the flattenable
365 }
366
367 SkString* namePtr = fFlattenableDict.find(index);
368 SkASSERT(namePtr);
369 name = *namePtr;
370 }
371
372 // Check if a custom Factory has been specified for this flattenable.
373 if (!(factory = this->getCustomFactory(name))) {
374 // If there is no custom Factory, check for a default.
375 if (!(factory = SkFlattenable::NameToFactory(name.c_str()))) {
376 return nullptr; // writer failed to give us the flattenable
377 }
350 } 378 }
351 } 379 }
352 380
353 // if we get here, factory may still be null, but if that is the case, the 381 // if we get here, factory may still be null, but if that is the case, the
354 // failure was ours, not the writer. 382 // failure was ours, not the writer.
355 sk_sp<SkFlattenable> obj; 383 sk_sp<SkFlattenable> obj;
356 uint32_t sizeRecorded = fReader.readU32(); 384 uint32_t sizeRecorded = fReader.readU32();
357 if (factory) { 385 if (factory) {
358 size_t offset = fReader.offset(); 386 size_t offset = fReader.offset();
359 obj = (*factory)(*this); 387 obj = (*factory)(*this);
(...skipping 20 matching lines...) Expand all
380 return; 408 return;
381 } 409 }
382 } else { 410 } else {
383 if (nullptr == this->readFunctionPtr()) { 411 if (nullptr == this->readFunctionPtr()) {
384 return; 412 return;
385 } 413 }
386 } 414 }
387 uint32_t sizeRecorded = fReader.readU32(); 415 uint32_t sizeRecorded = fReader.readU32();
388 fReader.skip(sizeRecorded); 416 fReader.skip(sizeRecorded);
389 } 417 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | src/core/SkValidatingReadBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698