1 #include "evas_common.h"
2 #include "evas_engine.h"
4 static int _xcb_err = 0;
7 evas_software_xcb_x_write_mask_line(Outbuf *buf,
8 Xcb_Output_Buffer *xcbob,
19 dst_ptr = evas_software_xcb_x_output_buffer_data(xcbob, &bpl);
20 dst_ptr = dst_ptr + (bpl * y);
22 if (buf->priv.x.bit_swap)
24 for (x = 0; x < w; x += 8)
27 ((A_VAL(&(src_ptr[0])) >> 7) << 7) |
28 ((A_VAL(&(src_ptr[1])) >> 7) << 6) |
29 ((A_VAL(&(src_ptr[2])) >> 7) << 5) |
30 ((A_VAL(&(src_ptr[3])) >> 7) << 4) |
31 ((A_VAL(&(src_ptr[4])) >> 7) << 3) |
32 ((A_VAL(&(src_ptr[5])) >> 7) << 2) |
33 ((A_VAL(&(src_ptr[6])) >> 7) << 1) |
34 ((A_VAL(&(src_ptr[7])) >> 7) << 0);
41 for (x = 0; x < w; x += 8)
44 ((A_VAL(&(src_ptr[0])) >> 7) << 0) |
45 ((A_VAL(&(src_ptr[1])) >> 7) << 1) |
46 ((A_VAL(&(src_ptr[2])) >> 7) << 2) |
47 ((A_VAL(&(src_ptr[3])) >> 7) << 3) |
48 ((A_VAL(&(src_ptr[4])) >> 7) << 4) |
49 ((A_VAL(&(src_ptr[5])) >> 7) << 5) |
50 ((A_VAL(&(src_ptr[6])) >> 7) << 6) |
51 ((A_VAL(&(src_ptr[7])) >> 7) << 7);
59 xcb_image_put_pixel(xcbob->image, x, y, A_VAL(src_ptr) >> 7);
65 evas_software_xcb_x_can_do_shm(xcb_connection_t *c,
68 static xcb_connection_t *cached_c = NULL;
69 static int cached_result = 0;
71 if (c == cached_c) return cached_result;
74 if (xcb_get_extension_data(c, &xcb_shm_id))
76 Xcb_Output_Buffer *xcbob;
78 xcbob = evas_software_xcb_x_output_buffer_new(c,
89 evas_software_xcb_x_output_buffer_free(xcbob, 1);
98 * FIXME: no error mechanism
102 /* x_output_tmp_xcb_err(xcb_connection_t *c, XErrorEvent * ev) */
109 evas_software_xcb_x_output_buffer_new(xcb_connection_t *c,
116 Xcb_Output_Buffer *xcbob;
118 xcbob = calloc(1, sizeof(Xcb_Output_Buffer));
119 if (!xcbob) return NULL;
121 xcbob->connection = c;
123 xcbob->shm_info = NULL;
131 xcbob->shm_info = malloc(sizeof(xcb_shm_segment_info_t));
134 xcbob->shm_info->shmseg = xcb_generate_id(c);
135 xcbob->image = xcb_image_create_native(c, w, h,
136 XCB_IMAGE_FORMAT_Z_PIXMAP,
137 depth, NULL, ~0, NULL);
140 xcbob->shm_info->shmid = shmget(IPC_PRIVATE,
143 if (xcbob->shm_info->shmid >= 0)
145 xcbob->shm_info->shmaddr = xcbob->image->data =
146 shmat(xcbob->shm_info->shmid, 0, 0);
147 if (xcbob->shm_info->shmaddr != NULL)
150 * FIXME: no error mechanism
153 /* XErrorHandler ph; */
154 /* EventHandlers eh; */
156 // free(xcb_get_input_focus_reply(c, xcb_get_input_focus_unchecked(c), NULL));
158 /* ph = XSetErrorHandler((XErrorHandler) */
159 /* x_output_tmp_x_err); */
161 xcbob->shm_info->shmseg,
162 xcbob->shm_info->shmid, 0);
163 // free(xcb_get_input_focus_reply(c, xcb_get_input_focus_unchecked(c), NULL));
164 /* XSetErrorHandler((XErrorHandler)ph); */
167 xcbob->bpl = xcbob->image->stride;
168 xcbob->psize = xcbob->bpl * xcbob->h;
172 shmdt(xcbob->shm_info->shmaddr);
173 shmctl(xcbob->shm_info->shmid, IPC_RMID, 0);
175 if (xcbob->image) xcb_image_destroy(xcbob->image);
178 if (xcbob->shm_info) free(xcbob->shm_info);
179 xcbob->shm_info = NULL;
183 if (try_shm > 1) return NULL;
185 xcbob->image = xcb_image_create_native(c, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP,
186 depth, NULL, ~0, NULL);
195 if (!xcbob->image->data)
197 xcbob->image->data = malloc(xcbob->image->size);
198 if (!xcbob->image->data)
200 xcb_image_destroy(xcbob->image);
206 xcbob->bpl = xcbob->image->stride;
207 xcbob->psize = xcbob->image->size;
213 evas_software_xcb_x_output_buffer_free(Xcb_Output_Buffer *xcbob,
219 free(xcb_get_input_focus_reply(xcbob->connection,
220 xcb_get_input_focus_unchecked(xcbob->connection),
222 xcb_shm_detach(xcbob->connection, xcbob->shm_info->shmseg);
223 xcb_image_destroy(xcbob->image);
224 shmdt(xcbob->shm_info->shmaddr);
225 shmctl(xcbob->shm_info->shmid, IPC_RMID, 0);
226 free(xcbob->shm_info);
230 if (xcbob->data) xcbob->image->data = NULL;
231 xcb_image_destroy(xcbob->image);
237 evas_software_xcb_x_output_buffer_paste(Xcb_Output_Buffer *xcbob,
246 xcb_image_shm_put(xcbob->connection, d, gc,
247 xcbob->image, *xcbob->shm_info,
250 xcbob->image->width, xcbob->image->height,
253 free(xcb_get_input_focus_reply(xcbob->connection,
254 xcb_get_input_focus_unchecked(xcbob->connection),
258 xcb_image_put(xcbob->connection, d, gc,
264 evas_software_xcb_x_output_buffer_data(Xcb_Output_Buffer *xcbob,
265 int *bytes_per_line_ret)
267 if (bytes_per_line_ret) *bytes_per_line_ret = xcbob->image->stride;
268 return xcbob->image->data;
272 evas_software_xcb_x_output_buffer_depth(Xcb_Output_Buffer *xcbob)
274 return xcbob->image->bpp;
278 evas_software_xcb_x_output_buffer_byte_order(Xcb_Output_Buffer *xcbob)
280 return xcbob->image->byte_order;
284 evas_software_xcb_x_output_buffer_bit_order(Xcb_Output_Buffer *xcbob)
286 return xcbob->image->bit_order;