[cairo] to much roundtrips in the x11 backend

Alexander Larsson alexl at redhat.com
Mon Dec 20 07:05:24 PST 2004


_cairo_xlib_surface_create_similar, which gets called for each glyph
when rendering text has a roundtrip (XGetGeometry) that is killing
performance. Here is a fix:

Index: src/cairo_xlib_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_xlib_surface.c,v
retrieving revision 1.28
diff -u -p -r1.28 cairo_xlib_surface.c
--- src/cairo_xlib_surface.c	5 Nov 2004 18:57:50 -0000	1.28
+++ src/cairo_xlib_surface.c	20 Dec 2004 15:02:19 -0000
@@ -118,6 +118,16 @@ _CAIRO_FORMAT_DEPTH (cairo_format_t form
 }
 
 static cairo_surface_t *
+_cairo_xlib_surface_create_with_size (Display		*dpy,
+				      Drawable		drawable,
+				      Visual		*visual,
+				      cairo_format_t	format,
+				      Colormap		colormap,
+				      int               width,
+				      int               height);
+
+
+static cairo_surface_t *
 _cairo_xlib_surface_create_similar (void		*abstract_src,
 				    cairo_format_t	format,
 				    int			drawable,
@@ -149,7 +159,8 @@ _cairo_xlib_surface_create_similar (void
 			 _CAIRO_FORMAT_DEPTH (format));
     
     surface = (cairo_xlib_surface_t *)
-	cairo_xlib_surface_create (dpy, pix, NULL, format, DefaultColormap (dpy, scr));
+	_cairo_xlib_surface_create_with_size (dpy, pix, NULL, format, DefaultColormap (dpy, scr),
+					      width, height);
     surface->owns_pixmap = 1;
 
     surface->width = width;
@@ -199,6 +210,7 @@ _cairo_xlib_surface_get_image (void *abs
 		  &surface->width, &surface->height,
 		  &bwidth_ignore, &depth_ignore);
 
+    /* XXX: This should try to use the XShm extension if availible */
     ximage = XGetImage (surface->dpy,
 			surface->drawable,
 			0, 0,
@@ -709,17 +721,20 @@ static const struct cairo_surface_backen
     _cairo_xlib_surface_show_glyphs
 };
 
-cairo_surface_t *
-cairo_xlib_surface_create (Display		*dpy,
-			   Drawable		drawable,
-			   Visual		*visual,
-			   cairo_format_t	format,
-			   Colormap		colormap)
+static cairo_surface_t *
+_cairo_xlib_surface_create_with_size (Display		*dpy,
+				      Drawable		drawable,
+				      Visual		*visual,
+				      cairo_format_t	format,
+				      Colormap		colormap,
+				      int               width,
+				      int               height)
 {
     cairo_xlib_surface_t *surface;
     int render_standard;
     Window w;
     unsigned int ignore;
+    int drawable_width, drawable_height;
 
     surface = malloc (sizeof (cairo_xlib_surface_t));
     if (surface == NULL)
@@ -758,12 +773,20 @@ cairo_xlib_surface_create (Display		*dpy
 	break;
     }
 
-    XGetGeometry(dpy, drawable, 
-		 &w, &ignore, &ignore, 
-		 &surface->width,
-		 &surface->height,
-		 &ignore, &ignore);
-
+    if (width < 0 || height < 0)
+    {
+	/* Note: This call is a roundtrip. */
+	XGetGeometry(dpy, drawable, 
+		     &w, &ignore, &ignore, 
+		     &drawable_width,
+		     &drawable_height,
+		     &ignore, &ignore);
+	if (width <= 0)
+	    width = drawable_width;
+	if (height <= 0)
+	    height = drawable_height;
+    }
+      
     /* XXX: I'm currently ignoring the colormap. Is that bad? */
     if (CAIRO_SURFACE_RENDER_HAS_CREATE_PICTURE (surface))
 	surface->picture = XRenderCreatePicture (dpy, drawable,
@@ -776,6 +799,17 @@ cairo_xlib_surface_create (Display		*dpy
 
     return (cairo_surface_t *) surface;
 }
+
+cairo_surface_t *
+cairo_xlib_surface_create (Display		*dpy,
+			   Drawable		drawable,
+			   Visual		*visual,
+			   cairo_format_t	format,
+			   Colormap		colormap)
+{
+  return _cairo_xlib_surface_create_with_size (dpy, drawable, visual, format,
+					       colormap, -1, -1);
+}
 DEPRECATE (cairo_surface_create_for_drawable, cairo_xlib_surface_create);
 
 


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl at redhat.com    alla at lysator.liu.se 
He's an immortal guerilla barbarian from a doomed world. She's a 
sharp-shooting streetsmart socialite fleeing from a Satanic cult. They fight 
crime! 




More information about the cairo mailing list