[cairo-commit] 8 commits - boilerplate/Makefile.am perf/cairo-perf-diff perf/cairo-perf-diff-files.c src/cairo-cache.c src/cairo-clip.c src/cairo-ps-surface.c src/cairo-scaled-font.c src/cairo-types-private.h src/.gitignore src/Makefile.am test/Makefile.am test/pdiff

Chris Wilson ickle at kemper.freedesktop.org
Sun Aug 17 03:43:21 PDT 2008


 boilerplate/Makefile.am      |    4 +
 perf/cairo-perf-diff         |    2 
 perf/cairo-perf-diff-files.c |   18 +++---
 src/.gitignore               |    2 
 src/Makefile.am              |    4 +
 src/cairo-cache.c            |   23 ++------
 src/cairo-clip.c             |   15 +++--
 src/cairo-ps-surface.c       |    2 
 src/cairo-scaled-font.c      |  120 +++++++++++++++++++++++++++++--------------
 src/cairo-types-private.h    |    1 
 test/Makefile.am             |    1 
 test/pdiff/Makefile.am       |    4 +
 12 files changed, 127 insertions(+), 69 deletions(-)

New commits:
commit 586dbaafe6ac8803c7d7b9ed38297486d47f60e9
Author: Peter O'Gorman <pogma at thewrittenword.com>
Date:   Fri Aug 15 14:46:22 2008 -0500

    Compile with old compilers
    
    Some compilers fail to compile non-constant struct initializers.

diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 8a7c98a..9f82db8 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -59,7 +59,7 @@ _cairo_clip_init (cairo_clip_t *clip, cairo_surface_t *target)
     clip->surface = NULL;
     clip->surface_rect.x = 0;
     clip->surface_rect.y = 0;
-    clip->surface_rect.width = 0;
+    clip->surface_rect.width  = 0;
     clip->surface_rect.height = 0;
 
     clip->serial = 0;
