added MouseWheel event support for Silverlight 3.0
[moon.git] / cairo / boilerplate / cairo-boilerplate-xcb.c
blobdca7acf9253401ad434d7cd8d0d172fb5b212b9c
1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2 /*
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
36 xcb_connection_t *c;
37 xcb_pixmap_t pixmap;
38 } xcb_target_closure_t;
40 void
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),
47 0));
50 cairo_surface_t *
51 _cairo_boilerplate_xcb_create_surface (const char *name,
52 cairo_content_t content,
53 int width,
54 int height,
55 int max_width,
56 int max_height,
57 cairo_boilerplate_mode_t mode,
58 int id,
59 void **closure)
61 xcb_screen_t *root;
62 xcb_target_closure_t *xtc;
63 xcb_connection_t *c;
64 xcb_render_pictforminfo_t *render_format;
65 xcb_pict_standard_t format;
67 *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));
69 if (width == 0)
70 width = 1;
71 if (height == 0)
72 height = 1;
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");
77 return NULL;
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,
84 width, height);
86 switch (content) {
87 case CAIRO_CONTENT_COLOR:
88 format = XCB_PICT_STANDARD_RGB_24;
89 break;
90 case CAIRO_CONTENT_COLOR_ALPHA:
91 format = XCB_PICT_STANDARD_ARGB_32;
92 break;
93 case CAIRO_CONTENT_ALPHA: /* would be XCB_PICT_STANDARD_A_8 */
94 default:
95 CAIRO_BOILERPLATE_LOG ("Invalid content for XCB test: %d\n", content);
96 return NULL;
99 render_format = xcb_render_util_find_standard_format (xcb_render_util_query_formats (c), format);
100 if (render_format->id == 0)
101 return NULL;
103 return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
104 render_format,
105 width, height);
108 void
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);
115 free (xtc);