OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 #ifndef SkBitmap_DEFINED | 8 #ifndef SkBitmap_DEFINED |
9 #define SkBitmap_DEFINED | 9 #define SkBitmap_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
14 #include "SkPoint.h" | 14 #include "SkPoint.h" |
15 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
16 | 16 |
17 #ifdef SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL | |
18 #define SK_ALLOCPIXELS_RETURN_TYPE bool | |
19 #define SK_ALLOCPIXELS_RETURN(predicate) return (predicate) | |
20 #else | |
21 #define SK_ALLOCPIXELS_RETURN_TYPE void | |
22 #define SK_ALLOCPIXELS_RETURN(arg) (arg) | |
23 #endif | |
24 | |
17 struct SkMask; | 25 struct SkMask; |
18 struct SkIRect; | 26 struct SkIRect; |
19 struct SkRect; | 27 struct SkRect; |
20 class SkPaint; | 28 class SkPaint; |
21 class SkPixelRef; | 29 class SkPixelRef; |
22 class SkPixelRefFactory; | 30 class SkPixelRefFactory; |
23 class SkRegion; | 31 class SkRegion; |
24 class SkString; | 32 class SkString; |
25 class GrTexture; | 33 class GrTexture; |
26 | 34 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 void getBounds(SkIRect* bounds) const; | 219 void getBounds(SkIRect* bounds) const; |
212 | 220 |
213 bool setInfo(const SkImageInfo&, size_t rowBytes = 0); | 221 bool setInfo(const SkImageInfo&, size_t rowBytes = 0); |
214 | 222 |
215 /** | 223 /** |
216 * Allocate the bitmap's pixels to match the requested image info. If the F actory | 224 * Allocate the bitmap's pixels to match the requested image info. If the F actory |
217 * is non-null, call it to allcoate the pixelref. If the ImageInfo requires | 225 * is non-null, call it to allcoate the pixelref. If the ImageInfo requires |
218 * a colortable, then ColorTable must be non-null, and will be ref'd. | 226 * a colortable, then ColorTable must be non-null, and will be ref'd. |
219 * On failure, the bitmap will be set to empty and return false. | 227 * On failure, the bitmap will be set to empty and return false. |
220 */ | 228 */ |
221 bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); | 229 bool allocPixelsCheck(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*) ; |
mtklein
2014/08/29 17:59:49
tryAllocPixels? allocPixelsCheck sounds a little
| |
230 | |
231 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, SkPixelRefFa ctory* factory, | |
232 SkColorTable* ctable) { | |
233 if (!this->allocPixelsCheck(info, factory, ctable)) { | |
234 sk_throw(); | |
235 } | |
236 SK_ALLOCPIXELS_RETURN(true); | |
237 } | |
222 | 238 |
223 /** | 239 /** |
224 * Allocate the bitmap's pixels to match the requested image info and | 240 * Allocate the bitmap's pixels to match the requested image info and |
225 * rowBytes. If the request cannot be met (e.g. the info is invalid or | 241 * rowBytes. If the request cannot be met (e.g. the info is invalid or |
226 * the requested rowBytes are not compatible with the info | 242 * the requested rowBytes are not compatible with the info |
227 * (e.g. rowBytes < info.minRowBytes() or rowBytes is not aligned with | 243 * (e.g. rowBytes < info.minRowBytes() or rowBytes is not aligned with |
228 * the pixel size specified by info.colorType()) then false is returned | 244 * the pixel size specified by info.colorType()) then false is returned |
229 * and the bitmap is set to empty. | 245 * and the bitmap is set to empty. |
230 */ | 246 */ |
231 bool allocPixels(const SkImageInfo& info, size_t rowBytes); | 247 bool allocPixelsCheck(const SkImageInfo& info, size_t rowBytes); |
248 | |
249 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, size_t rowBy tes) { | |
250 if (!this->allocPixelsCheck(info, rowBytes)) { | |
251 sk_throw(); | |
252 } | |
253 SK_ALLOCPIXELS_RETURN(true); | |
254 } | |
232 | 255 |
233 /** | 256 /** |
234 * Allocate a pixelref to match the specified image info, using the default | 257 * Allocate a pixelref to match the specified image info, using the default |
235 * allocator. | 258 * allocator. |
236 * On success, the bitmap's pixels will be "locked", and return true. | 259 * On success, the bitmap's pixels will be "locked", and return true. |
237 * On failure, the bitmap will be set to empty and return false. | 260 * On failure, the bitmap will be set to empty and return false. |
f(malita)
2014/08/29 18:21:15
Should also update the docs at some point.
| |
238 */ | 261 */ |
239 bool allocPixels(const SkImageInfo& info) { | 262 SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { |
240 return this->allocPixels(info, info.minRowBytes()); | 263 SK_ALLOCPIXELS_RETURN(this->allocPixels(info, info.minRowBytes())); |
241 } | 264 } |
242 | 265 |
243 bool allocN32Pixels(int width, int height, bool isOpaque = false) { | 266 SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaq ue = false) { |
244 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 267 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
245 if (isOpaque) { | 268 if (isOpaque) { |
246 info.fAlphaType = kOpaque_SkAlphaType; | 269 info.fAlphaType = kOpaque_SkAlphaType; |
247 } | 270 } |
248 return this->allocPixels(info); | 271 SK_ALLOCPIXELS_RETURN(this->allocPixels(info)); |
249 } | 272 } |
250 | 273 |
251 /** | 274 /** |
252 * Install a pixelref that wraps the specified pixels and rowBytes, and | 275 * Install a pixelref that wraps the specified pixels and rowBytes, and |
253 * optional ReleaseProc and context. When the pixels are no longer | 276 * optional ReleaseProc and context. When the pixels are no longer |
254 * referenced, if releaseProc is not null, it will be called with the | 277 * referenced, if releaseProc is not null, it will be called with the |
255 * pixels and context as parameters. | 278 * pixels and context as parameters. |
256 * On failure, the bitmap will be set to empty and return false. | 279 * On failure, the bitmap will be set to empty and return false. |
257 */ | 280 */ |
258 bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkColo rTable*, | 281 bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkColo rTable*, |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 | 859 |
837 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 860 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
838 SkASSERT(fPixels); | 861 SkASSERT(fPixels); |
839 SkASSERT(kIndex_8_SkColorType == this->colorType()); | 862 SkASSERT(kIndex_8_SkColorType == this->colorType()); |
840 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th is->height()); | 863 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th is->height()); |
841 SkASSERT(fColorTable); | 864 SkASSERT(fColorTable); |
842 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 865 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
843 } | 866 } |
844 | 867 |
845 #endif | 868 #endif |
OLD | NEW |