[cairo-commit] 4 commits - src/cairo-gstate.c src/cairo-xlib-display.c src/cairo-xlib-private.h src/cairo-xlib-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Aug 14 02:44:13 PDT 2008


 src/cairo-gstate.c       |   33 +++++++++++++++++++++++++--------
 src/cairo-xlib-display.c |   13 ++++++-------
 src/cairo-xlib-private.h |    5 ++---
 src/cairo-xlib-surface.c |   24 ++++++++++++------------
 4 files changed, 45 insertions(+), 30 deletions(-)

New commits:
commit 63befc6ab124059a8078493345d21463c4609f41
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 14 09:14:51 2008 +0100

    [xlib] Remove the key parameter from the close display hook.
    
    By inspecting all the users of the close display hooks, we can see that
    (a) the key is redundant and (b) the data is unique to the hook. This
    means we can trim the interface and stop the linear searches as soon as
    we've found the correct element.

diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index cdae8c9..895258d 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -326,7 +326,7 @@ UNLOCK:
 }
 
 cairo_bool_t
-_cairo_xlib_add_close_display_hook (Display *dpy, void (*func) (Display *, void *), void *data, const void *key)
+_cairo_xlib_add_close_display_hook (Display *dpy, void (*func) (Display *, void *), void *data)
 {
     cairo_xlib_display_t *display;
     cairo_xlib_hook_t *hook;
@@ -342,7 +342,6 @@ _cairo_xlib_add_close_display_hook (Display *dpy, void (*func) (Display *, void
 	if (hook != NULL) {
 	    hook->func = func;
 	    hook->data = data;
-	    hook->key = key;
 
 	    hook->next = display->close_display_hooks;
 	    display->close_display_hooks = hook;
@@ -357,7 +356,7 @@ _cairo_xlib_add_close_display_hook (Display *dpy, void (*func) (Display *, void
 }
 
 void
-_cairo_xlib_remove_close_display_hooks (Display *dpy, const void *key)
+_cairo_xlib_remove_close_display_hooks (Display *dpy, const void *data)
 {
     cairo_xlib_display_t *display;
     cairo_xlib_hook_t *hook, *next, **prev;
@@ -370,13 +369,13 @@ _cairo_xlib_remove_close_display_hooks (Display *dpy, const void *key)
     prev = &display->close_display_hooks;
     for (hook = display->close_display_hooks; hook != NULL; hook = next) {
 	next = hook->next;
-	if (hook->key == key) {
+	if (hook->data == data) {
 	    *prev = hook->next;
 	    _cairo_freelist_free (&display->hook_freelist, hook);
-	} else
-	    prev = &hook->next;
+	    break;
+	}
+	prev = &hook->next;
     }
-    *prev = NULL;
     CAIRO_MUTEX_UNLOCK (display->mutex);
 
     _cairo_xlib_display_destroy (display);
diff --git a/src/cairo-xlib-private.h b/src/cairo-xlib-private.h
index b8ca027..61ce889 100644
--- a/src/cairo-xlib-private.h
+++ b/src/cairo-xlib-private.h
@@ -51,7 +51,6 @@ struct _cairo_xlib_hook {
     cairo_xlib_hook_t *next;
     void (*func) (Display *display, void *data);
     void *data;
-    const void *key;
 };
 
 struct _cairo_xlib_display {
@@ -113,9 +112,9 @@ cairo_private void
 _cairo_xlib_display_destroy (cairo_xlib_display_t *info);
 
 cairo_private cairo_bool_t
-_cairo_xlib_add_close_display_hook (Display *display, void (*func) (Display *, void *), void *data, const void *key);
+_cairo_xlib_add_close_display_hook (Display *display, void (*func) (Display *, void *), void *data);
 cairo_private void
-_cairo_xlib_remove_close_display_hooks (Display *display, const void *key);
+_cairo_xlib_remove_close_display_hooks (Display *display, const void *data);
 
 cairo_private cairo_status_t
 _cairo_xlib_display_queue_work (cairo_xlib_display_t *display,
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 2fb46c2..4877e7e 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2436,7 +2436,8 @@ _cairo_xlib_surface_create_internal (Display		       *dpy,
     }
 
     if (! _cairo_xlib_add_close_display_hook (dpy,
-	    _cairo_xlib_surface_detach_display, surface, surface)) {
+	    _cairo_xlib_surface_detach_display, surface))
+    {
 	free (surface);
 	_cairo_xlib_screen_info_destroy (screen_info);
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
@@ -3011,7 +3012,7 @@ _cairo_xlib_surface_font_init (Display		    *dpy,
 
     if (! _cairo_xlib_add_close_display_hook (dpy,
 		                         _cairo_xlib_surface_remove_scaled_font,
-					 scaled_font, scaled_font))
+					 scaled_font))
     {
 	free (font_private);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
commit 84a541a041c6bb22c57517e267dc7adcfd7e84dc
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Nov 7 00:12:00 2007 +0000

    [cairo-xlib-surface] Remove status return for SUCCESS only function.
    
    Convert _cairo_xlib_surface_set_repeat() to a void return type, and
    update caller, as the function can only return CAIRO_STATUS_SUCCESS.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 2d3660e..2fb46c2 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1324,25 +1324,23 @@ _cairo_xlib_surface_set_filter (cairo_xlib_surface_t *surface,
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static void
 _cairo_xlib_surface_set_repeat (cairo_xlib_surface_t *surface, int repeat)
 {
     XRenderPictureAttributes pa;
     unsigned long	     mask;
 
     if (!surface->src_picture)
-	return CAIRO_STATUS_SUCCESS;
+	return;
 
     if (surface->repeat == repeat)
-	return CAIRO_STATUS_SUCCESS;
+	return;
 
     mask = CPRepeat;
     pa.repeat = repeat;
 
     XRenderChangePicture (surface->dpy, surface->src_picture, mask, &pa);
     surface->repeat = repeat;
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_int_status_t
@@ -1359,18 +1357,16 @@ _cairo_xlib_surface_set_attributes (cairo_xlib_surface_t	    *surface,
 
     switch (attributes->extend) {
     case CAIRO_EXTEND_NONE:
-	status = _cairo_xlib_surface_set_repeat (surface, 0);
+	_cairo_xlib_surface_set_repeat (surface, 0);
 	break;
     case CAIRO_EXTEND_REPEAT:
-	status = _cairo_xlib_surface_set_repeat (surface, 1);
+	_cairo_xlib_surface_set_repeat (surface, 1);
 	break;
     case CAIRO_EXTEND_REFLECT:
     case CAIRO_EXTEND_PAD:
     default:
-	status = CAIRO_INT_STATUS_UNSUPPORTED;
+	return CAIRO_INT_STATUS_UNSUPPORTED;
     }
-    if (status)
-	return status;
 
     status = _cairo_xlib_surface_set_filter (surface, attributes->filter);
     if (status)
commit 2699a986d3fe81d604c952513c62c896a95f1a3d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Nov 8 11:47:31 2007 +0000

    [cairo-gstate] Guard against unsetting the font unnecessary.
    
    Only unset the current font if we change any of the font settings, i.e.
    font_face, font_options, font_matrix and ctm.

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index b1c4627..2db9b36 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -99,8 +99,9 @@ _cairo_gstate_init (cairo_gstate_t  *gstate,
     gstate->parent_target = NULL;
     gstate->original_target = cairo_surface_reference (target);
 
-    _cairo_gstate_identity_matrix (gstate);
-    gstate->source_ctm_inverse = gstate->ctm_inverse;
+    cairo_matrix_init_identity (&gstate->ctm);
+    gstate->ctm_inverse = gstate->ctm;
+    gstate->source_ctm_inverse = gstate->ctm;
 
     gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK,
 						  CAIRO_CONTENT_COLOR);
@@ -653,6 +654,9 @@ _cairo_gstate_transform (cairo_gstate_t	      *gstate,
     cairo_matrix_t tmp;
     cairo_status_t status;
 
+    if (_cairo_matrix_is_identity (matrix))
+	return CAIRO_STATUS_SUCCESS;
+
     tmp = *matrix;
     status = cairo_matrix_invert (&tmp);
     if (status)
@@ -676,6 +680,9 @@ _cairo_gstate_set_matrix (cairo_gstate_t       *gstate,
 {
     cairo_status_t status;
 
+    if (memcmp (matrix, &gstate->ctm, sizeof (cairo_matrix_t)) == 0)
+	return CAIRO_STATUS_SUCCESS;
+
     if (! _cairo_matrix_is_invertible (matrix))
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
 
@@ -692,6 +699,9 @@ _cairo_gstate_set_matrix (cairo_gstate_t       *gstate,
 void
 _cairo_gstate_identity_matrix (cairo_gstate_t *gstate)
 {
+    if (_cairo_matrix_is_identity (&gstate->ctm))
+	return;
+
     _cairo_gstate_unset_scaled_font (gstate);
 
     cairo_matrix_init_identity (&gstate->ctm);
@@ -1240,6 +1250,9 @@ cairo_status_t
 _cairo_gstate_set_font_matrix (cairo_gstate_t	    *gstate,
 			       const cairo_matrix_t *matrix)
 {
+    if (memcmp (matrix, &gstate->font_matrix, sizeof (cairo_matrix_t)) == 0)
+	return CAIRO_STATUS_SUCCESS;
+
     if (! _cairo_matrix_is_invertible (matrix))
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
 
@@ -1261,6 +1274,9 @@ void
 _cairo_gstate_set_font_options (cairo_gstate_t             *gstate,
 				const cairo_font_options_t *options)
 {
+    if (memcmp (options, &gstate->font_options, sizeof (cairo_font_options_t)) == 0)
+	return;
+
     _cairo_gstate_unset_scaled_font (gstate);
 
     _cairo_font_options_init_copy (&gstate->font_options, options);
@@ -1390,8 +1406,8 @@ _cairo_gstate_ensure_font_face (cairo_gstate_t *gstate)
 
 
     font_face = cairo_toy_font_face_create (CAIRO_FONT_FAMILY_DEFAULT,
-					     CAIRO_FONT_SLANT_DEFAULT,
-					     CAIRO_FONT_WEIGHT_DEFAULT);
+					    CAIRO_FONT_SLANT_DEFAULT,
+					    CAIRO_FONT_WEIGHT_DEFAULT);
     if (font_face->status)
 	return font_face->status;
 
@@ -1476,10 +1492,11 @@ _cairo_gstate_set_font_face (cairo_gstate_t    *gstate,
     if (font_face && font_face->status)
 	return font_face->status;
 
-    if (font_face != gstate->font_face) {
-	cairo_font_face_destroy (gstate->font_face);
-	gstate->font_face = cairo_font_face_reference (font_face);
-    }
+    if (font_face == gstate->font_face)
+	return CAIRO_STATUS_SUCCESS;
+
+    cairo_font_face_destroy (gstate->font_face);
+    gstate->font_face = cairo_font_face_reference (font_face);
 
     _cairo_gstate_unset_scaled_font (gstate);
 
commit 8552e76ee5b2da2f4c39f916981fad7873974506
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 14 08:25:58 2008 +0100

    [xlib] Fix leak of pending_free_glyphs on CloseDisplay.
    
    Missing free of the pending_free_glyphs array in
    _cairo_xlib_surface_remove_scaled_font.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 0ad279b..2d3660e 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2992,6 +2992,9 @@ _cairo_xlib_surface_remove_scaled_font (Display *dpy,
 	    glyphset_info = &font_private->glyphset_info[i];
 	    if (glyphset_info->glyphset)
 		XRenderFreeGlyphSet (dpy, glyphset_info->glyphset);
+
+	    if (glyphset_info->pending_free_glyphs != NULL)
+		free (glyphset_info->pending_free_glyphs);
 	}
 
 	_cairo_xlib_display_destroy (font_private->display);


More information about the cairo-commit mailing list