don't use X.h constants, but XCB ones. fix the last leak. fix potential bugs. The last version of xcb is needed

SVN revision: 22445
This commit is contained in:
doursse 2006-05-02 22:00:51 +00:00 committed by doursse
parent c80dfaaf01
commit 9825d3dbd3
6 changed files with 137 additions and 95 deletions

View File

@ -18,16 +18,16 @@ struct _Evas_Engine_Info_Software_Xcb
XCBDRAWABLE mask;
XCBVISUALTYPE *visual;
XCBCOLORMAP colormap;
int depth;
int rotation;
int depth;
int rotation;
int alloc_grayscale : 1;
int debug : 1;
int shape_dither : 1;
int destination_alpha : 1;
int track_mask_changes : 1;
int alloc_grayscale : 1;
int debug : 1;
int shape_dither : 1;
int destination_alpha : 1;
int track_mask_changes : 1;
int alloc_colors_max;
int alloc_colors_max;
} info;
/* engine specific function calls to query stuff about the destination */
/* engine (what visual & colormap & depth to use, performance info etc. */

View File

@ -121,7 +121,7 @@ _output_setup(int w,
static XCBVISUALTYPE *
_best_visual_get(XCBConnection *conn, int screen)
{
XCBSCREEN *scr;
XCBSCREEN *scr;
if (!conn) return NULL;
scr = XCBAuxGetScreen(conn, screen);
@ -133,7 +133,7 @@ _best_visual_get(XCBConnection *conn, int screen)
static XCBCOLORMAP
_best_colormap_get(XCBConnection *conn, int screen)
{
XCBSCREEN *scr;
XCBSCREEN *scr;
XCBCOLORMAP c;
c.xid = 0;
@ -271,7 +271,7 @@ eng_setup(Evas *e, void *in)
info->info.visual,
info->info.colormap,
info->info.depth,
evas_software_xcb_outbuf_perf_restore_x(info->info.conn, info->info.drawable, info->info.visual, info->info.colormap, info->info.depth),
evas_software_xcb_outbuf_perf_restore_x(info->info.conn, info->info.drawable, info->info.visual, info->info.colormap, info->info.depth),
info->info.alloc_grayscale,
info->info.alloc_colors_max,
info->info.mask,

View File

@ -4,8 +4,9 @@
#include <sys/ipc.h>
#include <sys/shm.h>
#define X_H /* make sure we aren't using symbols from X.h */
#include <X11/XCB/xcb.h>
#include <X11/XCB/shm.h>
#include <X11/XCB/xcb_aux.h>
#include <X11/XCB/xcb_image.h>
@ -48,6 +49,7 @@ struct _Outbuf
XCBGCONTEXT gc;
XCBGCONTEXT gcm;
int swap : 1;
unsigned char bit_swap : 1;
} x;
struct {
DATA32 r, g, b;
@ -113,7 +115,8 @@ struct _Xcb_Output_Buffer
void evas_software_xcb_x_init (void);
/* buffer */
void evas_software_xcb_x_write_mask_line (Xcb_Output_Buffer *xcbob,
void evas_software_xcb_x_write_mask_line (Outbuf *buf,
Xcb_Output_Buffer *xcbob,
DATA32 *src,
int w,
int y);
@ -136,6 +139,7 @@ DATA8 *evas_software_xcb_x_output_buffer_data (Xcb_Output_Buffe
int *bytes_per_line_ret);
int evas_software_xcb_x_output_buffer_depth (Xcb_Output_Buffer *xcbob);
int evas_software_xcb_x_output_buffer_byte_order(Xcb_Output_Buffer *xcbob);
int evas_software_xcb_x_output_buffer_bit_order (Xcb_Output_Buffer *xcbob);
/* color */

View File

@ -87,13 +87,18 @@ evas_software_xcb_outbuf_setup_x(int w,
if (xcbob)
{
#ifdef WORDS_BIGENDIAN
if (evas_software_xcb_x_output_buffer_byte_order(xcbob) == LSBFirst)
if (evas_software_xcb_x_output_buffer_byte_order(xcbob) == XCBImageOrderLSBFirst)
buf->priv.x.swap = 1;
if (evas_software_xcb_x_output_buffer_bit_order(xcbob) == XCBImageOrderLSBFirst)
buf->priv.x.bit_swap = 1;
#else
if (evas_software_xcb_x_output_buffer_byte_order(xcbob) == MSBFirst)
if (evas_software_xcb_x_output_buffer_byte_order(xcbob) == XCBImageOrderMSBFirst)
buf->priv.x.swap = 1;
if (evas_software_xcb_x_output_buffer_bit_order(xcbob) == XCBImageOrderMSBFirst)
buf->priv.x.bit_swap = 1;
#endif
if ((vis->_class == TrueColor) || (vis->_class == DirectColor))
if ((vis->_class == XCBVisualClassTrueColor) ||
(vis->_class == XCBVisualClassDirectColor))
{
buf->priv.mask.r = (DATA32) vis->red_mask;
buf->priv.mask.g = (DATA32) vis->green_mask;
@ -105,13 +110,15 @@ evas_software_xcb_outbuf_setup_x(int w,
SWAP32(buf->priv.mask.b);
}
}
else if ((vis->_class == PseudoColor) ||
(vis->_class == StaticColor) ||
(vis->_class == GrayScale) || (vis->_class == StaticGray))
else if ((vis->_class == XCBVisualClassStaticGray) ||
(vis->_class == XCBVisualClassGrayScale) ||
(vis->_class == XCBVisualClassStaticColor) ||
(vis->_class == XCBVisualClassPseudoColor))
{
Convert_Pal_Mode pm = PAL_MODE_RGB332;
if ((vis->_class == GrayScale) || (vis->_class == StaticGray))
if ((vis->_class == XCBVisualClassGrayScale) ||
(vis->_class == XCBVisualClassStaticGray))
grayscale = 1;
if (grayscale)
{
@ -492,8 +499,8 @@ evas_software_xcb_outbuf_push_updated_region(Outbuf *buf,
conv_func(src_data, data,
0,
bpl /
((evas_software_xcb_x_output_buffer_depth(obr->xcbob) /
8)) - obr->w, obr->w, obr->h, x, y,
((evas_software_xcb_x_output_buffer_depth(obr->xcbob) / 8)) - obr->w,
obr->w, obr->h, x, y,
buf->priv.pal->lookup);
}
else
@ -504,8 +511,8 @@ evas_software_xcb_outbuf_push_updated_region(Outbuf *buf,
conv_func(src_data, data,
0,
bpl /
((evas_software_xcb_x_output_buffer_depth(obr->xcbob) /
8)) - obr->w, obr->w, obr->h, x, y, NULL);
((evas_software_xcb_x_output_buffer_depth(obr->xcbob) / 8)) - obr->w,
obr->w, obr->h, x, y, NULL);
/* FIXME: this is evil - but it makes ARGB targets look correct */
if ((buf->priv.destination_alpha) && (!obr->mxcbob) &&
(evas_software_xcb_x_output_buffer_depth(obr->xcbob) == 32))
@ -531,9 +538,10 @@ evas_software_xcb_outbuf_push_updated_region(Outbuf *buf,
if (obr->mxcbob)
{
for (yy = 0; yy < obr->h; yy++)
evas_software_xcb_x_write_mask_line(obr->mxcbob,
src_data +
(yy * obr->w), obr->w, yy);
evas_software_xcb_x_write_mask_line(buf,
obr->mxcbob,
src_data + (yy * obr->w),
obr->w, yy);
}
}
@ -637,7 +645,7 @@ evas_software_xcb_outbuf_debug_show(Outbuf *buf,
free (geom);
geom = XCBGetGeometryReply (buf->priv.x.conn, XCBGetGeometry (buf->priv.x.conn, root), 0);
i = XCBConnSetupSuccessRepRootsIter((XCBConnSetupSuccessRep *)XCBGetSetup(buf->priv.x.conn));
i = XCBSetupRootsIter((XCBSetup *)XCBGetSetup(buf->priv.x.conn));
for (; i.rem; XCBSCREENNext(&i))
if (i.data->root.xid == geom->root.xid)
{
@ -653,23 +661,23 @@ evas_software_xcb_outbuf_debug_show(Outbuf *buf,
CARD32 mask;
CARD32 value[2];
mask = GCForeground | GCGraphicsExposures;
mask = XCBGCForeground | XCBGCGraphicsExposures;
value[0] = screen->black_pixel;
value[1] = 0; /* no graphics exposures */
value[1] = XCBExposuresNotAllowed; /* no graphics exposures allowed */
XCBChangeGC(buf->priv.x.conn, buf->priv.x.gc, mask, value);
XCBPolyFillRectangle (buf->priv.x.conn, draw, buf->priv.x.gc, 1, &rect);
XCBSync(buf->priv.x.conn, 0);
image = XCBImageGet(buf->priv.x.conn, draw, x, y, w, h, 0xffffffff, ZPixmap);
image = XCBImageGet(buf->priv.x.conn, draw, x, y, w, h, XCBAllPlanes, XCBImageFormatZPixmap);
if (image)
XCBImageDestroy(image);
XCBSync(buf->priv.x.conn, 0);
mask = GCForeground | GCGraphicsExposures;
mask = XCBGCForeground | XCBGCGraphicsExposures;
value[0] = screen->white_pixel;
value[1] = 0; /* no graphics exposures */
value[1] = XCBExposuresNotAllowed; /* no graphics exposures allowed */
XCBChangeGC(buf->priv.x.conn, buf->priv.x.gc, mask, value);
XCBPolyFillRectangle (buf->priv.x.conn, draw, buf->priv.x.gc, 1, &rect);
XCBSync(buf->priv.x.conn, 0);
image = XCBImageGet(buf->priv.x.conn, draw, x, y, w, h, 0xffffffff, ZPixmap);
image = XCBImageGet(buf->priv.x.conn, draw, x, y, w, h, XCBAllPlanes, XCBImageFormatZPixmap);
if (image)
XCBImageDestroy(image);
XCBSync(buf->priv.x.conn, 0);
@ -755,7 +763,8 @@ evas_software_xcb_outbuf_perf_new_x(XCBConnection *conn,
perf->x.conn = conn;
root.window = XCBConnSetupSuccessRepRootsIter ((XCBConnSetupSuccessRep *)XCBGetSetup (conn)).data->root;
/* FIXME: should use the default screen */
root.window = XCBSetupRootsIter ((XCBSetup *)XCBGetSetup (conn)).data->root;
if (draw.window.xid)
{
XCBGetGeometryRep *geom;
@ -770,7 +779,7 @@ evas_software_xcb_outbuf_perf_new_x(XCBConnection *conn,
perf->x.h = (int)geom->height;
perf->x.screen_num = 0;
i = XCBConnSetupSuccessRepRootsIter((XCBConnSetupSuccessRep *)XCBGetSetup(conn));
i = XCBSetupRootsIter((XCBSetup *)XCBGetSetup(conn));
for (cur = 0; i.rem; XCBSCREENNext(&i), ++cur)
if (i.data->root.xid == geom->root.xid)
{
@ -782,11 +791,11 @@ evas_software_xcb_outbuf_perf_new_x(XCBConnection *conn,
perf->x.root = root;
perf->x.display = strdup (":0"); /* FIXME: strdup(DisplayString(disp)); in XCB ? */
perf->x.vendor = strdup(XCBConnSetupSuccessRepVendor((XCBConnSetupSuccessRep *)XCBGetSetup(conn)));
perf->x.version = (int)((XCBConnSetupSuccessRep *)XCBGetSetup(conn))->protocol_major_version;
perf->x.revision = (int)((XCBConnSetupSuccessRep *)XCBGetSetup(conn))->protocol_minor_version;
perf->x.release = (int)((XCBConnSetupSuccessRep *)XCBGetSetup(conn))->release_number;
perf->x.screen_count = XCBConnSetupSuccessRepRootsIter((XCBConnSetupSuccessRep *)XCBGetSetup(conn)).rem;
perf->x.vendor = strdup(XCBSetupVendor((XCBSetup *)XCBGetSetup(conn)));
perf->x.version = (int)((XCBSetup *)XCBGetSetup(conn))->protocol_major_version;
perf->x.revision = (int)((XCBSetup *)XCBGetSetup(conn))->protocol_minor_version;
perf->x.release = (int)((XCBSetup *)XCBGetSetup(conn))->release_number;
perf->x.screen_count = XCBSetupRootsIter((XCBSetup *)XCBGetSetup(conn)).rem;
perf->x.depth = x_depth;
perf->min_shm_image_pixel_count = 200 * 200; /* default hard-coded */
@ -911,10 +920,10 @@ evas_software_xcb_outbuf_perf_store_x(Outbuf_Perf *perf)
format = STRING;
str = evas_software_xcb_outbuf_perf_serialize_x(perf);
XCBChangeProperty(perf->x.conn, PropModeReplace, perf->x.root.window,
XCBChangeProperty(perf->x.conn, XCBPropModeReplace, perf->x.root.window,
type, format, 8,
strlen(str), str);
/* XSync(perf->x.disp, False); */
XCBSync(perf->x.conn, 0);
free(str);
free (rep);
}
@ -943,8 +952,12 @@ evas_software_xcb_outbuf_perf_restore_x(XCBConnection *conn,
strlen (type_str),
type_str),
NULL);
if (!type_rep)
return perf;
type = type_rep->atom;
format = STRING;
free(type_rep);
cookie = XCBGetProperty(conn, 0, perf->x.root.window,
type, format,
@ -994,21 +1007,22 @@ evas_software_xcb_outbuf_perf_x(XCBConnection *conn,
XCBDRAWABLE win;
CARD32 mask;
CARD32 value[7];
CARD32 value2[1];
int w, h;
int do_shm = 0;
perf = evas_software_xcb_outbuf_perf_new_x(conn, draw, vis, cmap, x_depth);
mask = CWBackingStore | CWColormap |
CWBackPixmap | CWBorderPixel |
CWBitGravity | CWEventMask | CWOverrideRedirect;
value[0] = Always;
value[1] = cmap.xid;
value[2] = None;
value[3] = 0;
value[4] = ForgetGravity;
value[5] = 0;
value[6] = 1;
mask = XCBCWBackPixmap | XCBCWBorderPixel |
XCBCWBitGravity | XCBCWBackingStore |
XCBCWOverrideRedirect | XCBCWEventMask | XCBCWColormap;
value[0] = XCBBackPixmapNone;
value[1] = 0;
value[2] = XCBGravityBitForget;
value[3] = XCBBackingStoreAlways;
value[4] = 1;
value[5] = XCBEventMaskNoEvent;
value[6] = cmap.xid;
w = perf->x.w;
h = perf->x.h;
win.window = XCBWINDOWNew (conn);
@ -1017,11 +1031,14 @@ evas_software_xcb_outbuf_perf_x(XCBConnection *conn,
0, 0,
w, h,
0,
InputOutput,
XCBWindowClassInputOutput,
vis->visual_id,
mask, value);
XCBSync(conn, 0);
XCBMapWindow (conn, win.window);
mask = XCBConfigWindowStackMode;
value[0] = XCBStackModeAbove;
XCBConfigureWindow (conn, win.window, mask, value2);
/* XCBMapWindow (conn, win.window); */
do_shm = evas_software_xcb_x_can_do_shm(conn);
@ -1032,7 +1049,6 @@ evas_software_xcb_outbuf_perf_x(XCBConnection *conn,
{
Xcb_Output_Buffer *xcbob;
XCBGCONTEXT gc;
CARD32 gcv;
int i;
int max;
int error;
@ -1044,7 +1060,7 @@ evas_software_xcb_outbuf_perf_x(XCBConnection *conn,
if (w > h)
max = h;
gc = XCBGCONTEXTNew (conn);
XCBCreateGC (conn, gc, win, 0, &gcv);
XCBCreateGC (conn, gc, win, 0, NULL);
for (i = 16; i < max; i += 16)
{
int l;

View File

@ -4,7 +4,8 @@
static int _xcb_err = 0;
void
evas_software_xcb_x_write_mask_line(Xcb_Output_Buffer *xcbob,
evas_software_xcb_x_write_mask_line(Outbuf *buf,
Xcb_Output_Buffer *xcbob,
DATA32 *src,
int w,
int y)
@ -17,20 +18,40 @@ evas_software_xcb_x_write_mask_line(Xcb_Output_Buffer *xcbob,
src_ptr = src;
dst_ptr = evas_software_xcb_x_output_buffer_data(xcbob, &bpl);
dst_ptr = dst_ptr + (bpl * y);
for (x = 0; x < w; x += 8)
{
*dst_ptr =
((A_VAL(&(src_ptr[0])) >> 7) << 0) |
((A_VAL(&(src_ptr[1])) >> 7) << 1) |
((A_VAL(&(src_ptr[2])) >> 7) << 2) |
((A_VAL(&(src_ptr[3])) >> 7) << 3) |
((A_VAL(&(src_ptr[4])) >> 7) << 4) |
((A_VAL(&(src_ptr[5])) >> 7) << 5) |
((A_VAL(&(src_ptr[6])) >> 7) << 6) |
((A_VAL(&(src_ptr[7])) >> 7) << 7);
src_ptr += 8;
dst_ptr++;
}
if (buf->priv.x.bit_swap)
{
for (x = 0; x < w; x += 8)
{
*dst_ptr =
((A_VAL(&(src_ptr[0])) >> 7) << 7) |
((A_VAL(&(src_ptr[1])) >> 7) << 6) |
((A_VAL(&(src_ptr[2])) >> 7) << 5) |
((A_VAL(&(src_ptr[3])) >> 7) << 4) |
((A_VAL(&(src_ptr[4])) >> 7) << 3) |
((A_VAL(&(src_ptr[5])) >> 7) << 2) |
((A_VAL(&(src_ptr[6])) >> 7) << 1) |
((A_VAL(&(src_ptr[7])) >> 7) << 0);
src_ptr += 8;
dst_ptr++;
}
}
else
{
for (x = 0; x < w; x += 8)
{
*dst_ptr =
((A_VAL(&(src_ptr[0])) >> 7) << 0) |
((A_VAL(&(src_ptr[1])) >> 7) << 1) |
((A_VAL(&(src_ptr[2])) >> 7) << 2) |
((A_VAL(&(src_ptr[3])) >> 7) << 3) |
((A_VAL(&(src_ptr[4])) >> 7) << 4) |
((A_VAL(&(src_ptr[5])) >> 7) << 5) |
((A_VAL(&(src_ptr[6])) >> 7) << 6) |
((A_VAL(&(src_ptr[7])) >> 7) << 7);
src_ptr += 8;
dst_ptr++;
}
}
for (; x < w; x ++)
{
XCBImagePutPixel(xcbob->image, x, y, A_VAL(src_ptr) >> 7);
@ -45,7 +66,7 @@ evas_software_xcb_x_can_do_shm(XCBConnection *c)
XCBDRAWABLE drawable;
int depth;
drawable.window = XCBConnSetupSuccessRepRootsIter (XCBGetSetup(c)).data->root;
drawable.window = XCBSetupRootsIter (XCBGetSetup(c)).data->root;
geom = XCBGetGeometryReply (c, XCBGetGeometry(c, drawable), 0);
if(!geom)
return 0;
@ -100,16 +121,11 @@ evas_software_xcb_x_output_buffer_new(XCBConnection *c,
if (try_shm > 0)
{
const XCBQueryExtensionRep *rep;
rep = XCBGetExtensionData(c, &XCBShmId);
if (rep && rep->present)
{
xcbob->shm_info = malloc(sizeof(XCBShmSegmentInfo));
if (xcbob->shm_info)
{
xcbob->shm_info->shmseg = XCBShmSEGNew(c);
xcbob->image = XCBImageSHMCreate(c, depth, ZPixmap, NULL, w, h);
xcbob->image = XCBImageSHMCreate(c, depth, XCBImageFormatZPixmap, NULL, w, h);
if (xcbob->image)
{
xcbob->shm_info->shmid = shmget(IPC_PRIVATE,
@ -152,12 +168,11 @@ evas_software_xcb_x_output_buffer_new(XCBConnection *c,
if (xcbob->shm_info) free(xcbob->shm_info);
xcbob->shm_info = NULL;
}
}
}
if (try_shm > 1) return NULL;
xcbob->image = XCBImageCreate(c, depth, ZPixmap, 0, data, w, h, 32, 0);
xcbob->image = XCBImageCreate(c, depth, XCBImageFormatZPixmap, 0, data, w, h, 32, 0);
if (!xcbob->image)
{
free(xcbob);
@ -247,3 +262,9 @@ evas_software_xcb_x_output_buffer_byte_order(Xcb_Output_Buffer *xcbob)
{
return xcbob->image->image_byte_order;
}
int
evas_software_xcb_x_output_buffer_bit_order(Xcb_Output_Buffer *xcbob)
{
return xcbob->image->bitmap_format_bit_order;
}

View File

@ -51,6 +51,7 @@ x_color_alloc_rgb(int nr,
i = 0;
color_lut = malloc((nr) * (ng) * (nb));
if (!color_lut) return NULL;
/* FIXME: remove the round-trip */
for (r = 0; r < (nr); r++)
{
for (g = 0; g < (ng); g++)
@ -63,11 +64,11 @@ x_color_alloc_rgb(int nr,
XCBAllocColorRep *rep;
val = (int)((((double)r) / ((nr) - 1)) * 65535);
xcl.red = (unsigned short)(val);
xcl.red = (CARD16)(val);
val = (int)((((double)g) / ((ng) - 1)) * 65535);
xcl.green = (unsigned short)(val);
xcl.green = (CARD16)(val);
val = (int)((((double)b) / ((nb) - 1)) * 65535);
xcl.blue = (unsigned short)(val);
xcl.blue = (CARD16)(val);
xcl_in = xcl;
rep = XCBAllocColorReply(conn,
XCBAllocColor(conn, cmap,
@ -83,13 +84,13 @@ x_color_alloc_rgb(int nr,
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
CARD32 pixels[256];
int j;
if (i > 0)
{
for(j = 0; j < i; j++)
pixels[j] = (unsigned long)color_lut[j];
pixels[j] = (CARD32)color_lut[j];
XCBFreeColors(conn, cmap, 0, i, pixels);
}
free(color_lut);
@ -127,9 +128,9 @@ x_color_alloc_gray(int ng,
XCBAllocColorRep *rep;
val = (int)((((double)g) / ((ng) - 1)) * 65535);
xcl.red = (unsigned short)(val);
xcl.green = (unsigned short)(val);
xcl.blue = (unsigned short)(val);
xcl.red = (CARD16)(val);
xcl.green = (CARD16)(val);
xcl.blue = (CARD16)(val);
xcl_in = xcl;
rep = XCBAllocColorReply(conn,
XCBAllocColor(conn, cmap,
@ -145,19 +146,19 @@ x_color_alloc_gray(int ng,
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
CARD32 pixels[256];
int j;
if (i > 0)
{
for(j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j];
pixels[j] = (CARD32) color_lut[j];
XCBFreeColors(conn, cmap, 0, i, pixels);
}
free(color_lut);
return NULL;
}
color_lut[i] = xcl.pixel;
color_lut[i] = rep->pixel;
i++;
free(rep);
}
@ -373,15 +374,15 @@ evas_software_xcb_x_color_deallocate(XCBConnection *conn,
XCBVISUALTYPE *vis,
Convert_Pal *pal)
{
unsigned long pixels[256];
int j;
CARD32 pixels[256];
int j;
pal->references--;
if (pal->references > 0) return;
if (pal->lookup)
{
for(j = 0; j < pal->count; j++)
pixels[j] = (unsigned long) pal->lookup[j];
pixels[j] = (CARD32) pal->lookup[j];
XCBFreeColors(conn, cmap, 0, pal->count, pixels);
free(pal->lookup);
}