summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-08-10 13:17:08 +0100
committerBen Murdoch <benm@google.com>2011-08-12 17:26:30 +0100
commit3e556736c899f74f2ccc010a8bc7401c36e9a1a0 (patch)
treed4938bc18892148a044ca7bf4715bdd040053946 /Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
parent6a94579dab1dca12e6555b01602efeb5debda17a (diff)
downloadexternal_webkit-3e556736c899f74f2ccc010a8bc7401c36e9a1a0.zip
external_webkit-3e556736c899f74f2ccc010a8bc7401c36e9a1a0.tar.gz
external_webkit-3e556736c899f74f2ccc010a8bc7401c36e9a1a0.tar.bz2
Check the available memory when allocating an ImageBuffer.
The ImageBuffers used by canvas can eat a ton of memory quickly, so be mindful of the available memory on the device before allocating them. See also frameworks/base change I3d0f85075497c2a374cd866b0223eecaaa4b5f46 Bug: 5142892 Change-Id: I74d243ef9d0d63aac168c16653e9aae0430dfa21
Diffstat (limited to 'Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp')
-rw-r--r--Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp b/Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
index 5807f87..bbde998 100644
--- a/Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
+++ b/Source/WebCore/platform/graphics/android/ImageBufferAndroid.cpp
@@ -31,6 +31,7 @@
#include "ColorSpace.h"
#include "GraphicsContext.h"
#include "NotImplemented.h"
+#include "PlatformBridge.h"
#include "PlatformGraphicsContext.h"
#include "SkBitmapRef.h"
#include "SkCanvas.h"
@@ -53,8 +54,13 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode, bool& s
: m_data(size)
, m_size(size)
{
- m_context.set(GraphicsContext::createOffscreenContext(size.width(), size.height()));
- success = true;
+ // GraphicsContext creates a 32bpp SkBitmap, so 4 bytes per pixel.
+ if (!PlatformBridge::canSatisfyMemoryAllocation(size.width() * size.height() * 4))
+ success = false;
+ else {
+ m_context.set(GraphicsContext::createOffscreenContext(size.width(), size.height()));
+ success = true;
+ }
}
ImageBuffer::~ImageBuffer()
@@ -74,10 +80,14 @@ bool ImageBuffer::drawsUsingCopy() const
PassRefPtr<Image> ImageBuffer::copyImage() const
{
ASSERT(context());
+
SkCanvas* canvas = context()->platformContext()->mCanvas;
SkDevice* device = canvas->getDevice();
const SkBitmap& orig = device->accessBitmap(false);
+ if (!PlatformBridge::canSatisfyMemoryAllocation(orig.getSize()))
+ return 0;
+
SkBitmap copy;
orig.copyTo(&copy, orig.config());