| 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" |
| 11 #include "SkOrderedReadBuffer.h" | 11 #include "SkOrderedReadBuffer.h" |
| 12 #include "SkStream.h" | 12 #include "SkStream.h" |
| 13 #include "SkTypeface.h" | 13 #include "SkTypeface.h" |
| 14 | 14 |
| 15 SkOrderedReadBuffer::SkOrderedReadBuffer() : INHERITED() { | 15 SkOrderedReadBuffer::SkOrderedReadBuffer() : INHERITED() { |
| 16 fMemoryPtr = NULL; | 16 fMemoryPtr = NULL; |
| 17 | 17 |
| 18 fBitmapStorage = NULL; | 18 fBitmapStorage = NULL; |
| 19 fTFArray = NULL; | 19 fTFArray = NULL; |
| 20 fTFCount = 0; | 20 fTFCount = 0; |
| 21 | 21 |
| 22 fFactoryTDArray = NULL; | 22 fFactoryTDArray = NULL; |
| 23 fFactoryArray = NULL; | 23 fFactoryArray = NULL; |
| 24 fFactoryCount = 0; | 24 fFactoryCount = 0; |
| 25 fBitmapDecoder = NULL; | 25 fBitmapDecoder = NULL; |
| 26 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 27 fDecodedBitmapIndex = -1; |
| 28 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 26 } | 29 } |
| 27 | 30 |
| 28 SkOrderedReadBuffer::SkOrderedReadBuffer(const void* data, size_t size) : INHERI
TED() { | 31 SkOrderedReadBuffer::SkOrderedReadBuffer(const void* data, size_t size) : INHERI
TED() { |
| 29 fReader.setMemory(data, size); | 32 fReader.setMemory(data, size); |
| 30 fMemoryPtr = NULL; | 33 fMemoryPtr = NULL; |
| 31 | 34 |
| 32 fBitmapStorage = NULL; | 35 fBitmapStorage = NULL; |
| 33 fTFArray = NULL; | 36 fTFArray = NULL; |
| 34 fTFCount = 0; | 37 fTFCount = 0; |
| 35 | 38 |
| 36 fFactoryTDArray = NULL; | 39 fFactoryTDArray = NULL; |
| 37 fFactoryArray = NULL; | 40 fFactoryArray = NULL; |
| 38 fFactoryCount = 0; | 41 fFactoryCount = 0; |
| 39 fBitmapDecoder = NULL; | 42 fBitmapDecoder = NULL; |
| 43 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 44 fDecodedBitmapIndex = -1; |
| 45 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 40 } | 46 } |
| 41 | 47 |
| 42 SkOrderedReadBuffer::SkOrderedReadBuffer(SkStream* stream) { | 48 SkOrderedReadBuffer::SkOrderedReadBuffer(SkStream* stream) { |
| 43 const size_t length = stream->getLength(); | 49 const size_t length = stream->getLength(); |
| 44 fMemoryPtr = sk_malloc_throw(length); | 50 fMemoryPtr = sk_malloc_throw(length); |
| 45 stream->read(fMemoryPtr, length); | 51 stream->read(fMemoryPtr, length); |
| 46 fReader.setMemory(fMemoryPtr, length); | 52 fReader.setMemory(fMemoryPtr, length); |
| 47 | 53 |
| 48 fBitmapStorage = NULL; | 54 fBitmapStorage = NULL; |
| 49 fTFArray = NULL; | 55 fTFArray = NULL; |
| 50 fTFCount = 0; | 56 fTFCount = 0; |
| 51 | 57 |
| 52 fFactoryTDArray = NULL; | 58 fFactoryTDArray = NULL; |
| 53 fFactoryArray = NULL; | 59 fFactoryArray = NULL; |
| 54 fFactoryCount = 0; | 60 fFactoryCount = 0; |
| 55 fBitmapDecoder = NULL; | 61 fBitmapDecoder = NULL; |
| 62 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 63 fDecodedBitmapIndex = -1; |
| 64 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 56 } | 65 } |
| 57 | 66 |
| 58 SkOrderedReadBuffer::~SkOrderedReadBuffer() { | 67 SkOrderedReadBuffer::~SkOrderedReadBuffer() { |
| 59 sk_free(fMemoryPtr); | 68 sk_free(fMemoryPtr); |
| 60 SkSafeUnref(fBitmapStorage); | 69 SkSafeUnref(fBitmapStorage); |
| 61 } | 70 } |
| 62 | 71 |
| 63 bool SkOrderedReadBuffer::readBool() { | 72 bool SkOrderedReadBuffer::readBool() { |
| 64 return fReader.readBool(); | 73 return fReader.readBool(); |
| 65 } | 74 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // fall through to use a place holder bitmap. | 194 // fall through to use a place holder bitmap. |
| 186 SkErrorInternals::SetError(kParseError_SkError, "SkOrderedWriteBuffe
r::writeBitmap " | 195 SkErrorInternals::SetError(kParseError_SkError, "SkOrderedWriteBuffe
r::writeBitmap " |
| 187 "stored the SkBitmap in an SkBitmapHeap,
but " | 196 "stored the SkBitmap in an SkBitmapHeap,
but " |
| 188 "SkOrderedReadBuffer has no SkBitmapHeapR
eader to " | 197 "SkOrderedReadBuffer has no SkBitmapHeapR
eader to " |
| 189 "retrieve the SkBitmap."); | 198 "retrieve the SkBitmap."); |
| 190 } | 199 } |
| 191 } else { | 200 } else { |
| 192 // The writer stored false, meaning the SkBitmap was not stored in an Sk
BitmapHeap. | 201 // The writer stored false, meaning the SkBitmap was not stored in an Sk
BitmapHeap. |
| 193 const size_t length = this->readUInt(); | 202 const size_t length = this->readUInt(); |
| 194 if (length > 0) { | 203 if (length > 0) { |
| 204 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 205 fDecodedBitmapIndex++; |
| 206 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 195 // A non-zero size means the SkBitmap was encoded. Read the data and
pixel | 207 // A non-zero size means the SkBitmap was encoded. Read the data and
pixel |
| 196 // offset. | 208 // offset. |
| 197 const void* data = this->skip(length); | 209 const void* data = this->skip(length); |
| 198 const int32_t xOffset = fReader.readS32(); | 210 const int32_t xOffset = fReader.readS32(); |
| 199 const int32_t yOffset = fReader.readS32(); | 211 const int32_t yOffset = fReader.readS32(); |
| 200 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap))
{ | 212 if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap))
{ |
| 201 if (bitmap->width() == width && bitmap->height() == height) { | 213 if (bitmap->width() == width && bitmap->height() == height) { |
| 214 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
| 215 if (0 != xOffset || 0 != yOffset) { |
| 216 SkDebugf("SkOrderedReadBuffer::readBitmap: heights match
," |
| 217 " but offset is not zero. \nInfo about the bitm
ap:" |
| 218 "\n\tIndex: %d\n\tDimensions: [%d %d]\n\tEncode
d" |
| 219 " data size: %d\n\tOffset: (%d, %d)\n", |
| 220 fDecodedBitmapIndex, width, height, length, xOf
fset, |
| 221 yOffset); |
| 222 } |
| 223 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
| 202 // If the width and height match, there should be no offset. | 224 // If the width and height match, there should be no offset. |
| 203 SkASSERT(0 == xOffset && 0 == yOffset); | 225 SkASSERT(0 == xOffset && 0 == yOffset); |
| 204 return; | 226 return; |
| 205 } | 227 } |
| 206 | 228 |
| 207 // This case can only be reached if extractSubset was called, so | 229 // This case can only be reached if extractSubset was called, so |
| 208 // the recorded width and height must be smaller than (or equal
to | 230 // the recorded width and height must be smaller than (or equal
to |
| 209 // the encoded width and height. | 231 // the encoded width and height. |
| 210 SkASSERT(width <= bitmap->width() && height <= bitmap->height())
; | 232 SkASSERT(width <= bitmap->width() && height <= bitmap->height())
; |
| 211 | 233 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (sizeRecorded != sizeRead) { | 305 if (sizeRecorded != sizeRead) { |
| 284 // we could try to fix up the offset... | 306 // we could try to fix up the offset... |
| 285 sk_throw(); | 307 sk_throw(); |
| 286 } | 308 } |
| 287 } else { | 309 } else { |
| 288 // we must skip the remaining data | 310 // we must skip the remaining data |
| 289 fReader.skip(sizeRecorded); | 311 fReader.skip(sizeRecorded); |
| 290 } | 312 } |
| 291 return obj; | 313 return obj; |
| 292 } | 314 } |
| OLD | NEW |