[cairo-commit] 5 commits - src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-scaled-font.c src/cairo-xlib-display.c src/cairo-xlib-screen.c test/cairo-test.c test/extend-pad-similar.c test/extend-reflect.c test/extend-reflect-similar.c test/extend-reflect-similar-ref.png test/extend-repeat.c test/extend-repeat-ref.png test/extend-repeat-similar.c test/extend-repeat-similar-ref.png test/.gitignore test/Makefile.am

Chris Wilson ickle at kemper.freedesktop.org
Thu Jan 17 09:50:42 PST 2008


 src/cairo-pdf-surface.c             |    2 
 src/cairo-ps-surface.c              |    2 
 src/cairo-scaled-font.c             |   15 ++---
 src/cairo-xlib-display.c            |    7 --
 src/cairo-xlib-screen.c             |    6 --
 test/.gitignore                     |    4 +
 test/Makefile.am                    |   11 +++
 test/cairo-test.c                   |    2 
 test/extend-pad-similar.c           |  105 ++++++++++++++++++++++++++++++++++++
 test/extend-reflect-similar-ref.png |binary
 test/extend-reflect-similar.c       |   56 +++++++++++++++++++
 test/extend-reflect.c               |    2 
 test/extend-repeat-ref.png          |binary
 test/extend-repeat-similar-ref.png  |binary
 test/extend-repeat-similar.c        |   56 +++++++++++++++++++
 test/extend-repeat.c                |   34 +++++++++++
 16 files changed, 279 insertions(+), 23 deletions(-)

New commits:
commit 630536f17681b083db658414d68db2c0eb167af3
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 17:44:57 2008 +0000

    [test/extend-*] Add various cairo_pattern_set_extend() test cases.
    
    Add various test cases to exercise
    _cairo_pattern_acquire_surface_for_surface(), most notably using similar
    source surfaces to provide coverage of the non-image surface branch.

diff --git a/test/.gitignore b/test/.gitignore
index 0d4b86c..682b6fc 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -43,7 +43,11 @@ degenerate-pen
 device-offset
 device-offset-positive
 extend-pad
+extend-pad-similar
 extend-reflect
+extend-reflect-similar
+extend-repeat
+extend-repeat-similar
 fallback-resolution
 fallback-resolution.pdf
 fallback-resolution.ps
diff --git a/test/Makefile.am b/test/Makefile.am
index 12d89ab..5ed76eb 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -36,6 +36,11 @@ degenerate-pen$(EXEEXT)					\
 device-offset$(EXEEXT)					\
 device-offset-positive$(EXEEXT)				\
 extend-pad$(EXEEXT)					\
+extend-pad-similar$(EXEEXT)				\
+extend-reflect$(EXEEXT)					\
+extend-reflect-similar$(EXEEXT)				\
+extend-repeat$(EXEEXT)					\
+extend-repeat-similar$(EXEEXT)				\
 fill-and-stroke$(EXEEXT)				\
 fill-and-stroke-alpha$(EXEEXT)				\
 fill-and-stroke-alpha-add$(EXEEXT)			\
@@ -169,7 +174,6 @@ zero-alpha$(EXEEXT)
 #	that's just a bug in the test rig that should just consider
 #	the abort an XFAIL like any other.
 DISABLED_TESTS =			\
-extend-reflect$(EXEEXT)			\
 show-glyphs-many$(EXEEXT)		\
 text-glyph-range$(EXEEXT)
 
@@ -290,7 +294,11 @@ REFERENCE_IMAGES = \
 	device-offset-ref.png	\
 	device-offset-rgb24-ref.png	\
 	extend-pad-ref.png	\
+	extend-pad-similar-ref.png	\
 	extend-reflect-ref.png	\
+	extend-reflect-similar-ref.png	\
+	extend-repeat-ref.png	\
+	extend-repeat-similar-ref.png	\
 	fill-and-stroke-alpha-add-quartz-ref.png	\
 	fill-and-stroke-alpha-add-ref.png	\
 	fill-and-stroke-alpha-quartz-ref.png	\
@@ -514,6 +522,7 @@ XFAIL_TESTS =					\
 a8-mask$(EXEEXT)				\
 big-trap$(EXEEXT)				\
 extend-pad$(EXEEXT)				\
