[cairo-commit] 4 commits - src/cairo-ft-font.c src/cairo-png.c src/cairo-scaled-font.c test/a1-clip.c test/a1-clip-fill-equal.ref.png test/a1-clip-fill.ref.png test/a1-clip-paint.ref.png test/a1-clip-stroke.ref.png test/Makefile.refs test/Makefile.sources

Chris Wilson ickle at kemper.freedesktop.org
Wed Jul 13 04:37:11 PDT 2011


 src/cairo-ft-font.c             |   36 +++++---
 src/cairo-png.c                 |   16 +--
 src/cairo-scaled-font.c         |    4 
 test/Makefile.refs              |    6 +
 test/Makefile.sources           |    1 
 test/a1-clip-fill-equal.ref.png |binary
 test/a1-clip-fill.ref.png       |binary
 test/a1-clip-paint.ref.png      |binary
 test/a1-clip-stroke.ref.png     |binary
 test/a1-clip.c                  |  175 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 214 insertions(+), 24 deletions(-)

New commits:
commit cd4b2d843b2a8c06ba78c15ff65763b5bdf54dc6
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jul 13 12:33:48 2011 +0100

    scaled-font: Key the cache on the orignal font_face
    
    We check the incoming scaled font using the original font fce, so we
    need to also store it in the cache using the same face, and not the
    resolved font_face (which will remain the same unless the fontconfig
    configuration is updated).
    
    Hides the quadratic behaviour of font retrieval in recent cairo-traces.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 1a95cda..1b3cd5e 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -963,7 +963,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	    }
 	}
 
-	_cairo_scaled_font_init_key (&key, font_face,
+	_cairo_scaled_font_init_key (&key, original_font_face,
 				     font_matrix, ctm, options);
     }
     else
@@ -979,7 +979,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	    }
 	}
 
