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

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

Issue 1938033002: Remove SkBitmapHeap and SkBitmapHeapReader. They're unused. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore ability to partially read old SKPs Created 4 years, 7 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"
11 #include "SkImageGenerator.h" 11 #include "SkImageGenerator.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTypeface.h" 14 #include "SkTypeface.h"
15 15
16 static uint32_t default_flags() { 16 static uint32_t default_flags() {
17 uint32_t flags = 0; 17 uint32_t flags = 0;
18 flags |= SkReadBuffer::kScalarIsFloat_Flag; 18 flags |= SkReadBuffer::kScalarIsFloat_Flag;
19 if (8 == sizeof(void*)) { 19 if (8 == sizeof(void*)) {
20 flags |= SkReadBuffer::kPtrIs64Bit_Flag; 20 flags |= SkReadBuffer::kPtrIs64Bit_Flag;
21 } 21 }
22 return flags; 22 return flags;
23 } 23 }
24 24
25 SkReadBuffer::SkReadBuffer() { 25 SkReadBuffer::SkReadBuffer() {
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;
31 fTFArray = nullptr; 30 fTFArray = nullptr;
32 fTFCount = 0; 31 fTFCount = 0;
33 32
34 fFactoryArray = nullptr; 33 fFactoryArray = nullptr;
35 fFactoryCount = 0; 34 fFactoryCount = 0;
36 fBitmapDecoder = nullptr; 35 fBitmapDecoder = nullptr;
37 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 36 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
38 fDecodedBitmapIndex = -1; 37 fDecodedBitmapIndex = -1;
39 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 38 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
40 } 39 }
41 40
42 SkReadBuffer::SkReadBuffer(const void* data, size_t size) { 41 SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
43 fFlags = default_flags(); 42 fFlags = default_flags();
44 fVersion = 0; 43 fVersion = 0;
45 fReader.setMemory(data, size); 44 fReader.setMemory(data, size);
46 fMemoryPtr = nullptr; 45 fMemoryPtr = nullptr;
47 46
48 fBitmapStorage = nullptr;
49 fTFArray = nullptr; 47 fTFArray = nullptr;
50 fTFCount = 0; 48 fTFCount = 0;
51 49
52 fFactoryArray = nullptr; 50 fFactoryArray = nullptr;
53 fFactoryCount = 0; 51 fFactoryCount = 0;
54 fBitmapDecoder = nullptr; 52 fBitmapDecoder = nullptr;
55 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 53 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
56 fDecodedBitmapIndex = -1; 54 fDecodedBitmapIndex = -1;
57 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 55 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
58 } 56 }
59 57
60 SkReadBuffer::SkReadBuffer(SkStream* stream) { 58 SkReadBuffer::SkReadBuffer(SkStream* stream) {
61 fFlags = default_flags(); 59 fFlags = default_flags();
62 fVersion = 0; 60 fVersion = 0;
63 const size_t length = stream->getLength(); 61 const size_t length = stream->getLength();
64 fMemoryPtr = sk_malloc_throw(length); 62 fMemoryPtr = sk_malloc_throw(length);
65 stream->read(fMemoryPtr, length); 63 stream->read(fMemoryPtr, length);
66 fReader.setMemory(fMemoryPtr, length); 64 fReader.setMemory(fMemoryPtr, length);
67 65
68 fBitmapStorage = nullptr;
69 fTFArray = nullptr; 66 fTFArray = nullptr;
70 fTFCount = 0; 67 fTFCount = 0;
71 68
72 fFactoryArray = nullptr; 69 fFactoryArray = nullptr;
73 fFactoryCount = 0; 70 fFactoryCount = 0;
74 fBitmapDecoder = nullptr; 71 fBitmapDecoder = nullptr;
75 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 72 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
76 fDecodedBitmapIndex = -1; 73 fDecodedBitmapIndex = -1;
77 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 74 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
78 } 75 }
79 76
80 SkReadBuffer::~SkReadBuffer() { 77 SkReadBuffer::~SkReadBuffer() {
81 sk_free(fMemoryPtr); 78 sk_free(fMemoryPtr);
82 SkSafeUnref(fBitmapStorage);
83 } 79 }
84 80
85 bool SkReadBuffer::readBool() { 81 bool SkReadBuffer::readBool() {
86 return fReader.readBool(); 82 return fReader.readBool();
87 } 83 }
88 84
89 SkColor SkReadBuffer::readColor() { 85 SkColor SkReadBuffer::readColor() {
90 return fReader.readInt(); 86 return fReader.readInt();
91 } 87 }
92 88
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return readArray(values, size, sizeof(SkScalar)); 175 return readArray(values, size, sizeof(SkScalar));
180 } 176 }
181 177
182 uint32_t SkReadBuffer::getArrayCount() { 178 uint32_t SkReadBuffer::getArrayCount() {
183 return *(uint32_t*)fReader.peek(); 179 return *(uint32_t*)fReader.peek();
184 } 180 }
185 181
186 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) { 182 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) {
187 const int width = this->readInt(); 183 const int width = this->readInt();
188 const int height = this->readInt(); 184 const int height = this->readInt();
185
189 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during 186 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during
190 // writing. 187 // writing. That feature is deprecated.
191 if (this->readBool()) { 188 if (this->readBool()) {
192 // An SkBitmapHeap was used for writing. Read the index from the stream and find the 189 this->readUInt(); // Bitmap index
193 // corresponding SkBitmap in fBitmapStorage. 190 this->readUInt(); // Bitmap generation ID
194 const uint32_t index = this->readUInt(); 191 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writeBit map "
195 this->readUInt(); // bitmap generation ID (see SkWriteBuffer::writeBitma p) 192 "stored the SkBitmap in an SkBitmapHeap, but "
196 if (fBitmapStorage) { 193 "that feature is no longer supported.");
197 *bitmap = *fBitmapStorage->getBitmap(index);
198 fBitmapStorage->releaseRef(index);
199 return true;
200 } else {
201 // The bitmap was stored in a heap, but there is no way to access it . Set an error and
202 // fall through to use a place holder bitmap.
203 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ eBitmap "
204 "stored the SkBitmap in an SkBitmapHeap, but "
205 "SkReadBuffer has no SkBitmapHeapReader t o "
206 "retrieve the SkBitmap.");
207 }
208 } else { 194 } else {
209 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap. 195 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap.
210 const size_t length = this->readUInt(); 196 const size_t length = this->readUInt();
211 if (length > 0) { 197 if (length > 0) {
212 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 198 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
213 fDecodedBitmapIndex++; 199 fDecodedBitmapIndex++;
214 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 200 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
215 // A non-zero size means the SkBitmap was encoded. Read the data and pixel 201 // A non-zero size means the SkBitmap was encoded. Read the data and pixel
216 // offset. 202 // offset.
217 const void* data = this->skip(length); 203 const void* data = this->skip(length);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (sizeRecorded != sizeRead) { 371 if (sizeRecorded != sizeRead) {
386 this->validate(false); 372 this->validate(false);
387 return nullptr; 373 return nullptr;
388 } 374 }
389 } else { 375 } else {
390 // we must skip the remaining data 376 // we must skip the remaining data
391 fReader.skip(sizeRecorded); 377 fReader.skip(sizeRecorded);
392 } 378 }
393 return obj.release(); 379 return obj.release();
394 } 380 }
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