[cairo-commit] 2 commits - src/cairo-surface-fallback.c test/clip-device-offset.argb32.ref.png test/clip-device-offset.c test/clip-device-offset.rgb24.ref.png test/Makefile.am test/Makefile.sources

Chris Wilson ickle at kemper.freedesktop.org
Thu Oct 15 06:09:16 PDT 2009


 src/cairo-surface-fallback.c           |   41 ++++++++++++++---
 test/Makefile.am                       |    2 
 test/Makefile.sources                  |    1 
 test/clip-device-offset.argb32.ref.png |binary
 test/clip-device-offset.c              |   79 +++++++++++++++++++++++++++++++++
 test/clip-device-offset.rgb24.ref.png  |binary
 6 files changed, 117 insertions(+), 6 deletions(-)

New commits:
commit 79190d89853958ee8252440d35a662fabf122afd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Oct 15 14:05:37 2009 +0100

    [surface] Avoid double application of device offset when calling fill()
    
    _cairo_surface_fallback_paint() attempts to avoid a clipped operation if
    we can convert the paint into a fill of the clipmask. However by calling
    _cairo_surface_fill() we incur a double application of device offset to
    the source, triggering various failures.
    
    Company spotted this and managed to extract an excellent minimal test
    case, test/clip-device-offset. This commit fixes that failure.

diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index 77ae0ed..068f06d 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -982,6 +982,35 @@ _clip_to_boxes (cairo_clip_t **clip,
     return status;
 }
 
+/* XXX _cairo_surface_backend_fill? */
+static cairo_status_t
+_wrap_surface_fill (cairo_surface_t	*surface,
+		    cairo_operator_t	 op,
+		    const cairo_pattern_t *source,
+		    cairo_path_fixed_t	*path,
+		    cairo_fill_rule_t	 fill_rule,
+		    double		 tolerance,
+		    cairo_antialias_t	 antialias,
+		    cairo_clip_t	*clip)
+{
+    if (surface->backend->fill != NULL) {
+	cairo_status_t status;
+
+	status = surface->backend->fill (surface, op, source,
+					 path, fill_rule,
+					 tolerance, antialias,
+					 clip);
+
+	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
+	    return status;
+    }
+
+    return _cairo_surface_fallback_fill (surface, op, source,
+					 path, fill_rule,
+					 tolerance, antialias,
+					 clip);
+}
+
 cairo_status_t
 _cairo_surface_fallback_paint (cairo_surface_t		*surface,
 			       cairo_operator_t		 op,
@@ -1035,12 +1064,12 @@ _cairo_surface_fallback_paint (cairo_surface_t		*surface,
     if (clip != NULL && clip_path->prev == NULL &&
 	_cairo_operator_bounded_by_mask (op))
     {
-	return _cairo_surface_fill (surface, op, source,
-				    &clip_path->path,
-				    clip_path->fill_rule,
-				    clip_path->tolerance,
-				    clip_path->antialias,
-				    NULL);
+	return _wrap_surface_fill (surface, op, source,
+				   &clip_path->path,
+				   clip_path->fill_rule,
+				   clip_path->tolerance,
+				   clip_path->antialias,
+				   NULL);
     }
 
     status = _cairo_traps_init_boxes (&traps, boxes, num_boxes);
commit ade55037ffa596b690c6a1051394589f76eb1f48
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Oct 15 13:19:11 2009 +0100

    [test] Add clip-device-offset
    
    Exercises a bug demonstrated by WebKit with clipping + device offsets.

diff --git a/test/Makefile.am b/test/Makefile.am
index a6e8be3..9ad41f5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -167,6 +167,8 @@ REFERENCE_IMAGES = \
 	clear.svg12.argb32.xfail.png \
 	clear.svg12.rgb24.xfail.png \
 	clip-all.ref.png \
+	clip-device-offset.argb32.ref.png \
+	clip-device-offset.rgb24.ref.png \
 	clip-disjoint.ref.png \
 	clip-disjoint.xlib.ref.png \
 	clip-empty.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 769fb0f..c313852 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -15,6 +15,7 @@ test_sources = \
 	clear.c						\
 	clip-all.c					\
 	clip-disjoint.c					\
+	clip-device-offset.c				\
 	clip-empty.c					\
 	clip-fill.c					\
 	clip-fill-rule.c				\
diff --git a/test/clip-device-offset.argb32.ref.png b/test/clip-device-offset.argb32.ref.png
new file mode 100644
index 0000000..06be985
Binary files /dev/null and b/test/clip-device-offset.argb32.ref.png differ
diff --git a/test/clip-device-offset.c b/test/clip-device-offset.c
new file mode 100644
index 0000000..eb0e249
--- /dev/null
+++ b/test/clip-device-offset.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2009 Benjamin Otte
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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.
+ *
+ * Authors: Benjamin Otte <otte at gnome.org>
+ */
+
+#include "cairo-test.h"
+
+#define WIDTH 50
+#define HEIGHT 50
+
+static cairo_pattern_t *
+create_green_source (void)
+{
+  cairo_surface_t *image;
+  cairo_pattern_t *pattern;
+  cairo_t *cr;
+
+  image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT);
+  cr = cairo_create (image);
+  cairo_surface_destroy (image);
+
+  cairo_set_source_rgb (cr, 0, 1, 0);
+  cairo_paint (cr);
+
+  pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
+  cairo_destroy (cr);
+
+  return pattern;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+  cairo_pattern_t *source;
+  double old_x, old_y;
+
+  cairo_surface_get_device_offset (cairo_get_target (cr), &old_x, &old_y);
+  cairo_surface_set_device_offset (cairo_get_target (cr), old_x+5, old_y+5);
+
+  source = create_green_source ();
+  cairo_set_source (cr, source);
+  cairo_pattern_destroy (source);
+
+  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+  cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
+  cairo_clip (cr);
+  cairo_paint (cr);
+
+  cairo_surface_set_device_offset (cairo_get_target (cr), old_x, old_y);
+
+  return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (clip_device_offset,
+	    "Test clipping on surfaces with device offsets",
+	    "clip", /* keywords */
+	    NULL, /* requirements */
+	    WIDTH+10, HEIGHT+10,
+	    NULL, draw)
diff --git a/test/clip-device-offset.rgb24.ref.png b/test/clip-device-offset.rgb24.ref.png
new file mode 100644
index 0000000..2419384
Binary files /dev/null and b/test/clip-device-offset.rgb24.ref.png differ


More information about the cairo-commit mailing list