Index: src/core/SkBitmapDevice.cpp |
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp |
index 369f10c1bf470e3633042525021a16ba271963bb..2d7e41337d4269378653192050b19521e20d192a 100644 |
--- a/src/core/SkBitmapDevice.cpp |
+++ b/src/core/SkBitmapDevice.cpp |
@@ -29,7 +29,10 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& |
SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { |
fBitmap.setConfig(config, width, height, 0, isOpaque ? |
kOpaque_SkAlphaType : kPremul_SkAlphaType); |
- fBitmap.allocPixels(); |
+ if (!fBitmap.allocPixels()) { |
+ fBitmap.setConfig(config, 0, 0, 0, isOpaque ? |
+ kOpaque_SkAlphaType : kPremul_SkAlphaType); |
+ } |
if (!isOpaque) { |
fBitmap.eraseColor(SK_ColorTRANSPARENT); |
} |
@@ -41,7 +44,10 @@ SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b |
fBitmap.setConfig(config, width, height, 0, isOpaque ? |
kOpaque_SkAlphaType : kPremul_SkAlphaType); |
- fBitmap.allocPixels(); |
+ if (!fBitmap.allocPixels()) { |
+ fBitmap.setConfig(config, 0, 0, 0, isOpaque ? |
+ kOpaque_SkAlphaType : kPremul_SkAlphaType); |
+ } |
if (!isOpaque) { |
fBitmap.eraseColor(SK_ColorTRANSPARENT); |
} |
@@ -61,8 +67,14 @@ SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, |
int width, int height, |
bool isOpaque, |
Usage usage) { |
- return SkNEW_ARGS(SkBitmapDevice,(config, width, height, isOpaque, |
- this->getDeviceProperties())); |
+ SkBitmapDevice* device = SkNEW_ARGS(SkBitmapDevice,(config, width, height, |
+ isOpaque, this->getDeviceProperties())); |
+ // Check if allocation failed and delete device if it did fail |
+ if ((device->width() != width) || (device->height() != height)) { |
+ SkDELETE(device); |
+ device = NULL; |
+ } |
+ return device; |
} |
void SkBitmapDevice::lockPixels() { |