mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-03 14:00:18 +01:00
[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.
This commit is contained in:
parent
f59f22eecb
commit
a4c960a93c
15 changed files with 544 additions and 4 deletions
6
test/.gitignore
vendored
6
test/.gitignore
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
BIN
test/glitz-surface-source-ref.png
Normal file
BIN
test/glitz-surface-source-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
196
test/glitz-surface-source.c
Normal file
196
test/glitz-surface-source.c
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* 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@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#include "cairo-test.h"
|
||||
#include <cairo-glitz.h>
|
||||
#include <cairo-xlib.h>
|
||||
#include <cairo-xlib-xrender.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define NAME "glitz"
|
||||
#include "surface-source.c"
|
||||
|
||||
static cairo_user_data_key_t closure_key;
|
||||
|
||||
#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
|
||||
#include <glitz-glx.h>
|
||||
|
||||
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
|
||||
BIN
test/image-surface-source-ref.png
Normal file
BIN
test/image-surface-source-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
35
test/image-surface-source.c
Normal file
35
test/image-surface-source.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#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);
|
||||
}
|
||||
BIN
test/pdf-surface-source-ref.png
Normal file
BIN
test/pdf-surface-source-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
41
test/pdf-surface-source.c
Normal file
41
test/pdf-surface-source.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#include "cairo-test.h"
|
||||
#include <cairo-pdf.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
BIN
test/ps-surface-source-ref.png
Normal file
BIN
test/ps-surface-source-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
41
test/ps-surface-source.c
Normal file
41
test/ps-surface-source.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#include "cairo-test.h"
|
||||
#include <cairo-ps.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
93
test/surface-source.c
Normal file
93
test/surface-source.c
Normal file
|
|
@ -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 <chris@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#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);
|
||||
}
|
||||
BIN
test/svg-surface-source-ref.png
Normal file
BIN
test/svg-surface-source-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
41
test/svg-surface-source.c
Normal file
41
test/svg-surface-source.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#include "cairo-test.h"
|
||||
#include <cairo-svg.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
BIN
test/xlib-surface-source-ref.png
Normal file
BIN
test/xlib-surface-source-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
76
test/xlib-surface-source.c
Normal file
76
test/xlib-surface-source.c
Normal file
|
|
@ -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@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#include "cairo-test.h"
|
||||
#include <cairo-xlib.h>
|
||||
#if CAIRO_HAS_XLIB_XRENDER_SURFACE
|
||||
#include <cairo-xlib-xrender.h>
|
||||
#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;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue