2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / cairo / test / xlib-surface-source.c
blob3c33516323ad000a737641e9eb089a99dd870350
1 /*
2 * Copyright © 2008 Chris Wilson
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Chris Wilson not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Chris Wilson makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Chris Wilson <chris@chris-wilson.co.uk>
26 #include "cairo-test.h"
27 #include <cairo-xlib.h>
28 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
29 #include <cairo-xlib-xrender.h>
30 #endif
32 #define NAME "xlib"
33 #include "surface-source.c"
35 static cairo_user_data_key_t closure_key;
37 struct closure {
38 Display *dpy;
39 Pixmap pix;
42 static void
43 cleanup (void *data)
45 struct closure *arg = data;
47 XFreePixmap (arg->dpy, arg->pix);
48 XCloseDisplay (arg->dpy);
50 free (arg);
53 static cairo_surface_t *
54 create_source_surface (int size)
56 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
57 XRenderPictFormat *xrender_format;
58 struct closure *data;
59 cairo_surface_t *surface;
61 data = xmalloc (sizeof (struct closure));
63 data->dpy = XOpenDisplay (NULL);
64 if (!data->dpy) {
65 return NULL;
68 xrender_format = XRenderFindStandardFormat (data->dpy, PictStandardARGB32);
70 data->pix = XCreatePixmap (data->dpy, DefaultRootWindow (data->dpy),
71 size, size, xrender_format->depth);
73 surface = cairo_xlib_surface_create_with_xrender_format (data->dpy,
74 data->pix,
75 DefaultScreenOfDisplay (data->dpy),
76 xrender_format,
77 size, size);
78 cairo_surface_set_user_data (surface, &closure_key, data, cleanup);
80 return surface;
81 #else
82 return NULL;
83 #endif