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

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: rebase Created 6 years, 3 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 | « gyp/skia_for_chromium_defines.gypi ('k') | samplecode/SampleApp.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..c58c78d764da91da4eddb4435d5c96245cd52fa7 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 SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*);
+
+ 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
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698