2 * Copyright © 2007 Bart Massey <bart@cs.pdx.edu>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the names of the authors or their
22 * institutions shall not be used in advertising or otherwise to promote the
23 * sale, use or other dealings in this Software without prior written
24 * authorization from the authors.
36 #include "../aux/xcb_aux.h"
37 #include "xcb_image.h"
45 main (int argc, char *argv[])
51 xcb_rectangle_t rect_coord = { 0, 0, W_W, W_H};
52 xcb_gcontext_t bgcolor, fgcolor;
53 xcb_point_t points[2];
59 xcb_generic_event_t *e;
62 /* Open the connexion to the X server and get the first screen */
63 c = xcb_connect (NULL, &screen_nbr);
64 screen = xcb_aux_get_screen (c, screen_nbr);
65 depth = xcb_aux_get_depth (c, screen);
67 /* Create a black graphic context for drawing in the foreground */
70 fgcolor = xcb_generate_id(c);
71 mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
72 valgc[0] = screen->black_pixel;
73 valgc[1] = 0; /* no graphics exposures */
74 xcb_create_gc(c, fgcolor, win, mask, valgc);
76 bgcolor = xcb_generate_id(c);
77 mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
78 valgc[0] = screen->white_pixel;
79 valgc[1] = 0; /* no graphics exposures */
80 xcb_create_gc(c, bgcolor, win, mask, valgc);
83 printf ("shm test begin\n");
85 xcb_shm_query_version_reply_t *rep;
86 xcb_shm_segment_info_t shminfo;
88 rep = xcb_shm_query_version_reply (c,
89 xcb_shm_query_version (c),
91 if (!rep || !rep->shared_pixmaps ||
92 rep->major_version < 1 ||
93 (rep->major_version == 1 && rep->minor_version == 0))
95 printf ("No or insufficient shm support...\n");
98 format = rep->pixmap_format;
99 img = xcb_image_create_native (c, W_W, W_H, format, depth,
104 printf ("Can't create image...\n");
108 printf ("Create image summary:\n");
109 printf (" * format..........: %d\n", img->format);
110 printf (" * byte order......: %d\n", img->byte_order);
111 printf (" * bitmap unit.....: %d\n", img->bpp);
112 printf (" * bitmap order....: %d\n", img->bit_order);
113 printf (" * bitmap pad......: %d\n", img->scanline_pad);
115 shminfo.shmid = shmget (IPC_PRIVATE, img->size, IPC_CREAT|0777);
116 shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
117 img->data = shminfo.shmaddr;
119 shminfo.shmseg = xcb_generate_id (c);
120 xcb_shm_attach(c, shminfo.shmseg, shminfo.shmid, 0);
121 shmctl(shminfo.shmid, IPC_RMID, 0);
123 /* Draw in the image */
124 printf ("put the pixel\n");
125 xcb_image_put_pixel (img, 20, 20, 65535);
126 printf ("fin put pixel\n");
128 /* Ask for our window's Id */
129 win = xcb_generate_id(c);
131 /* Create the window */
132 mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE;
133 valwin[0] = screen->white_pixel;
134 valwin[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE;
135 valwin[2] = XCB_EVENT_MASK_BUTTON_PRESS;
136 xcb_create_window (c, /* Connection */
139 screen->root, /* parent window */
141 W_W, W_H, /* width, height */
142 10, /* border_width */
143 XCB_WINDOW_CLASS_INPUT_OUTPUT,/* class */
144 screen->root_visual, /* visual */
145 mask, valwin); /* masks, not used yet */
147 /* Map the window on the screen */
148 xcb_map_window (c, win);
150 /* Create a Pixmap that will fill the window */
151 rect = xcb_generate_id (c);
152 xcb_create_pixmap(c, depth, rect, win, W_W, W_H);
153 xcb_poly_fill_rectangle(c, rect, bgcolor, 1, &rect_coord);
158 xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, rect, fgcolor, 2, points);
162 while ((e = xcb_wait_for_event(c)))
164 switch (e->response_type)
168 xcb_copy_area(c, rect, win, bgcolor,
169 0, 0, 0, 0, W_W, W_H);
170 printf ("put image\n");
171 xcb_image_shm_put (c, win, fgcolor,