--- WebKit/gtk/WebView/CairoCompat.cpp | 145 +++++++++++++++++++++++++++++++++++ WebKit/gtk/WebView/webkitwebview.cpp | 2 2 files changed, 146 insertions(+), 1 deletion(-) --- /dev/null +++ webkit-gtk-0.1+svnr28656-r4/WebKit/gtk/WebView/CairoCompat.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2005 Red Hat, Inc. + * Copyright (C) 2006 Alp Toker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !GTK_CHECK_VERSION(2,8,0) + +#include +#include +#include + +extern "C" { + +cairo_t* gdk_cairo_create(GdkDrawable* drawable) +{ + g_return_val_if_fail(GDK_IS_DRAWABLE(drawable), NULL); + + gint x_off, y_off; + gdk_window_get_internal_paint_info(GDK_WINDOW(drawable), &drawable, &x_off, &y_off); + + gint width, height; + gdk_drawable_get_size(drawable, &width, &height); + cairo_surface_t* x11_surface = cairo_xlib_surface_create + (gdk_x11_drawable_get_xdisplay(drawable), + gdk_x11_drawable_get_xid(drawable), + gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(drawable)), + width, height); + + cairo_surface_set_device_offset(x11_surface, -x_off, -y_off); + + cairo_t* cr = cairo_create(x11_surface); + cairo_surface_destroy(x11_surface); + + return cr; +} + +void +gdk_cairo_set_source_pixbuf (cairo_t *cr, + const GdkPixbuf *pixbuf, + double pixbuf_x, + double pixbuf_y) +{ + gint width = gdk_pixbuf_get_width (pixbuf); + gint height = gdk_pixbuf_get_height (pixbuf); + guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); + int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf); + int n_channels = gdk_pixbuf_get_n_channels (pixbuf); + guchar *cairo_pixels; + cairo_format_t format; + cairo_surface_t *surface; + static cairo_user_data_key_t key; + int j; + + if (n_channels == 3) + format = CAIRO_FORMAT_RGB24; + else + format = CAIRO_FORMAT_ARGB32; + + cairo_pixels = g_malloc (4 * width * height); + surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels, + format, + width, height, 4 * width); + cairo_surface_set_user_data (surface, &key, + cairo_pixels, (cairo_destroy_func_t)g_free); + + for (j = height; j; j--) + { + guchar *p = gdk_pixels; + guchar *q = cairo_pixels; + + if (n_channels == 3) + { + guchar *end = p + 3 * width; + + while (p < end) + { +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + q[0] = p[2]; + q[1] = p[1]; + q[2] = p[0]; +#else + q[1] = p[0]; + q[2] = p[1]; + q[3] = p[2]; +#endif + p += 3; + q += 4; + } + } + else + { + guchar *end = p + 4 * width; + guint t1,t2,t3; + +#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END + + while (p < end) + { +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + MULT(q[0], p[2], p[3], t1); + MULT(q[1], p[1], p[3], t2); + MULT(q[2], p[0], p[3], t3); + q[3] = p[3]; +#else + q[0] = p[3]; + MULT(q[1], p[0], p[3], t1); + MULT(q[2], p[1], p[3], t2); + MULT(q[3], p[2], p[3], t3); +#endif + + p += 4; + q += 4; + } + +#undef MULT + } + + gdk_pixels += gdk_rowstride; + cairo_pixels += 4 * width; + } + + cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); + cairo_surface_destroy (surface); +} + + + +} + +#endif --- webkit-gtk-0.1+svnr28656-r4.orig/WebKit/gtk/WebView/webkitwebview.cpp +++ webkit-gtk-0.1+svnr28656-r4/WebKit/gtk/WebView/webkitwebview.cpp @@ -53,10 +53,11 @@ #include "PlatformKeyboardEvent.h" #include "PlatformWheelEvent.h" #include "SubstituteData.h" #include +#include "CairoCompat.cpp" using namespace WebKit; using namespace WebCore; extern "C" {