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 |
| 53 SkPixelRef* SkPixelRef::NewPrelockedAllocate( |
| 54 const SkImageInfo& info, |
| 55 size_t rowBytes, |
| 56 SkColorTable* ctable) { |
| 57 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable); |
| 58 } |
| 59 |
52 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, | 60 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, |
53 size_t requestedRowBytes, | 61 size_t requestedRowBytes, |
54 SkColorTable* ctable) { | 62 SkColorTable* ctable) { |
55 if (!is_valid(info, ctable)) { | 63 if (!is_valid(info, ctable)) { |
56 return NULL; | 64 return NULL; |
57 } | 65 } |
58 | 66 |
59 int32_t minRB = SkToS32(info.minRowBytes()); | 67 int32_t minRB = SkToS32(info.minRowBytes()); |
60 if (minRB < 0) { | 68 if (minRB < 0) { |
61 return NULL; // allocation will be too large | 69 return NULL; // allocation will be too large |
(...skipping 19 matching lines...) Expand all Loading... |
81 void* addr = sk_malloc_flags(size, 0); | 89 void* addr = sk_malloc_flags(size, 0); |
82 if (NULL == addr) { | 90 if (NULL == addr) { |
83 return NULL; | 91 return NULL; |
84 } | 92 } |
85 | 93 |
86 return SkNEW_ARGS(SkMallocPixelRef, | 94 return SkNEW_ARGS(SkMallocPixelRef, |
87 (info, addr, rowBytes, ctable, | 95 (info, addr, rowBytes, ctable, |
88 sk_free_releaseproc, NULL)); | 96 sk_free_releaseproc, NULL)); |
89 } | 97 } |
90 | 98 |
| 99 SkPixelRef* SkPixelRef::NewPrelockedDirectWithProc( |
| 100 const SkImageInfo& info, |
| 101 size_t rowBytes, |
| 102 SkColorTable* ctable, |
| 103 void* addr, |
| 104 void (*releaseProc)(void* addr, void* context), |
| 105 void* releaseProcContext) { |
| 106 return SkMallocPixelRef::NewWithProc( |
| 107 info, rowBytes, ctable, addr, releaseProc, releaseProcContext); |
| 108 } |
| 109 |
91 SkMallocPixelRef* SkMallocPixelRef::NewWithProc(const SkImageInfo& info, | 110 SkMallocPixelRef* SkMallocPixelRef::NewWithProc(const SkImageInfo& info, |
92 size_t rowBytes, | 111 size_t rowBytes, |
93 SkColorTable* ctable, | 112 SkColorTable* ctable, |
94 void* addr, | 113 void* addr, |
95 SkMallocPixelRef::ReleaseProc pr
oc, | 114 SkMallocPixelRef::ReleaseProc pr
oc, |
96 void* context) { | 115 void* context) { |
97 if (!is_valid(info, ctable)) { | 116 if (!is_valid(info, ctable)) { |
98 return NULL; | 117 return NULL; |
99 } | 118 } |
100 return SkNEW_ARGS(SkMallocPixelRef, | 119 return SkNEW_ARGS(SkMallocPixelRef, |
101 (info, addr, rowBytes, ctable, proc, context)); | 120 (info, addr, rowBytes, ctable, proc, context)); |
102 } | 121 } |
103 | 122 |
104 static void sk_data_releaseproc(void*, void* dataPtr) { | 123 static void sk_data_releaseproc(void*, void* dataPtr) { |
105 (static_cast<SkData*>(dataPtr))->unref(); | 124 (static_cast<SkData*>(dataPtr))->unref(); |
106 } | 125 } |
107 | 126 |
| 127 SkPixelRef* SkPixelRef::NewPrelockedWithData( |
| 128 const SkImageInfo& info, |
| 129 size_t rowBytes, |
| 130 SkColorTable* ctable, |
| 131 SkData* data, |
| 132 size_t offset) { |
| 133 return SkMallocPixelRef::NewWithData(info, rowBytes, ctable, data, offset); |
| 134 } |
| 135 |
108 SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info, | 136 SkMallocPixelRef* SkMallocPixelRef::NewWithData(const SkImageInfo& info, |
109 size_t rowBytes, | 137 size_t rowBytes, |
110 SkColorTable* ctable, | 138 SkColorTable* ctable, |
111 SkData* data, | 139 SkData* data, |
112 size_t offset) { | 140 size_t offset) { |
113 SkASSERT(data != NULL); | 141 SkASSERT(data != NULL); |
114 SkASSERT(offset <= data->size()); | 142 SkASSERT(offset <= data->size()); |
115 if (!is_valid(info, ctable)) { | 143 if (!is_valid(info, ctable)) { |
116 return NULL; | 144 return NULL; |
117 } | 145 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 267 |
240 this->setPreLocked(fStorage, fRB, fCTable); | 268 this->setPreLocked(fStorage, fRB, fCTable); |
241 } | 269 } |
242 | 270 |
243 /////////////////////////////////////////////////////////////////////////////// | 271 /////////////////////////////////////////////////////////////////////////////// |
244 | 272 |
245 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, | 273 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, |
246 SkColorTable* ctable) { | 274 SkColorTable* ctable) { |
247 return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable); | 275 return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable); |
248 } | 276 } |
OLD | NEW |