OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkMallocPixelRef.h" | 8 #include "SkMallocPixelRef.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 void* addr, | 42 void* addr, |
43 size_t rowBytes, | 43 size_t rowBytes, |
44 SkColorTable* ctable) { | 44 SkColorTable* ctable) { |
45 if (!is_valid(info, ctable)) { | 45 if (!is_valid(info, ctable)) { |
46 return NULL; | 46 return NULL; |
47 } | 47 } |
48 return SkNEW_ARGS(SkMallocPixelRef, | 48 return SkNEW_ARGS(SkMallocPixelRef, |
49 (info, addr, rowBytes, ctable, NULL, NULL)); | 49 (info, addr, rowBytes, ctable, NULL, NULL)); |
50 } | 50 } |
51 | 51 |
| 52 |
52 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, | 53 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, |
53 size_t requestedRowBytes, | 54 size_t requestedRowBytes, |
54 SkColorTable* ctable) { | 55 SkColorTable* ctable) { |
55 if (!is_valid(info, ctable)) { | 56 if (!is_valid(info, ctable)) { |
56 return NULL; | 57 return NULL; |
57 } | 58 } |
58 | 59 |
59 int32_t minRB = SkToS32(info.minRowBytes()); | 60 int32_t minRB = SkToS32(info.minRowBytes()); |
60 if (minRB < 0) { | 61 if (minRB < 0) { |
61 return NULL; // allocation will be too large | 62 return NULL; // allocation will be too large |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 (info, addr, rowBytes, ctable, proc, context)); | 102 (info, addr, rowBytes, ctable, proc, context)); |
102 } | 103 } |
103 | 104 |
104 static void sk_data_releaseproc(void*, void* dataPtr) { | 105 static void sk_data_releaseproc(void*, void* dataPtr) { |
105 (static_cast<SkData*>(dataPtr))->unref(); | 106 (static_cast<SkData*>(dataPtr))->unref(); |
106 } | 107 } |
107 | 108 |
108 SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info, | 109 SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info, |
109 size_t rowBytes, | 110 size_t rowBytes, |
110 SkColorTable* ctable, | 111 SkColorTable* ctable, |
111 SkData* data, | 112 SkData* data) { |
112 size_t offset) { | |
113 SkASSERT(data != NULL); | 113 SkASSERT(data != NULL); |
114 SkASSERT(offset <= data->size()); | |
115 if (!is_valid(info, ctable)) { | 114 if (!is_valid(info, ctable)) { |
116 return NULL; | 115 return NULL; |
117 } | 116 } |
118 if ((rowBytes < info.minRowBytes()) | 117 if ((rowBytes < info.minRowBytes()) |
119 || ((data->size() - offset) < info.getSafeSize(rowBytes))) { | 118 || (data->size() < info.getSafeSize(rowBytes))) { |
120 return NULL; | 119 return NULL; |
121 } | 120 } |
122 data->ref(); | 121 data->ref(); |
123 const void* ptr = static_cast<const void*>(data->bytes() + offset); | |
124 SkMallocPixelRef* pr | 122 SkMallocPixelRef* pr |
125 = SkNEW_ARGS(SkMallocPixelRef, | 123 = SkNEW_ARGS(SkMallocPixelRef, |
126 (info, const_cast<void*>(ptr), rowBytes, ctable, | 124 (info, const_cast<void*>(data->data()), rowBytes, ctable, |
127 sk_data_releaseproc, static_cast<void*>(data))); | 125 sk_data_releaseproc, static_cast<void*>(data))); |
128 SkASSERT(pr != NULL); | 126 SkASSERT(pr != NULL); |
129 // We rely on the immutability of the pixels to make the | 127 // We rely on the immutability of the pixels to make the |
130 // const_cast okay. | 128 // const_cast okay. |
131 pr->setImmutable(); | 129 pr->setImmutable(); |
132 return pr; | 130 return pr; |
133 } | 131 } |
134 | 132 |
135 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
136 | 134 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 237 |
240 this->setPreLocked(fStorage, fRB, fCTable); | 238 this->setPreLocked(fStorage, fRB, fCTable); |
241 } | 239 } |
242 | 240 |
243 /////////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////////// |
244 | 242 |
245 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, | 243 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, |
246 SkColorTable* ctable) { | 244 SkColorTable* ctable) { |
247 return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable); | 245 return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable); |
248 } | 246 } |
OLD | NEW |