+extend-pad-similar$(EXEEXT)			\
 filter-nearest-offset$(EXEEXT)			\
 long-lines$(EXEEXT)				\
 self-intersecting$(EXEEXT)			\
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 8fbd5e3..fb09fee 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -701,8 +701,6 @@ cairo_test_create_surface_from_png (const char *filename)
 	    image = cairo_image_surface_create_from_png (srcdir_filename);
 	    free (srcdir_filename);
 	}
-	if (cairo_surface_status(image))
-	    return NULL;
     }
 
     return image;
diff --git a/test/extend-pad-similar.c b/test/extend-pad-similar.c
new file mode 100644
index 0000000..d523f54
--- /dev/null
+++ b/test/extend-pad-similar.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2007 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: Behdad Esfahbod <behdad at behdad.org>
+ */
+
+#include "cairo-test.h"
+
+#define SIZE 90
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "extend-pad-similar",
+    "Test CAIRO_EXTEND_PAD for surface patterns",
+    SIZE, SIZE,
+    draw
+};
+
+static cairo_surface_t *
+create_source_surface (cairo_surface_t *target)
+{
+    const int surface_size = (SIZE - 30) / 10;
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    /* Create an image surface with my favorite four colors in each
+     * quadrant. */
+    surface = cairo_surface_create_similar (target, CAIRO_CONTENT_COLOR,
+					    surface_size, surface_size);
+    cr = cairo_create (surface);
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_rectangle (cr,
+		     0, 0,
+		     surface_size / 2, surface_size / 2);
+    cairo_fill (cr);
+    cairo_set_source_rgb (cr, 1, 0, 0);
+    cairo_rectangle (cr,
+		     surface_size / 2, 0,
+		     surface_size / 2, surface_size / 2);
+    cairo_fill (cr);
+    cairo_set_source_rgb (cr, 0, 1, 0);
+    cairo_rectangle (cr,
+		     0, surface_size / 2,
+		     surface_size / 2, surface_size / 2);
+    cairo_fill (cr);
+    cairo_set_source_rgb (cr, 0, 0, 1);
+    cairo_rectangle (cr,
+		     surface_size / 2, surface_size / 2,
+		     surface_size / 2, surface_size / 2);
+    cairo_fill (cr);
+    cairo_destroy (cr);
+
+    return surface;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *surface;
+
+    surface = create_source_surface (cairo_get_group_target (cr));
+
+    cairo_set_source_rgba (cr, 0, 0, 0, 1);
+    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
+    cairo_fill (cr);
+
+    cairo_scale (cr, 10, 10);
+    cairo_set_source_surface (cr, surface, 1.5, 1.5);
+    cairo_surface_destroy (surface);
+
+    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
+    cairo_rectangle (cr, 1.5, 1.5, 6, 6);
+    cairo_clip (cr);
+
+    cairo_paint (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
diff --git a/test/extend-reflect-similar-ref.png b/test/extend-reflect-similar-ref.png
new file mode 100644
index 0000000..93a8b00
Binary files /dev/null and b/test/extend-reflect-similar-ref.png differ
diff --git a/test/extend-reflect-similar.c b/test/extend-reflect-similar.c
new file mode 100644
index 0000000..1ff4039
--- /dev/null
+++ b/test/extend-reflect-similar.c
@@ -0,0 +1,56 @@
+#include "cairo-test.h"
+
+const char	png_filename[]	= "romedalen.png";
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "extend-reflect-similar",
+    "Test CAIRO_EXTEND_REFLECT for surface patterns",
+    256 + 32*2, 192 + 32*2,
+    draw
+};
+
+static cairo_surface_t *
+clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
+{
+    cairo_t *cr;
+    cairo_surface_t *similar;
+
+    similar = cairo_surface_create_similar (target,
+	                              cairo_surface_get_content (surface),
+				      cairo_image_surface_get_width (surface),
+				      cairo_image_surface_get_height (surface));
+    cr = cairo_create (similar);
+    cairo_set_source_surface (cr, surface, 0, 0);
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+    cairo_paint (cr);
+    cairo_destroy (cr);
+
+    return similar;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *surface;
+    cairo_surface_t *similar;
+
+    surface = cairo_test_create_surface_from_png (png_filename);
+    similar = clone_similar_surface (cairo_get_group_target (cr), surface);
+    cairo_set_source_surface (cr, similar, 32, 32);
+    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REFLECT);
+
+    cairo_paint (cr);
+
+    cairo_surface_destroy (similar);
+    cairo_surface_destroy (surface);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
diff --git a/test/extend-reflect.c b/test/extend-reflect.c
index e23c8f6..e9d07cc 100644
--- a/test/extend-reflect.c
+++ b/test/extend-reflect.c
@@ -24,6 +24,8 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_paint (cr);
 
+    cairo_surface_destroy (surface);
+
     return CAIRO_TEST_SUCCESS;
 }
 
