summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 00:35:04 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 00:35:04 +0000
commit983f7bd3fa88bbdac942dbfaf0269b1684a5c1ee (patch)
tree119108c285b45fa1f8caa4b02016e2604f24684d
parent4d590127a9d0aff4aa077b2eb1f8988619ac05c2 (diff)
downloadchromium_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
-rw-r--r--base/gfx/bitmap_platform_device_linux.cc32
-rw-r--r--base/gfx/bitmap_platform_device_linux.h60
-rw-r--r--skia/include/corecg/SkUserConfig.h20
-rw-r--r--webkit/tools/test_shell/gtk/webwidget_host.cc8
4 files changed, 84 insertions, 36 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
diff --git a/skia/include/corecg/SkUserConfig.h b/skia/include/corecg/SkUserConfig.h
index a9d4fea..2a646ce 100644
--- a/skia/include/corecg/SkUserConfig.h
+++ b/skia/include/corecg/SkUserConfig.h
@@ -116,6 +116,26 @@ typedef unsigned uint32_t;
#define SK_G32_SHIFT 8
#define SK_B32_SHIFT 16
+#elif defined(SK_BUILD_FOR_UNIX)
+
+#ifdef SK_CPU_BENDIAN
+// Below we set the order for ARGB channels in registers. I suspect that, on
+// big endian machines, you can keep this the same and everything will work.
+// The in-memory order will be different, of course, but as long as everything
+// is reading memory as words rather than bytes, it will all work. However, if
+// you find that colours are messed up I thought that I would leave a helpful
+// locator for you. Also see the comments in
+// base/gfx/bitmap_platform_device_linux.h
+#error Read the comment at this location
+#endif
+
+// For Linux we want to match the most common X visual, which is
+// ARGB (in registers)
+#define SK_A32_SHIFT 24
+#define SK_R32_SHIFT 16
+#define SK_G32_SHIFT 8
+#define SK_B32_SHIFT 0
+
#endif
// Don't use skia debug mode even when compiled as debug, because we don't
diff --git a/webkit/tools/test_shell/gtk/webwidget_host.cc b/webkit/tools/test_shell/gtk/webwidget_host.cc
index 79e39f58..f89f5f9 100644
--- a/webkit/tools/test_shell/gtk/webwidget_host.cc
+++ b/webkit/tools/test_shell/gtk/webwidget_host.cc
@@ -4,6 +4,7 @@
#include "webkit/tools/test_shell/webwidget_host.h"
+#include <cairo/cairo.h>
#include <gtk/gtk.h>
#include "base/logging.h"
@@ -232,8 +233,11 @@ void WebWidgetHost::Paint() {
gfx::PlatformDeviceLinux &platdev = canvas_->getTopPlatformDevice();
gfx::BitmapPlatformDeviceLinux* const bitdev =
static_cast<gfx::BitmapPlatformDeviceLinux* >(&platdev);
- gdk_draw_pixbuf(view_->window, NULL, bitdev->pixbuf(),
- 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0);
+
+ cairo_t* cairo_drawable = gdk_cairo_create(view_->window);
+ cairo_set_source_surface(cairo_drawable, bitdev->surface(), 0, 0);
+ cairo_paint(cairo_drawable);
+ cairo_destroy(cairo_drawable);
}
void WebWidgetHost::ResetScrollRect() {