Cache the cairo context for the pixmap. I'm not really sure if this cpw.qulogic.cairo

Sat, 21 Aug 2010 06:04:13 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sat, 21 Aug 2010 06:04:13 +0000
branch
cpw.qulogic.cairo
changeset 30698
ef2d03910e90
parent 30697
c3db46195e97
child 31207
c145118f9237

Cache the cairo context for the pixmap. I'm not really sure if this
makes things any faster or anything.

pidgin/gtkwhiteboard.c file | annotate | diff | comparison | revisions
--- a/pidgin/gtkwhiteboard.c	Sat Aug 21 05:42:17 2010 +0000
+++ b/pidgin/gtkwhiteboard.c	Sat Aug 21 06:04:13 2010 +0000
@@ -282,6 +282,9 @@
 	/* Clear graphical memory */
 	if(gtkwb->pixmap)
 	{
+		cairo_t *cr = g_object_get_data(G_OBJECT(gtkwb->pixmap), "cairo-context");
+		if (cr)
+			cairo_destroy(cr);
 		g_object_unref(gtkwb->pixmap);
 		gtkwb->pixmap = NULL;
 	}
@@ -356,8 +359,12 @@
 	GdkPixmap *pixmap = gtkwb->pixmap;
 	cairo_t *cr;
 
-	if(pixmap)
+	if (pixmap) {
+		cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context");
+		if (cr)
+			cairo_destroy(cr);
 		g_object_unref(pixmap);
+	}
 
 	pixmap = gdk_pixmap_new(widget->window,
 							widget->allocation.width,
@@ -366,12 +373,12 @@
 	gtkwb->pixmap = pixmap;
 
 	cr = gdk_cairo_create(GDK_DRAWABLE(pixmap));
+	g_object_set_data(G_OBJECT(pixmap), "cairo-context", cr);
 	gdk_cairo_set_source_color(cr, &widget->style->white);
 	cairo_rectangle(cr,
 	                0, 0,
 	                widget->allocation.width, widget->allocation.height);
 	cairo_fill(cr);
-	cairo_destroy(cr);
 
 	return TRUE;
 }
@@ -588,7 +595,7 @@
 	GtkWidget *widget = gtkwb->drawing_area;
 	GdkPixmap *pixmap = gtkwb->pixmap;
 
-	cairo_t *gfx_con = gdk_cairo_create(GDK_DRAWABLE(pixmap));
+	cairo_t *gfx_con = g_object_get_data(G_OBJECT(pixmap), "cairo-context");
 	GdkColor col;
 
 	/* Interpret and convert color */
@@ -606,8 +613,6 @@
 	gtk_widget_queue_draw_area(widget,
 							   x - size / 2, y - size / 2,
 							   size, size);
-
-	cairo_destroy(gfx_con);
 }
 
 /* Uses Bresenham's algorithm (as provided by Wikipedia) */
@@ -698,7 +703,7 @@
 	PidginWhiteboard *gtkwb = wb->ui_data;
 	GdkPixmap *pixmap = gtkwb->pixmap;
 	GtkWidget *drawing_area = gtkwb->drawing_area;
-	cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(pixmap));
+	cairo_t *cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context");
 
 	gdk_cairo_set_source_color(cr, &drawing_area->style->white);
 	cairo_rectangle(cr,
@@ -706,7 +711,6 @@
 	                drawing_area->allocation.width,
 	                drawing_area->allocation.height);
 	cairo_fill(cr);
-	cairo_destroy(cr);
 
 	gtk_widget_queue_draw_area(drawing_area,
 							   0, 0,

mercurial