diff --git a/test/extend-repeat-ref.png b/test/extend-repeat-ref.png
new file mode 100644
index 0000000..ee2527f
Binary files /dev/null and b/test/extend-repeat-ref.png differ
diff --git a/test/extend-repeat-similar-ref.png b/test/extend-repeat-similar-ref.png
new file mode 100644
index 0000000..ee2527f
Binary files /dev/null and b/test/extend-repeat-similar-ref.png differ
diff --git a/test/extend-repeat-similar.c b/test/extend-repeat-similar.c
new file mode 100644
index 0000000..1a14125
--- /dev/null
+++ b/test/extend-repeat-similar.c
@@ -0,0 +1,56 @@
+#include "cairo-test.h"
+
+const char	png_filename[]	= "romedalen.png";
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "extend-repeat-similar",
+    "Test CAIRO_EXTEND_REPEAT for surface patterns",
+    256 + 32*2, 192 + 32*2,
+    draw
+};
+
+static cairo_surface_t *
+clone_similar_surface (cairo_surface_t * target, cairo_surface_t *surface)
+{
+    cairo_t *cr;
+    cairo_surface_t *similar;
+
+    similar = cairo_surface_create_similar (target,
+	                              cairo_surface_get_content (surface),
+				      cairo_image_surface_get_width (surface),
+				      cairo_image_surface_get_height (surface));
+    cr = cairo_create (similar);
+    cairo_set_source_surface (cr, surface, 0, 0);
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+    cairo_paint (cr);
+    cairo_destroy (cr);
+
+    return similar;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *surface;
+    cairo_surface_t *similar;
+
+    surface = cairo_test_create_surface_from_png (png_filename);
+    similar = clone_similar_surface (cairo_get_group_target (cr), surface);
+    cairo_set_source_surface (cr, similar, 32, 32);
+    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
+
+    cairo_paint (cr);
+
+    cairo_surface_destroy (similar);
+    cairo_surface_destroy (surface);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
diff --git a/test/extend-repeat.c b/test/extend-repeat.c
new file mode 100644
index 0000000..351b63b
--- /dev/null
+++ b/test/extend-repeat.c
@@ -0,0 +1,34 @@
+#include "cairo-test.h"
+
+const char	png_filename[]	= "romedalen.png";
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "extend-repeat",
+    "Test CAIRO_EXTEND_REPEAT for surface patterns",
+    256 + 32*2, 192 + 32*2,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *surface;
+
+    surface = cairo_test_create_surface_from_png (png_filename);
+    cairo_set_source_surface (cr, surface, 32, 32);
+    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
+
+    cairo_paint (cr);
+
+    cairo_surface_destroy (surface);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
commit dec2daeaf396be9dc6e8952417cc615d3a607926
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 15:34:51 2008 +0000

    [cairo-{ps,pdf}-surface] Assert the font is supported during emission.
    
    Add an ASSERT_NOT_REACHED to the tail of the font subset emission
    functions - as they should always, at least, be supported by the
    fallbacks.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 238f4f9..ce21d2d 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3659,6 +3659,7 @@ _cairo_pdf_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t *font_s
             return status;
     }
 
+    ASSERT_NOT_REACHED;
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -3673,6 +3674,7 @@ _cairo_pdf_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_sub
     if (status != CAIRO_INT_STATUS_UNSUPPORTED)
 	return status;
 
