[cairo] gtkcairo: patch: update gtkcairo to use current cairo API
Bertram Felgenhauer
bf3 at mail.inf.tu-dresden.de
Sat Aug 6 13:57:31 PDT 2005
Hi,
I've created a patch to update gtkcairo to follow some cairo API
changes. I realize that gtkcairo is not used much but I think
it will not hurt to have a version that works either.
The patch also updates the README file to point out that there
will be builtin cairo support in the upcoming GTK+.
Bertram
-------------- next part --------------
? old
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/gtkcairo/ChangeLog,v
retrieving revision 1.31
diff -u -b -r1.31 ChangeLog
--- ChangeLog 8 Apr 2005 10:27:25 -0000 1.31
+++ ChangeLog 6 Aug 2005 20:35:15 -0000
@@ -1,3 +1,25 @@
+2005-08-06 Bertram Felgenhauer <int-e at gmx.de>
+
+ * README: added note about cairo support in upcoming GTK+.
+
+2005-08-02 Bertram Felgenhauer <int-e at gmx.de>
+
+ * configure.in: bump cairo requirements
+
+ * tests/demo.c (paint): replace deprecated functions.
+
+ * gtkcairo/gtkcairo.c (gtk_cairo_expose): don't save cairo's state
+ here.
+ (gtk_cairo_set_gdk_color): replace deprecated function.
+
+ * gtkcairo/gdkcairo.c: change to use new cairo_create() semantics
+ (gdkcairo_destroy): free glitz_surface if it was allocated
+ (gdkcairo_size_allocate): make a temporary reference to glitz_surface
+ to prevent it from being freed.
+ (gdkcairo_expose): (xlib backend) use actual drawable width and height
+ for the X11 surface, create new cairo state for every expose.
+ (gdkcairo_expose): (glitz backend) save cairo's state.
+
2005-04-08 Dave Beckett <Dave.Beckett at bristol.ac.uk>
* autogen.sh: Use LIBTOOLIZE_FLAGS
Index: README
===================================================================
RCS file: /cvs/cairo/gtkcairo/README,v
retrieving revision 1.6
diff -u -b -r1.6 README
--- README 1 Apr 2005 14:37:17 -0000 1.6
+++ README 6 Aug 2005 20:35:15 -0000
@@ -5,6 +5,11 @@
cairo api using a few backends (xlib w/Render acceleration, and glitz
w/open gl acceleration).
+NOTE: GTK+ 2.7+ supports creating cairo contexts for GDK drawables,
+making GtkCairo obsolete; see gdk_drawable_get_cairo().
+GtkCairo can still be used as a convenient interface to cairo for
+earlier GTK+ versions.
+
Synopsis
========
Index: configure.in
===================================================================
RCS file: /cvs/cairo/gtkcairo/configure.in,v
retrieving revision 1.10
diff -u -b -r1.10 configure.in
--- configure.in 25 Jan 2005 20:53:11 -0000 1.10
+++ configure.in 6 Aug 2005 20:35:15 -0000
@@ -39,7 +39,7 @@
AC_PATH_XTRA
dnl ===========================================================================
-PKG_CHECK_MODULES(GTKCAIRO, gtk+-2.0 cairo >= 0.1.1)
+PKG_CHECK_MODULES(GTKCAIRO, gtk+-2.0 cairo >= 0.6.0)
AC_SUBST(GTKCAIRO_CFLAGS)
AC_SUBST(GTKCAIRO_LIBS)
Index: gtkcairo/gdkcairo.c
===================================================================
RCS file: /cvs/cairo/gtkcairo/gtkcairo/gdkcairo.c,v
retrieving revision 1.14
diff -u -b -r1.14 gdkcairo.c
--- gtkcairo/gdkcairo.c 30 Mar 2005 12:54:35 -0000 1.14
+++ gtkcairo/gdkcairo.c 6 Aug 2005 20:35:15 -0000
@@ -29,13 +29,16 @@
#include <cairo-xlib.h>
#endif
+#ifdef CAIRO_HAS_GLITZ_SURFACE
+#include <cairo-glitz.h>
+#endif
+
static void
gdkcairo_init (gdkcairo_t *self,
GtkWidget *widget)
{
self->widget = widget;
- self->cr = cairo_create ();
-
+ self->cr = NULL;
self->backend = GDKCAIRO_BACKEND_IMAGE;
#ifdef CAIRO_HAS_XLIB_SURFACE
@@ -110,11 +113,22 @@
void
gdkcairo_destroy (gdkcairo_t *self)
{
- if (self->cr)
+ GtkWidget *widget = self->widget;
+
+ if (self->cr != NULL)
{
cairo_destroy (self->cr);
self->cr = NULL;
}
+#ifdef USE_GL
+ if (self->glitz_surface != NULL)
+ {
+ glitz_surface_destroy (self->glitz_surface);
+ self->glitz_surface = NULL;
+ }
+#endif
+ /* FIXME: gtk_style_detach (self->widget->style) is missing */
+ /* FIXME: how is self freed? */
}
void
@@ -199,6 +213,7 @@
glitz_drawable_t *drawable;
glitz_format_t *format;
XID xid;
+ cairo_surface_t *cr_surface;
vinfo = glitz_glx_get_visual_info_from_format (dpy, screen,
dformat);
@@ -237,7 +252,9 @@
glitz_drawable_destroy (drawable);
- cairo_set_target_glitz (self->cr, self->glitz_surface);
+ cr_surface = cairo_glitz_surface_create (self->glitz_surface);
+ self->cr = cairo_create (cr_surface);
+ cairo_surface_destroy (cr_surface);
}
else
{
@@ -281,11 +298,15 @@
glitz_format_t *format;
glitz_drawable_t *drawable;
glitz_drawable_format_t *dformat;
+ cairo_surface_t *cr_surface;
format = glitz_surface_get_format (self->glitz_surface);
drawable = glitz_surface_get_drawable (self->glitz_surface);
+ glitz_drawable_reference (drawable);
dformat = glitz_drawable_get_format (drawable);
+ cairo_destroy(self->cr);
+
glitz_surface_destroy (self->glitz_surface);
glitz_drawable_update_size (drawable, width, height);
@@ -293,6 +314,7 @@
self->glitz_surface =
glitz_surface_create (drawable, format, width, height,
0, NULL);
+ glitz_drawable_destroy(drawable);
glitz_surface_attach (self->glitz_surface,
drawable,
@@ -300,7 +322,9 @@
GLITZ_DRAWABLE_BUFFER_BACK_COLOR :
GLITZ_DRAWABLE_BUFFER_FRONT_COLOR, 0, 0);
- cairo_set_target_glitz (self->cr, self->glitz_surface);
+ cr_surface = cairo_glitz_surface_create (self->glitz_surface);
+ self->cr = cairo_create (cr_surface);
+ cairo_surface_destroy(cr_surface);
}
break;
@@ -337,7 +361,11 @@
cairo_fill (self->cr);
cairo_restore (self->cr);
+ cairo_save (self->cr);
g_signal_emit_by_name (self->widget, "paint", self->cr);
+ cairo_restore (self->cr);
+
+ /* FIXME: flush cairo first. */
drawable = glitz_surface_get_drawable (self->glitz_surface);
dformat = glitz_drawable_get_format (drawable);
@@ -356,28 +384,28 @@
{
GdkDrawable *gdkdrawable;
gint x_off, y_off;
+ gint width, height;
+ cairo_surface_t *x11_surface;
+ /* find drawable, offset and size */
gdk_window_get_internal_paint_info (widget->window,
&gdkdrawable, &x_off, &y_off);
+ gdk_drawable_get_size (gdkdrawable, &width, &height);
- cairo_set_target_drawable (self->cr,
- gdk_x11_drawable_get_xdisplay
- (gdkdrawable),
- gdk_x11_drawable_get_xid (gdkdrawable));
+ x11_surface = cairo_xlib_surface_create
+ (gdk_x11_drawable_get_xdisplay (gdkdrawable),
+ gdk_x11_drawable_get_xid (gdkdrawable),
+ gdk_x11_visual_get_xvisual (gdk_drawable_get_visual (gdkdrawable)),
+ width, height);
+ cairo_surface_set_device_offset (x11_surface, -x_off, -y_off);
- /* counter offset of expose */
- if (x_off || y_off)
- {
- cairo_save (self->cr);
- cairo_translate (self->cr, -x_off, -y_off);
- }
+ self->cr = cairo_create (x11_surface);
+ cairo_surface_destroy (x11_surface);
g_signal_emit_by_name (self->widget, "paint", self->cr);
- if (x_off || y_off)
- {
- cairo_restore (self->cr);
- }
+ cairo_destroy (self->cr);
+ self->cr = NULL;
}
break;
#endif
Index: gtkcairo/gtkcairo.c
===================================================================
RCS file: /cvs/cairo/gtkcairo/gtkcairo/gtkcairo.c,v
retrieving revision 1.18
diff -u -b -r1.18 gtkcairo.c
--- gtkcairo/gtkcairo.c 11 Dec 2004 16:04:42 -0000 1.18
+++ gtkcairo/gtkcairo.c 6 Aug 2005 20:35:15 -0000
@@ -177,9 +177,7 @@
gtkcairo = GTK_CAIRO (widget);
- cairo_save (gtk_cairo_get_cairo (gtkcairo));
gdkcairo_expose (gtkcairo->gdkcairo, event);
- cairo_restore (gtk_cairo_get_cairo (gtkcairo));
return FALSE;
}
@@ -201,7 +199,7 @@
green = color->green / 65535.0;
blue = color->blue / 65535.0;
- cairo_set_rgb_color (cr, red, green, blue);
+ cairo_set_source_rgb (cr, red, green, blue);
}
int
Index: tests/demo.c
===================================================================
RCS file: /cvs/cairo/gtkcairo/tests/demo.c,v
retrieving revision 1.9
diff -u -b -r1.9 demo.c
--- tests/demo.c 11 Dec 2004 16:04:42 -0000 1.9
+++ tests/demo.c 6 Aug 2005 20:35:15 -0000
@@ -21,12 +21,12 @@
gint box_size = (width + height) / 6;
cairo_save (cairo);
- cairo_default_matrix (cairo);
+ cairo_identity_matrix (cairo);
cairo_translate (cairo, width / 2, height / 2);
cairo_rotate (cairo, gtk_range_get_value (range));
cairo_rectangle (cairo, -box_size, -box_size, box_size, box_size);
- cairo_set_rgb_color (cairo, 1, 0, 0);
+ cairo_set_source_rgb (cairo, 1, 0, 0);
cairo_fill (cairo);
cairo_restore (cairo);
}
More information about the cairo
mailing list