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

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

Issue 1837913003: Add support for serializing/deserializing of SkDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add ability to specify custom flattenable factories on SkReadBuffer 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 15 matching lines...) Expand all
26 fFlags = default_flags(); 26 fFlags = default_flags();
27 fVersion = 0; 27 fVersion = 0;
28 fMemoryPtr = nullptr; 28 fMemoryPtr = nullptr;
29 29
30 fBitmapStorage = nullptr; 30 fBitmapStorage = nullptr;
31 fTFArray = nullptr; 31 fTFArray = nullptr;
32 fTFCount = 0; 32 fTFCount = 0;
33 33
34 fFactoryArray = nullptr; 34 fFactoryArray = nullptr;
35 fFactoryCount = 0; 35 fFactoryCount = 0;
36 fCustomFactory.reset(new SkTHashMap<SkFlattenable::Factory, SkFlattenable::F actory>());
36 fBitmapDecoder = nullptr; 37 fBitmapDecoder = nullptr;
37 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 38 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
38 fDecodedBitmapIndex = -1; 39 fDecodedBitmapIndex = -1;
39 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 40 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
40 } 41 }
41 42
42 SkReadBuffer::SkReadBuffer(const void* data, size_t size) { 43 SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
43 fFlags = default_flags(); 44 fFlags = default_flags();
44 fVersion = 0; 45 fVersion = 0;
45 fReader.setMemory(data, size); 46 fReader.setMemory(data, size);
46 fMemoryPtr = nullptr; 47 fMemoryPtr = nullptr;
47 48
48 fBitmapStorage = nullptr; 49 fBitmapStorage = nullptr;
49 fTFArray = nullptr; 50 fTFArray = nullptr;
50 fTFCount = 0; 51 fTFCount = 0;
51 52
52 fFactoryArray = nullptr; 53 fFactoryArray = nullptr;
53 fFactoryCount = 0; 54 fFactoryCount = 0;
55 fCustomFactory.reset(new SkTHashMap<SkFlattenable::Factory, SkFlattenable::F actory>());
54 fBitmapDecoder = nullptr; 56 fBitmapDecoder = nullptr;
55 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 57 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
56 fDecodedBitmapIndex = -1; 58 fDecodedBitmapIndex = -1;
57 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 59 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
58 } 60 }
59 61
60 SkReadBuffer::SkReadBuffer(SkStream* stream) { 62 SkReadBuffer::SkReadBuffer(SkStream* stream) {
61 fFlags = default_flags(); 63 fFlags = default_flags();
62 fVersion = 0; 64 fVersion = 0;
63 const size_t length = stream->getLength(); 65 const size_t length = stream->getLength();
64 fMemoryPtr = sk_malloc_throw(length); 66 fMemoryPtr = sk_malloc_throw(length);
65 stream->read(fMemoryPtr, length); 67 stream->read(fMemoryPtr, length);
66 fReader.setMemory(fMemoryPtr, length); 68 fReader.setMemory(fMemoryPtr, length);
67 69
68 fBitmapStorage = nullptr; 70 fBitmapStorage = nullptr;
69 fTFArray = nullptr; 71 fTFArray = nullptr;
70 fTFCount = 0; 72 fTFCount = 0;
71 73
72 fFactoryArray = nullptr; 74 fFactoryArray = nullptr;
73 fFactoryCount = 0; 75 fFactoryCount = 0;
76 fCustomFactory.reset(new SkTHashMap<SkFlattenable::Factory, SkFlattenable::F actory>());
74 fBitmapDecoder = nullptr; 77 fBitmapDecoder = nullptr;
75 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 78 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
76 fDecodedBitmapIndex = -1; 79 fDecodedBitmapIndex = -1;
77 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 80 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
78 } 81 }
79 82
80 SkReadBuffer::~SkReadBuffer() { 83 SkReadBuffer::~SkReadBuffer() {
81 sk_free(fMemoryPtr); 84 sk_free(fMemoryPtr);
82 SkSafeUnref(fBitmapStorage); 85 SkSafeUnref(fBitmapStorage);
83 } 86 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if ((unsigned)index >= (unsigned)fFactoryCount) { 348 if ((unsigned)index >= (unsigned)fFactoryCount) {
346 this->validate(false); 349 this->validate(false);
347 return nullptr; 350 return nullptr;
348 } 351 }
349 factory = fFactoryArray[index]; 352 factory = fFactoryArray[index];
350 } else { 353 } else {
351 factory = (SkFlattenable::Factory)readFunctionPtr(); 354 factory = (SkFlattenable::Factory)readFunctionPtr();
352 if (nullptr == factory) { 355 if (nullptr == factory) {
353 return nullptr; // writer failed to give us the flattenable 356 return nullptr; // writer failed to give us the flattenable
354 } 357 }
358
359 // Check if a custom Factory has been specified for this flattenable.
360 SkFlattenable::Factory* customFactoryPtr = getCustomFactory(factory);
361 if (customFactoryPtr) {
362 factory = *customFactoryPtr;
363 }
355 } 364 }
356 365
357 // if we get here, factory may still be null, but if that is the case, the 366 // if we get here, factory may still be null, but if that is the case, the
358 // failure was ours, not the writer. 367 // failure was ours, not the writer.
359 SkFlattenable* obj = nullptr; 368 SkFlattenable* obj = nullptr;
360 uint32_t sizeRecorded = fReader.readU32(); 369 uint32_t sizeRecorded = fReader.readU32();
361 if (factory) { 370 if (factory) {
362 size_t offset = fReader.offset(); 371 size_t offset = fReader.offset();
363 obj = (*factory)(*this); 372 obj = (*factory)(*this);
364 // check that we read the amount we expected 373 // check that we read the amount we expected
(...skipping 19 matching lines...) Expand all
384 return; 393 return;
385 } 394 }
386 } else { 395 } else {
387 if (nullptr == this->readFunctionPtr()) { 396 if (nullptr == this->readFunctionPtr()) {
388 return; 397 return;
389 } 398 }
390 } 399 }
391 uint32_t sizeRecorded = fReader.readU32(); 400 uint32_t sizeRecorded = fReader.readU32();
392 fReader.skip(sizeRecorded); 401 fReader.skip(sizeRecorded);
393 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698