Chromium Code Reviews| Index: include/core/SkBitmap.h |
| diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h |
| index 13a7e304c8b8c89c871fe404d84ccb936aff1209..2b577fb9d7d6db1f75a2101fb7b30da370a6e617 100644 |
| --- a/include/core/SkBitmap.h |
| +++ b/include/core/SkBitmap.h |
| @@ -14,6 +14,16 @@ |
| #include "SkPoint.h" |
| #include "SkRefCnt.h" |
| +#ifdef SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL |
| + #define SK_ALLOCPIXELS_RETURN_TYPE bool |
| + #define SK_ALLOCPIXELS_RETURN_TRUE return true |
| + #define SK_ALLOCPIXELS_RETURN_FAIL return false |
| +#else |
| + #define SK_ALLOCPIXELS_RETURN_TYPE void |
| + #define SK_ALLOCPIXELS_RETURN_TRUE return |
| + #define SK_ALLOCPIXELS_RETURN_FAIL sk_throw() |
| +#endif |
| + |
| struct SkMask; |
| struct SkIRect; |
| struct SkRect; |
| @@ -218,7 +228,15 @@ public: |
| * a colortable, then ColorTable must be non-null, and will be ref'd. |
| * On failure, the bitmap will be set to empty and return false. |
| */ |
| - bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); |
| + bool tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); |
|
mtklein
2014/09/02 18:50:26
Can't SK_WARN_UNUSED_RESULT here too?
reed1
2014/09/02 19:35:28
Done.
|
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, |
| + SkColorTable* ctable) { |
| + if (!this->tryAllocPixels(info, factory, ctable)) { |
| + SK_ALLOCPIXELS_RETURN_FAIL; |
| + } |
| + SK_ALLOCPIXELS_RETURN_TRUE; |
| + } |
| /** |
| * Allocate the bitmap's pixels to match the requested image info and |
| @@ -228,26 +246,39 @@ public: |
| * the pixel size specified by info.colorType()) then false is returned |
| * and the bitmap is set to empty. |
| */ |
| - bool allocPixels(const SkImageInfo& info, size_t rowBytes); |
| + bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes); |
| - /** |
| - * Allocate a pixelref to match the specified image info, using the default |
| - * allocator. |
| - * On success, the bitmap's pixels will be "locked", and return true. |
| - * On failure, the bitmap will be set to empty and return false. |
| - */ |
| - bool allocPixels(const SkImageInfo& info) { |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, size_t rowBytes) { |
| + if (!this->tryAllocPixels(info, rowBytes)) { |
| + SK_ALLOCPIXELS_RETURN_FAIL; |
| + } |
| + SK_ALLOCPIXELS_RETURN_TRUE; |
| + } |
| + |
| + bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) { |
| + return this->tryAllocPixels(info, info.minRowBytes()); |
| + } |
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { |
| return this->allocPixels(info, info.minRowBytes()); |
| } |
| - bool allocN32Pixels(int width, int height, bool isOpaque = false) { |
| + bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) { |
| + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| + if (isOpaque) { |
| + info.fAlphaType = kOpaque_SkAlphaType; |
| + } |
| + return this->tryAllocPixels(info); |
| + } |
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaque = false) { |
| SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| if (isOpaque) { |
| info.fAlphaType = kOpaque_SkAlphaType; |
| } |
| return this->allocPixels(info); |
| } |
| - |
| + |
| /** |
| * Install a pixelref that wraps the specified pixels and rowBytes, and |
| * optional ReleaseProc and context. When the pixels are no longer |
| @@ -320,7 +351,11 @@ public: |
| @return true if the allocation succeeds. If not the pixelref field of |
| the bitmap will be unchanged. |
| */ |
| - bool allocPixels(SkColorTable* ctable = NULL) { |
| + bool SK_WARN_UNUSED_RESULT tryAllocPixels(SkColorTable* ctable = NULL) { |
| + return this->tryAllocPixels(NULL, ctable); |
| + } |
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(SkColorTable* ctable = NULL) { |
| return this->allocPixels(NULL, ctable); |
| } |
| @@ -342,7 +377,14 @@ public: |
| @return true if the allocation succeeds. If not the pixelref field of |
| the bitmap will be unchanged. |
| */ |
| - bool allocPixels(Allocator* allocator, SkColorTable* ctable); |
| + bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator, SkColorTable* ctable); |
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(Allocator* allocator, SkColorTable* ctable) { |
| + if (!this->tryAllocPixels(allocator, ctable)) { |
| + SK_ALLOCPIXELS_RETURN_FAIL; |
| + } |
| + SK_ALLOCPIXELS_RETURN_TRUE; |
| + } |
| /** |
| * Return the current pixelref object or NULL if there is none. This does |