From 00943a1667adf57fef13668e9e028b31e3f5be28 Mon Sep 17 00:00:00 2001
From: Benjamin Otte <otte@gnome.org>
Date: Tue, 13 Oct 2009 22:19:20 +0200
Subject: [PATCH 06/12] [cairo] Make copySurface() surface type agnostic

---
 .../platform/graphics/cairo/ImageBufferCairo.cpp   |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index a2c00aa..dd7da31 100644
--- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -41,18 +41,21 @@
 #include <pixman.h>
 #include <wtf/Vector.h>
 #include <math.h>
+#if PLATFORM(GTK)
+#include <gdk/gdk.h>
+#endif
 
 using namespace std;
 
+namespace WebCore {
+
 // Cairo doesn't provide a way to copy a cairo_surface_t.
 // See http://lists.cairographics.org/archives/cairo/2007-June/010877.html
 // Once cairo provides the way, use the function instead of this.
-static inline cairo_surface_t* copySurface(cairo_surface_t* surface)
+static inline cairo_surface_t* copySurface(cairo_surface_t* surface, const IntSize& size)
 {
-    cairo_format_t format = cairo_image_surface_get_format(surface);
-    int width = cairo_image_surface_get_width(surface);
-    int height = cairo_image_surface_get_height(surface);
-    cairo_surface_t* newsurface = cairo_image_surface_create(format, width, height);
+    cairo_surface_t* newsurface = cairo_surface_create_similar(surface,
+        cairo_surface_get_content(surface), size.width(), size.height());
 
     cairo_t* cr = cairo_create(newsurface);
     cairo_set_source_surface(cr, surface, 0, 0);
@@ -63,8 +66,6 @@ static inline cairo_surface_t* copySurface(cairo_surface_t* surface)
     return newsurface;
 }
 
-namespace WebCore {
-
 ImageBufferData::ImageBufferData(const IntSize& size)
     : m_surface(0)
 {
@@ -111,7 +112,7 @@ Image* ImageBuffer::image() const
         //
         // This seems silly, but is the way the CG port works: image() is
         // intended to be used only when rendering is "complete."
-        cairo_surface_t* newsurface = copySurface(m_data.m_surface);
+        cairo_surface_t* newsurface = copySurface(m_data.m_surface, m_size);
 
         // BitmapImage will release the passed in surface on destruction
         m_image = BitmapImage::create(newsurface);
-- 
1.6.3.3

