diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 00:35:04 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 00:35:04 +0000 |
commit | 983f7bd3fa88bbdac942dbfaf0269b1684a5c1ee (patch) | |
tree | 119108c285b45fa1f8caa4b02016e2604f24684d /base | |
parent | 4d590127a9d0aff4aa077b2eb1f8988619ac05c2 (diff) | |
download | chromium_src-983f7bd3fa88bbdac942dbfaf0269b1684a5c1ee.zip chromium_src-983f7bd3fa88bbdac942dbfaf0269b1684a5c1ee.tar.gz chromium_src-983f7bd3fa88bbdac942dbfaf0269b1684a5c1ee.tar.bz2 |
Switch from using GdkPixbuf to cairo for painting on Drawables.
Make everything use ARGB order in registers (B.G.R.A order in memory on
little-endian systems)
Review URL: http://codereview.chromium.org/8227
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/gfx/bitmap_platform_device_linux.cc | 32 | ||||
-rw-r--r-- | base/gfx/bitmap_platform_device_linux.h | 60 |
2 files changed, 58 insertions, 34 deletions
diff --git a/base/gfx/bitmap_platform_device_linux.cc b/base/gfx/bitmap_platform_device_linux.cc index f86323e..c80a273 100644 --- a/base/gfx/bitmap_platform_device_linux.cc +++ b/base/gfx/bitmap_platform_device_linux.cc @@ -4,8 +4,7 @@ #include "base/gfx/bitmap_platform_device_linux.h" -#include <gdk/gdk.h> -#include <gdk-pixbuf/gdk-pixbuf.h> +#include <cairo/cairo.h> #include "base/logging.h" @@ -17,21 +16,14 @@ namespace gfx { // data. BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( int width, int height, bool is_opaque) { - GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height); - if (!pixbuf) - return NULL; - - DCHECK_EQ(gdk_pixbuf_get_colorspace(pixbuf), GDK_COLORSPACE_RGB); - DCHECK_EQ(gdk_pixbuf_get_bits_per_sample(pixbuf), 8); - DCHECK(gdk_pixbuf_get_has_alpha(pixbuf)); - DCHECK_EQ(gdk_pixbuf_get_n_channels(pixbuf), 4); - DCHECK_EQ(gdk_pixbuf_get_width(pixbuf), width); - DCHECK_EQ(gdk_pixbuf_get_height(pixbuf), height); + cairo_surface_t* surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + width, height); SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, - gdk_pixbuf_get_rowstride(pixbuf)); - bitmap.setPixels(gdk_pixbuf_get_pixels(pixbuf)); + cairo_image_surface_get_stride(surface)); + bitmap.setPixels(cairo_image_surface_get_data(surface)); bitmap.setIsOpaque(is_opaque); #ifndef NDEBUG @@ -41,15 +33,15 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( #endif // The device object will take ownership of the graphics context. - return new BitmapPlatformDeviceLinux(bitmap, pixbuf); + return new BitmapPlatformDeviceLinux(bitmap, 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, - GdkPixbuf* pixbuf) + cairo_surface_t* surface) : PlatformDeviceLinux(bitmap), - pixbuf_(pixbuf) { + surface_(surface) { } BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( @@ -59,9 +51,9 @@ BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( } BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { - if (pixbuf_) { - g_object_unref(pixbuf_); - pixbuf_ = NULL; + if (surface_) { + cairo_surface_destroy(surface_); + surface_ = NULL; } } diff --git a/base/gfx/bitmap_platform_device_linux.h b/base/gfx/bitmap_platform_device_linux.h index 99ca534..c029293 100644 --- a/base/gfx/bitmap_platform_device_linux.h +++ b/base/gfx/bitmap_platform_device_linux.h @@ -8,21 +8,51 @@ #include "base/gfx/platform_device_linux.h" #include "base/ref_counted.h" -#include <gdk-pixbuf/gdk-pixbuf.h> +typedef struct _cairo_surface cairo_surface_t; + +// ----------------------------------------------------------------------------- +// Image byte ordering on Linux: +// +// Pixels are packed into 32-bit words these days. Even for 24-bit images, +// often 8-bits will be left unused for alignment reasons. Thus, when you see +// ARGB as the byte order you have to wonder if that's in memory order or +// little-endian order. Here I'll write A.R.G.B to specifiy the memory order. +// +// GdkPixbuf's provide a nice backing store and defaults to R.G.B.A order. +// They'll do the needed byte swapping to match the X server when drawn. +// +// Skia can be controled in skia/include/corecg/SkUserConfig.h (see bits about +// SK_R32_SHIFT). For Linux we define it to be ARGB in registers. For little +// endian machines that means B.G.R.A in memory. +// +// The image loaders are controlled in +// webkit/port/platform/image-decoders/ImageDecoder.h (see setRGBA). These are +// also configured for ARGB in registers. +// +// Cairo's only 32-bit mode is ARGB in registers. +// +// X servers commonly have a 32-bit visual with xRGB in registers (since they +// typically don't do alpha blending of drawables at the user level. Composite +// extensions aside.) +// +// We don't use GdkPixbuf because its byte order differs from the rest. Most +// importantly, it differs from Cairo which, being a system library, is +// something that we can't easily change. +// ----------------------------------------------------------------------------- namespace gfx { // ----------------------------------------------------------------------------- -// This is the Linux bitmap backing for Skia. It's a GdkPixbuf of the correct -// size and we implement a SkPixelRef in order that Skia can write directly to -// the pixel memory backing the Pixbuf. +// This is the Linux bitmap backing for Skia. We create a Cairo image surface +// to store the backing buffer. This buffer is BGRA in memory (on little-endian +// machines). // -// We then provide an accessor for getting the pixbuf object and that can be -// drawn to a GDK drawing area to display the rendering result. +// For now we are also using Cairo to paint to the Drawables so we provide an +// accessor for getting the surface. // // This is all quite ok for test_shell. In the future we will want to use // shared memory between the renderer and the main process at least. In this -// case we'll probably create the pixbuf from a precreated region of memory. +// case we'll probably create the buffer from a precreated region of memory. // ----------------------------------------------------------------------------- class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { public: @@ -30,11 +60,13 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { static BitmapPlatformDeviceLinux* Create(int width, int height, bool is_opaque); - /// Create a BitmapPlatformDeviceLinux from an already constructed bitmap; - /// you should probably be using Create(). This may become private later if - /// we ever have to share state between some native drawing UI and Skia, like - /// the Windows and Mac versions of this class do. - BitmapPlatformDeviceLinux(const SkBitmap& other, GdkPixbuf* pixbuf); + // Create a BitmapPlatformDeviceLinux from an already constructed bitmap; + // you should probably be using Create(). This may become private later if + // 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); virtual ~BitmapPlatformDeviceLinux(); // A stub copy constructor. Needs to be properly implemented. @@ -43,10 +75,10 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { // Bitmaps aren't vector graphics. virtual bool IsVectorial() { return false; } - GdkPixbuf* pixbuf() const { return pixbuf_; } + cairo_surface_t* surface() const { return surface_; } private: - GdkPixbuf* pixbuf_; + cairo_surface_t* surface_; }; } // namespace gfx |