OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkErrorInternals.h" | 10 #include "SkErrorInternals.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 void* SkReadBuffer::readEncodedString(size_t* length, SkPaint::TextEncoding enco ding) { | 123 void* SkReadBuffer::readEncodedString(size_t* length, SkPaint::TextEncoding enco ding) { |
124 SkDEBUGCODE(int32_t encodingType = ) fReader.readInt(); | 124 SkDEBUGCODE(int32_t encodingType = ) fReader.readInt(); |
125 SkASSERT(encodingType == encoding); | 125 SkASSERT(encodingType == encoding); |
126 *length = fReader.readInt(); | 126 *length = fReader.readInt(); |
127 void* data = sk_malloc_throw(*length); | 127 void* data = sk_malloc_throw(*length); |
128 memcpy(data, fReader.skip(SkAlign4(*length)), *length); | 128 memcpy(data, fReader.skip(SkAlign4(*length)), *length); |
129 return data; | 129 return data; |
130 } | 130 } |
131 | 131 |
132 void SkReadBuffer::readPoint(SkPoint* point) { | 132 void SkReadBuffer::readPoint(SkPoint* point) { |
133 point->fX = fReader.readScalar(); | 133 point->fX = this->readScalar(); |
134 point->fY = fReader.readScalar(); | 134 point->fY = this->readScalar(); |
135 } | 135 } |
136 | 136 |
137 void SkReadBuffer::readMatrix(SkMatrix* matrix) { | 137 void SkReadBuffer::readMatrix(SkMatrix* matrix) { |
138 fReader.readMatrix(matrix); | 138 fReader.readMatrix(matrix); |
139 } | 139 } |
140 | 140 |
141 void SkReadBuffer::readIRect(SkIRect* rect) { | 141 void SkReadBuffer::readIRect(SkIRect* rect) { |
142 memcpy(rect, fReader.skip(sizeof(SkIRect)), sizeof(SkIRect)); | 142 memcpy(rect, fReader.skip(sizeof(SkIRect)), sizeof(SkIRect)); |
143 } | 143 } |
144 | 144 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 } | 192 } |
193 | 193 |
194 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) { | 194 bool SkReadBuffer::readBitmap(SkBitmap* bitmap) { |
195 const int width = this->readInt(); | 195 const int width = this->readInt(); |
196 const int height = this->readInt(); | 196 const int height = this->readInt(); |
197 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during | 197 // The writer stored a boolean value to determine whether an SkBitmapHeap wa s used during |
198 // writing. | 198 // writing. |
199 if (this->readBool()) { | 199 if (this->readBool()) { |
200 // An SkBitmapHeap was used for writing. Read the index from the stream and find the | 200 // An SkBitmapHeap was used for writing. Read the index from the stream and find the |
201 // corresponding SkBitmap in fBitmapStorage. | 201 // corresponding SkBitmap in fBitmapStorage. |
202 const uint32_t index = fReader.readU32(); | 202 const uint32_t index = this->readUInt(); |
203 fReader.readU32(); // bitmap generation ID (see SkWriteBuffer::writeBitm ap) | 203 this->readUInt(); // bitmap generation ID (see SkWriteBuffer::writeBitma p) |
204 if (fBitmapStorage) { | 204 if (fBitmapStorage) { |
205 *bitmap = *fBitmapStorage->getBitmap(index); | 205 *bitmap = *fBitmapStorage->getBitmap(index); |
206 fBitmapStorage->releaseRef(index); | 206 fBitmapStorage->releaseRef(index); |
207 return true; | 207 return true; |
208 } else { | 208 } else { |
209 // The bitmap was stored in a heap, but there is no way to access it . Set an error and | 209 // The bitmap was stored in a heap, but there is no way to access it . Set an error and |
210 // fall through to use a place holder bitmap. | 210 // fall through to use a place holder bitmap. |
211 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ eBitmap " | 211 SkErrorInternals::SetError(kParseError_SkError, "SkWriteBuffer::writ eBitmap " |
212 "stored the SkBitmap in an SkBitmapHeap, but " | 212 "stored the SkBitmap in an SkBitmapHeap, but " |
213 "SkReadBuffer has no SkBitmapHeapReader t o " | 213 "SkReadBuffer has no SkBitmapHeapReader t o " |
214 "retrieve the SkBitmap."); | 214 "retrieve the SkBitmap."); |
215 } | 215 } |
216 } else { | 216 } else { |
217 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap. | 217 // The writer stored false, meaning the SkBitmap was not stored in an Sk BitmapHeap. |
218 const size_t length = this->readUInt(); | 218 const size_t length = this->readUInt(); |
219 if (length > 0) { | 219 if (length > 0) { |
220 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 220 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
221 fDecodedBitmapIndex++; | 221 fDecodedBitmapIndex++; |
222 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 222 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
223 // A non-zero size means the SkBitmap was encoded. Read the data and pixel | 223 // A non-zero size means the SkBitmap was encoded. Read the data and pixel |
224 // offset. | 224 // offset. |
225 const void* data = this->skip(length); | 225 const void* data = this->skip(length); |
226 const int32_t xOffset = fReader.readS32(); | 226 const int32_t xOffset = this->readFixed(); |
reed1
2014/06/05 12:33:05
These are ints, not fixed.
sugoi
2014/06/05 12:43:16
readS32() is equivalent to readFixed(), so if I us
| |
227 const int32_t yOffset = fReader.readS32(); | 227 const int32_t yOffset = this->readFixed(); |
228 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) { | 228 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) { |
229 if (bitmap->width() == width && bitmap->height() == height) { | 229 if (bitmap->width() == width && bitmap->height() == height) { |
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
231 if (0 != xOffset || 0 != yOffset) { | 231 if (0 != xOffset || 0 != yOffset) { |
232 SkDebugf("SkReadBuffer::readBitmap: heights match," | 232 SkDebugf("SkReadBuffer::readBitmap: heights match," |
233 " but offset is not zero. \nInfo about the bitm ap:" | 233 " but offset is not zero. \nInfo about the bitm ap:" |
234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d" | 234 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode d" |
235 " data size: %d\n\tOffset: (%d, %d)\n", | 235 " data size: %d\n\tOffset: (%d, %d)\n", |
236 fDecodedBitmapIndex, width, height, length, xOf fset, | 236 fDecodedBitmapIndex, width, height, length, xOf fset, |
237 yOffset); | 237 yOffset); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 return; | 357 return; |
358 } | 358 } |
359 } else { | 359 } else { |
360 if (NULL == this->readFunctionPtr()) { | 360 if (NULL == this->readFunctionPtr()) { |
361 return; | 361 return; |
362 } | 362 } |
363 } | 363 } |
364 uint32_t sizeRecorded = fReader.readU32(); | 364 uint32_t sizeRecorded = fReader.readU32(); |
365 fReader.skip(sizeRecorded); | 365 fReader.skip(sizeRecorded); |
366 } | 366 } |
OLD | NEW |