[cairo-commit] 7 commits - src/cairo-array.c src/cairo-cache.c src/cairo-compiler-private.h src/cairo-hull.c src/cairo-pattern.c src/cairo-skiplist.c src/cairo-slope.c src/cairo-wideint-private.h test/.gitignore test/Makefile.am test/twin.c test/twin-ps2-ref.png test/twin-ps3-ref.png test/twin-ref.png

Chris Wilson ickle at kemper.freedesktop.org
Mon Oct 6 17:46:51 PDT 2008


 src/cairo-array.c            |   26 ++++++++++++++----
 src/cairo-cache.c            |    3 --
 src/cairo-compiler-private.h |    2 +
 src/cairo-hull.c             |   31 +++++++++++++---------
 src/cairo-pattern.c          |    5 +--
 src/cairo-skiplist.c         |   16 +++++++----
 src/cairo-slope.c            |   14 ++++------
 src/cairo-wideint-private.h  |    2 -
 test/.gitignore              |    1 
 test/Makefile.am             |    4 ++
 test/twin-ps2-ref.png        |binary
 test/twin-ps3-ref.png        |binary
 test/twin-ref.png            |binary
 test/twin.c                  |   60 +++++++++++++++++++++++++++++++++++++++++++
 14 files changed, 126 insertions(+), 38 deletions(-)

New commits:
commit 8cf399b944294645833088ee2ac1313093948b66
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 18:59:15 2008 +0100

    [test] Add a test to exercise the internal twin font
    
    Although Behdad promises that the rendering is subject to improvement,
    introduce a test to check consistency across platforms and update as
    required.

diff --git a/test/.gitignore b/test/.gitignore
index a0feadb..5b44c85 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -225,6 +225,7 @@ transforms
 translate-show-surface
 trap-clip
 truetype-tables
+twin
 unantialiased-shapes
 unbounded-operator
 user-data
diff --git a/test/Makefile.am b/test/Makefile.am
index df41a3d..9f01ca6 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -173,6 +173,7 @@ transforms$(EXEEXT)					\
 translate-show-surface$(EXEEXT)				\
 trap-clip$(EXEEXT)					\
 truetype-tables$(EXEEXT)				\
+twin$(EXEEXT)						\
 unantialiased-shapes$(EXEEXT)				\
 unbounded-operator$(EXEEXT)				\
 user-data$(EXEEXT)					\
@@ -868,6 +869,9 @@ REFERENCE_IMAGES = \
 	trap-clip-rgb24-ref.png	\
 	trap-clip-pdf-argb32-ref.png \
 	trap-clip-pdf-rgb24-ref.png \
+	twin-ref.png \
+	twin-ps2-ref.png \
+	twin-ps3-ref.png \
 	unantialiased-shapes-ref.png	\
 	unantialiased-shapes-quartz-ref.png \
 	unbounded-operator-ref.png	\
