2 * Copyright © 2009 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 #if CAIRO_HAS_XCB_SURFACE
28 #include <cairo-xcb.h>
31 #include "surface-source.c"
33 #if CAIRO_HAS_XCB_SURFACE
34 static cairo_user_data_key_t closure_key;
37 cairo_device_t *device;
38 xcb_connection_t *connection;
45 struct closure *arg = data;
47 cairo_device_finish (arg->device);
48 cairo_device_destroy (arg->device);
50 xcb_free_pixmap (arg->connection, arg->pixmap);
51 xcb_disconnect (arg->connection);
56 static xcb_render_pictforminfo_t *
57 find_depth (xcb_connection_t *connection, int depth, void **formats_out)
59 xcb_render_query_pict_formats_reply_t *formats;
60 xcb_render_query_pict_formats_cookie_t cookie;
61 xcb_render_pictforminfo_iterator_t i;
63 cookie = xcb_render_query_pict_formats (connection);
64 xcb_flush (connection);
66 formats = xcb_render_query_pict_formats_reply (connection, cookie, 0);
70 for (i = xcb_render_query_pict_formats_formats_iterator (formats);
72 xcb_render_pictforminfo_next (&i))
74 if (XCB_RENDER_PICT_TYPE_DIRECT != i.data->type)
77 if (depth != i.data->depth)
80 *formats_out = formats;
89 static cairo_surface_t *
90 create_source_surface (int size)
92 #if CAIRO_HAS_XCB_SURFACE
93 xcb_connection_t *connection;
94 xcb_render_pictforminfo_t *render_format;
96 cairo_surface_t *surface;
98 xcb_void_cookie_t cookie;
101 connection = xcb_connect (NULL, NULL);
102 if (connection == NULL)
105 data = xmalloc (sizeof (struct closure));
106 data->connection = connection;
108 render_format = find_depth (connection, 32, &formats);
109 if (render_format == NULL) {
110 xcb_disconnect (connection);
115 root = xcb_setup_roots_iterator (xcb_get_setup (connection)).data;
117 data->pixmap = xcb_generate_id (connection);
118 cookie = xcb_create_pixmap_checked (connection, 32,
119 data->pixmap, root->root, size, size);
121 if (xcb_request_check (connection, cookie) != NULL) {
123 xcb_disconnect (connection);
128 surface = cairo_xcb_surface_create_with_xrender_format (connection,
135 data->device = cairo_device_reference (cairo_surface_get_device (surface));
136 cairo_surface_set_user_data (surface, &closure_key, data, cleanup);
144 CAIRO_TEST (xcb_surface_source,
145 "Test using a XCB surface as the source",
146 "source", /* keywords */
147 NULL, /* requirements */