[cairo-commit] 3 commits - src/cairo-pattern.c src/test-meta-surface.c test/alpha-similar.c test/alpha-similar-ref.png test/alpha-similar-rgb24-ref.png test/.gitignore test/Makefile.am

Chris Wilson ickle at kemper.freedesktop.org
Tue Sep 23 15:36:11 PDT 2008


 src/cairo-pattern.c              |    4 +-
 src/test-meta-surface.c          |   35 -----------------
 test/.gitignore                  |    1 
 test/Makefile.am                 |    3 +
 test/alpha-similar-ref.png       |binary
 test/alpha-similar-rgb24-ref.png |binary
 test/alpha-similar.c             |   76 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 82 insertions(+), 37 deletions(-)

New commits:
commit 8f51ea4657d872f75e1a6493aadcc769fd3b9324
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Sep 23 23:19:02 2008 +0100

    [pattern] Beware unsigned wrap-around with pathological surface patterns.
    
    A surface pattern under an extreme transformation could lie entirely in
    the negative quadrant. This would trigger the fixup such that it's lower
    left corner was clamped to the origin, but the upper right corner was left
    unchecked. This could result in the width,height being negative and
    wrapping around to large values instead of being clamped to 0.

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index b6c40e3..60b1c2b 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1821,8 +1821,8 @@ _cairo_pattern_acquire_surface_for_surface (cairo_surface_pattern_t   *pattern,
 		 */
 		x = MAX (0, floor (x1) - 1);
 		y = MAX (0, floor (y1) - 1);
-		width = MIN (extents.width, ceil (x2) + 1) - x;
-		height = MIN (extents.height, ceil (y2) + 1) - y;
+		width = MAX (MIN (extents.width, ceil (x2) + 1) - x, 0);
+		height = MAX (MIN (extents.height, ceil (y2) + 1) - y, 0);
 	    }
 	    x += tx;
 	    y += ty;
commit 3c6d3684e965523acdeec9f24ccf71bf4e974622
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Sep 23 22:52:42 2008 +0100

    [test] Add a test case for create_similar(CONTENT_ALPHA)
    
    Application of a pure-alpha similar source is inconsistently handled
    across the backends. The PDF/PS backends allow the rgb channels to bleed
    through and the SVG backend mixes in pure white.

diff --git a/test/.gitignore b/test/.gitignore
index 3068cac..5800cdf 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -10,6 +10,7 @@ a1-image-sample
 a1-mask
 a1-traps-sample
 a8-mask
+alpha-similar
 any2ppm
 .any2ppm
 .any2ppm.pid
diff --git a/test/Makefile.am b/test/Makefile.am
index d5fdead..629eda4 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,6 +8,7 @@ a1-image-sample$(EXEEXT)				\
 a1-mask$(EXEEXT)					\
 a1-traps-sample$(EXEEXT)				\
 a8-mask$(EXEEXT)					\
+alpha-similar$(EXEEXT)					\
 big-line$(EXEEXT)					\
 big-trap$(EXEEXT)					\
 bilevel-image$(EXEEXT)					\
@@ -291,6 +292,8 @@ REFERENCE_IMAGES = \
 	a1-mask-ref.png	\
 	a1-traps-sample-ref.png		\
 	a8-mask-ref.png	\
+	alpha-similar-ref.png	\
+	alpha-similar-rgb24-ref.png	\
 	big-line-ref.png		\
 	big-line-rgb24-ref.png		\
 	big-line-ps-ref.png		\
diff --git a/test/alpha-similar-ref.png b/test/alpha-similar-ref.png
new file mode 100644
index 0000000..9e1bfaa
Binary files /dev/null and b/test/alpha-similar-ref.png differ
diff --git a/test/alpha-similar-rgb24-ref.png b/test/alpha-similar-rgb24-ref.png
new file mode 100644
index 0000000..4085d60
Binary files /dev/null and b/test/alpha-similar-rgb24-ref.png differ
diff --git a/test/alpha-similar.c b/test/alpha-similar.c
new file mode 100644
index 0000000..c1bddb8
--- /dev/null
+++ b/test/alpha-similar.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2008 Chris Wilson
+ *
+ * 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
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_draw_function_t draw;
+
+static const cairo_test_t test = {
+    "alpha-similar",
+    "Tests creation of similar alpha surfaces",
+    10, 10,
+    draw
+};
+
+static cairo_surface_t *
+create_source (cairo_surface_t *target, int width, int height)
+{
+    cairo_surface_t *similar;
+    cairo_t *cr;
+
+    similar = cairo_surface_create_similar (target,
+					    CAIRO_CONTENT_ALPHA,
+					    width, height);
+    cr = cairo_create (similar);
+    cairo_surface_destroy (similar);
+
+    cairo_set_source_rgba (cr, 1, 0, 0, .5);
+    cairo_paint (cr);
+
+    similar = cairo_surface_reference (cairo_get_target (cr));
+    cairo_destroy (cr);
+
+    return similar;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *source;
+
+    source = create_source (cairo_get_target (cr), width, height);
+    cairo_set_source_surface (cr, source, 0, 0);
+    cairo_surface_destroy (source);
+
+    cairo_paint (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
commit 5e5408412694bf067e47d12c9c739801452d8f41
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Sep 23 21:49:37 2008 +0100

    [test-meta] Use real meta-surface snapshot.
    
    The meta-surface workaround an old bug, which is no longer present in the
    tree and open-coded the surface snapshot. However, the workaround itself
    was buggy (not respecting the surface content). The lesson to take away
    from this is not to add workarounds in test code for bugs in the library!

diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c
index 4d1527a..9554c53 100644
--- a/src/test-meta-surface.c
+++ b/src/test-meta-surface.c
@@ -307,43 +307,8 @@ static cairo_surface_t *
 _test_meta_surface_snapshot (void *abstract_other)
 {
     test_meta_surface_t *other = abstract_other;
-    cairo_status_t status;
 
-    /* XXX: Just making a snapshot of other->meta is what we really
-     * want. But this currently triggers a bug somewhere (the "mask"
-     * test from the test suite segfaults).
-     *
-     * For now, we'll create a new image surface and replay onto
-     * that. It would be tempting to replay into other->image and then
-     * return a snapshot of that, but that will cause the self-copy
-     * test to fail, (since our replay will be affected by a clip that
-     * should not have any effect on the use of the resulting snapshot
-     * as a source).
-     */
-
-#if 0
     return _cairo_surface_snapshot (other->meta);
-#else
-    cairo_rectangle_int_t extents;
-    cairo_surface_t *surface;
-
-    status = _cairo_surface_get_extents (other->image, &extents);
-    if (status)
-	return _cairo_surface_create_in_error (status);
-
-    surface = cairo_surface_create_similar (other->image,
-					    CAIRO_CONTENT_COLOR_ALPHA,
-					    extents.width,
-					    extents.height);
-
-    status = _cairo_meta_surface_replay (other->meta, surface);
-    if (status) {
-	cairo_surface_destroy (surface);
-	surface = _cairo_surface_create_in_error (status);
-    }
-
-    return surface;
-#endif
 }
 
 static const cairo_surface_backend_t test_meta_surface_backend = {


More information about the cairo-commit mailing list