aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c
diff options
context:
space:
mode:
Diffstat (limited to 'legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c')
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c454
1 files changed, 254 insertions, 200 deletions
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c
index afec5f1a6a..6789b94db2 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_image.c
@@ -4,27 +4,31 @@
#include <xcb/xcb_event.h>
#include <xcb/shm.h>
-struct _Ecore_X_Image
+struct _Ecore_X_Image
{
xcb_shm_segment_info_t shminfo;
- xcb_image_t *xim;
- Ecore_X_Visual vis;
- int depth, w, h;
- int bpl, bpp, rows;
- unsigned char *data;
- Eina_Bool shm : 1;
+ xcb_image_t *xim;
+ Ecore_X_Visual vis;
+ int depth, w, h;
+ int bpl, bpp, rows;
+ unsigned char *data;
+ Eina_Bool shm : 1;
};
/* local function prototypes */
-static void _ecore_xcb_image_shm_check(void);
-static void _ecore_xcb_image_shm_create(Ecore_X_Image *im);
-static xcb_format_t *_ecore_xcb_image_find_format(const xcb_setup_t *setup, uint8_t depth);
+static void _ecore_xcb_image_shm_check(void);
+static void _ecore_xcb_image_shm_create(Ecore_X_Image *im);
+static xcb_format_t *_ecore_xcb_image_find_format(const xcb_setup_t *setup,
+ uint8_t depth);
/* local variables */
static int _ecore_xcb_image_shm_can = -1;
EAPI Ecore_X_Image *
-ecore_x_image_new(int w, int h, Ecore_X_Visual vis, int depth)
+ecore_x_image_new(int w,
+ int h,
+ Ecore_X_Visual vis,
+ int depth)
{
Ecore_X_Image *im;
@@ -40,16 +44,16 @@ ecore_x_image_new(int w, int h, Ecore_X_Visual vis, int depth)
return im;
}
-EAPI void
-ecore_x_image_free(Ecore_X_Image *im)
+EAPI void
+ecore_x_image_free(Ecore_X_Image *im)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
CHECK_XCB_CONN;
if (!im) return;
- if (im->shm)
+ if (im->shm)
{
- if (im->xim)
+ if (im->xim)
{
xcb_shm_detach(_ecore_xcb_conn, im->shminfo.shmseg);
xcb_image_destroy(im->xim);
@@ -57,7 +61,7 @@ ecore_x_image_free(Ecore_X_Image *im)
shmctl(im->shminfo.shmid, IPC_RMID, 0);
}
}
- else if (im->xim)
+ else if (im->xim)
{
if (im->xim->data) free(im->xim->data);
im->xim->data = NULL;
@@ -68,29 +72,36 @@ ecore_x_image_free(Ecore_X_Image *im)
// ecore_x_flush();
}
-EAPI Eina_Bool
-ecore_x_image_get(Ecore_X_Image *im, Ecore_X_Drawable draw, int x, int y, int sx, int sy, int w, int h)
+EAPI Eina_Bool
+ecore_x_image_get(Ecore_X_Image *im,
+ Ecore_X_Drawable draw,
+ int x,
+ int y,
+ int sx,
+ int sy,
+ int w,
+ int h)
{
Eina_Bool ret = EINA_TRUE;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
CHECK_XCB_CONN;
- if (im->shm)
+ if (im->shm)
{
if (!im->xim) _ecore_xcb_image_shm_create(im);
if (!im->xim) return EINA_FALSE;
- if ((sx == 0) && (w == im->w))
+ if ((sx == 0) && (w == im->w))
{
- im->xim->data = (uint8_t *)im->data + (im->xim->stride * sy) +
+ im->xim->data = (uint8_t *)im->data + (im->xim->stride * sy) +
(sx * im->bpp);
im->xim->width = w;
im->xim->height = h;
ecore_x_grab();
- if (!xcb_image_shm_get(_ecore_xcb_conn, draw, im->xim,
- im->shminfo, x, y, 0xffffffff))
+ if (!xcb_image_shm_get(_ecore_xcb_conn, draw, im->xim,
+ im->shminfo, x, y, 0xffffffff))
{
DBG("\tImage Shm Get Failed");
ret = EINA_FALSE;
@@ -98,31 +109,31 @@ ecore_x_image_get(Ecore_X_Image *im, Ecore_X_Drawable draw, int x, int y, int sx
ecore_x_ungrab();
ecore_x_sync(); // needed
}
- else
+ else
{
Ecore_X_Image *tim;
tim = ecore_x_image_new(w, h, im->vis, im->depth);
- if (tim)
+ if (tim)
{
ret = ecore_x_image_get(tim, draw, x, y, 0, 0, w, h);
- if (ret)
+ if (ret)
{
unsigned char *spixels, *pixels;
int sbpp = 0, sbpl = 0, srows = 0;
int bpp = 0, bpl = 0, rows = 0;
- spixels =
+ spixels =
ecore_x_image_data_get(tim, &sbpl, &srows, &sbpp);
pixels = ecore_x_image_data_get(im, &bpl, &rows, &bpp);
- if ((spixels) && (pixels))
+ if ((spixels) && (pixels))
{
unsigned char *p, *sp;
int r = 0;
p = (pixels + (sy * bpl) + (sx * bpp));
sp = spixels;
- for (r = srows; r > 0; r--)
+ for (r = srows; r > 0; r--)
{
memcpy(p, sp, sbpl);
p += bpl;
@@ -134,18 +145,18 @@ ecore_x_image_get(Ecore_X_Image *im, Ecore_X_Drawable draw, int x, int y, int sx
}
}
}
- else
+ else
{
ret = EINA_FALSE;
ecore_x_grab();
- im->xim =
- xcb_image_get(_ecore_xcb_conn, draw, x, y, w, h,
+ im->xim =
+ xcb_image_get(_ecore_xcb_conn, draw, x, y, w, h,
0xffffffff, XCB_IMAGE_FORMAT_Z_PIXMAP);
if (!im->xim) ret = EINA_FALSE;
ecore_x_ungrab();
ecore_x_sync(); // needed
- if (im->xim)
+ if (im->xim)
{
im->data = (unsigned char *)im->xim->data;
im->bpl = im->xim->stride;
@@ -163,7 +174,10 @@ ecore_x_image_get(Ecore_X_Image *im, Ecore_X_Drawable draw, int x, int y, int sx
}
EAPI void *
-ecore_x_image_data_get(Ecore_X_Image *im, int *bpl, int *rows, int *bpp)
+ecore_x_image_data_get(Ecore_X_Image *im,
+ int *bpl,
+ int *rows,
+ int *bpp)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -178,15 +192,23 @@ ecore_x_image_data_get(Ecore_X_Image *im, int *bpl, int *rows, int *bpp)
return im->data;
}
-EAPI void
-ecore_x_image_put(Ecore_X_Image *im, Ecore_X_Drawable draw, Ecore_X_GC gc, int x, int y, int sx, int sy, int w, int h)
+EAPI void
+ecore_x_image_put(Ecore_X_Image *im,
+ Ecore_X_Drawable draw,
+ Ecore_X_GC gc,
+ int x,
+ int y,
+ int sx,
+ int sy,
+ int w,
+ int h)
{
Ecore_X_GC tgc = 0;
LOGFN(__FILE__, __LINE__, __FUNCTION__);
CHECK_XCB_CONN;
- if (!gc)
+ if (!gc)
{
uint32_t mask, values[1];
@@ -197,26 +219,25 @@ ecore_x_image_put(Ecore_X_Image *im, Ecore_X_Drawable draw, Ecore_X_GC gc, int x
gc = tgc;
}
if (!im->xim) _ecore_xcb_image_shm_create(im);
- if (im->xim)
+ if (im->xim)
{
- if (im->shm)
- xcb_shm_put_image(_ecore_xcb_conn, draw, gc, im->xim->width,
- im->xim->height, sx, sy, w, h, x, y,
- im->xim->depth, im->xim->format, 0,
- im->shminfo.shmseg,
+ if (im->shm)
+ xcb_shm_put_image(_ecore_xcb_conn, draw, gc, im->xim->width,
+ im->xim->height, sx, sy, w, h, x, y,
+ im->xim->depth, im->xim->format, 0,
+ im->shminfo.shmseg,
im->xim->data - im->shminfo.shmaddr);
-// xcb_image_shm_put(_ecore_xcb_conn, draw, gc, im->xim,
+// xcb_image_shm_put(_ecore_xcb_conn, draw, gc, im->xim,
// im->shminfo, sx, sy, x, y, w, h, 0);
- else
+ else
xcb_image_put(_ecore_xcb_conn, draw, gc, im->xim, sx, sy, 0);
-
}
if (tgc) ecore_x_gc_free(tgc);
ecore_x_sync();
}
-EAPI Eina_Bool
-ecore_x_image_is_argb32_get(Ecore_X_Image *im)
+EAPI Eina_Bool
+ecore_x_image_is_argb32_get(Ecore_X_Image *im)
{
xcb_visualtype_t *vis;
@@ -226,16 +247,16 @@ ecore_x_image_is_argb32_get(Ecore_X_Image *im)
vis = (xcb_visualtype_t *)im->vis;
if (!im->xim) _ecore_xcb_image_shm_create(im);
- if (((vis->_class == XCB_VISUAL_CLASS_TRUE_COLOR) ||
- (vis->_class == XCB_VISUAL_CLASS_DIRECT_COLOR)) &&
- (im->depth >= 24) && (vis->red_mask == 0xff0000) &&
+ if (((vis->_class == XCB_VISUAL_CLASS_TRUE_COLOR) ||
+ (vis->_class == XCB_VISUAL_CLASS_DIRECT_COLOR)) &&
+ (im->depth >= 24) && (vis->red_mask == 0xff0000) &&
(vis->green_mask == 0x00ff00) && (vis->blue_mask == 0x0000ff))
{
#ifdef WORDS_BIGENDIAN
- if (im->xim->byte_order == XCB_IMAGE_ORDER_LSB_FIRST)
+ if (im->xim->byte_order == XCB_IMAGE_ORDER_LSB_FIRST)
return EINA_TRUE;
#else
- if (im->xim->byte_order == XCB_IMAGE_ORDER_MSB_FIRST)
+ if (im->xim->byte_order == XCB_IMAGE_ORDER_MSB_FIRST)
return EINA_TRUE;
#endif
}
@@ -243,25 +264,37 @@ ecore_x_image_is_argb32_get(Ecore_X_Image *im)
return EINA_FALSE;
}
-EAPI Eina_Bool
-ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c, Ecore_X_Visual v, int x, int y, int w, int h, unsigned int *dst, int dbpl, int dx, int dy)
+EAPI Eina_Bool
+ecore_x_image_to_argb_convert(void *src,
+ int sbpp,
+ int sbpl,
+ Ecore_X_Colormap c,
+ Ecore_X_Visual v,
+ int x,
+ int y,
+ int w,
+ int h,
+ unsigned int *dst,
+ int dbpl,
+ int dx,
+ int dy)
{
xcb_visualtype_t *vis;
uint32_t *cols;
int n = 0, nret = 0, i, row, mode = 0;
unsigned int pal[256], r, g, b;
enum
- {
- rgbnone = 0,
- rgb565,
- bgr565,
- rgbx555,
- argbx888,
- abgrx888,
- rgba888x,
- bgra888x,
- argbx666
- };
+ {
+ rgbnone = 0,
+ rgb565,
+ bgr565,
+ rgbx555,
+ argbx888,
+ abgrx888,
+ rgba888x,
+ bgra888x,
+ argbx666
+ };
LOGFN(__FILE__, __LINE__, __FUNCTION__);
CHECK_XCB_CONN;
@@ -272,14 +305,14 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
n = vis->colormap_entries;
if ((n <= 256) &&
((vis->_class == XCB_VISUAL_CLASS_PSEUDO_COLOR) ||
- (vis->_class == XCB_VISUAL_CLASS_STATIC_COLOR) ||
- (vis->_class == XCB_VISUAL_CLASS_GRAY_SCALE) ||
- (vis->_class == XCB_VISUAL_CLASS_STATIC_GRAY)))
+ (vis->_class == XCB_VISUAL_CLASS_STATIC_COLOR) ||
+ (vis->_class == XCB_VISUAL_CLASS_GRAY_SCALE) ||
+ (vis->_class == XCB_VISUAL_CLASS_STATIC_GRAY)))
{
xcb_query_colors_cookie_t cookie;
xcb_query_colors_reply_t *reply;
- if (!c)
+ if (!c)
{
c = (xcb_colormap_t)((xcb_screen_t *)
_ecore_xcb_screen)->default_colormap;
@@ -291,61 +324,61 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
cookie = xcb_query_colors_unchecked(_ecore_xcb_conn, c, n, cols);
reply = xcb_query_colors_reply(_ecore_xcb_conn, cookie, NULL);
- if (reply)
+ if (reply)
{
xcb_rgb_iterator_t iter;
xcb_rgb_t *ret;
iter = xcb_query_colors_colors_iterator(reply);
ret = xcb_query_colors_colors(reply);
- if (ret)
+ if (ret)
{
- for (i = 0; iter.rem; xcb_rgb_next(&iter), i++)
+ for (i = 0; iter.rem; xcb_rgb_next(&iter), i++)
{
- pal[i] = 0xff000000 |
- ((iter.data->red >> 8) << 16) |
+ pal[i] = 0xff000000 |
+ ((iter.data->red >> 8) << 16) |
((iter.data->green >> 8) << 8) |
- ((iter.data->blue >> 8));
+ ((iter.data->blue >> 8));
}
nret = n;
}
free(reply);
}
}
- else if ((vis->_class == XCB_VISUAL_CLASS_TRUE_COLOR) ||
+ else if ((vis->_class == XCB_VISUAL_CLASS_TRUE_COLOR) ||
(vis->_class == XCB_VISUAL_CLASS_DIRECT_COLOR))
{
- if ((vis->red_mask == 0x00ff0000) &&
+ if ((vis->red_mask == 0x00ff0000) &&
(vis->green_mask == 0x0000ff00) &&
- (vis->blue_mask == 0x000000ff))
+ (vis->blue_mask == 0x000000ff))
mode = argbx888;
- else if ((vis->red_mask == 0x000000ff) &&
+ else if ((vis->red_mask == 0x000000ff) &&
(vis->green_mask == 0x0000ff00) &&
- (vis->blue_mask == 0x00ff0000))
+ (vis->blue_mask == 0x00ff0000))
mode = abgrx888;
- else if ((vis->red_mask == 0xff000000) &&
+ else if ((vis->red_mask == 0xff000000) &&
(vis->green_mask == 0x00ff0000) &&
- (vis->blue_mask == 0x0000ff00))
+ (vis->blue_mask == 0x0000ff00))
mode = rgba888x;
- else if ((vis->red_mask == 0x0000ff00) &&
+ else if ((vis->red_mask == 0x0000ff00) &&
(vis->green_mask == 0x00ff0000) &&
- (vis->blue_mask == 0xff000000))
+ (vis->blue_mask == 0xff000000))
mode = bgra888x;
- else if ((vis->red_mask == 0x0003f000) &&
+ else if ((vis->red_mask == 0x0003f000) &&
(vis->green_mask == 0x00000fc0) &&
- (vis->blue_mask == 0x0000003f))
+ (vis->blue_mask == 0x0000003f))
mode = argbx666;
- else if ((vis->red_mask == 0x0000f800) &&
+ else if ((vis->red_mask == 0x0000f800) &&
(vis->green_mask == 0x000007e0) &&
- (vis->blue_mask == 0x0000001f))
+ (vis->blue_mask == 0x0000001f))
mode = rgb565;
- else if ((vis->red_mask == 0x0000001f) &&
+ else if ((vis->red_mask == 0x0000001f) &&
(vis->green_mask == 0x000007e0) &&
- (vis->blue_mask == 0x0000f800))
+ (vis->blue_mask == 0x0000f800))
mode = bgr565;
- else if ((vis->red_mask == 0x00007c00) &&
+ else if ((vis->red_mask == 0x00007c00) &&
(vis->green_mask == 0x000003e0) &&
- (vis->blue_mask == 0x0000001f))
+ (vis->blue_mask == 0x0000001f))
mode = rgbx555;
else
return EINA_FALSE;
@@ -356,13 +389,13 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
unsigned short *s16;
unsigned int *s32, *dp, *de;
- dp = ((unsigned int *)(((unsigned char *)dst) +
+ dp = ((unsigned int *)(((unsigned char *)dst) +
((dy + row) * dbpl))) + dx;
de = dp + w;
switch (sbpp)
{
case 8:
- s8 = ((unsigned char *)(((unsigned char *)src) +
+ s8 = ((unsigned char *)(((unsigned char *)src) +
((y + row) * sbpl))) + x;
if (nret > 0)
{
@@ -375,8 +408,9 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
else
return EINA_FALSE;
break;
+
case 16:
- s16 = ((unsigned short *)(((unsigned char *)src) +
+ s16 = ((unsigned short *)(((unsigned char *)src) +
((y + row) * sbpl))) + x;
switch (mode)
{
@@ -393,6 +427,7 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s16++; dp++;
}
break;
+
case bgr565:
while (dp < de)
{
@@ -406,6 +441,7 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s16++; dp++;
}
break;
+
case rgbx555:
while (dp < de)
{
@@ -419,14 +455,16 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s16++; dp++;
}
break;
+
default:
return EINA_FALSE;
break;
}
break;
+
case 24:
case 32:
- s32 = ((unsigned int *)(((unsigned char *)src) +
+ s32 = ((unsigned int *)(((unsigned char *)src) +
((y + row) * sbpl))) + x;
switch (mode)
{
@@ -437,6 +475,7 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s32++; dp++;
}
break;
+
case abgrx888:
while (dp < de)
{
@@ -447,6 +486,7 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s32++; dp++;
}
break;
+
case rgba888x:
while (dp < de)
{
@@ -454,6 +494,7 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s32++; dp++;
}
break;
+
case bgra888x:
while (dp < de)
{
@@ -464,6 +505,7 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s32++; dp++;
}
break;
+
case argbx666:
while (dp < de)
{
@@ -477,12 +519,14 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
s32++; dp++;
}
break;
+
default:
return EINA_FALSE;
break;
}
break;
break;
+
default:
return EINA_FALSE;
break;
@@ -492,107 +536,107 @@ ecore_x_image_to_argb_convert(void *src, int sbpp, int sbpl, Ecore_X_Colormap c,
}
/* local functions */
-static void
-_ecore_xcb_image_shm_check(void)
+static void
+_ecore_xcb_image_shm_check(void)
{
// xcb_shm_query_version_reply_t *reply;
- xcb_shm_segment_info_t shminfo;
- xcb_shm_get_image_cookie_t cookie;
- xcb_shm_get_image_reply_t *ireply;
- xcb_image_t *img = 0;
- uint8_t depth = 0;
-
- if (_ecore_xcb_image_shm_can != -1) return;
- CHECK_XCB_CONN;
-
- /* reply = */
- /* xcb_shm_query_version_reply(_ecore_xcb_conn, */
- /* xcb_shm_query_version(_ecore_xcb_conn), NULL); */
- /* if (!reply) */
- /* { */
- /* _ecore_xcb_image_shm_can = 0; */
- /* return; */
- /* } */
-
- /* if ((reply->major_version < 1) || */
- /* ((reply->major_version == 1) && (reply->minor_version == 0))) */
- /* { */
- /* _ecore_xcb_image_shm_can = 0; */
- /* free(reply); */
- /* return; */
- /* } */
-
- /* free(reply); */
-
- depth = ((xcb_screen_t *)_ecore_xcb_screen)->root_depth;
-
- ecore_x_sync(); // needed
-
- img = _ecore_xcb_image_create_native(1, 1, XCB_IMAGE_FORMAT_Z_PIXMAP,
- depth, NULL, ~0, NULL);
- if (!img)
- {
- _ecore_xcb_image_shm_can = 0;
- return;
- }
-
- shminfo.shmid =
- shmget(IPC_PRIVATE, img->stride * img->height, (IPC_CREAT | 0666));
- if (shminfo.shmid == (uint32_t)-1)
- {
- xcb_image_destroy(img);
- _ecore_xcb_image_shm_can = 0;
- return;
- }
-
- shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
- img->data = shminfo.shmaddr;
- if (img->data == (uint8_t *)-1)
- {
- xcb_image_destroy(img);
- _ecore_xcb_image_shm_can = 0;
- return;
- }
-
- shminfo.shmseg = xcb_generate_id(_ecore_xcb_conn);
- xcb_shm_attach(_ecore_xcb_conn, shminfo.shmseg, shminfo.shmid, 0);
-
- cookie =
- xcb_shm_get_image(_ecore_xcb_conn,
- ((xcb_screen_t *)_ecore_xcb_screen)->root,
- 0, 0, img->width, img->height,
- 0xffffffff, img->format,
- shminfo.shmseg, img->data - shminfo.shmaddr);
-
- ecore_x_sync(); // needed
-
- ireply = xcb_shm_get_image_reply(_ecore_xcb_conn, cookie, NULL);
- if (ireply)
- {
- _ecore_xcb_image_shm_can = 1;
- free(ireply);
- }
- else
- _ecore_xcb_image_shm_can = 0;
-
- xcb_shm_detach(_ecore_xcb_conn, shminfo.shmseg);
- xcb_image_destroy(img);
- shmdt(shminfo.shmaddr);
- shmctl(shminfo.shmid, IPC_RMID, 0);
+ xcb_shm_segment_info_t shminfo;
+ xcb_shm_get_image_cookie_t cookie;
+ xcb_shm_get_image_reply_t *ireply;
+ xcb_image_t *img = 0;
+ uint8_t depth = 0;
+
+ if (_ecore_xcb_image_shm_can != -1) return;
+ CHECK_XCB_CONN;
+
+ /* reply = */
+ /* xcb_shm_query_version_reply(_ecore_xcb_conn, */
+ /* xcb_shm_query_version(_ecore_xcb_conn), NULL); */
+ /* if (!reply) */
+ /* { */
+ /* _ecore_xcb_image_shm_can = 0; */
+ /* return; */
+ /* } */
+
+ /* if ((reply->major_version < 1) || */
+ /* ((reply->major_version == 1) && (reply->minor_version == 0))) */
+ /* { */
+ /* _ecore_xcb_image_shm_can = 0; */
+ /* free(reply); */
+ /* return; */
+ /* } */
+
+ /* free(reply); */
+
+ depth = ((xcb_screen_t *)_ecore_xcb_screen)->root_depth;
+
+ ecore_x_sync(); // needed
+
+ img = _ecore_xcb_image_create_native(1, 1, XCB_IMAGE_FORMAT_Z_PIXMAP,
+ depth, NULL, ~0, NULL);
+ if (!img)
+ {
+ _ecore_xcb_image_shm_can = 0;
+ return;
+ }
+
+ shminfo.shmid =
+ shmget(IPC_PRIVATE, img->stride * img->height, (IPC_CREAT | 0666));
+ if (shminfo.shmid == (uint32_t)-1)
+ {
+ xcb_image_destroy(img);
+ _ecore_xcb_image_shm_can = 0;
+ return;
+ }
+
+ shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
+ img->data = shminfo.shmaddr;
+ if (img->data == (uint8_t *)-1)
+ {
+ xcb_image_destroy(img);
+ _ecore_xcb_image_shm_can = 0;
+ return;
+ }
+
+ shminfo.shmseg = xcb_generate_id(_ecore_xcb_conn);
+ xcb_shm_attach(_ecore_xcb_conn, shminfo.shmseg, shminfo.shmid, 0);
+
+ cookie =
+ xcb_shm_get_image(_ecore_xcb_conn,
+ ((xcb_screen_t *)_ecore_xcb_screen)->root,
+ 0, 0, img->width, img->height,
+ 0xffffffff, img->format,
+ shminfo.shmseg, img->data - shminfo.shmaddr);
+
+ ecore_x_sync(); // needed
+
+ ireply = xcb_shm_get_image_reply(_ecore_xcb_conn, cookie, NULL);
+ if (ireply)
+ {
+ _ecore_xcb_image_shm_can = 1;
+ free(ireply);
+ }
+ else
+ _ecore_xcb_image_shm_can = 0;
+
+ xcb_shm_detach(_ecore_xcb_conn, shminfo.shmseg);
+ xcb_image_destroy(img);
+ shmdt(shminfo.shmaddr);
+ shmctl(shminfo.shmid, IPC_RMID, 0);
}
-static void
-_ecore_xcb_image_shm_create(Ecore_X_Image *im)
+static void
+_ecore_xcb_image_shm_create(Ecore_X_Image *im)
{
CHECK_XCB_CONN;
- im->xim =
- _ecore_xcb_image_create_native(im->w, im->h, XCB_IMAGE_FORMAT_Z_PIXMAP,
+ im->xim =
+ _ecore_xcb_image_create_native(im->w, im->h, XCB_IMAGE_FORMAT_Z_PIXMAP,
im->depth, NULL, ~0, NULL);
if (!im->xim) return;
im->shminfo.shmid = shmget(IPC_PRIVATE, im->xim->size, (IPC_CREAT | 0666));
- if (im->shminfo.shmid == (uint32_t)-1)
+ if (im->shminfo.shmid == (uint32_t)-1)
{
xcb_image_destroy(im->xim);
return;
@@ -624,7 +668,13 @@ _ecore_xcb_image_shm_create(Ecore_X_Image *im)
}
xcb_image_t *
-_ecore_xcb_image_create_native(int w, int h, xcb_image_format_t format, uint8_t depth, void *base, uint32_t bytes, uint8_t *data)
+_ecore_xcb_image_create_native(int w,
+ int h,
+ xcb_image_format_t format,
+ uint8_t depth,
+ void *base,
+ uint32_t bytes,
+ uint8_t *data)
{
static uint8_t dpth = 0;
static xcb_format_t *fmt = NULL;
@@ -633,8 +683,8 @@ _ecore_xcb_image_create_native(int w, int h, xcb_image_format_t format, uint8_t
CHECK_XCB_CONN;
- /* NB: We cannot use xcb_image_create_native as it only creates images
- * using MSB_FIRST, so this routine recreates that function and uses
+ /* NB: We cannot use xcb_image_create_native as it only creates images
+ * using MSB_FIRST, so this routine recreates that function and uses
* the endian-ness of the server setup */
setup = xcb_get_setup(_ecore_xcb_conn);
xif = format;
@@ -642,26 +692,28 @@ _ecore_xcb_image_create_native(int w, int h, xcb_image_format_t format, uint8_t
if ((xif == XCB_IMAGE_FORMAT_Z_PIXMAP) && (depth == 1))
xif = XCB_IMAGE_FORMAT_XY_PIXMAP;
- if (dpth != depth)
+ if (dpth != depth)
{
dpth = depth;
fmt = _ecore_xcb_image_find_format(setup, depth);
if (!fmt) return 0;
}
- switch (xif)
+ switch (xif)
{
case XCB_IMAGE_FORMAT_XY_BITMAP:
if (depth != 1) return 0;
+
case XCB_IMAGE_FORMAT_XY_PIXMAP:
case XCB_IMAGE_FORMAT_Z_PIXMAP:
- return xcb_image_create(w, h, xif,
- fmt->scanline_pad,
- fmt->depth, fmt->bits_per_pixel,
- setup->bitmap_format_scanline_unit,
- setup->image_byte_order,
- setup->bitmap_format_bit_order,
+ return xcb_image_create(w, h, xif,
+ fmt->scanline_pad,
+ fmt->depth, fmt->bits_per_pixel,
+ setup->bitmap_format_scanline_unit,
+ setup->image_byte_order,
+ setup->bitmap_format_bit_order,
base, bytes, data);
+
default:
break;
}
@@ -670,7 +722,8 @@ _ecore_xcb_image_create_native(int w, int h, xcb_image_format_t format, uint8_t
}
static xcb_format_t *
-_ecore_xcb_image_find_format(const xcb_setup_t *setup, uint8_t depth)
+_ecore_xcb_image_find_format(const xcb_setup_t *setup,
+ uint8_t depth)
{
xcb_format_t *fmt, *fmtend;
@@ -679,8 +732,9 @@ _ecore_xcb_image_find_format(const xcb_setup_t *setup, uint8_t depth)
fmt = xcb_setup_pixmap_formats(setup);
fmtend = fmt + xcb_setup_pixmap_formats_length(setup);
for (; fmt != fmtend; ++fmt)
- if (fmt->depth == depth)
+ if (fmt->depth == depth)
return fmt;
return 0;
}
+