From ade55037ffa596b690c6a1051394589f76eb1f48 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 15 Oct 2009 13:19:11 +0100 Subject: [test] Add clip-device-offset Exercises a bug demonstrated by WebKit with clipping + device offsets. --- test/Makefile.am | 2 + test/Makefile.sources | 1 + test/clip-device-offset.argb32.ref.png | Bin 0 -> 175 bytes test/clip-device-offset.c | 79 +++++++++++++++++++++++++++++++++ test/clip-device-offset.rgb24.ref.png | Bin 0 -> 168 bytes 5 files changed, 82 insertions(+) create mode 100644 test/clip-device-offset.argb32.ref.png create mode 100644 test/clip-device-offset.c create mode 100644 test/clip-device-offset.rgb24.ref.png diff --git a/test/Makefile.am b/test/Makefile.am index a6e8be32..9ad41f52 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 769fb0f3..c313852c 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 00000000..06be9851 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 00000000..eb0e2495 --- /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 + */ + +#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 00000000..24193845 Binary files /dev/null and b/test/clip-device-offset.rgb24.ref.png differ -- cgit v1.2.3