OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 } |
OLD | NEW |