diff --git a/test/twin-ps2-ref.png b/test/twin-ps2-ref.png
new file mode 100644
index 0000000..a58dc5b
Binary files /dev/null and b/test/twin-ps2-ref.png differ
diff --git a/test/twin-ps3-ref.png b/test/twin-ps3-ref.png
new file mode 100644
index 0000000..a58dc5b
Binary files /dev/null and b/test/twin-ps3-ref.png differ
diff --git a/test/twin-ref.png b/test/twin-ref.png
new file mode 100644
index 0000000..f2a5636
Binary files /dev/null and b/test/twin-ref.png differ
diff --git a/test/twin.c b/test/twin.c
new file mode 100644
index 0000000..d114b86
--- /dev/null
+++ b/test/twin.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2008 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_draw_function_t draw;
+
+static const cairo_test_t test = {
+    "twin",
+    "Tests the internal font",
+    128, 20,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+    cairo_set_source_rgb (cr, 0, 0, 0);
+
+    cairo_select_font_face (cr,
+			    "cairo",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, 16);
+
+    cairo_move_to (cr, 4, 14);
+    cairo_show_text (cr, "Is cairo's twin giza?");
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
commit 1f813ff04022a36a91bf9d1b0f7f2ae1c63b399f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 17:55:37 2008 +0100

    [array] Silence gtk-doc complaints.
    
    gtk-doc fails make check for array as it insists that even the simplest
    functions must have a long description and cannot be entirely described by
    their arguments and return value.

diff --git a/src/cairo-array.c b/src/cairo-array.c
index 1b2c903..b2790c8 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -85,6 +85,7 @@ _cairo_array_init_snapshot (cairo_array_t	*array,
 
 /**
  * _cairo_array_fini:
+ * @array: A #cairo_array_t
  *
  * Free all resources associated with @array. After this call, @array
  * should not be used again without a subsequent call to
@@ -104,6 +105,7 @@ _cairo_array_fini (cairo_array_t *array)
 
 /**
  * _cairo_array_grow_by:
+ * @array: a #cairo_array_t
  *
  * Increase the size of @array (if needed) so that there are at least
  * @additional free spaces in the array. The actual size of the array
@@ -158,6 +160,7 @@ _cairo_array_grow_by (cairo_array_t *array, unsigned int additional)
 
 /**
  * _cairo_array_truncate:
+ * @array: a #cairo_array_t
  *
  * Truncate size of the array to @num_elements if less than the
  * current size. No memory is actually freed. The stored objects
@@ -174,14 +177,16 @@ _cairo_array_truncate (cairo_array_t *array, unsigned int num_elements)
 
 /**
  * _cairo_array_index:
+ * @array: a #cairo_array_t
+ * Returns: A pointer to the object stored at @index.
  *
- * Return value: A pointer to object stored at @index. If the
- * resulting value is assigned to a pointer to an object of the same
+ * If the resulting value is assigned to a pointer to an object of the same
  * element_size as initially passed to _cairo_array_init() then that
  * pointer may be used for further direct indexing with []. For
  * example:
  *
- * 	#cairo_array_t array;
+ * <informalexample><programlisting>
+ *	cairo_array_t array;
  *	double *values;
  *
  *	_cairo_array_init (&array, sizeof(double));
@@ -190,6 +195,7 @@ _cairo_array_truncate (cairo_array_t *array, unsigned int num_elements)
  *	values = _cairo_array_index (&array, 0);
  *      for (i = 0; i < _cairo_array_num_elements (&array); i++)
  *	    ... use values[i] here ...
+ * </programlisting></informalexample>
  **/
 void *
 _cairo_array_index (cairo_array_t *array, unsigned int index)
@@ -215,6 +221,7 @@ _cairo_array_index (cairo_array_t *array, unsigned int index)
 
 /**
  * _cairo_array_copy_element:
+ * @array: a #cairo_array_t
  *
  * Copy a single element out of the array from index @index into the
  * location pointed to by @dst.
@@ -227,6 +234,7 @@ _cairo_array_copy_element (cairo_array_t *array, int index, void *dst)
 
 /**
  * _cairo_array_append:
+ * @array: a #cairo_array_t
  *
  * Append a single item onto the array by growing the array by at
  * least one element, then copying element_size bytes from @element
@@ -250,6 +258,7 @@ _cairo_array_append (cairo_array_t	*array,
 
 /**
  * _cairo_array_append:
+ * @array: a #cairo_array_t
  *
  * Append one or more items onto the array by growing the array by
  * @num_elements, then copying @num_elements * element_size bytes from
@@ -280,6 +289,7 @@ _cairo_array_append_multiple (cairo_array_t	*array,
 
 /**
  * _cairo_array_allocate:
+ * @array: a #cairo_array_t
  *
  * Allocate space at the end of the array for @num_elements additional
  * elements, providing the address of the new memory chunk in
@@ -314,8 +324,10 @@ _cairo_array_allocate (cairo_array_t	 *array,
 
 /**
  * _cairo_array_num_elements:
+ * @array: a #cairo_array_t
+ * Returns: The number of elements stored in @array.
  *
- * Return value: The number of elements stored in @array.
+ * This space was left intentionally blank, but gtk-doc filled it.
  **/
 int
 _cairo_array_num_elements (cairo_array_t *array)
@@ -325,9 +337,11 @@ _cairo_array_num_elements (cairo_array_t *array)
 
 /**
  * _cairo_array_size:
+ * @array: a #cairo_array_t
+ * Returns: The number of elements for which there is currently space
+ * allocated in @array.
  *
- * Return value: The number of elements for which there is currently
- * space allocated in array.
+ * This space was left intentionally blank, but gtk-doc filled it.
  **/
 int
 _cairo_array_size (cairo_array_t *array)
commit 7cb9ccb4cb2106bb59e181ee284f8dcc5504eb7a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 17:44:03 2008 +0100

    Fixup a couple of trivials doc warnings.
    
    Correct the 'Returns' statement to match what gtk-doc expects.

diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index a9823d1..1c458df 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -92,6 +92,7 @@ _cairo_cache_fini (cairo_cache_t *cache)
  * @keys_equal: a function to return %TRUE if two keys are equal
  * @entry_destroy: destroy notifier for cache entries
  * @max_size: the maximum size for this cache
+ * Returns: the newly created #cairo_cache_t
  *
  * Creates a new cache using the keys_equal() function to determine
  * the equality of entries.
@@ -119,8 +120,6 @@ _cairo_cache_fini (cairo_cache_t *cache)
  * _cairo_cache_freeze() and _cairo_cache_thaw() calls can be
  * used to establish a window during which no automatic removal of
  * entries will occur.
- *
- * Return value:
  **/
 cairo_cache_t *
 _cairo_cache_create (cairo_cache_keys_equal_func_t keys_equal,
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 71dfda2..33a99a1 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1663,11 +1663,10 @@ _cairo_pattern_is_opaque (const cairo_pattern_t *abstract_pattern)
 }
 
 /**
- * _cairo_pattern_analyze_filter
+ * _cairo_pattern_analyze_filter:
  * @pattern: surface pattern
  * @pad_out: location to store necessary padding in the source image, or %NULL
- *
- * Returns the optimized #cairo_filter_t to use with @pattern.
+ * Returns: the optimized #cairo_filter_t to use with @pattern.
  *
  * Analyze the filter to determine how much extra needs to be sampled
  * from the source image to account for the filter radius and whether
commit d6f0351b6cbb0d542a069eb5d0a7377eb85a6e4e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 17:17:04 2008 +0100

    [skiplist] Avoid repeated calls to compare on the same element when inserting.
    
    During insertion we must traverse the skiplist in order to find the
    insertion point for the new element. As we descend each level, the next
    element in the chain for this level is sometimes the same as the one we
    just compared against (and know that the new element is greater than).
    Hence we can skip the search on that level and descend to the next. During
    world_map this reduces the number of calls into _sweep_line_elt_compare()
    by ~2.5% (and when performing trapezoidation on strokes gives a similar
    speed up of about 2% - not bad for the addition of a single line.)

diff --git a/src/cairo-skiplist.c b/src/cairo-skiplist.c
index ebeb52c..e2b793e 100644
--- a/src/cairo-skiplist.c
+++ b/src/cairo-skiplist.c
@@ -322,16 +322,20 @@ _cairo_skip_list_insert (cairo_skip_list_t *list, void *data, int unique)
     /*
      * Find links along each chain
      */
+    elt = NULL;
     next = list->chains;
     for (i = list->max_level; --i >= 0; )
     {
-	for (; (elt = next[i]); next = elt->next)
+	if (elt != next[i])
 	{
-	    int cmp = list->compare (list, ELT_DATA(elt), data);
-	    if (unique && 0 == cmp)
-		return ELT_DATA(elt);
-	    if (cmp > 0)
-		break;
+	    for (; (elt = next[i]); next = elt->next)
+	    {
+		int cmp = list->compare (list, ELT_DATA(elt), data);
+		if (unique && 0 == cmp)
+		    return ELT_DATA(elt);
+		if (cmp > 0)
+		    break;
+	    }
 	}
         update[i] = next;
 	if (next != list->chains)
commit 1440399625ae0579d0748475fc924cfe74339a21
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 16:15:29 2008 +0100

    [hull] Replace open-coding of 64bit arithmetic.
    
    Use primitives from cairo-wideint-private.h - in this case it helps to
    make the code more readable as well as reduce dependence on native 64bit
    integers.

diff --git a/src/cairo-hull.c b/src/cairo-hull.c
index 77ee790..008ba7f 100644
--- a/src/cairo-hull.c
+++ b/src/cairo-hull.c
@@ -78,6 +78,13 @@ _cairo_hull_init (cairo_hull_t			*hull,
     }
 }
 
+static inline cairo_int64_t
+_slope_length (cairo_slope_t *slope)
+{
+    return _cairo_int64_add (_cairo_int32x32_64_mul (slope->dx, slope->dx),
+			     _cairo_int32x32_64_mul (slope->dy, slope->dy));
+}
+
 static int
 _cairo_hull_vertex_compare (const void *av, const void *bv)
 {
@@ -87,21 +94,21 @@ _cairo_hull_vertex_compare (const void *av, const void *bv)
 
     ret = _cairo_slope_compare (&a->slope, &b->slope);
 
-    /* In the case of two vertices with identical slope from the
-       extremal point discard the nearer point. */
-
+    /*
+     * In the case of two vertices with identical slope from the
+     * extremal point discard the nearer point.
+     */
     if (ret == 0) {
-	cairo_fixed_48_16_t a_dist, b_dist;
-	a_dist = ((cairo_fixed_48_16_t) a->slope.dx * a->slope.dx +
-		  (cairo_fixed_48_16_t) a->slope.dy * a->slope.dy);
-	b_dist = ((cairo_fixed_48_16_t) b->slope.dx * b->slope.dx +
-		  (cairo_fixed_48_16_t) b->slope.dy * b->slope.dy);
+	int cmp;
+
+	cmp = _cairo_int64_cmp (_slope_length (&a->slope),
+				_slope_length (&b->slope));
+
 	/*
-	 * Use the point's ids to ensure a total ordering.
-	 * a well-defined ordering, and avoid setting discard on
-	 * both points.
+	 * Use the points' ids to ensure a well-defined ordering,
+	 * and avoid setting discard on both points.
 	 */
-	if (a_dist < b_dist || (a_dist == b_dist && a->id < b->id)) {
+	if (cmp < 0 || (cmp == 0 && a->id < b->id)) {
 	    a->discard = 1;
 	    ret = -1;
 	} else {
commit c6a6bf580fa7036e4c28137f8c038beb5c347244
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 16:13:21 2008 +0100

    [slope] Replace open-coding 64bit integer arithmetic.
    
    Prefer to use the operations form cairo-wideint-private.h in order to
    improve readability and reduce our assumptions on the availability of
    64bit integers.

diff --git a/src/cairo-slope.c b/src/cairo-slope.c
index e3a070b..35c5372 100644
--- a/src/cairo-slope.c
+++ b/src/cairo-slope.c
@@ -66,15 +66,13 @@ _cairo_slope_init (cairo_slope_t *slope,
 int
 _cairo_slope_compare (const cairo_slope_t *a, const cairo_slope_t *b)
 {
-    cairo_fixed_48_16_t diff;
+    cairo_int64_t ady_bdx = _cairo_int32x32_64_mul (a->dy, b->dx);
+    cairo_int64_t bdy_adx = _cairo_int32x32_64_mul (b->dy, a->dx);
+    int cmp;
 
-    diff = ((cairo_fixed_48_16_t) a->dy * (cairo_fixed_48_16_t) b->dx
-	    - (cairo_fixed_48_16_t) b->dy * (cairo_fixed_48_16_t) a->dx);
-
-    if (diff > 0)
-	return 1;
-    if (diff < 0)
-	return -1;
+    cmp = _cairo_int64_cmp (ady_bdx, bdy_adx);
+    if (cmp)
+	return cmp;
 
     /* special-case zero vectors.  the intended logic here is:
      * zero vectors all compare equal, and more positive than any
commit 5e3fcb7934f568bb7e304a1c434a9370b693df17
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 17:02:54 2008 +0100

    [wideint] Declare the wideint arithmetic functions as const.
    
    'const' is a stricter form of 'pure' in that functions declared with that
    attribute do not access any values other than their arguments (in
    contrast to 'pure' which is allowed to read from global memory).

diff --git a/src/cairo-compiler-private.h b/src/cairo-compiler-private.h
index d772f77..9e2b4f6 100644
--- a/src/cairo-compiler-private.h
+++ b/src/cairo-compiler-private.h
@@ -113,8 +113,10 @@
 
 #if __GNUC__ >= 3
 #define cairo_pure __attribute__((pure))
+#define cairo_const __attribute__((const))
 #else
 #define cairo_pure
+#define cairo_const
 #endif
 
 #ifndef __GNUC__
diff --git a/src/cairo-wideint-private.h b/src/cairo-wideint-private.h
index 60c560f..f2f6d20 100644
--- a/src/cairo-wideint-private.h
+++ b/src/cairo-wideint-private.h
@@ -47,7 +47,7 @@
  * as a pair of 32-bit ints
  */
 
-#define I cairo_private cairo_pure
+#define I cairo_private cairo_const
 
 #if !HAVE_UINT64_T
 


More information about the cairo-commit mailing list