summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--skia/ext/bitmap_platform_device.h15
-rw-r--r--skia/ext/bitmap_platform_device_android.cc3
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc3
3 files changed, 21 insertions, 0 deletions
diff --git a/skia/ext/bitmap_platform_device.h b/skia/ext/bitmap_platform_device.h
index 6b119c1..56e4176 100644
--- a/skia/ext/bitmap_platform_device.h
+++ b/skia/ext/bitmap_platform_device.h
@@ -18,4 +18,19 @@
#include "skia/ext/bitmap_platform_device_linux.h"
#endif
+namespace skia {
+ // Returns true if it is unsafe to attempt to allocate an offscreen buffer
+ // given these dimensions.
+ inline bool RasterDeviceTooBigToAllocate(int width, int height) {
+
+#ifndef SKIA_EXT_RASTER_DEVICE_ALLOCATION_MAX
+#define SKIA_EXT_RASTER_DEVICE_ALLOCATION_MAX (2 * 256 * 1024 * 1024)
+#endif
+
+ int bytesPerPixel = 4;
+ int64_t bytes = (int64_t)width * height * bytesPerPixel;
+ return bytes > SKIA_EXT_RASTER_DEVICE_ALLOCATION_MAX;
+ }
+}
+
#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_H_
diff --git a/skia/ext/bitmap_platform_device_android.cc b/skia/ext/bitmap_platform_device_android.cc
index f49b6a8..892e9f6 100644
--- a/skia/ext/bitmap_platform_device_android.cc
+++ b/skia/ext/bitmap_platform_device_android.cc
@@ -8,6 +8,9 @@ namespace skia {
BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
bool is_opaque) {
+ if (RasterDeviceTooBigToAllocate(width, height))
+ return NULL;
+
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
if (bitmap.allocPixels()) {
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index 826719b..b0cb888 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -114,6 +114,9 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context,
int width,
int height,
bool is_opaque) {
+ if (RasterDeviceTooBigToAllocate(width, height))
+ return NULL;
+
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
if (bitmap.allocPixels() != true)