[cairo-commit] 3 commits - src/cairo-xcb-private.h src/cairo-xcb-surface-render.c test/Makefile.refs test/Makefile.sources test/tighten-bounds.c test/tighten-bounds.ref.png

Uli Schlachter psychon at kemper.freedesktop.org
Tue Aug 30 13:21:41 PDT 2011


 src/cairo-xcb-private.h        |    4 
 src/cairo-xcb-surface-render.c |    3 
 test/Makefile.refs             |    1 
 test/Makefile.sources          |    1 
 test/tighten-bounds.c          |  172 +++++++++++++++++++++++++++++++++++++++++
 test/tighten-bounds.ref.png    |binary
 6 files changed, 179 insertions(+), 2 deletions(-)

New commits:
commit d66d9cd777c362e2f99a41aa77bbe3428cf0c60d
Author: Uli Schlachter <psychon at znc.in>
Date:   Tue Aug 30 22:19:33 2011 +0200

    xcb: Fix fallback for *_shm_put_image
    
    This function shouldn't ever be called is xcb-shm is disabled. However, it is
    still defined to avoid lots of #ifdefs.
    
    Additionally, this removes the only use of uint64_t from cairo-xcb.
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/src/cairo-xcb-private.h b/src/cairo-xcb-private.h
index 648bd57..c99f117 100644
--- a/src/cairo-xcb-private.h
+++ b/src/cairo-xcb-private.h
@@ -612,7 +612,7 @@ cairo_private void
 _cairo_xcb_connection_shm_detach (cairo_xcb_connection_t *connection,
 				  uint32_t segment);
 #else
-static inline uint64_t
+static inline void
 _cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection,
 				     xcb_drawable_t dst,
 				     xcb_gcontext_t gc,
@@ -628,7 +628,7 @@ _cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection,
 				     uint32_t shm,
 				     uint32_t offset)
 {
-    return 0;
+    ASSERT_NOT_REACHED;
 }
 #endif
 
