1 #include "evas_common.h"
3 #include "evas_xcb_buffer.h"
5 static int _xcb_err = 0;
8 evas_software_xcb_x_write_mask_line(Outbuf *buf,
9 Xcb_Output_Buffer *xcbob,
20 dst_ptr = evas_software_xcb_x_output_buffer_data(xcbob, &bpl);
21 dst_ptr = dst_ptr + (bpl * y);
23 if (buf->priv.x11.xcb.bit_swap)
25 for (x = 0; x < w; x += 8)
28 ((A_VAL(&(src_ptr[0])) >> 7) << 7) |
29 ((A_VAL(&(src_ptr[1])) >> 7) << 6) |
30 ((A_VAL(&(src_ptr[2])) >> 7) << 5) |
31 ((A_VAL(&(src_ptr[3])) >> 7) << 4) |
32 ((A_VAL(&(src_ptr[4])) >> 7) << 3) |
33 ((A_VAL(&(src_ptr[5])) >> 7) << 2) |
34 ((A_VAL(&(src_ptr[6])) >> 7) << 1) |
35 ((A_VAL(&(src_ptr[7])) >> 7) << 0);
42 for (x = 0; x < w; x += 8)
45 ((A_VAL(&(src_ptr[0])) >> 7) << 0) |
46 ((A_VAL(&(src_ptr[1])) >> 7) << 1) |
47 ((A_VAL(&(src_ptr[2])) >> 7) << 2) |
48 ((A_VAL(&(src_ptr[3])) >> 7) << 3) |
49 ((A_VAL(&(src_ptr[4])) >> 7) << 4) |
50 ((A_VAL(&(src_ptr[5])) >> 7) << 5) |
51 ((A_VAL(&(src_ptr[6])) >> 7) << 6) |
52 ((A_VAL(&(src_ptr[7])) >> 7) << 7);
60 xcb_image_put_pixel(xcbob->image, x, y, A_VAL(src_ptr) >> 7);
66 evas_software_xcb_x_write_mask_line_rev(Outbuf *buf,
67 Xcb_Output_Buffer *xcbob,
77 src_ptr = src + w - 1;
78 dst_ptr = evas_software_xcb_x_output_buffer_data(xcbob, &bpl);
79 dst_ptr = dst_ptr + (bpl * y);
81 if (buf->priv.x11.xcb.bit_swap)
83 for (x = 0; x < w; x += 8)
86 ((A_VAL(&(src_ptr[ 0])) >> 7) << 7) |
87 ((A_VAL(&(src_ptr[-1])) >> 7) << 6) |
88 ((A_VAL(&(src_ptr[-2])) >> 7) << 5) |
89 ((A_VAL(&(src_ptr[-3])) >> 7) << 4) |
90 ((A_VAL(&(src_ptr[-4])) >> 7) << 3) |
91 ((A_VAL(&(src_ptr[-5])) >> 7) << 2) |
92 ((A_VAL(&(src_ptr[-6])) >> 7) << 1) |
93 ((A_VAL(&(src_ptr[-7])) >> 7) << 0);
100 for (x = 0; x < w; x += 8)
103 ((A_VAL(&(src_ptr[ 0])) >> 7) << 0) |
104 ((A_VAL(&(src_ptr[-1])) >> 7) << 1) |
105 ((A_VAL(&(src_ptr[-2])) >> 7) << 2) |
106 ((A_VAL(&(src_ptr[-3])) >> 7) << 3) |
107 ((A_VAL(&(src_ptr[-4])) >> 7) << 4) |
108 ((A_VAL(&(src_ptr[-5])) >> 7) << 5) |
109 ((A_VAL(&(src_ptr[-6])) >> 7) << 6) |
110 ((A_VAL(&(src_ptr[-7])) >> 7) << 7);
118 xcb_image_put_pixel(xcbob->image, x, y, A_VAL(src_ptr) >> 7);
124 evas_software_xcb_x_write_mask_line_vert(Outbuf *buf,
125 Xcb_Output_Buffer *xcbob,
137 dst_ptr = evas_software_xcb_x_output_buffer_data(xcbob, &bpl);
138 dst_ptr = dst_ptr + (bpl * ym);
140 if (buf->priv.x11.xcb.bit_swap)
142 for (y = 0; y < h; y += 8)
145 ((A_VAL(&(src_ptr[0 * w])) >> 7) << 7) |
146 ((A_VAL(&(src_ptr[1 * w])) >> 7) << 6) |
147 ((A_VAL(&(src_ptr[2 * w])) >> 7) << 5) |
148 ((A_VAL(&(src_ptr[3 * w])) >> 7) << 4) |
149 ((A_VAL(&(src_ptr[4 * w])) >> 7) << 3) |
150 ((A_VAL(&(src_ptr[5 * w])) >> 7) << 2) |
151 ((A_VAL(&(src_ptr[6 * w])) >> 7) << 1) |
152 ((A_VAL(&(src_ptr[7 * w])) >> 7) << 0);
159 for (y = 0; y < h; y += 8)
162 ((A_VAL(&(src_ptr[0 * w])) >> 7) << 0) |
163 ((A_VAL(&(src_ptr[1 * w])) >> 7) << 1) |
164 ((A_VAL(&(src_ptr[2 * w])) >> 7) << 2) |
165 ((A_VAL(&(src_ptr[3 * w])) >> 7) << 3) |
166 ((A_VAL(&(src_ptr[4 * w])) >> 7) << 4) |
167 ((A_VAL(&(src_ptr[5 * w])) >> 7) << 5) |
168 ((A_VAL(&(src_ptr[6 * w])) >> 7) << 6) |
169 ((A_VAL(&(src_ptr[7 * w])) >> 7) << 7);
177 xcb_image_put_pixel(xcbob->image, y, ym, A_VAL(src_ptr) >> 7);
183 evas_software_xcb_x_write_mask_line_vert_rev(Outbuf *buf,
184 Xcb_Output_Buffer *xcbob,
195 src_ptr = src + ((h - 1) * w);
196 dst_ptr = evas_software_xcb_x_output_buffer_data(xcbob, &bpl);
197 dst_ptr = dst_ptr + (bpl * ym);
199 if (buf->priv.x11.xcb.bit_swap)
201 for (y = 0; y < h; y += 8)
204 ((A_VAL(&(src_ptr[ 0 * w])) >> 7) << 7) |
205 ((A_VAL(&(src_ptr[-1 * w])) >> 7) << 6) |
206 ((A_VAL(&(src_ptr[-2 * w])) >> 7) << 5) |
207 ((A_VAL(&(src_ptr[-3 * w])) >> 7) << 4) |
208 ((A_VAL(&(src_ptr[-4 * w])) >> 7) << 3) |
209 ((A_VAL(&(src_ptr[-5 * w])) >> 7) << 2) |
210 ((A_VAL(&(src_ptr[-6 * w])) >> 7) << 1) |
211 ((A_VAL(&(src_ptr[-7 * w])) >> 7) << 0);
218 for (y = 0; y < h; y += 8)
221 ((A_VAL(&(src_ptr[ 0 * w])) >> 7) << 0) |
222 ((A_VAL(&(src_ptr[-1 * w])) >> 7) << 1) |
223 ((A_VAL(&(src_ptr[-2 * w])) >> 7) << 2) |
224 ((A_VAL(&(src_ptr[-3 * w])) >> 7) << 3) |
225 ((A_VAL(&(src_ptr[-4 * w])) >> 7) << 4) |
226 ((A_VAL(&(src_ptr[-5 * w])) >> 7) << 5) |
227 ((A_VAL(&(src_ptr[-6 * w])) >> 7) << 6) |
228 ((A_VAL(&(src_ptr[-7 * w])) >> 7) << 7);
236 xcb_image_put_pixel(xcbob->image, y, ym, A_VAL(src_ptr) >> 7);
242 evas_software_xcb_x_can_do_shm(xcb_connection_t *c,
243 xcb_screen_t *screen)
245 static xcb_connection_t *cached_c = NULL;
246 static int cached_result = 0;
248 if (c == cached_c) return cached_result;
251 if (xcb_get_extension_data(c, &xcb_shm_id))
253 Xcb_Output_Buffer *xcbob;
255 xcbob = evas_software_xcb_x_output_buffer_new(c,
266 evas_software_xcb_x_output_buffer_free(xcbob, 1);
275 * FIXME: no error mechanism
279 /* x_output_tmp_xcb_err(xcb_connection_t *c, XErrorEvent * ev) */
286 evas_software_xcb_x_output_buffer_new(xcb_connection_t *c,
293 Xcb_Output_Buffer *xcbob;
295 xcbob = calloc(1, sizeof(Xcb_Output_Buffer));
296 if (!xcbob) return NULL;
298 xcbob->connection = c;
300 xcbob->shm_info = NULL;
306 xcbob->shm_info = malloc(sizeof(xcb_shm_segment_info_t));
309 xcbob->shm_info->shmseg = xcb_generate_id(c);
310 xcbob->image = xcb_image_create_native(c, w, h,
311 XCB_IMAGE_FORMAT_Z_PIXMAP,
312 depth, NULL, ~0, NULL);
315 xcbob->shm_info->shmid = shmget(IPC_PRIVATE,
318 if (xcbob->shm_info->shmid >= 0)
320 xcbob->shm_info->shmaddr = xcbob->image->data =
321 shmat(xcbob->shm_info->shmid, 0, 0);
322 if (xcbob->shm_info->shmaddr != NULL)
325 * FIXME: no error mechanism
328 /* XErrorHandler ph; */
329 /* EventHandlers eh; */
331 free(xcb_get_input_focus_reply(c, xcb_get_input_focus_unchecked(c), NULL));
333 /* ph = XSetErrorHandler((XErrorHandler) */
334 /* x_output_tmp_x_err); */
336 xcbob->shm_info->shmseg,
337 xcbob->shm_info->shmid, 0);
338 free(xcb_get_input_focus_reply(c, xcb_get_input_focus_unchecked(c), NULL));
339 /* XSetErrorHandler((XErrorHandler)ph); */
342 xcbob->bpl = xcbob->image->stride;
343 xcbob->psize = xcbob->bpl * xcbob->h;
347 shmdt(xcbob->shm_info->shmaddr);
348 shmctl(xcbob->shm_info->shmid, IPC_RMID, 0);
350 if (xcbob->image) xcb_image_destroy(xcbob->image);
353 if (xcbob->shm_info) free(xcbob->shm_info);
354 xcbob->shm_info = NULL;
358 if (try_shm > 1) return NULL;
360 xcbob->image = xcb_image_create_native(c, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP,
361 depth, NULL, ~0, NULL);
370 if (!xcbob->image->data)
372 xcbob->image->data = malloc(xcbob->image->size);
373 if (!xcbob->image->data)
375 xcb_image_destroy(xcbob->image);
381 xcbob->bpl = xcbob->image->stride;
382 xcbob->psize = xcbob->image->size;
388 evas_software_xcb_x_output_buffer_free(Xcb_Output_Buffer *xcbob,
394 free(xcb_get_input_focus_reply(xcbob->connection,
395 xcb_get_input_focus_unchecked(xcbob->connection),
397 xcb_shm_detach(xcbob->connection, xcbob->shm_info->shmseg);
398 free(xcbob->image->data);
399 xcb_image_destroy(xcbob->image);
400 shmdt(xcbob->shm_info->shmaddr);
401 shmctl(xcbob->shm_info->shmid, IPC_RMID, 0);
402 free(xcbob->shm_info);
406 if (xcbob->data) xcbob->image->data = NULL;
407 free(xcbob->image->data);
408 xcb_image_destroy(xcbob->image);
414 evas_software_xcb_x_output_buffer_paste(Xcb_Output_Buffer *xcbob,
423 xcb_image_shm_put(xcbob->connection, d, gc,
424 xcbob->image, *xcbob->shm_info,
427 xcbob->image->width, xcbob->image->height,
430 free(xcb_get_input_focus_reply(xcbob->connection,
431 xcb_get_input_focus_unchecked(xcbob->connection),
435 xcb_image_put(xcbob->connection, d, gc,
441 evas_software_xcb_x_output_buffer_data(Xcb_Output_Buffer *xcbob,
442 int *bytes_per_line_ret)
444 if (bytes_per_line_ret) *bytes_per_line_ret = xcbob->image->stride;
445 return xcbob->image->data;
449 evas_software_xcb_x_output_buffer_depth(Xcb_Output_Buffer *xcbob)
451 return xcbob->image->bpp;
455 evas_software_xcb_x_output_buffer_byte_order(Xcb_Output_Buffer *xcbob)
457 return xcbob->image->byte_order;
461 evas_software_xcb_x_output_buffer_bit_order(Xcb_Output_Buffer *xcbob)
463 return xcbob->image->bit_order;