[Xcb-commit] xcb-util
Jamey Sharp
jamey at kemper.freedesktop.org
Thu Apr 20 15:38:55 PDT 2006
xcb-util/image/.gitignore | 1
xcb-util/image/Makefile.am | 5 +
xcb-util/image/test_formats.c | 147 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 152 insertions(+), 1 deletion(-)
New commits:
diff-tree 030675942bbfe8354320a454c640075faf91054b (from d91e9c9de974b8b517ad289a30de5246a3855016)
Author: Jamey Sharp <jamey at minilop.net>
Date: Thu Apr 20 15:38:41 2006 -0700
Add the test app I wrote for trying different pixmap formats. It does not work for XYPixmaps.
diff --git a/xcb-util/image/.gitignore b/xcb-util/image/.gitignore
index aafe1c6..f72f791 100644
--- a/xcb-util/image/.gitignore
+++ b/xcb-util/image/.gitignore
@@ -1,2 +1,3 @@
test_xcb_image
test_xcb_image_shm
+test_formats
diff --git a/xcb-util/image/Makefile.am b/xcb-util/image/Makefile.am
index 738949d..522102f 100644
--- a/xcb-util/image/Makefile.am
+++ b/xcb-util/image/Makefile.am
@@ -15,10 +15,13 @@ pkgconfig_DATA = xcb-image.pc
EXTRA_DIST=xcb-image.pc.in
-noinst_PROGRAMS = test_xcb_image test_xcb_image_shm
+noinst_PROGRAMS = test_xcb_image test_xcb_image_shm test_formats
test_xcb_image_LDADD = $(LDADD) -L. -lXCBImage
test_xcb_image_SOURCES = test_xcb_image.c
test_xcb_image_shm_LDADD = $(LDADD) -L. -lXCBImage
test_xcb_image_shm_SOURCES = test_xcb_image_shm.c
+
+test_formats_LDADD = $(LDADD) -L. -lXCBImage
+test_formats_SOURCES = test_formats.c
diff --git a/xcb-util/image/test_formats.c b/xcb-util/image/test_formats.c
new file mode 100644
index 0000000..98b60b4
--- /dev/null
+++ b/xcb-util/image/test_formats.c
@@ -0,0 +1,147 @@
+#include <X11/XCB/xcb.h>
+#include <X11/XCB/shm.h>
+#include "xcb_image.h"
+#include "xcb_aux.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#define WIDTH 50
+#define HEIGHT 50
+
+#if 0
+static int xpad(int depth)
+{
+ if(depth <= 8)
+ return 8;
+ if(depth <= 16)
+ return 16;
+ return 32;
+}
+#endif
+
+/* FIXME: this function doesn't work correctly for XYPixmaps yet. */
+static XCBImage *create_image(XCBConnection *c, int depth, int format)
+{
+#if 0
+ int pad = (format == ZPixmap ? xpad(depth) : 8);
+#endif
+ XCBImage *im;
+ int x, y;
+ CARD32 i = 0;
+ printf("Image depth %d, format %d\n", depth, format);
+ im = XCBImageCreate(c, depth, format, 0, 0, WIDTH, HEIGHT, 32, 0);
+ if(!im)
+ {
+ printf("ImageCreate failed.\n");
+ return 0;
+ }
+ im->data = malloc(im->bytes_per_line * HEIGHT * (format == ZPixmap ? 1 : depth));
+ if(!im->data)
+ {
+ XCBImageDestroy(im);
+ return 0;
+ }
+ for(x = 0; x < WIDTH; ++x)
+ for(y = 0; y < HEIGHT; ++y)
+ {
+ XCBImagePutPixel(im, x, y, i);
+ ++i;
+ i &= (1 << depth) - 1;
+ }
+ return im;
+}
+
+static XCBWINDOW create_window(XCBConnection *c, XCBSCREEN *root)
+{
+ static const CARD32 mask = XCBCWEventMask;
+ static const CARD32 values[] = { ExposureMask };
+ unsigned int seq;
+ XCBWINDOW w = XCBWINDOWNew(c);
+ seq = XCBCreateWindow(c, root->root_depth, w, root->root, 30, 30, WIDTH, HEIGHT, 0, InputOutput, root->root_visual, mask, values).sequence;
+ printf("CreateWindow sequence %d, depth %d\n", seq, root->root_depth);
+ seq = XCBMapWindow(c, w).sequence;
+ printf("MapWindow sequence %d\n", seq);
+ return w;
+}
+
+static XCBPIXMAP create_pixmap(XCBConnection *c, XCBDRAWABLE d, CARD8 depth)
+{
+ XCBPIXMAP p = XCBPIXMAPNew(c);
+ unsigned int seq;
+ seq = XCBCreatePixmap(c, depth, p, d, WIDTH, HEIGHT).sequence;
+ printf("CreatePixmap sequence %d, depth %d\n", seq, depth);
+ return p;
+}
+
+static XCBGCONTEXT create_gcontext(XCBConnection *c, XCBSCREEN *root)
+{
+ static const CARD32 mask = GCForeground | GCBackground;
+ const CARD32 values[] = { root->black_pixel, root->white_pixel };
+ const XCBDRAWABLE d = { root->root };
+ unsigned int seq;
+ XCBGCONTEXT gc = XCBGCONTEXTNew(c);
+ seq = XCBCreateGC(c, gc, d, mask, values).sequence;
+ printf("CreateGC sequence %d\n", seq);
+ return gc;
+}
+
+int main(int argc, char **argv)
+{
+ int screen, depth, format = ZPixmap;
+ XCBSCREEN *root;
+ XCBImage *im;
+ XCBDRAWABLE d, w = { { 0 } };
+ XCBGCONTEXT gc;
+ XCBGenericEvent *ev;
+ XCBConnection *c = XCBConnect(0, &screen);
+ if(!c)
+ {
+ printf("Connection failed.\n");
+ exit(1);
+ }
+ root = XCBAuxGetScreen(c, screen);
+ if(argc > 1)
+ format = atoi(argv[1]);
+ if(format == XYBitmap || argc > 2)
+ depth = 1;
+ else
+ depth = root->root_depth;
+
+ im = create_image(c, depth, format);
+ d.window = create_window(c, root);
+ if(depth != root->root_depth)
+ {
+ w = d;
+ d.pixmap = create_pixmap(c, w, depth);
+ }
+ gc = create_gcontext(c, root);
+ XCBFlush(c);
+
+ if(im)
+ {
+ while((ev = XCBWaitForEvent(c)))
+ {
+ if(ev->response_type == XCBExpose && ((XCBExposeEvent *) ev)->count == 0)
+ {
+ XCBImagePut(c, d, gc, im, 0, 0, 0, 0, WIDTH, HEIGHT);
+ if(w.window.xid)
+ {
+ unsigned int seq;
+ seq = XCBCopyPlane(c, d, w, gc, 0, 0, WIDTH, HEIGHT, 0, 0, 1).sequence;
+ printf("CopyPlane sequence %d\n", seq);
+ }
+ XCBFlush(c);
+ }
+ else if(ev->response_type == 0)
+ {
+ XCBGenericError *err = (XCBGenericError *) ev;
+ printf("Error: %d after sequence %d\n", err->error_code, (unsigned int) err->full_sequence);
+ }
+ free(ev);
+ }
+ XCBImageDestroy(im);
+ }
+
+ XCBDisconnect(c);
+ exit(0);
+}
More information about the xcb-commit
mailing list