-	_cairo_scaled_font_init_key (&key, font_face,
+	_cairo_scaled_font_init_key (&key, original_font_face,
 				     font_matrix, ctm, options);
 
 	while ((scaled_font = _cairo_hash_table_lookup (font_map->hash_table,
commit 84c66589bc6f6a9f924863e578a49e4f2492ec87
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jul 13 12:32:24 2011 +0100

    ft-font: If the pattern is already resolved, use it immediately
    
    This skips an relatively expensive search for the a good match if the
    pattern already contains a face or a filename.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index acb7121..e6d7de3 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -2946,28 +2946,38 @@ _cairo_ft_resolve_pattern (FcPattern		      *pattern,
 
     FcDefaultSubstitute (pattern);
 
-    resolved = FcFontMatch (NULL, pattern, &result);
-    if (!resolved) {
-	/* We failed to find any font. Substitute twin so that the user can
-	 * see something (and hopefully recognise that the font is missing)
-	 * and not just receive a NO_MEMORY error during rendering.
-	 */
-	font_face = _cairo_font_face_twin_create_fallback ();
+    status = _cairo_ft_unscaled_font_create_for_pattern (pattern, &unscaled);
+    if (unlikely (status)) {
+	font_face = (cairo_font_face_t *)&_cairo_font_face_nil;
 	goto FREE_PATTERN;
     }
 
-    status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled);
-    if (unlikely (status || unscaled == NULL)) {
-	font_face = (cairo_font_face_t *)&_cairo_font_face_nil;
-	goto FREE_RESOLVED;
-    }
+    if (unscaled == NULL) {
+	resolved = FcFontMatch (NULL, pattern, &result);
+	if (!resolved) {
+	    /* We failed to find any font. Substitute twin so that the user can
+	     * see something (and hopefully recognise that the font is missing)
+	     * and not just receive a NO_MEMORY error during rendering.
+	     */
+	    font_face = _cairo_font_face_twin_create_fallback ();
+	    goto FREE_PATTERN;
+	}
+
+	status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled);
+	if (unlikely (status || unscaled == NULL)) {
+	    font_face = (cairo_font_face_t *)&_cairo_font_face_nil;
+	    goto FREE_RESOLVED;
+	}
+    } else
+	resolved = pattern;
 
     _get_pattern_ft_options (resolved, &ft_options);
     font_face = _cairo_ft_font_face_create (unscaled, &ft_options);
     _cairo_unscaled_font_destroy (&unscaled->base);
 
 FREE_RESOLVED:
-    FcPatternDestroy (resolved);
+    if (resolved != pattern)
+	FcPatternDestroy (resolved);
 
 FREE_PATTERN:
     FcPatternDestroy (pattern);
commit 727a0092d1128f8dd6e6054efb586f26e47fa2d0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jul 8 21:58:07 2011 +0100

    test: Test a1 clipping semantics
    
    If I've written the tests correctly, these should produce identical
    images as the a1 rasterisation tests.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/Makefile.refs b/test/Makefile.refs
index 26f5566..5b2acb1 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -1,10 +1,14 @@
 # Note REFERENCE_IMAGES must be in lexicographical order.
-# Use generate_refs on a git checkout with updated images.
+# Use generate_refs.sh on a git checkout with updated images.
 REFERENCE_IMAGES = \
 	a1-bug.image16.ref.png \
 	a1-bug.quartz.xfail.png \
 	a1-bug.ref.png \
 	a1-bug.xlib.ref.png \
+	a1-clip-fill-equal.ref.png \
+	a1-clip-fill.ref.png \
+	a1-clip-paint.ref.png \
+	a1-clip-stroke.ref.png \
 	a1-image-sample.gl.xfail.png \
 	a1-image-sample.ref.png \
 	a1-mask-sample.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 0dee384..e4212f0 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -1,5 +1,6 @@
 test_sources = \
 	a1-bug.c					\
+	a1-clip.c					\
 	a1-image-sample.c 				\
 	a1-mask.c					\
 	a1-mask-sample.c 				\
diff --git a/test/a1-clip-fill-equal.ref.png b/test/a1-clip-fill-equal.ref.png
new file mode 100644
index 0000000..b4e81eb
Binary files /dev/null and b/test/a1-clip-fill-equal.ref.png differ
diff --git a/test/a1-clip-fill.ref.png b/test/a1-clip-fill.ref.png
new file mode 100644
index 0000000..b4e81eb
Binary files /dev/null and b/test/a1-clip-fill.ref.png differ
diff --git a/test/a1-clip-paint.ref.png b/test/a1-clip-paint.ref.png
new file mode 100644
index 0000000..b4e81eb
Binary files /dev/null and b/test/a1-clip-paint.ref.png differ
diff --git a/test/a1-clip-stroke.ref.png b/test/a1-clip-stroke.ref.png
new file mode 100644
index 0000000..b4e81eb
Binary files /dev/null and b/test/a1-clip-stroke.ref.png differ
diff --git a/test/a1-clip.c b/test/a1-clip.c
new file mode 100644
index 0000000..0e84cd3
--- /dev/null
+++ b/test/a1-clip.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#define POINTS	10
+#define STEP	(1.0 / POINTS)
+#define PAD	1
+#define WIDTH	(PAD + POINTS * 2 + PAD)
+#define HEIGHT	(WIDTH)
+
+static cairo_test_status_t
+paint (cairo_t *cr, int width, int height)
+{
+    int i, j;
+
+    /* Fill background white */
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    /* Draw in black */
+    cairo_set_source_rgb (cr, 0, 0, 0);
+
+    cairo_translate (cr, PAD, PAD);
+    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+    for (i = 0; i < POINTS; i++)
+	for (j = 0; j < POINTS; j++) {
+	    cairo_save (cr);
+	    cairo_rectangle (cr, 2 * i + i * STEP, 2 * j + j * STEP, 1, 1);
+	    cairo_clip (cr);
+	    cairo_paint (cr);
+	    cairo_restore (cr);
+	}
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+fill_equal (cairo_t *cr, int width, int height)
+{
+    int i, j;
+
+    /* Fill background white */
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    /* Draw in black */
+    cairo_set_source_rgb (cr, 0, 0, 0);
+
+    cairo_translate (cr, PAD, PAD);
+    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+    for (i = 0; i < POINTS; i++)
+	for (j = 0; j < POINTS; j++) {
+	    cairo_save (cr);
+	    cairo_rectangle (cr, 2 * i + i * STEP, 2 * j + j * STEP, 1, 1);
+	    cairo_clip_preserve (cr);
+	    cairo_fill (cr);
+	    cairo_restore (cr);
+	}
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+fill (cairo_t *cr, int width, int height)
+{
+    int i, j;
+
+    /* Fill background white */
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    /* Draw in black */
+    cairo_set_source_rgb (cr, 0, 0, 0);
+
+    cairo_translate (cr, PAD, PAD);
+    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+    for (i = 0; i < POINTS; i++)
+	for (j = 0; j < POINTS; j++) {
+	    cairo_save (cr);
+	    cairo_rectangle (cr, 2 * i + i * STEP, 2 * j + j * STEP, 1, 1);
+	    cairo_clip (cr);
+	    cairo_rectangle (cr, 2 * i, 2 * j, 2, 2);
+	    cairo_fill (cr);
+	    cairo_restore (cr);
+	}
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+stroke (cairo_t *cr, int width, int height)
+{
+    int i, j;
+
+    /* Fill background white */
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    /* Draw in black */
+    cairo_set_source_rgb (cr, 0, 0, 0);
+
+    cairo_translate (cr, PAD, PAD);
+    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+    cairo_set_line_width (cr, 2);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+
+    for (i = 0; i < POINTS; i++)
+	for (j = 0; j < POINTS; j++) {
+	    cairo_save (cr);
+	    cairo_rectangle (cr, 2 * i + i * STEP, 2 * j + j * STEP, 1, 1);
+	    cairo_clip (cr);
+	    cairo_move_to (cr, 2 * i, 2 * j + 1);
+	    cairo_line_to (cr, 2 * i + 2, 2 * j + 1);
+	    cairo_stroke (cr);
+	    cairo_restore (cr);
+	}
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (a1_clip_paint,
+	    "Test sample position when drawing trapezoids with ANTIALIAS_NONE",
+	    "alpha, clip", /* keywords */
+	    "target=raster", /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, paint)
+
+CAIRO_TEST (a1_clip_fill,
+	    "Test sample position when drawing trapezoids with ANTIALIAS_NONE",
+	    "alpha, clip", /* keywords */
+	    "target=raster", /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, fill)
+
+CAIRO_TEST (a1_clip_fill_equal,
+	    "Test sample position when drawing trapezoids with ANTIALIAS_NONE",
+	    "alpha, clip", /* keywords */
+	    "target=raster", /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, fill_equal)
+
+CAIRO_TEST (a1_clip_stroke,
+	    "Test sample position when drawing trapezoids with ANTIALIAS_NONE",
+	    "alpha, clip", /* keywords */
+	    "target=raster", /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, stroke)
commit af71e7717e3eb89f6ebaa6b43b1267341dc15116
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jul 8 21:56:32 2011 +0100

    png: Fix support of depth-30 images
    
    Rename the variable depth to bpc to prevent future confusion.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-png.c b/src/cairo-png.c
index e176043..5cb132e 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -178,7 +178,7 @@ write_png (cairo_surface_t	*surface,
     png_byte **volatile rows = NULL;
     png_color_16 white;
     int png_color_type;
-    int depth;
+    int bpc;
 
     status = _cairo_surface_acquire_source_image (surface,
 						  &image,
@@ -235,26 +235,26 @@ write_png (cairo_surface_t	*surface,
 
     switch (clone->format) {
     case CAIRO_FORMAT_ARGB32:
-	depth = 8;
+	bpc = 8;
 	if (_cairo_image_analyze_transparency (clone) == CAIRO_IMAGE_IS_OPAQUE)
 	    png_color_type = PNG_COLOR_TYPE_RGB;
 	else
 	    png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
 	break;
     case CAIRO_FORMAT_RGB30:
-	depth = 30;
+	bpc = 10;
 	png_color_type = PNG_COLOR_TYPE_RGB;
 	break;
     case CAIRO_FORMAT_RGB24:
-	depth = 8;
+	bpc = 8;
 	png_color_type = PNG_COLOR_TYPE_RGB;
 	break;
     case CAIRO_FORMAT_A8:
-	depth = 8;
+	bpc = 8;
 	png_color_type = PNG_COLOR_TYPE_GRAY;
 	break;
     case CAIRO_FORMAT_A1:
-	depth = 1;
+	bpc = 1;
 	png_color_type = PNG_COLOR_TYPE_GRAY;
 #ifndef WORDS_BIGENDIAN
 	png_set_packswap (png);
@@ -269,13 +269,13 @@ write_png (cairo_surface_t	*surface,
 
     png_set_IHDR (png, info,
 		  clone->width,
-		  clone->height, depth,
+		  clone->height, bpc,
 		  png_color_type,
 		  PNG_INTERLACE_NONE,
 		  PNG_COMPRESSION_TYPE_DEFAULT,
 		  PNG_FILTER_TYPE_DEFAULT);
 
-    white.gray = (1 << depth) - 1;
+    white.gray = (1 << bpc) - 1;
     white.red = white.blue = white.green = white.gray;
     png_set_bKGD (png, info, &white);
 


More information about the cairo-commit mailing list