[cairo-commit] src/cairo-xlib-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Apr 19 12:37:15 PDT 2007


 src/cairo-xlib-surface.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

New commits:
diff-tree 55ea0466e25de2c60171a9d6c96536bc2e7fb9e3 (from 7906a993403e75aa34b32d2d9338ec179896d765)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Apr 19 20:24:27 2007 +0100

    Embed simple clip XRectangles in cairo_xlib_surface_t
    
    Toolkits like GTK+ almost always set a simple rectangular clip mask before
    any cairo operation, so avoid the allocation for this simple case by
    embedding a small number of XRectangles into the surface structure.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 5eef3f1..4d53bdb 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -123,6 +123,7 @@ struct _cairo_xlib_surface {
     Picture dst_picture, src_picture;
 
     cairo_bool_t have_clip_rects;
+    XRectangle embedded_clip_rects[4];
     XRectangle *clip_rects;
     int num_clip_rects;
 
@@ -347,7 +348,7 @@ _cairo_xlib_surface_finish (void *abstra
     if (surface->gc != NULL)
 	XFreeGC (surface->dpy, surface->gc);
 
-    if (surface->clip_rects != NULL)
+    if (surface->clip_rects != surface->embedded_clip_rects)
 	free (surface->clip_rects);
 
     if (surface->screen_info != NULL)
@@ -1717,9 +1718,12 @@ _cairo_xlib_surface_set_clip_region (voi
 {
     cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface;
 
-    if (surface->clip_rects) {
+    if (surface->have_clip_rects == FALSE && region == NULL)
+	return CAIRO_STATUS_SUCCESS;
+
+    if (surface->clip_rects != surface->embedded_clip_rects) {
 	free (surface->clip_rects);
-	surface->clip_rects = NULL;
+	surface->clip_rects = surface->embedded_clip_rects;
     }
 
     surface->have_clip_rects = FALSE;
@@ -1741,12 +1745,12 @@ _cairo_xlib_surface_set_clip_region (voi
 	int n_boxes, i;
 
 	n_boxes = pixman_region_num_rects (region);
-	if (n_boxes > 0) {
+	if (n_boxes > ARRAY_LENGTH (surface->embedded_clip_rects)) {
 	    rects = malloc (sizeof(XRectangle) * n_boxes);
 	    if (rects == NULL)
 		return CAIRO_STATUS_NO_MEMORY;
-	} else {
-	    rects = NULL;
+	}else {
+	    rects = surface->embedded_clip_rects;
 	}
 
 	boxes = pixman_region_rects (region);
@@ -1950,7 +1954,7 @@ _cairo_xlib_surface_create_internal (Dis
     surface->xtransform = identity;
 
     surface->have_clip_rects = FALSE;
-    surface->clip_rects = NULL;
+    surface->clip_rects = surface->embedded_clip_rects;
     surface->num_clip_rects = 0;
 
     return (cairo_surface_t *) surface;


More information about the cairo-commit mailing list