Chromium Code Reviews| Index: include/core/SkBitmap.h |
| diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h |
| index 13a7e304c8b8c89c871fe404d84ccb936aff1209..1a0c42d2cff0c4d1ae335516eb8fbc8d664cb088 100644 |
| --- a/include/core/SkBitmap.h |
| +++ b/include/core/SkBitmap.h |
| @@ -14,6 +14,14 @@ |
| #include "SkPoint.h" |
| #include "SkRefCnt.h" |
| +#ifdef SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL |
| + #define SK_ALLOCPIXELS_RETURN_TYPE bool |
| + #define SK_ALLOCPIXELS_RETURN(predicate) return (predicate) |
| +#else |
| + #define SK_ALLOCPIXELS_RETURN_TYPE void |
| + #define SK_ALLOCPIXELS_RETURN(arg) (arg) |
| +#endif |
| + |
| struct SkMask; |
| struct SkIRect; |
| struct SkRect; |
| @@ -218,7 +226,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 allocPixelsCheck(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); |
|
mtklein
2014/08/29 17:59:49
tryAllocPixels? allocPixelsCheck sounds a little
|
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, |
| + SkColorTable* ctable) { |
| + if (!this->allocPixelsCheck(info, factory, ctable)) { |
| + sk_throw(); |
| + } |
| + SK_ALLOCPIXELS_RETURN(true); |
| + } |
| /** |
| * Allocate the bitmap's pixels to match the requested image info and |
| @@ -228,7 +244,14 @@ 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 allocPixelsCheck(const SkImageInfo& info, size_t rowBytes); |
| + |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, size_t rowBytes) { |
| + if (!this->allocPixelsCheck(info, rowBytes)) { |
| + sk_throw(); |
| + } |
| + SK_ALLOCPIXELS_RETURN(true); |
| + } |
| /** |
| * Allocate a pixelref to match the specified image info, using the default |
| @@ -236,16 +259,16 @@ public: |
| * On success, the bitmap's pixels will be "locked", and return true. |
| * 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.
|
| */ |
| - bool allocPixels(const SkImageInfo& info) { |
| - return this->allocPixels(info, info.minRowBytes()); |
| + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { |
| + SK_ALLOCPIXELS_RETURN(this->allocPixels(info, info.minRowBytes())); |
| } |
| - bool allocN32Pixels(int width, int height, bool isOpaque = false) { |
| + 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); |
| + SK_ALLOCPIXELS_RETURN(this->allocPixels(info)); |
| } |
| /** |