@@ -86,6 +86,7 @@ _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other)
 
     if (other->has_region) {
 	cairo_status_t status;
+
 	status = _cairo_region_copy (&clip->region, &other->region);
 	if (status) {
 	    _cairo_region_fini (&clip->region);
@@ -388,6 +389,7 @@ _cairo_clip_intersect_region (cairo_clip_t    *clip,
 	    clip->has_region = TRUE;
     } else {
 	cairo_region_t intersection;
+
         _cairo_region_init (&intersection);
 
 	status = _cairo_region_intersect (&intersection,
@@ -727,7 +729,7 @@ _cairo_clip_int_rect_to_user (cairo_gstate_t *gstate,
 
     user_rect->x = x1;
     user_rect->y = y1;
-    user_rect->width = x2 - x1;
+    user_rect->width  = x2 - x1;
     user_rect->height = y2 - y1;
 
     return is_tight;
@@ -764,9 +766,12 @@ _cairo_clip_copy_rectangle_list (cairo_clip_t *clip, cairo_gstate_t *gstate)
 	    }
 
 	    for (i = 0; i < n_boxes; ++i) {
-		cairo_rectangle_int_t clip_rect = { boxes[i].p1.x, boxes[i].p1.y,
-						    boxes[i].p2.x - boxes[i].p1.x,
-						    boxes[i].p2.y - boxes[i].p1.y };
+               cairo_rectangle_int_t clip_rect;
+
+               clip_rect.x = boxes[i].p1.x;
+               clip_rect.y = boxes[i].p1.y;
+               clip_rect.width  = boxes[i].p2.x - boxes[i].p1.x;
+               clip_rect.height = boxes[i].p2.y - boxes[i].p1.y;
 
 		if (!_cairo_clip_int_rect_to_user(gstate, &clip_rect, &rectangles[i])) {
 		    _cairo_error_throw (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE);
commit 3998040c1151ffbc3f8748ca430af5bd81ca92e4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Aug 17 11:35:58 2008 +0100

    [cairo-cache] Simplify a status return to boolean.
    
    _cairo_cache_remove_random() just returned whether it found an entry to
    remove and so the code can be simplified by returning a boolean as opposed
    to a status code.

diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index bb5c719..16acbda 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -239,22 +239,21 @@ _cairo_cache_lookup (cairo_cache_t	  *cache,
  *
  * Remove a random entry from the cache.
  *
- * Return value: %CAIRO_STATUS_SUCCESS if an entry was successfully
- * removed. %CAIRO_INT_STATUS_CACHE_EMPTY if there are no entries that
- * can be removed.
+ * Return value: TRUE if an entry was successfully removed.
+ * FALSE if there are no entries that can be removed.
  **/
-static cairo_int_status_t
+static cairo_bool_t
 _cairo_cache_remove_random (cairo_cache_t *cache)
 {
     cairo_cache_entry_t *entry;
 
     entry = _cairo_hash_table_random_entry (cache->hash_table, NULL);
     if (entry == NULL)
-	return CAIRO_INT_STATUS_CACHE_EMPTY;
+	return FALSE;
 
     _cairo_cache_remove (cache, entry);
 
-    return CAIRO_STATUS_SUCCESS;
+    return TRUE;
 }
 
 /**
@@ -269,20 +268,14 @@ _cairo_cache_remove_random (cairo_cache_t *cache)
  **/
 static void
 _cairo_cache_shrink_to_accommodate (cairo_cache_t *cache,
-				   unsigned long  additional)
+				    unsigned long  additional)
 {
-    cairo_int_status_t status;
-
     if (cache->freeze_count)
 	return;
 
     while (cache->size + additional > cache->max_size) {
-	status = _cairo_cache_remove_random (cache);
-	if (status) {
-	    if (status == CAIRO_INT_STATUS_CACHE_EMPTY)
-		return;
-	    ASSERT_NOT_REACHED;
-	}
+	if (! _cairo_cache_remove_random (cache))
+	    return;
     }
 }
 
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 02afdc0..f2a6f63 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -138,7 +138,6 @@ typedef enum _cairo_int_status {
     CAIRO_INT_STATUS_UNSUPPORTED = 100,
     CAIRO_INT_STATUS_DEGENERATE,
     CAIRO_INT_STATUS_NOTHING_TO_DO,
-    CAIRO_INT_STATUS_CACHE_EMPTY,
     CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY,
     CAIRO_INT_STATUS_IMAGE_FALLBACK,
     CAIRO_INT_STATUS_ANALYZE_META_SURFACE_PATTERN,
commit 841fe91c0e0ef0b88f84e8130b8e2afaa8abb610
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Aug 15 17:09:51 2008 +0100

    [ps] Promote char to an int to avoid valgrind warnings.
    
    valgrind warns about an uninitialized read after a single char is promoted
    to an int when passed to the printf. Silence the warning by using a
    explicitly promoting the output byte to a full int.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index e6ce3f3..fab3b31 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -410,7 +410,7 @@ _cairo_ps_emit_imagemask (cairo_image_surface_t *image,
 				 "   /DataSource   {<");
     for (row = image->data, rows = image->height; rows; row += image->stride, rows--) {
 	for (byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) {
-	    unsigned char output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
+	    unsigned int output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
 	    _cairo_output_stream_printf (stream, "%02x ", output_byte);
 	}
 	_cairo_output_stream_printf (stream, "\n   ");
commit 8f567279869432b4748dda2fed5c30056c68d44c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 14 18:22:47 2008 +0100

    [perf] Beware $OS may not be set.
    
    Avoid a warning by ensuring that the two strings in the equality check are
    not empty.

diff --git a/perf/cairo-perf-diff b/perf/cairo-perf-diff
index 18aa4dd..5094ec3 100755
--- a/perf/cairo-perf-diff
+++ b/perf/cairo-perf-diff
@@ -189,7 +189,7 @@ git_setup
 # Build cairo-perf-diff-files if not available
 if [ ! -e $CAIRO_DIR/perf/cairo-perf-diff-files ]; then
     echo "Building cairo-perf-diff-files"
-    if [ $OS = "Windows_NT" ]; then 
+    if [ "x$OS" = "xWindows_NT" ]; then
         make -f Makefile.win32 -C $CAIRO_DIR/perf/ cairo-perf-diff-files CFG=debug
     else
         make -C $CAIRO_DIR/perf/ cairo-perf-diff-files
commit c44f2ab4d1c975dfc6ba2f8a271da6b578c08983
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 14 18:21:22 2008 +0100

    [perf] Silence trivial compiler warning.
    
    The compiler complained about passing a non-string literal as the format
    to printf, so just to sanitize the code and keep the compiler happy, add
    the magic "%s" format.

diff --git a/perf/cairo-perf-diff-files.c b/perf/cairo-perf-diff-files.c
index 79d844c..9098c91 100644
--- a/perf/cairo-perf-diff-files.c
+++ b/perf/cairo-perf-diff-files.c
@@ -566,28 +566,28 @@ print_change_bar (double change, double max_change, int use_utf)
     change -= 1.0;
 
     while (change > units_per_cell) {
-	printf(boxes[0]);
+	printf ("%s", boxes[0]);
 	change -= units_per_cell;
     }
 
     change /= units_per_cell;
 
     if (change > 7.5/8.0)
-	printf(boxes[0]);
+	printf ("%s", boxes[0]);
     else if (change > 6.5/8.0)
-	printf(boxes[1]);
+	printf ("%s", boxes[1]);
     else if (change > 5.5/8.0)
-	printf(boxes[2]);
+	printf ("%s", boxes[2]);
     else if (change > 4.5/8.0)
-	printf(boxes[3]);
+	printf ("%s", boxes[3]);
     else if (change > 3.5/8.0)
-	printf(boxes[4]);
+	printf ("%s", boxes[4]);
     else if (change > 2.5/8.0)
-	printf(boxes[5]);
+	printf ("%s", boxes[5]);
     else if (change > 1.5/8.0)
-	printf(boxes[6]);
+	printf ("%s", boxes[6]);
     else if (change > 0.5/8.0)
-	printf(boxes[7]);
+	printf ("%s", boxes[7]);
 
     printf ("\n");
 }
commit db7e3cb85467496686289d1a666b4ca274524fdd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 14 16:30:54 2008 +0100

    [Makefile.am] Delete intermediates
    
    Clean up after calling 'gcc -save-temps'.

diff --git a/boilerplate/Makefile.am b/boilerplate/Makefile.am
index fdf46fa..b025acd 100644
--- a/boilerplate/Makefile.am
+++ b/boilerplate/Makefile.am
@@ -102,4 +102,8 @@ INCLUDES =					\
 CLEANFILES =					\
 	$(EXTRA_LTLIBRARIES)
 
+# Delete intermediate files as well
+clean-local:
+	-${FIND} . -name '*.[is]'   -print | ${XARGS} ${RM}
+
 check test: libcairoboilerplate.la
diff --git a/src/Makefile.am b/src/Makefile.am
index 24694fc..7869877 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -364,6 +364,10 @@ TESTS = check-def.sh check-plt.sh check-headers.sh check-cairoint.sh check-doc-s
 EXTRA_DIST += $(TESTS) check-has-hidden-symbols.c
 DISTCLEANFILES += check-has-hidden-symbols.i
 
+# Delete intermediate files as well
+clean-local:
+	-${FIND} . -name '*.[is]'   -print | ${XARGS} ${RM}
+
 # The pre-processed result is used by check-{def,plt}.sh to determine whether
 # cairo has been compiled with symbol hiding.
 .c.i: $(cairoinclude_HEADERS) $(nodist_cairoinclude_HEADERS) cairoint.h $(top_builddir)/config.h
diff --git a/test/Makefile.am b/test/Makefile.am
index 939640e..dd1cb90 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -921,6 +921,7 @@ clean-local:
 	-${FIND} . -name '*-out.png'  -print | ${XARGS} ${RM}
 	-${FIND} . -name '*-diff.png' -print | ${XARGS} ${RM}
 	-${FIND} . -name '*.log'      -print | ${XARGS} ${RM}
+	-${FIND} . -name '*.[is]'     -print | ${XARGS} ${RM}
 
 # The following definitions both should work.
 #FAILED_TESTS = `grep -l '\<FAIL\>' $(TESTS:$(EXEEXT)=.log) 2>/dev/null | sed -e 's/[.]log$$//' | xargs echo`
diff --git a/test/pdiff/Makefile.am b/test/pdiff/Makefile.am
index 7545907..6abae51 100644
--- a/test/pdiff/Makefile.am
+++ b/test/pdiff/Makefile.am
@@ -15,3 +15,7 @@ perceptualdiff_SOURCES =	\
 
 INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src $(CAIRO_CFLAGS)
 LDADD = libpdiff.la $(top_builddir)/src/libcairo.la
+#
+# Delete intermediate files as well
+clean-local:
+	-${FIND} . -name '*.[is]'   -print | ${XARGS} ${RM}
commit 67326b728bca24dc02df7f144b9471636d5e1d4c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Aug 14 16:25:49 2008 +0100

    [gitignore] Ignore *.[is]
    
    Playing with 'gcc -save-temps' understandably leaves behind large amounts
    of clutter.

diff --git a/src/.gitignore b/src/.gitignore
index 551aa8f..04dcae3 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -11,6 +11,8 @@ Makefile.in
 cairo-features.h
 cairo-no-features.h
 cairo.def
+*.i
+*.s
 *.o
 *.obj
 *.pdb
commit bafcbc633a12ae50cbafd579a03d12260ac3e04a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Nov 8 22:27:39 2007 +0000

    [cairo-scaled-font] Check the most recently used font used first.
    
    When searching for a matching font, check the most recently used font
    first. This optimizes the common case where pango calls save() and restore()
    around rendering each layout, but almost all consecutive layouts use the
    same font.

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 9ac43d1..889c060 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -299,6 +299,7 @@ slim_hidden_def (cairo_scaled_font_status);
 #define CAIRO_SCALED_FONT_MAX_HOLDOVERS 256
 
 typedef struct _cairo_scaled_font_map {
+    cairo_scaled_font_t *mru_scaled_font;
     cairo_hash_table_t *hash_table;
     cairo_scaled_font_t *holdovers[CAIRO_SCALED_FONT_MAX_HOLDOVERS];
     int num_holdovers;
@@ -319,6 +320,7 @@ _cairo_scaled_font_map_lock (void)
 	if (cairo_scaled_font_map == NULL)
 	    goto CLEANUP_MUTEX_LOCK;
 
+	cairo_scaled_font_map->mru_scaled_font = NULL;
 	cairo_scaled_font_map->hash_table =
 	    _cairo_hash_table_create (_cairo_scaled_font_keys_equal);
 
@@ -358,11 +360,17 @@ _cairo_scaled_font_map_destroy (void)
         goto CLEANUP_MUTEX_LOCK;
     }
 
+    scaled_font = font_map->mru_scaled_font;
+    if (scaled_font != NULL) {
+	CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_map_mutex);
+	cairo_scaled_font_destroy (scaled_font);
+	CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex);
+    }
+
     /* remove scaled_fonts starting from the end so that font_map->holdovers
      * is always in a consistent state when we release the mutex. */
     while (font_map->num_holdovers) {
 	scaled_font = font_map->holdovers[font_map->num_holdovers-1];
-
 	assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count));
 	_cairo_hash_table_remove (font_map->hash_table,
 				  &scaled_font->hash_entry);
@@ -745,7 +753,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 {
     cairo_status_t status;
     cairo_scaled_font_map_t *font_map;
-    cairo_scaled_font_t key, *scaled_font = NULL;
+    cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL;
 
     if (font_face->status)
 	return _cairo_scaled_font_create_in_error (font_face->status);
@@ -763,42 +771,12 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 
     _cairo_scaled_font_init_key (&key, font_face,
 				 font_matrix, ctm, options);
-
-
-    while (_cairo_hash_table_lookup (font_map->hash_table, &key.hash_entry,
-				     (cairo_hash_entry_t**) &scaled_font))
-    {
-	if (!scaled_font->placeholder)
-	    break;
-
-	/* If the scaled font is being created (happens for user-font),
-	 * just wait until it's done, then retry */
-	_cairo_scaled_font_placeholder_wait_for_creation_to_finish (scaled_font);
-    }
-
-    /* Return existing scaled_font if it exists in the hash table. */
-    if (scaled_font)
+    scaled_font = font_map->mru_scaled_font;
+    if (scaled_font != NULL &&
+	scaled_font->hash_entry.hash == key.hash_entry.hash &&
+	_cairo_scaled_font_keys_equal (scaled_font, &key))
     {
-	/* If the original reference count is 0, then this font must have
-	 * been found in font_map->holdovers, (which means this caching is
-	 * actually working). So now we remove it from the holdovers
-	 * array. */
-	if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) {
-	    int i;
-
-	    for (i = 0; i < font_map->num_holdovers; i++)
-		if (font_map->holdovers[i] == scaled_font)
-		    break;
-	    assert (i < font_map->num_holdovers);
-
-	    font_map->num_holdovers--;
-	    memmove (&font_map->holdovers[i],
-		     &font_map->holdovers[i+1],
-		     (font_map->num_holdovers - i) * sizeof (cairo_scaled_font_t*));
-
-	    /* reset any error status */
-	    scaled_font->status = CAIRO_STATUS_SUCCESS;
-	}
+	assert (! scaled_font->placeholder);
 
 	if (scaled_font->status == CAIRO_STATUS_SUCCESS) {
 	    /* We increment the reference count manually here, (rather
@@ -814,6 +792,66 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	_cairo_hash_table_remove (font_map->hash_table, &key.hash_entry);
 	scaled_font->hash_entry.hash = ZOMBIE;
     }
+    else
+    {
+	while (_cairo_hash_table_lookup (font_map->hash_table, &key.hash_entry,
+					 (cairo_hash_entry_t**) &scaled_font))
+	{
+	    if (! scaled_font->placeholder)
+		break;
+
+	    /* If the scaled font is being created (happens for user-font),
+	     * just wait until it's done, then retry */
+	    _cairo_scaled_font_placeholder_wait_for_creation_to_finish (scaled_font);
+	}
+
+	/* Return existing scaled_font if it exists in the hash table. */
+	if (scaled_font != NULL) {
+	    /* If the original reference count is 0, then this font must have
+	     * been found in font_map->holdovers, (which means this caching is
+	     * actually working). So now we remove it from the holdovers
+	     * array. */
+	    if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) {
+		int i;
+
+		for (i = 0; i < font_map->num_holdovers; i++)
+		    if (font_map->holdovers[i] == scaled_font)
+			break;
+		assert (i < font_map->num_holdovers);
+
+		font_map->num_holdovers--;
+		memmove (&font_map->holdovers[i],
+			 &font_map->holdovers[i+1],
+			 (font_map->num_holdovers - i) * sizeof (cairo_scaled_font_t*));
+
+		/* reset any error status */
+		scaled_font->status = CAIRO_STATUS_SUCCESS;
+	    }
+
+	    if (scaled_font->status == CAIRO_STATUS_SUCCESS) {
+		/* We increment the reference count manually here, (rather
+		 * than calling into cairo_scaled_font_reference), since we
+		 * must modify the reference count while our lock is still
+		 * held. */
+
+		old = font_map->mru_scaled_font;
+		font_map->mru_scaled_font = scaled_font;
+		/* increment reference count for the mru cache */
+		_cairo_reference_count_inc (&scaled_font->ref_count);
+		/* and increment for the returned reference */
+		_cairo_reference_count_inc (&scaled_font->ref_count);
+		_cairo_scaled_font_map_unlock ();
+
+		cairo_scaled_font_destroy (old);
+
+		return scaled_font;
+	    }
+
+	    /* the font has been put into an error status - abandon the cache */
+	    _cairo_hash_table_remove (font_map->hash_table, &key.hash_entry);
+	    scaled_font->hash_entry.hash = ZOMBIE;
+	}
+    }
 
     /* Otherwise create it and insert it into the hash table. */
     status = font_face->backend->scaled_font_create (font_face, font_matrix,
@@ -826,6 +864,12 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 
     status = _cairo_hash_table_insert (font_map->hash_table,
 				       &scaled_font->hash_entry);
+    if (status == CAIRO_STATUS_SUCCESS) {
+	old = font_map->mru_scaled_font;
+	font_map->mru_scaled_font = scaled_font;
+	_cairo_reference_count_inc (&scaled_font->ref_count);
+    }
+
     _cairo_scaled_font_map_unlock ();
 
     if (status) {
@@ -837,6 +881,8 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	return _cairo_scaled_font_create_in_error (status);
     }
 
+    cairo_scaled_font_destroy (old);
+
     return scaled_font;
 }
 slim_hidden_def (cairo_scaled_font_create);


More information about the cairo-commit mailing list