[cairo-commit] 2 commits - src/cairo.c test/Makefile.sources test/push-group-path-offset.c test/push-group-path-offset.ref.png

Benjamin Otte company at kemper.freedesktop.org
Fri Jun 25 04:48:44 PDT 2010


 src/cairo.c                         |    5 +-
 test/Makefile.sources               |    1 
 test/push-group-path-offset.c       |   90 ++++++++++++++++++++++++++++++++++++
 test/push-group-path-offset.ref.png |binary
 4 files changed, 94 insertions(+), 2 deletions(-)

New commits:
commit 2e8571d95ca36f8ad9e20796990cdc0b3f763082
Author: Benjamin Otte <otte at redhat.com>
Date:   Fri Jun 25 13:41:22 2010 +0200

    push-group: Fix path translation when pushing a group with device offsets
    
    With the previous code, the parent's device offset wasn't undone before
    applying the new device offset.
    Tested by push-group-path-offset test.

diff --git a/src/cairo.c b/src/cairo.c
index 9d28aee..d43c031 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -615,6 +615,7 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 	cairo_surface_t *parent_surface;
 	const cairo_rectangle_int_t *clip_extents;
 	cairo_rectangle_int_t extents;
+        cairo_matrix_t matrix;
 	cairo_bool_t is_empty;
 
 	parent_surface = _cairo_gstate_get_target (cr->gstate);
@@ -646,8 +647,8 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 
 	/* If we have a current path, we need to adjust it to compensate for
 	 * the device offset just applied. */
-	_cairo_path_fixed_transform (cr->path,
-				     &group_surface->device_transform);
+        cairo_matrix_init_translate (&matrix, -extents.x, -extents.y);
+	_cairo_path_fixed_transform (cr->path, &matrix);
     }
 
     /* create a new gstate for the redirect */
commit a9b8d1a94ea624ea8b12a125bdf70c6f248e7ca7
Author: Benjamin Otte <otte at redhat.com>
Date:   Fri Jun 25 13:38:40 2010 +0200

    test: Add a new test for a bug with device-offset tests
    
    All the credit for this one goes to make distcheck

diff --git a/test/Makefile.sources b/test/Makefile.sources
index dba2f2c..d6c84a0 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -191,6 +191,7 @@ test_sources = \
 	png.c						\
 	push-group.c					\
 	push-group-color.c				\
+	push-group-path-offset.c			\
 	radial-gradient.c				\
 	radial-gradient-extend.c			\
 	radial-gradient-mask.c				\
diff --git a/test/push-group-path-offset.c b/test/push-group-path-offset.c
new file mode 100644
index 0000000..ec6015b
--- /dev/null
+++ b/test/push-group-path-offset.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2010 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: Benjamin Otte <otte at gnome.org>
+ */
+
+#include "cairo-test.h"
+
+#define DEVICE_OFFSET -10
+#define CLIP_OFFSET 25
+#define CLIP_SIZE 20
+
+#define WIDTH 50
+#define HEIGHT 50
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *similar;
+    cairo_t *similar_cr;
+
+    similar = cairo_surface_create_similar (cairo_get_target (cr), 
+                                            cairo_surface_get_content (cairo_get_target (cr)),
+                                            width, height);
+    cairo_surface_set_device_offset (similar, DEVICE_OFFSET, DEVICE_OFFSET);
+
+    similar_cr = cairo_create (similar);
+
+    /* Neutral gray background */
+    cairo_set_source_rgb (similar_cr, 0.51613, 0.55555, 0.51613);
+    cairo_paint (similar_cr);
+
+    /* add a rectangle */
+    cairo_rectangle (similar_cr, CLIP_OFFSET, CLIP_OFFSET, CLIP_SIZE, CLIP_SIZE);
+
+    /* clip to the rectangle */
+    cairo_clip_preserve (similar_cr);
+
+    /* push a group. We now have a device offset. */
+    cairo_push_group (similar_cr);
+
+    /* push a group again. This is where the bug used to happen. */
+
+    /* draw something */
+    cairo_set_source_rgb (similar_cr, 1, 0, 0);
+    cairo_fill (similar_cr);
+
+    /* make sure the stuff we drew ends up on the output */
+    cairo_pop_group_to_source (similar_cr);
+    cairo_paint (similar_cr);
+
+    cairo_pop_group_to_source (similar_cr);
+    cairo_paint (similar_cr);
+
+    cairo_destroy (similar_cr);
+
+    cairo_set_source_surface (cr, similar, DEVICE_OFFSET, DEVICE_OFFSET);
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+    cairo_paint (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (push_group_path_offset,
+	    "Exercises a bug in Cairo 1.9 where existing paths applied the target's"
+            " device offset twice when cairo_push_group() was called.",
+	    "group, path", /* keywords */
+	    NULL, /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, draw)
diff --git a/test/push-group-path-offset.ref.png b/test/push-group-path-offset.ref.png
new file mode 100644
index 0000000..b836a91
Binary files /dev/null and b/test/push-group-path-offset.ref.png differ


More information about the cairo-commit mailing list