Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: include/core/SkBitmap.h

Issue 510423005: make allocPixels throw on failure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkBitmap.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
/**
« no previous file with comments | « no previous file | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698