diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 00:56:50 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 00:56:50 +0000 |
commit | 6ebcc35add48c0aeac7aa7bb417d7d819fbf11ba (patch) | |
tree | 5eb72e99bbc16a9d01dec62fcfe9c40954a41f4c /base | |
parent | 55cc33475ae6c10cd0c29b77ff9f322f70e5b507 (diff) | |
download | chromium_src-6ebcc35add48c0aeac7aa7bb417d7d819fbf11ba.zip chromium_src-6ebcc35add48c0aeac7aa7bb417d7d819fbf11ba.tar.gz chromium_src-6ebcc35add48c0aeac7aa7bb417d7d819fbf11ba.tar.bz2 |
Add pixel layout test support for Linux
Tracking down this error turned out to be a total pain. Image dumping is
the first bit of code that we have run into on Linux that copies bitmap
platform devices. Previously we didn't reference count them like Windows
does.
Review URL: http://codereview.chromium.org/11459
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5657 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/gfx/bitmap_platform_device_linux.cc | 52 | ||||
-rw-r--r-- | base/gfx/bitmap_platform_device_linux.h | 13 |
2 files changed, 52 insertions, 13 deletions
diff --git a/base/gfx/bitmap_platform_device_linux.cc b/base/gfx/bitmap_platform_device_linux.cc index c80a273..18f8ab1 100644 --- a/base/gfx/bitmap_platform_device_linux.cc +++ b/base/gfx/bitmap_platform_device_linux.cc @@ -10,6 +10,31 @@ namespace gfx { +// ----------------------------------------------------------------------------- +// These objects are reference counted and own a Cairo surface. The surface is +// the backing store for a Skia bitmap and we reference count it so that we can +// copy BitmapPlatformDeviceLinux objects without having to copy all the image +// data. +// ----------------------------------------------------------------------------- +class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData + : public base::RefCounted<BitmapPlatformDeviceLinuxData> { + public: + explicit BitmapPlatformDeviceLinuxData(cairo_surface_t* surface) + : surface_(surface) { } + + cairo_surface_t* surface() const { return surface_; } + + protected: + cairo_surface_t *const surface_; + + friend class base::RefCounted<BitmapPlatformDeviceLinuxData>; + ~BitmapPlatformDeviceLinuxData() { + cairo_surface_destroy(surface_); + } + + DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceLinuxData); +}; + // We use this static factory function instead of the regular constructor so // that we can create the pixel data before calling the constructor. This is // required so that we can call the base class' constructor with the pixel @@ -33,28 +58,37 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( #endif // The device object will take ownership of the graphics context. - return new BitmapPlatformDeviceLinux(bitmap, surface); + return new BitmapPlatformDeviceLinux + (bitmap, new BitmapPlatformDeviceLinuxData(surface)); } // The device will own the bitmap, which corresponds to also owning the pixel // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. -BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap, - cairo_surface_t* surface) +BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( + const SkBitmap& bitmap, + BitmapPlatformDeviceLinuxData* data) : PlatformDeviceLinux(bitmap), - surface_(surface) { + data_(data) { } BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( const BitmapPlatformDeviceLinux& other) : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( - other).accessBitmap(true)) { + other).accessBitmap(true)), + data_(other.data_) { } BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { - if (surface_) { - cairo_surface_destroy(surface_); - surface_ = NULL; - } +} + +cairo_surface_t* BitmapPlatformDeviceLinux::surface() const { + return data_->surface(); +} + +BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=( + const BitmapPlatformDeviceLinux& other) { + data_ = other.data_; + return *this; } } // namespace gfx diff --git a/base/gfx/bitmap_platform_device_linux.h b/base/gfx/bitmap_platform_device_linux.h index c029293..629fd1d 100644 --- a/base/gfx/bitmap_platform_device_linux.h +++ b/base/gfx/bitmap_platform_device_linux.h @@ -55,6 +55,9 @@ namespace gfx { // case we'll probably create the buffer from a precreated region of memory. // ----------------------------------------------------------------------------- class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { + // A reference counted cairo surface + class BitmapPlatformDeviceLinuxData; + public: /// Static constructor. I don't understand this, it's just a copy of the mac static BitmapPlatformDeviceLinux* Create(int width, int height, @@ -65,9 +68,11 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { // 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 @surface. - BitmapPlatformDeviceLinux(const SkBitmap& other, cairo_surface_t* surface); + // This object takes ownership of @data. + BitmapPlatformDeviceLinux(const SkBitmap& other, + BitmapPlatformDeviceLinuxData* data); virtual ~BitmapPlatformDeviceLinux(); + BitmapPlatformDeviceLinux& operator=(const BitmapPlatformDeviceLinux& other); // A stub copy constructor. Needs to be properly implemented. BitmapPlatformDeviceLinux(const BitmapPlatformDeviceLinux& other); @@ -75,10 +80,10 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { // Bitmaps aren't vector graphics. virtual bool IsVectorial() { return false; } - cairo_surface_t* surface() const { return surface_; } + cairo_surface_t* surface() const; private: - cairo_surface_t* surface_; + scoped_refptr<BitmapPlatformDeviceLinuxData> data_; }; } // namespace gfx |