1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
3 * Copyright © 2004,2006 Red Hat, Inc.
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. Red Hat, Inc. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
16 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-boilerplate.h"
28 #include "cairo-boilerplate-xcb-private.h"
30 #include <cairo-xcb-xrender.h>
32 #include <xcb/xcb_renderutil.h>
34 typedef struct _xcb_target_closure
38 } xcb_target_closure_t
;
41 _cairo_boilerplate_xcb_synchronize (void *closure
)
43 xcb_target_closure_t
*xtc
= closure
;
44 free (xcb_get_image_reply (xtc
->c
,
45 xcb_get_image (xtc
->c
, XCB_IMAGE_FORMAT_Z_PIXMAP
,
46 xtc
->pixmap
, 0, 0, 1, 1, /* AllPlanes */ ~0UL),
51 _cairo_boilerplate_xcb_create_surface (const char *name
,
52 cairo_content_t content
,
57 cairo_boilerplate_mode_t mode
,
62 xcb_target_closure_t
*xtc
;
64 xcb_render_pictforminfo_t
*render_format
;
65 xcb_pict_standard_t format
;
67 *closure
= xtc
= xmalloc (sizeof (xcb_target_closure_t
));
74 xtc
->c
= c
= xcb_connect(NULL
,NULL
);
75 if (xcb_connection_has_error(c
)) {
76 CAIRO_BOILERPLATE_LOG ("Failed to connect to X server through XCB\n");
80 root
= xcb_setup_roots_iterator(xcb_get_setup(c
)).data
;
82 xtc
->pixmap
= xcb_generate_id (c
);
83 xcb_create_pixmap (c
, 32, xtc
->pixmap
, root
->root
,
87 case CAIRO_CONTENT_COLOR
:
88 format
= XCB_PICT_STANDARD_RGB_24
;
90 case CAIRO_CONTENT_COLOR_ALPHA
:
91 format
= XCB_PICT_STANDARD_ARGB_32
;
93 case CAIRO_CONTENT_ALPHA
: /* would be XCB_PICT_STANDARD_A_8 */
95 CAIRO_BOILERPLATE_LOG ("Invalid content for XCB test: %d\n", content
);
99 render_format
= xcb_render_util_find_standard_format (xcb_render_util_query_formats (c
), format
);
100 if (render_format
->id
== 0)
103 return cairo_xcb_surface_create_with_xrender_format (c
, xtc
->pixmap
, root
,
109 _cairo_boilerplate_xcb_cleanup (void *closure
)
111 xcb_target_closure_t
*xtc
= closure
;
113 xcb_free_pixmap (xtc
->c
, xtc
->pixmap
);
114 xcb_disconnect (xtc
->c
);