+    ASSERT_NOT_REACHED;
     return CAIRO_STATUS_SUCCESS;
 }
 
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 327243f..87efa40 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -854,6 +854,7 @@ _cairo_ps_surface_emit_unscaled_font_subset (cairo_scaled_font_subset_t	*font_su
     if (status != CAIRO_INT_STATUS_UNSUPPORTED)
 	return status;
 
+    ASSERT_NOT_REACHED;
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -872,6 +873,7 @@ _cairo_ps_surface_emit_scaled_font_subset (cairo_scaled_font_subset_t *font_subs
     if (status != CAIRO_INT_STATUS_UNSUPPORTED)
 	return status;
 
+    ASSERT_NOT_REACHED;
     return CAIRO_STATUS_SUCCESS;
 }
 
commit bde68fd4d6271daf8ca374e472deab95a9a7acff
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 15:06:13 2008 +0000

    [cairo-scaled-font] Propagate the error to the font.
    
    If we encounter an error whilst using the font backend to convert the
    text to the glyphs, flag the scaled font with that error.

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 63936d7..2ea85ad 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -907,10 +907,9 @@ cairo_scaled_font_text_extents (cairo_scaled_font_t   *scaled_font,
 	goto ZERO_EXTENTS;
 
     status = _cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., utf8, &glyphs, &num_glyphs);
-    if (status) {
-        status = _cairo_scaled_font_set_error (scaled_font, status);
+    if (status)
 	goto ZERO_EXTENTS;
-    }
+
     cairo_scaled_font_glyph_extents (scaled_font, glyphs, num_glyphs, extents);
     free (glyphs);
 
@@ -1111,7 +1110,7 @@ _cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,
     if (ucs4)
 	free (ucs4);
 
-    return status;
+    return _cairo_scaled_font_set_error (scaled_font, status);
 }
 
 /*
commit d664e3253e3c310c34264eb0070c2c3c309e071b
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 15:05:10 2008 +0000

    [cairo-scaled-font] Typo.
    
    s/ZERO_EXENTS/ZERO_EXTENTS/

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 6e7d414..63936d7 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -901,22 +901,22 @@ cairo_scaled_font_text_extents (cairo_scaled_font_t   *scaled_font,
     int num_glyphs;
 
     if (scaled_font->status)
-	goto ZERO_EXENTS;
+	goto ZERO_EXTENTS;
 
     if (utf8 == NULL)
-	goto ZERO_EXENTS;
+	goto ZERO_EXTENTS;
 
     status = _cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., utf8, &glyphs, &num_glyphs);
     if (status) {
         status = _cairo_scaled_font_set_error (scaled_font, status);
-	goto ZERO_EXENTS;
+	goto ZERO_EXTENTS;
     }
     cairo_scaled_font_glyph_extents (scaled_font, glyphs, num_glyphs, extents);
     free (glyphs);
 
     return;
 
-ZERO_EXENTS:
+ZERO_EXTENTS:
     extents->x_bearing = 0.0;
     extents->y_bearing = 0.0;
     extents->width  = 0.0;
commit fcdc525dde52c3bf7124d00a98b6be64ca522cb9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 17 14:47:43 2008 +0000

    [cairo-xlib] Remove the NULL safeguards.
    
    No need to guarding against the pointer being NULL on internal functions
    as no path can call the function will a NULL pointer and no path should
    ever try, which in any case it would be better to crash immediately.

diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index 8b1fa0a..d10ed1e 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -125,9 +125,6 @@ _cairo_xlib_display_discard_screens (cairo_xlib_display_t *display)
 cairo_xlib_display_t *
 _cairo_xlib_display_reference (cairo_xlib_display_t *display)
 {
-    if (display == NULL)
-	return NULL;
-
     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&display->ref_count));
 
     _cairo_reference_count_inc (&display->ref_count);
@@ -138,9 +135,6 @@ _cairo_xlib_display_reference (cairo_xlib_display_t *display)
 void
 _cairo_xlib_display_destroy (cairo_xlib_display_t *display)
 {
-    if (display == NULL)
-	return;
-
     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&display->ref_count));
 
     if (! _cairo_reference_count_dec_and_test (&display->ref_count))
@@ -213,6 +207,7 @@ _cairo_xlib_close_display (Display *dpy, XExtCodes *codes)
     }
     CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex);
 
+    assert (display != NULL);
     _cairo_xlib_display_destroy (display);
 
     /* Return value in accordance with requirements of
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index f8d5936..b759a85 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -244,9 +244,6 @@ _cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *in
 cairo_xlib_screen_info_t *
 _cairo_xlib_screen_info_reference (cairo_xlib_screen_info_t *info)
 {
-    if (info == NULL)
-	return NULL;
-
     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&info->ref_count));
 
     _cairo_reference_count_inc (&info->ref_count);
@@ -273,9 +270,6 @@ _cairo_xlib_screen_info_destroy (cairo_xlib_screen_info_t *info)
     cairo_xlib_screen_info_t **prev;
     cairo_xlib_screen_info_t *list;
 
-    if (info == NULL)
-	return;
-
     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&info->ref_count));
 
     if (! _cairo_reference_count_dec_and_test (&info->ref_count))


More information about the cairo-commit mailing list