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 "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 #include "SkTypeface.h" | 13 #include "SkTypeface.h" |
14 | 14 |
15 static uint32_t default_flags() { | 15 static uint32_t default_flags() { |
16 uint32_t flags = 0; | 16 uint32_t flags = 0; |
17 #ifdef SK_SCALAR_IS_FLOAT | 17 #ifdef SK_SCALAR_IS_FLOAT |
18 flags |= SkReadBuffer::kScalarIsFloat_Flag; | 18 flags |= SkReadBuffer::kScalarIsFloat_Flag; |
19 #endif | 19 #endif |
20 if (8 == sizeof(void*)) { | 20 if (8 == sizeof(void*)) { |
21 flags |= SkReadBuffer::kPtrIs64Bit_Flag; | 21 flags |= SkReadBuffer::kPtrIs64Bit_Flag; |
22 } | 22 } |
23 return flags; | 23 return flags; |
24 } | 24 } |
25 | 25 |
26 SkReadBuffer::SkReadBuffer() { | 26 SkReadBuffer::SkReadBuffer() { |
27 fFlags = default_flags(); | 27 fFlags = default_flags(); |
28 fPictureVersion = 0; | 28 fVersion = 0; |
29 fMemoryPtr = NULL; | 29 fMemoryPtr = NULL; |
30 | 30 |
31 fBitmapStorage = NULL; | 31 fBitmapStorage = NULL; |
32 fTFArray = NULL; | 32 fTFArray = NULL; |
33 fTFCount = 0; | 33 fTFCount = 0; |
34 | 34 |
35 fFactoryTDArray = NULL; | 35 fFactoryTDArray = NULL; |
36 fFactoryArray = NULL; | 36 fFactoryArray = NULL; |
37 fFactoryCount = 0; | 37 fFactoryCount = 0; |
38 fBitmapDecoder = NULL; | 38 fBitmapDecoder = NULL; |
39 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 39 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
40 fDecodedBitmapIndex = -1; | 40 fDecodedBitmapIndex = -1; |
41 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 41 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
42 } | 42 } |
43 | 43 |
44 SkReadBuffer::SkReadBuffer(const void* data, size_t size) { | 44 SkReadBuffer::SkReadBuffer(const void* data, size_t size) { |
45 fFlags = default_flags(); | 45 fFlags = default_flags(); |
46 fPictureVersion = 0; | 46 fVersion = 0; |
47 fReader.setMemory(data, size); | 47 fReader.setMemory(data, size); |
48 fMemoryPtr = NULL; | 48 fMemoryPtr = NULL; |
49 | 49 |
50 fBitmapStorage = NULL; | 50 fBitmapStorage = NULL; |
51 fTFArray = NULL; | 51 fTFArray = NULL; |
52 fTFCount = 0; | 52 fTFCount = 0; |
53 | 53 |
54 fFactoryTDArray = NULL; | 54 fFactoryTDArray = NULL; |
55 fFactoryArray = NULL; | 55 fFactoryArray = NULL; |
56 fFactoryCount = 0; | 56 fFactoryCount = 0; |
57 fBitmapDecoder = NULL; | 57 fBitmapDecoder = NULL; |
58 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | 58 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
59 fDecodedBitmapIndex = -1; | 59 fDecodedBitmapIndex = -1; |
60 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | 60 #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
61 } | 61 } |
62 | 62 |
63 SkReadBuffer::SkReadBuffer(SkStream* stream) { | 63 SkReadBuffer::SkReadBuffer(SkStream* stream) { |
64 fFlags = default_flags(); | 64 fFlags = default_flags(); |
65 fPictureVersion = 0; | 65 fVersion = 0; |
66 const size_t length = stream->getLength(); | 66 const size_t length = stream->getLength(); |
67 fMemoryPtr = sk_malloc_throw(length); | 67 fMemoryPtr = sk_malloc_throw(length); |
68 stream->read(fMemoryPtr, length); | 68 stream->read(fMemoryPtr, length); |
69 fReader.setMemory(fMemoryPtr, length); | 69 fReader.setMemory(fMemoryPtr, length); |
70 | 70 |
71 fBitmapStorage = NULL; | 71 fBitmapStorage = NULL; |
72 fTFArray = NULL; | 72 fTFArray = NULL; |
73 fTFCount = 0; | 73 fTFCount = 0; |
74 | 74 |
75 fFactoryTDArray = NULL; | 75 fFactoryTDArray = NULL; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (sizeRecorded != sizeRead) { | 328 if (sizeRecorded != sizeRead) { |
329 // we could try to fix up the offset... | 329 // we could try to fix up the offset... |
330 sk_throw(); | 330 sk_throw(); |
331 } | 331 } |
332 } else { | 332 } else { |
333 // we must skip the remaining data | 333 // we must skip the remaining data |
334 fReader.skip(sizeRecorded); | 334 fReader.skip(sizeRecorded); |
335 } | 335 } |
336 return obj; | 336 return obj; |
337 } | 337 } |
OLD | NEW |