1 #include "evas_common.h"
3 #include "evas_xlib_buffer.h"
8 evas_software_xlib_x_write_mask_line(Outbuf *buf, X_Output_Buffer *xob, DATA32 *src, int w, int y)
16 dst_ptr = evas_software_xlib_x_output_buffer_data(xob, &bpl);
17 dst_ptr = dst_ptr + (bpl * y);
19 if (buf->priv.x11.xlib.bit_swap)
21 for (x = 0; x < w; x += 8)
24 ((A_VAL(&(src_ptr[0])) >> 7) << 7) |
25 ((A_VAL(&(src_ptr[1])) >> 7) << 6) |
26 ((A_VAL(&(src_ptr[2])) >> 7) << 5) |
27 ((A_VAL(&(src_ptr[3])) >> 7) << 4) |
28 ((A_VAL(&(src_ptr[4])) >> 7) << 3) |
29 ((A_VAL(&(src_ptr[5])) >> 7) << 2) |
30 ((A_VAL(&(src_ptr[6])) >> 7) << 1) |
31 ((A_VAL(&(src_ptr[7])) >> 7) << 0);
38 for (x = 0; x < w; x += 8)
41 ((A_VAL(&(src_ptr[0])) >> 7) << 0) |
42 ((A_VAL(&(src_ptr[1])) >> 7) << 1) |
43 ((A_VAL(&(src_ptr[2])) >> 7) << 2) |
44 ((A_VAL(&(src_ptr[3])) >> 7) << 3) |
45 ((A_VAL(&(src_ptr[4])) >> 7) << 4) |
46 ((A_VAL(&(src_ptr[5])) >> 7) << 5) |
47 ((A_VAL(&(src_ptr[6])) >> 7) << 6) |
48 ((A_VAL(&(src_ptr[7])) >> 7) << 7);
56 XPutPixel(xob->xim, x, y, A_VAL(src_ptr) >> 7);
62 evas_software_xlib_x_write_mask_line_rev(Outbuf *buf, X_Output_Buffer *xob, DATA32 *src, int w, int y)
69 src_ptr = src + w - 1;
70 dst_ptr = evas_software_xlib_x_output_buffer_data(xob, &bpl);
71 dst_ptr = dst_ptr + (bpl * y);
73 if (buf->priv.x11.xlib.bit_swap)
75 for (x = 0; x < w; x += 8)
78 ((A_VAL(&(src_ptr[ 0])) >> 7) << 7) |
79 ((A_VAL(&(src_ptr[-1])) >> 7) << 6) |
80 ((A_VAL(&(src_ptr[-2])) >> 7) << 5) |
81 ((A_VAL(&(src_ptr[-3])) >> 7) << 4) |
82 ((A_VAL(&(src_ptr[-4])) >> 7) << 3) |
83 ((A_VAL(&(src_ptr[-5])) >> 7) << 2) |
84 ((A_VAL(&(src_ptr[-6])) >> 7) << 1) |
85 ((A_VAL(&(src_ptr[-7])) >> 7) << 0);
92 for (x = 0; x < w; x += 8)
95 ((A_VAL(&(src_ptr[ 0])) >> 7) << 0) |
96 ((A_VAL(&(src_ptr[-1])) >> 7) << 1) |
97 ((A_VAL(&(src_ptr[-2])) >> 7) << 2) |
98 ((A_VAL(&(src_ptr[-3])) >> 7) << 3) |
99 ((A_VAL(&(src_ptr[-4])) >> 7) << 4) |
100 ((A_VAL(&(src_ptr[-5])) >> 7) << 5) |
101 ((A_VAL(&(src_ptr[-6])) >> 7) << 6) |
102 ((A_VAL(&(src_ptr[-7])) >> 7) << 7);
110 XPutPixel(xob->xim, x, y, A_VAL(src_ptr) >> 7);
116 evas_software_xlib_x_write_mask_line_vert(Outbuf *buf, X_Output_Buffer *xob,
118 int h, int ym, int w)
126 dst_ptr = evas_software_xlib_x_output_buffer_data(xob, &bpl);
127 dst_ptr = dst_ptr + (bpl * ym);
129 if (buf->priv.x11.xlib.bit_swap)
131 for (y = 0; y < h; y += 8)
134 ((A_VAL(&(src_ptr[0 * w])) >> 7) << 7) |
135 ((A_VAL(&(src_ptr[1 * w])) >> 7) << 6) |
136 ((A_VAL(&(src_ptr[2 * w])) >> 7) << 5) |
137 ((A_VAL(&(src_ptr[3 * w])) >> 7) << 4) |
138 ((A_VAL(&(src_ptr[4 * w])) >> 7) << 3) |
139 ((A_VAL(&(src_ptr[5 * w])) >> 7) << 2) |
140 ((A_VAL(&(src_ptr[6 * w])) >> 7) << 1) |
141 ((A_VAL(&(src_ptr[7 * w])) >> 7) << 0);
148 for (y = 0; y < h; y += 8)
151 ((A_VAL(&(src_ptr[0 * w])) >> 7) << 0) |
152 ((A_VAL(&(src_ptr[1 * w])) >> 7) << 1) |
153 ((A_VAL(&(src_ptr[2 * w])) >> 7) << 2) |
154 ((A_VAL(&(src_ptr[3 * w])) >> 7) << 3) |
155 ((A_VAL(&(src_ptr[4 * w])) >> 7) << 4) |
156 ((A_VAL(&(src_ptr[5 * w])) >> 7) << 5) |
157 ((A_VAL(&(src_ptr[6 * w])) >> 7) << 6) |
158 ((A_VAL(&(src_ptr[7 * w])) >> 7) << 7);
166 XPutPixel(xob->xim, y, ym, A_VAL(src_ptr) >> 7);
172 evas_software_xlib_x_write_mask_line_vert_rev(Outbuf *buf, X_Output_Buffer *xob,
174 int h, int ym, int w)
181 src_ptr = src + ((h - 1) * w);
182 dst_ptr = evas_software_xlib_x_output_buffer_data(xob, &bpl);
183 dst_ptr = dst_ptr + (bpl * ym);
185 if (buf->priv.x11.xlib.bit_swap)
187 for (y = 0; y < h; y += 8)
190 ((A_VAL(&(src_ptr[ 0 * w])) >> 7) << 7) |
191 ((A_VAL(&(src_ptr[-1 * w])) >> 7) << 6) |
192 ((A_VAL(&(src_ptr[-2 * w])) >> 7) << 5) |
193 ((A_VAL(&(src_ptr[-3 * w])) >> 7) << 4) |
194 ((A_VAL(&(src_ptr[-4 * w])) >> 7) << 3) |
195 ((A_VAL(&(src_ptr[-5 * w])) >> 7) << 2) |
196 ((A_VAL(&(src_ptr[-6 * w])) >> 7) << 1) |
197 ((A_VAL(&(src_ptr[-7 * w])) >> 7) << 0);
204 for (y = 0; y < h; y += 8)
207 ((A_VAL(&(src_ptr[ 0 * w])) >> 7) << 0) |
208 ((A_VAL(&(src_ptr[-1 * w])) >> 7) << 1) |
209 ((A_VAL(&(src_ptr[-2 * w])) >> 7) << 2) |
210 ((A_VAL(&(src_ptr[-3 * w])) >> 7) << 3) |
211 ((A_VAL(&(src_ptr[-4 * w])) >> 7) << 4) |
212 ((A_VAL(&(src_ptr[-5 * w])) >> 7) << 5) |
213 ((A_VAL(&(src_ptr[-6 * w])) >> 7) << 6) |
214 ((A_VAL(&(src_ptr[-7 * w])) >> 7) << 7);
222 XPutPixel(xob->xim, y, ym, A_VAL(src_ptr) >> 7);
228 evas_software_xlib_x_can_do_shm(Display *d)
230 static Display *cached_d = NULL;
231 static int cached_result = 0;
233 if (d == cached_d) return cached_result;
235 if (XShmQueryExtension(d))
237 X_Output_Buffer *xob;
239 xob = evas_software_xlib_x_output_buffer_new
240 (d, DefaultVisual(d, DefaultScreen(d)),
241 DefaultDepth(d, DefaultScreen(d)), 16, 16, 2, NULL);
247 evas_software_xlib_x_output_buffer_free(xob, 1);
256 x_output_tmp_x_err(Display *d __UNUSED__, XErrorEvent *ev __UNUSED__)
262 //static int creates = 0;
265 evas_software_xlib_x_output_buffer_new(Display *d, Visual *v, int depth, int w, int h, int try_shm, void *data)
267 X_Output_Buffer *xob;
269 xob = calloc(1, sizeof(X_Output_Buffer));
270 if (!xob) return NULL;
275 xob->shm_info = NULL;
281 xob->shm_info = malloc(sizeof(XShmSegmentInfo));
284 xob->xim = XShmCreateImage(d, v, depth, ZPixmap, NULL,
285 xob->shm_info, w, h);
288 xob->shm_info->shmid = shmget(IPC_PRIVATE,
289 xob->xim->bytes_per_line *
292 if (xob->shm_info->shmid >= 0)
294 xob->shm_info->readOnly = False;
295 xob->shm_info->shmaddr = xob->xim->data =
296 shmat(xob->shm_info->shmid, 0, 0);
297 if (xob->shm_info->shmaddr != NULL)
301 if (try_shm == 2) // only needed during testing
305 ph = XSetErrorHandler((XErrorHandler)
308 #if defined(EVAS_FRAME_QUEUING) && defined(LIBXEXT_VERSION_LOW)
309 /* workaround for libXext of lower then 1.1.1 */
310 if (evas_common_frameq_enabled())
313 XShmAttach(d, xob->shm_info);
314 #if defined(EVAS_FRAME_QUEUING) && defined(LIBXEXT_VERSION_LOW)
315 /* workaround for libXext of lower then 1.1.1 */
316 if (evas_common_frameq_enabled())
320 if (try_shm == 2) // only needed during testing
323 XSetErrorHandler((XErrorHandler)ph);
327 // printf("SHM++ ID=%i -> %i bytes [%i creates]\n",
328 // xob->shm_info->shmid,
329 // xob->xim->bytes_per_line * xob->xim->height,
332 xob->bpl = xob->xim->bytes_per_line;
333 xob->psize = xob->bpl * xob->h;
337 shmdt(xob->shm_info->shmaddr);
338 shmctl(xob->shm_info->shmid, IPC_RMID, 0);
340 if (xob->xim) XDestroyImage(xob->xim);
343 if (xob->shm_info) free(xob->shm_info);
344 xob->shm_info = NULL;
348 if (try_shm > 1) return NULL;
350 xob->xim = XCreateImage(d, v, depth, ZPixmap, 0, data, w, h, 32, 0);
361 xob->xim->data = malloc(xob->xim->bytes_per_line * xob->xim->height);
364 XDestroyImage(xob->xim);
369 xob->bpl = xob->xim->bytes_per_line;
370 xob->psize = xob->bpl * xob->h;
375 evas_software_xlib_x_output_buffer_free(X_Output_Buffer *xob, int sync)
379 // printf("SHM-- ID=%i -> %i bytes, [sync=%i]\n",
380 // xob->shm_info->shmid,
381 // xob->xim->bytes_per_line * xob->xim->height,
383 if (sync) XSync(xob->display, False);
384 XShmDetach(xob->display, xob->shm_info);
385 XDestroyImage(xob->xim);
386 shmdt(xob->shm_info->shmaddr);
387 shmctl(xob->shm_info->shmid, IPC_RMID, 0);
392 if (xob->data) xob->xim->data = NULL;
393 XDestroyImage(xob->xim);
399 evas_software_xlib_x_output_buffer_paste(X_Output_Buffer *xob, Drawable d, GC gc, int x, int y, int sync)
404 XShmPutImage(xob->display, d, gc, xob->xim, 0, 0, x, y,
405 xob->w, xob->h, False);
406 if (sync) XSync(xob->display, False);
410 // printf("NO! shm\n");
411 XPutImage(xob->display, d, gc, xob->xim, 0, 0, x, y,
417 evas_software_xlib_x_output_buffer_data(X_Output_Buffer *xob, int *bytes_per_line_ret)
419 if (bytes_per_line_ret) *bytes_per_line_ret = xob->xim->bytes_per_line;
420 return (DATA8 *)xob->xim->data;
424 evas_software_xlib_x_output_buffer_depth(X_Output_Buffer *xob)
426 return xob->xim->bits_per_pixel;
430 evas_software_xlib_x_output_buffer_byte_order(X_Output_Buffer *xob)
432 return xob->xim->byte_order;
436 evas_software_xlib_x_output_buffer_bit_order(X_Output_Buffer *xob)
438 return xob->xim->bitmap_bit_order;