summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorjunov@chromium.org <junov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-19 17:31:27 +0000
committerjunov@chromium.org <junov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-19 17:31:27 +0000
commitf40857d4097783ae77e4d596c9e40391a38620c1 (patch)
tree92d4cd142f26523c90623efcbbb64c5b38d25b23 /skia
parentf125146993f5b26d7aaf9264cdff891b0b45c681 (diff)
downloadchromium_src-f40857d4097783ae77e4d596c9e40391a38620c1.zip
chromium_src-f40857d4097783ae77e4d596c9e40391a38620c1.tar.gz
chromium_src-f40857d4097783ae77e4d596c9e40391a38620c1.tar.bz2
Fix crash when allocation of very large HTML canvas fails.
This change introduces skia::TryCreateBitmapCanvas, which is a non-crashing version of CreateBitmapCanvas. This patch alone does not fix that crash. A patch in WebKit will be necessary to make the ImageBuffer constructor in ImageBufferSkia.cpp call TryCreateBitmapCanvas. BUG=88038 TEST=http://www.atopon.org/maze/ Review URL: http://codereview.chromium.org/7686006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/platform_canvas.cc9
-rw-r--r--skia/ext/platform_canvas.h7
2 files changed, 16 insertions, 0 deletions
diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc
index df7ded6..279af45 100644
--- a/skia/ext/platform_canvas.cc
+++ b/skia/ext/platform_canvas.cc
@@ -34,6 +34,15 @@ SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) {
return new PlatformCanvas(width, height, is_opaque);
}
+SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque) {
+ PlatformCanvas* canvas = new PlatformCanvas();
+ if (!canvas->initialize(width, height, is_opaque)) {
+ delete canvas;
+ canvas = NULL;
+ }
+ return canvas;
+}
+
SkDevice* GetTopDevice(const SkCanvas& canvas) {
SkCanvas::LayerIter iter(const_cast<SkCanvas*>(&canvas), false);
return iter.device();
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index 54650ff..354314b 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -109,6 +109,13 @@ SK_API SkDevice* GetTopDevice(const SkCanvas& canvas);
// transparency: this will enable some optimizations.
SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque);
+// Non-crashing version of CreateBitmapCanvas
+// returns NULL if allocation fails for any reason.
+// Use this instead of CreateBitmapCanvas in places that are likely to
+// attempt to allocate very large canvases (therefore likely to fail),
+// and where it is possible to recover gracefully from the failed allocation.
+SK_API SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque);
+
// Returns true if native platform routines can be used to draw on the
// given canvas. If this function returns false, BeginPlatformPaint will
// return NULL PlatformSurface.