#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;
public:
class SK_API Allocator;
-#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
- enum Config {
- kNo_Config, //!< bitmap has not been configured
- kA8_Config, //!< 8-bits per pixel, with only alpha specified (0 is transparent, 0xFF is opaque)
- kIndex8_Config, //!< 8-bits per pixel, using SkColorTable to specify the colors
- kRGB_565_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packing)
- kARGB_4444_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packing)
- kARGB_8888_Config, //!< 32-bits per pixel, (see SkColorPriv.h for packing)
- };
-
- // do not add this to the Config enum, otherwise the compiler will let us
- // pass this as a valid parameter for Config.
- enum {
- kConfigCount = kARGB_8888_Config + 1
- };
-
- /** Return the config for the bitmap. */
- Config config() const;
-
- SK_ATTR_DEPRECATED("use config()")
- Config getConfig() const { return this->config(); }
-#endif
-
/**
* Default construct creates a bitmap with zero width and height, and no pixels.
* Its colortype is set to kUnknown_SkColorType.
const SkImageInfo& info() const { return fInfo; }
- int width() const { return fInfo.fWidth; }
- int height() const { return fInfo.fHeight; }
- SkColorType colorType() const { return fInfo.fColorType; }
- SkAlphaType alphaType() const { return fInfo.fAlphaType; }
+ int width() const { return fInfo.width(); }
+ int height() const { return fInfo.height(); }
+ SkColorType colorType() const { return fInfo.colorType(); }
+ SkAlphaType alphaType() const { return fInfo.alphaType(); }
/**
* Return the number of bytes per pixel based on the colortype. If the colortype is
Note this truncates the result to 32bits. Call getSize64() to detect
if the real size exceeds 32bits.
*/
- size_t getSize() const { return fInfo.fHeight * fRowBytes; }
+ size_t getSize() const { return fInfo.height() * fRowBytes; }
/** Return the number of bytes from the pointer returned by getPixels()
to the end of the allocated space in the buffer. Required in
* Return the full size of the bitmap, in bytes.
*/
int64_t computeSize64() const {
- return sk_64_mul(fInfo.fHeight, fRowBytes);
+ return sk_64_mul(fInfo.height(), fRowBytes);
}
/**
* 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
* 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) {
- SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
- if (isOpaque) {
- info.fAlphaType = kOpaque_SkAlphaType;
- }
+ bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) {
+ SkImageInfo info = SkImageInfo::MakeN32(width, height,
+ isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
+ return this->tryAllocPixels(info);
+ }
+
+ SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaque = false) {
+ SkImageInfo info = SkImageInfo::MakeN32(width, height,
+ isOpaque ? kOpaque_SkAlphaType : kPremul_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
@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);
}
@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
*/
bool readyToDraw() const {
return this->getPixels() != NULL &&
- (this->colorType() != kIndex_8_SkColorType || NULL != fColorTable);
+ (this->colorType() != kIndex_8_SkColorType || fColorTable);
}
/** Returns the pixelRef's texture, or NULL
return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)];
}
-#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
-///////////////////////////////////////////////////////////////////////////////
-//
-// Helpers until we can fully deprecate SkBitmap::Config
-//
-SK_API SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType);
-SK_API SkColorType SkBitmapConfigToColorType(SkBitmap::Config);
-#endif
-
#endif