diff options
author | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-20 16:58:01 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-20 16:58:01 +0000 |
commit | b8148be0c452bb08eccd8dbfd5fb118b313a693e (patch) | |
tree | 9d6fbd0f24cc0d58d3c5eab8a673300d48a838ae /skia/ext | |
parent | d26da8db4aefc7ddade5f6c06896154d590ed42e (diff) | |
download | chromium_src-b8148be0c452bb08eccd8dbfd5fb118b313a693e.zip chromium_src-b8148be0c452bb08eccd8dbfd5fb118b313a693e.tar.gz chromium_src-b8148be0c452bb08eccd8dbfd5fb118b313a693e.tar.bz2 |
create cairo before we hand-off the surface, in case the surface is destroyed
BUG=
Review URL: https://codereview.chromium.org/172563002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r-- | skia/ext/bitmap_platform_device_cairo.cc | 18 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_cairo.h | 4 |
2 files changed, 15 insertions, 7 deletions
diff --git a/skia/ext/bitmap_platform_device_cairo.cc b/skia/ext/bitmap_platform_device_cairo.cc index 1608354..b76ccbc 100644 --- a/skia/ext/bitmap_platform_device_cairo.cc +++ b/skia/ext/bitmap_platform_device_cairo.cc @@ -23,6 +23,10 @@ void CairoSurfaceReleaseProc(void*, void* context) { // Back the destination bitmap by a Cairo surface. The bitmap's // pixelRef takes ownership of the passed-in surface and will call // cairo_surface_destroy() upon destruction. +// +// Note: it may immediately destroy the surface, if it fails to create a bitmap +// with pixels, thus the caller must either ref() the surface before hand, or +// it must not refer to the surface after this call. bool InstallCairoSurfacePixels(SkBitmap* dst, cairo_surface_t* surface, bool is_opaque) { @@ -99,13 +103,18 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, return NULL; } + // must call this before trying to install the surface, since that may result + // in the surface being destroyed. + cairo_t* cairo = cairo_create(surface); + SkBitmap bitmap; if (!InstallCairoSurfacePixels(&bitmap, surface, is_opaque)) { + cairo_destroy(cairo); return NULL; } // The device object will take ownership of the graphics context. - return new BitmapPlatformDevice(bitmap, surface); + return new BitmapPlatformDevice(bitmap, cairo); } BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, @@ -142,13 +151,12 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, return Create(width, height, is_opaque, surface); } -// The device will own the bitmap, which corresponds to also owning the pixel -// data. Therefore, we do not transfer ownership to the SkBitmapDevice's bitmap. +// Ownership of the cairo object is transferred. BitmapPlatformDevice::BitmapPlatformDevice( const SkBitmap& bitmap, - cairo_surface_t* surface) + cairo_t* cairo) : SkBitmapDevice(bitmap), - cairo_(cairo_create(surface)), + cairo_(cairo), config_dirty_(true), transform_(SkMatrix::I()) { // Want to load the config next time. SetPlatformDevice(this, this); diff --git a/skia/ext/bitmap_platform_device_cairo.h b/skia/ext/bitmap_platform_device_cairo.h index 5b3c46c..8d8f388 100644 --- a/skia/ext/bitmap_platform_device_cairo.h +++ b/skia/ext/bitmap_platform_device_cairo.h @@ -63,8 +63,8 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { // we ever have to share state between some native drawing UI and Skia, like // the Windows and Mac versions of this class do. // - // This object takes ownership of @data. - BitmapPlatformDevice(const SkBitmap& other, cairo_surface_t* surface); + // This object takes ownership of @cairo. + BitmapPlatformDevice(const SkBitmap& other, cairo_t* cairo); virtual ~BitmapPlatformDevice(); // Constructs a device with size |width| * |height| with contents initialized |