From a4c960a93cf5f37819b933d19f92e17e6c047c66 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 18 Jan 2008 17:14:17 +0000 Subject: [PATCH] [test] Add tests using each backend as a source. Inspired by bug 7362 (painting a glitz surface onto an xlib surface crashes cairo) and the lack of coverage for _cairo_paginated_surface_acquire_source_image(), these tests attempt to use each backend as a source surface for all the other backends. For example, this checks that one can construct a PS file ready for printing and then copy that surface to an image/xlib for previewing. --- test/.gitignore | 6 + test/Makefile.am | 19 ++- test/glitz-surface-source-ref.png | Bin 0 -> 268 bytes test/glitz-surface-source.c | 196 ++++++++++++++++++++++++++++++ test/image-surface-source-ref.png | Bin 0 -> 268 bytes test/image-surface-source.c | 35 ++++++ test/pdf-surface-source-ref.png | Bin 0 -> 268 bytes test/pdf-surface-source.c | 41 +++++++ test/ps-surface-source-ref.png | Bin 0 -> 268 bytes test/ps-surface-source.c | 41 +++++++ test/surface-source.c | 93 ++++++++++++++ test/svg-surface-source-ref.png | Bin 0 -> 268 bytes test/svg-surface-source.c | 41 +++++++ test/xlib-surface-source-ref.png | Bin 0 -> 268 bytes test/xlib-surface-source.c | 76 ++++++++++++ 15 files changed, 544 insertions(+), 4 deletions(-) create mode 100644 test/glitz-surface-source-ref.png create mode 100644 test/glitz-surface-source.c create mode 100644 test/image-surface-source-ref.png create mode 100644 test/image-surface-source.c create mode 100644 test/pdf-surface-source-ref.png create mode 100644 test/pdf-surface-source.c create mode 100644 test/ps-surface-source-ref.png create mode 100644 test/ps-surface-source.c create mode 100644 test/surface-source.c create mode 100644 test/svg-surface-source-ref.png create mode 100644 test/svg-surface-source.c create mode 100644 test/xlib-surface-source-ref.png create mode 100644 test/xlib-surface-source.c diff --git a/test/.gitignore b/test/.gitignore index 51b64acf0..12b9973aa 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -73,10 +73,12 @@ get-clip get-group-target get-path-extents get-render-format +glitz-surface-source glyph-cache-pressure gradient-alpha gradient-zero-stops imagediff +image-surface-source infinite-join in-fill-empty-trapezoid in-fill-trapezoid @@ -117,9 +119,11 @@ pattern-getters pdf2png pdf-features pdf-features.pdf +pdf-surface-source png-flatten ps-features ps-features.ps +ps-surface-source push-group radial-gradient random-intersections @@ -129,6 +133,7 @@ svg-clip svg-clip.svg svg-surface svg-surface.svg +svg-surface-source pixman-rotate pthread-show-text rectangle-rounding-error @@ -171,6 +176,7 @@ unantialiased-shapes unbounded-operator user-data xlib-surface +xlib-surface-source zero-alpha valgrind-log *-out.pdf diff --git a/test/Makefile.am b/test/Makefile.am index 39d5e0631..e0823070f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -59,9 +59,10 @@ get-group-target$(EXEEXT) \ get-path-extents$(EXEEXT) \ gradient-alpha$(EXEEXT) \ gradient-zero-stops$(EXEEXT) \ +image-surface-source$(EXEEXT) \ infinite-join$(EXEEXT) \ in-fill-empty-trapezoid$(EXEEXT) \ -in-fill-trapezoid$(EXEEXT) \ +in-fill-trapezoid$(EXEEXT) \ invalid-matrix$(EXEEXT) \ leaky-dash$(EXEEXT) \ leaky-polygon$(EXEEXT) \ @@ -194,21 +195,30 @@ TESTS += ft-text-vertical-layout-type3$(EXEEXT) TESTS += ft-text-antialias-none$(EXEEXT) endif -if CAIRO_HAS_SVG_SURFACE -TESTS += svg-surface$(EXEEXT) -TESTS += svg-clip$(EXEEXT) +# Need to add win32-surface-source, quartz-surface-source +if CAIRO_HAS_GLITZ_SURFACE +TESTS += glitz-surface-source$(EXEEXT) endif if CAIRO_HAS_PDF_SURFACE TESTS += pdf-features$(EXEEXT) +TESTS += pdf-surface-source$(EXEEXT) endif if CAIRO_HAS_PS_SURFACE TESTS += ps-features$(EXEEXT) +TESTS += ps-surface-source$(EXEEXT) +endif + +if CAIRO_HAS_SVG_SURFACE +TESTS += svg-surface$(EXEEXT) +TESTS += svg-clip$(EXEEXT) +TESTS += svg-surface-source$(EXEEXT) endif if CAIRO_HAS_XLIB_SURFACE TESTS += xlib-surface$(EXEEXT) +TESTS += xlib-surface-source$(EXEEXT) endif if CAIRO_HAS_XLIB_XRENDER_SURFACE @@ -515,6 +525,7 @@ EXTRA_DIST = \ 6x13.pcf \ make-html.pl \ romedalen.png \ +surface-source.c \ $(REFERENCE_IMAGES) # Any test for which the code committed to CVS is expected to fail diff --git a/test/glitz-surface-source-ref.png b/test/glitz-surface-source-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..3fa8bbe55ed7fc6f1002da27ea7561c9bb19fe02 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^Q6S901SGegx)utg*pj^6T^Rm@;DWu&Cj&*;OFVsD z*>5lk3CIcW6o@wm3a#^WaSW-L^Y*49-w^{IhJ#D~|1aj#U+w7NZ+v6Zn$U=AAOr34 z`uU?Y{tjHP{Di~Osc!=D f6f@8nKg{j7o?$J&qnhCY + */ + +#include "cairo-test.h" +#include +#include +#include + +#include + +#define NAME "glitz" +#include "surface-source.c" + +static cairo_user_data_key_t closure_key; + +#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE +#include + +struct closure { + Display *dpy; + Window win; +}; + +static void +cleanup (void *data) +{ + struct closure *closure = data; + + glitz_glx_fini (); + + if (closure->win) + XDestroyWindow (closure->dpy, closure->win); + + XCloseDisplay (closure->dpy); + + free (closure); +} + +static glitz_surface_t * +_glitz_glx_create_surface (glitz_format_name_t formatname, + int width, + int height, + struct closure *closure) +{ + Display * dpy = closure->dpy; + int scr = DefaultScreen(dpy); + glitz_drawable_format_t templ; + glitz_drawable_format_t * dformat = NULL; + unsigned long mask; + glitz_drawable_t * drawable = NULL; + glitz_format_t * format; + glitz_surface_t * sr; + + XSizeHints xsh; + XSetWindowAttributes xswa; + XVisualInfo * vinfo; + + memset(&templ, 0, sizeof(templ)); + templ.color.red_size = 8; + templ.color.green_size = 8; + templ.color.blue_size = 8; + templ.color.alpha_size = 8; + templ.color.fourcc = GLITZ_FOURCC_RGB; + templ.samples = 1; + + glitz_glx_init (NULL); + + mask = GLITZ_FORMAT_SAMPLES_MASK | + GLITZ_FORMAT_FOURCC_MASK | + GLITZ_FORMAT_RED_SIZE_MASK | + GLITZ_FORMAT_GREEN_SIZE_MASK | + GLITZ_FORMAT_BLUE_SIZE_MASK; + if (formatname == GLITZ_STANDARD_ARGB32) + mask |= GLITZ_FORMAT_ALPHA_SIZE_MASK; + + /* Try for a pbuffer first */ + if (!getenv("CAIRO_TEST_FORCE_GLITZ_WINDOW")) + dformat = glitz_glx_find_pbuffer_format (dpy, scr, mask, &templ, 0); + + if (dformat) { + closure->win = None; + + drawable = glitz_glx_create_pbuffer_drawable (dpy, scr, dformat, + width, height); + if (!drawable) + goto FAIL; + } else { + /* No pbuffer, try window */ + dformat = glitz_glx_find_window_format (dpy, scr, mask, &templ, 0); + + if (!dformat) + goto FAIL; + + vinfo = glitz_glx_get_visual_info_from_format(dpy, + DefaultScreen(dpy), + dformat); + + if (!vinfo) + goto FAIL; + + xsh.flags = PSize; + xsh.x = 0; + xsh.y = 0; + xsh.width = width; + xsh.height = height; + + xswa.colormap = XCreateColormap (dpy, RootWindow(dpy, scr), + vinfo->visual, AllocNone); + closure->win = XCreateWindow (dpy, RootWindow(dpy, scr), + xsh.x, xsh.y, xsh.width, xsh.height, + 0, vinfo->depth, CopyFromParent, + vinfo->visual, CWColormap, &xswa); + XFree (vinfo); + + drawable = + glitz_glx_create_drawable_for_window (dpy, scr, + dformat, closure->win, + width, height); + + if (!drawable) + goto DESTROY_WINDOW; + } + + format = glitz_find_standard_format (drawable, formatname); + if (!format) + goto DESTROY_DRAWABLE; + + sr = glitz_surface_create (drawable, format, width, height, 0, NULL); + if (!sr) + goto DESTROY_DRAWABLE; + + if (closure->win == None || dformat->doublebuffer) { + glitz_surface_attach (sr, drawable, GLITZ_DRAWABLE_BUFFER_BACK_COLOR); + } else { + XMapWindow (closure->dpy, closure->win); + glitz_surface_attach (sr, drawable, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR); + } + + glitz_drawable_destroy (drawable); + + return sr; + DESTROY_DRAWABLE: + glitz_drawable_destroy (drawable); + DESTROY_WINDOW: + if (closure->win) + XDestroyWindow (dpy, closure->win); + FAIL: + return NULL; +} + +static cairo_surface_t * +create_source_surface (int size) +{ + struct closure *closure; + glitz_surface_t * glitz_surface; + cairo_surface_t *surface; + + closure = xcalloc (1, sizeof (struct closure)); + + closure->dpy = XOpenDisplay (getenv("CAIRO_TEST_GLITZ_DISPLAY")); + assert (closure->dpy); + + glitz_surface = _glitz_glx_create_surface (GLITZ_STANDARD_ARGB32, + size, size, + closure); + assert (glitz_surface != NULL); + + surface = cairo_glitz_surface_create (glitz_surface); + + cairo_surface_set_user_data (surface, &closure_key, closure, cleanup); + + return surface; +} +#endif diff --git a/test/image-surface-source-ref.png b/test/image-surface-source-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..3fa8bbe55ed7fc6f1002da27ea7561c9bb19fe02 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^Q6S901SGegx)utg*pj^6T^Rm@;DWu&Cj&*;OFVsD z*>5lk3CIcW6o@wm3a#^WaSW-L^Y*49-w^{IhJ#D~|1aj#U+w7NZ+v6Zn$U=AAOr34 z`uU?Y{tjHP{Di~Osc!=D f6f@8nKg{j7o?$J&qnhCY + */ + +#include "cairo-test.h" + +#define NAME "image" +#include "surface-source.c" + +static cairo_surface_t * +create_source_surface (int size) +{ + return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size); +} diff --git a/test/pdf-surface-source-ref.png b/test/pdf-surface-source-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..3fa8bbe55ed7fc6f1002da27ea7561c9bb19fe02 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^Q6S901SGegx)utg*pj^6T^Rm@;DWu&Cj&*;OFVsD z*>5lk3CIcW6o@wm3a#^WaSW-L^Y*49-w^{IhJ#D~|1aj#U+w7NZ+v6Zn$U=AAOr34 z`uU?Y{tjHP{Di~Osc!=D f6f@8nKg{j7o?$J&qnhCY + */ + +#include "cairo-test.h" +#include + +#define NAME "pdf" +#include "surface-source.c" + +static cairo_surface_t * +create_source_surface (int size) +{ + cairo_surface_t *surface; + + surface = cairo_pdf_surface_create ("pdf-surface-source.pdf", size, size); + cairo_surface_set_fallback_resolution (surface, 72., 72.); + + return surface; +} diff --git a/test/ps-surface-source-ref.png b/test/ps-surface-source-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..3fa8bbe55ed7fc6f1002da27ea7561c9bb19fe02 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^Q6S901SGegx)utg*pj^6T^Rm@;DWu&Cj&*;OFVsD z*>5lk3CIcW6o@wm3a#^WaSW-L^Y*49-w^{IhJ#D~|1aj#U+w7NZ+v6Zn$U=AAOr34 z`uU?Y{tjHP{Di~Osc!=D f6f@8nKg{j7o?$J&qnhCY + */ + +#include "cairo-test.h" +#include + +#define NAME "ps" +#include "surface-source.c" + +static cairo_surface_t * +create_source_surface (int size) +{ + cairo_surface_t *surface; + + surface = cairo_ps_surface_create ("ps-surface-source.ps", size, size); + cairo_surface_set_fallback_resolution (surface, 72., 72.); + + return surface; +} diff --git a/test/surface-source.c b/test/surface-source.c new file mode 100644 index 000000000..c7f333469 --- /dev/null +++ b/test/surface-source.c @@ -0,0 +1,93 @@ +/* + * 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 + */ + +#include "cairo-test.h" + +static cairo_test_draw_function_t draw; +static cairo_surface_t *create_source_surface (int size); + +#define SIZE 90 + +cairo_test_t test = { + NAME "-surface-source", + "Test using various surfaces as the source", + SIZE, SIZE, + draw +}; + +static void +draw_pattern (cairo_surface_t *surface, int surface_size) +{ + cairo_t *cr = cairo_create (surface); + + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_rectangle (cr, + 0, 0, + surface_size / 2, surface_size / 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_rectangle (cr, + surface_size / 2, 0, + surface_size / 2, surface_size / 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 0, 1, 0); + cairo_rectangle (cr, + 0, surface_size / 2, + surface_size / 2, surface_size / 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_rectangle (cr, + surface_size / 2, surface_size / 2, + surface_size / 2, surface_size / 2); + cairo_fill (cr); + + cairo_destroy (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *surface; + int surface_size; + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); + + surface_size = SIZE - 30; + surface = create_source_surface (surface_size); + draw_pattern (surface, surface_size); + + cairo_set_source_surface (cr, surface, 15, 15); + cairo_surface_destroy (surface); + cairo_paint (cr); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test); +} diff --git a/test/svg-surface-source-ref.png b/test/svg-surface-source-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..3fa8bbe55ed7fc6f1002da27ea7561c9bb19fe02 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^Q6S901SGegx)utg*pj^6T^Rm@;DWu&Cj&*;OFVsD z*>5lk3CIcW6o@wm3a#^WaSW-L^Y*49-w^{IhJ#D~|1aj#U+w7NZ+v6Zn$U=AAOr34 z`uU?Y{tjHP{Di~Osc!=D f6f@8nKg{j7o?$J&qnhCY + */ + +#include "cairo-test.h" +#include + +#define NAME "svg" +#include "surface-source.c" + +static cairo_surface_t * +create_source_surface (int size) +{ + cairo_surface_t *surface; + + surface = cairo_svg_surface_create ("svg-surface-source.svg", size, size); + cairo_surface_set_fallback_resolution (surface, 72., 72.); + + return surface; +} diff --git a/test/xlib-surface-source-ref.png b/test/xlib-surface-source-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..3fa8bbe55ed7fc6f1002da27ea7561c9bb19fe02 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^Q6S901SGegx)utg*pj^6T^Rm@;DWu&Cj&*;OFVsD z*>5lk3CIcW6o@wm3a#^WaSW-L^Y*49-w^{IhJ#D~|1aj#U+w7NZ+v6Zn$U=AAOr34 z`uU?Y{tjHP{Di~Osc!=D f6f@8nKg{j7o?$J&qnhCY + */ + +#include "cairo-test.h" +#include +#if CAIRO_HAS_XLIB_XRENDER_SURFACE +#include +#endif + +#define NAME "xlib" +#include "surface-source.c" + +static cairo_user_data_key_t closure_key; + +struct closure { + Display *dpy; + Pixmap pix; +}; + +static void +cleanup (void *data) +{ + struct closure *arg = data; + + XFreePixmap (arg->dpy, arg->pix); + XCloseDisplay (arg->dpy); + + free (arg); +} + +static cairo_surface_t * +create_source_surface (int size) +{ + XRenderPictFormat *xrender_format; + struct closure *data; + cairo_surface_t *surface; + + data = xmalloc (sizeof (struct closure)); + + data->dpy = XOpenDisplay (NULL); + xrender_format = XRenderFindStandardFormat (data->dpy, PictStandardARGB32); + + data->pix = XCreatePixmap (data->dpy, DefaultRootWindow (data->dpy), + size, size, xrender_format->depth); + + surface = cairo_xlib_surface_create_with_xrender_format (data->dpy, + data->pix, + DefaultScreenOfDisplay (data->dpy), + xrender_format, + size, size); + cairo_surface_set_user_data (surface, &closure_key, data, cleanup); + + return surface; +}