commit 5f45f696d0a82dd9f9d4534d135fe75ce11b5223
Author: Uli Schlachter <psychon at znc.in>
Date:   Tue Aug 30 22:10:34 2011 +0200

    xcb: Add an assert for the tighten-bounds test
    
    This code casts the result of _cairo_xcb_surface_create_similar() to
    cairo_xcb_surface_t*. However, the tighten-bounds test makes this run with
    bounded extents of size 0x0 and thus _cairo_xcb_surface_create_similar() falls
    back to an image surface. Ugly.
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/src/cairo-xcb-surface-render.c b/src/cairo-xcb-surface-render.c
index 2627837..8231962 100644
--- a/src/cairo-xcb-surface-render.c
+++ b/src/cairo-xcb-surface-render.c
@@ -1841,6 +1841,9 @@ _clip_and_composite_combine (cairo_clip_t		*clip,
     if (unlikely (tmp->base.status))
 	return tmp->base.status;
 
+    /* create_similar() could have done a fallback to an image surface */
+    assert (tmp->base.backend == &_cairo_xcb_surface_backend);
+
     _cairo_xcb_surface_ensure_picture (tmp);
 
     if (pattern == NULL) {
commit 70118ee119c352322860926bd7ce3d0af7c1a3a4
Author: Uli Schlachter <psychon at znc.in>
Date:   Tue Aug 30 22:03:33 2011 +0200

    test: Add tighten-bounds
    
    In the spirit of the new big-{little,empty}-{box,triangle} tests, this test
    combines various paths. However, these paths are not only filled but also used
    for clipping, resulting in 120 different combinations.
    
    No backend currently succeeds the test. The reference image is a gimp-ination of
    the image and test-fallback results and thus certainly wrong. Feel free to fix.
    
    Additionally, this makes the xcb backend die with an ugly failed assert.
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/test/Makefile.refs b/test/Makefile.refs
index d1ae2b0..b09f781 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -1337,6 +1337,7 @@ REFERENCE_IMAGES = \
 	text-transform.ps.ref.png \
 	text-transform.ref.png \
 	text-transform.svg.ref.png \
+	tighten-bounds.ref.png \
 	transforms.image16.ref.png \
 	transforms.ps2.ref.png \
 	transforms.ps3.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 1fa7b78..526ac8a 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -309,6 +309,7 @@ test_sources = \
 	text-rotate.c					\
 	text-transform.c				\
 	text-zero-len.c					\
+	tighten-bounds.c				\
 	toy-font-face.c					\
 	transforms.c					\
 	translate-show-surface.c			\
diff --git a/test/tighten-bounds.c b/test/tighten-bounds.c
new file mode 100644
index 0000000..02fc81a
--- /dev/null
+++ b/test/tighten-bounds.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright © 2011 Uli Schlachter
+ *
+ * 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: Uli Schlachter <psychon at znc.in>
+ */
+
+#include "cairo-test.h"
+
+static void path_none (cairo_t *cr, int size)
+{
+}
+
+static void path_box (cairo_t *cr, int size)
+{
+    cairo_rectangle (cr, 0, 0, size, size);
+}
+
+static void path_box_unaligned (cairo_t *cr, int size)
+{
+    cairo_rectangle (cr, 0.5, 0.5, size - 1, size - 1);
+}
+
+static void path_triangle (cairo_t *cr, int size)
+{
+    cairo_move_to (cr, 0, 0);
+    cairo_line_to (cr, size/2, size);
+    cairo_line_to (cr, size, 0);
+    cairo_close_path (cr);
+}
+
+static void path_circle (cairo_t *cr, int size)
+{
+    cairo_arc (cr, size / 2.0, size / 2.0, size / 2.0, 0, 2 * M_PI);
+}
+
+static void (* const path_funcs[])(cairo_t *cr, int size) = {
+    path_none,
+    path_box,
+    path_box_unaligned,
+    path_triangle,
+    path_circle
+};
+
+#define SIZE 20
+#define PAD 2
+#define TYPES 6
+/* All-clipped is boring, thus we skip path_none for clipping */
+#define CLIP_OFFSET 1
+#define IMAGE_WIDTH ((ARRAY_LENGTH (path_funcs) - CLIP_OFFSET) * TYPES * (SIZE + PAD) - PAD)
+#define IMAGE_HEIGHT (ARRAY_LENGTH (path_funcs) * (SIZE + PAD) - PAD)
+
+static void
+draw_idx (cairo_t *cr, int i, int j, int type)
+{
+    cairo_bool_t little_path = type & (1 << 0);
+    cairo_bool_t empty_clip;
+    cairo_bool_t little_clip;
+
+    /* The lowest bit controls the path, the rest the clip */
+    little_path = type & 1;
+
+    /* We don't want the combination "empty_clip = TRUE, little_clip = FALSE"
+     * (== all clipped).
+     */
+    switch (type >> 1)
+    {
+    case 0:
+	empty_clip = FALSE;
+	little_clip = FALSE;
+	break;
+    case 1:
+	empty_clip = FALSE;
+	little_clip = TRUE;
+	break;
+    case 2:
+	empty_clip = TRUE;
+	little_clip = TRUE;
+	break;
+    default:
+	return;
+    }
+
+    cairo_save (cr);
+
+    /* Thanks to the fill rule, drawing something twice removes it again */
+    cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+
+    path_funcs[i] (cr, SIZE);
+    if (empty_clip)
+	path_funcs[i] (cr, SIZE);
+    if (little_clip)
+    {
+	cairo_save (cr);
+	cairo_translate (cr, SIZE / 4, SIZE / 4);
+	path_funcs[i] (cr, SIZE / 2);
+	cairo_restore (cr);
+    }
+    cairo_clip (cr);
+
+    path_funcs[j] (cr, SIZE);
+    path_funcs[j] (cr, SIZE);
+    if (little_path)
+    {
+	/* Draw the object again in the center of itself */
+	cairo_save (cr);
+	cairo_translate (cr, SIZE / 4, SIZE / 4);
+	path_funcs[j] (cr, SIZE / 2);
+	cairo_restore (cr);
+    }
+    cairo_fill (cr);
+    cairo_restore (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    size_t i, j, k;
+
+    cairo_set_source_rgb (cr, 0, 1, 0);
+    cairo_paint (cr);
+
+    /* Set an unbounded operator so that we can see how accurate the bounded
+     * extents were.
+     */
+    cairo_set_operator (cr, CAIRO_OPERATOR_IN);
+    cairo_set_source_rgb (cr, 1, 1, 1);
+
+    for (j = 0; j < ARRAY_LENGTH (path_funcs); j++) {
+	cairo_save (cr);
+	for (i = CLIP_OFFSET; i < ARRAY_LENGTH (path_funcs); i++) {
+	    for (k = 0; k < TYPES; k++) {
+		cairo_save (cr);
+		cairo_rectangle (cr, 0, 0, SIZE, SIZE);
+		cairo_clip (cr);
+		draw_idx (cr, i, j, k);
+		cairo_restore (cr);
+		cairo_translate (cr, SIZE + PAD, 0);
+	    }
+	}
+	cairo_restore (cr);
+	cairo_translate (cr, 0, SIZE + PAD);
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (tighten_bounds,
+	    "Tests that we tighten the bounds after tessellation.",
+	    "fill", /* keywords */
+	    NULL, /* requirements */
+	    IMAGE_WIDTH, IMAGE_HEIGHT,
+	    NULL, draw)
diff --git a/test/tighten-bounds.ref.png b/test/tighten-bounds.ref.png
new file mode 100644
index 0000000..8231082
Binary files /dev/null and b/test/tighten-bounds.ref.png differ


More information about the cairo-commit mailing list