2009-04-23 Zan Dobersek <zandobersek@gmail.com>
authorkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Apr 2009 15:39:29 +0000 (15:39 +0000)
committerkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Apr 2009 15:39:29 +0000 (15:39 +0000)
        Reviewed by Gustavo Noronha.

        https://bugs.webkit.org/show_bug.cgi?id=15654
        GdkPixbuf support for ImageCairo

        Add support for converting a Cairo surface to a GdkPixbuf.

        * platform/graphics/BitmapImage.h:
        * platform/graphics/Image.h:
        (WebCore::Image::getGdkPixbuf):
        * platform/graphics/gtk/ImageGtk.cpp:
        (WebCore::BitmapImage::getGdkPixbuf):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@42780 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/BitmapImage.h
WebCore/platform/graphics/Image.h
WebCore/platform/graphics/gtk/ImageGtk.cpp

index 76b63e7..60c9987 100644 (file)
@@ -1,3 +1,18 @@
+2009-04-23  Zan Dobersek  <zandobersek@gmail.com>
+
+        Reviewed by Gustavo Noronha.
+
+        https://bugs.webkit.org/show_bug.cgi?id=15654
+        GdkPixbuf support for ImageCairo
+
+        Add support for converting a Cairo surface to a GdkPixbuf.
+
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/Image.h:
+        (WebCore::Image::getGdkPixbuf):
+        * platform/graphics/gtk/ImageGtk.cpp:
+        (WebCore::BitmapImage::getGdkPixbuf):
+
 2009-04-23  Kenneth Rohde Christiansen  <kenneth.christiansen@openbossa.org>
 
         Reviewed by Simon Hausmann.
index 422c356..8b770a1 100644 (file)
@@ -140,6 +140,10 @@ public:
     virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE);
 #endif
 
+#if PLATFORM(GTK)
+    virtual GdkPixbuf* getGdkPixbuf();
+#endif
+
     virtual NativeImagePtr nativeImageForCurrentFrame() { return frameAtIndex(currentFrame()); }
 
 protected:
index d6bde11..bb61043 100644 (file)
@@ -61,6 +61,10 @@ class NativeImageSkia;
 #include <QPixmap>
 #endif
 
+#if PLATFORM(GTK)
+typedef struct _GdkPixbuf GdkPixbuf;
+#endif
+
 namespace WebCore {
 
 class TransformationMatrix;
@@ -142,6 +146,10 @@ public:
     virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE) { return false; }
 #endif
 
+#if PLATFORM(GTK)
+    virtual GdkPixbuf* getGdkPixbuf() { return 0; }
+#endif
+
 protected:
     Image(ImageObserver* = 0);
 
index b745209..caf3068 100644 (file)
@@ -27,6 +27,9 @@
 
 #include "BitmapImage.h"
 
+#include <cairo.h>
+#include <gtk/gtk.h>
+
 // This function loads resources from WebKit
 Vector<char> loadResourceIntoArray(const char*);
 
@@ -49,4 +52,21 @@ PassRefPtr<Image> Image::loadPlatformResource(const char *name)
     return img.release();
 }
 
+GdkPixbuf* BitmapImage::getGdkPixbuf()
+{
+    int width = cairo_image_surface_get_width(frameAtIndex(currentFrame()));
+    int height = cairo_image_surface_get_height(frameAtIndex(currentFrame()));
+
+    GdkPixmap* pixmap = gdk_pixmap_new(0, width, height, 32);
+    cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(pixmap));
+    cairo_set_source_surface(cr, frameAtIndex(currentFrame()), 0, 0);
+    cairo_paint(cr);
+    cairo_destroy(cr);
+
+    GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(0, GDK_DRAWABLE(pixmap), 0, 0, 0, 0, 0, width, height);
+    g_object_unref(pixmap);
+
+    return pixbuf;
+}
+
 }