[cairo-commit] cairo/test cairo-test.c,1.35,1.36

Carl Worth commit at pdx.freedesktop.org
Tue May 17 06:11:34 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv22875/test

Modified Files:
	cairo-test.c 
Log Message:

        * src/Makefile.am:
        * src/cairo-xcb.h:
        * src/cairo-xcb-xrender.h:
        * src/cairo-xcb-surface.c:
        (cairo_xcb_surface_create),
        (cairo_xcb_surface_create_for_bitmap),
        (cairo_xcb_surface_create_with_xrender_format): Update cairo-xcb.h
        to provide the same style of interface as cairo-xlib.h.

        * test/cairo-test.c: Update to match new cairo_xcb_surface_t
        create functions.


Index: cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- cairo-test.c	17 May 2005 13:05:13 -0000	1.35
+++ cairo-test.c	17 May 2005 13:11:32 -0000	1.36
@@ -193,13 +193,102 @@
 #endif
 
 #if CAIRO_HAS_XCB_SURFACE
-#include "cairo-xcb.h"
+#include "cairo-xcb-xrender.h"
 typedef struct _xcb_target_closure
 {
     XCBConnection *c;
-    XCBPIXMAP pixmap;
+    XCBDRAWABLE drawable;
 } xcb_target_closure_t;
 
+/* XXX: This is a nasty hack. Something like this should be in XCB's
+ * bindings for Render, not here in this test. */
+static XCBRenderPICTFORMINFO
+_format_from_cairo(XCBConnection *c, cairo_format_t fmt)
+{
+    XCBRenderPICTFORMINFO ret = {{ 0 }};
+    struct tmpl_t {
+	XCBRenderDIRECTFORMAT direct;
+	CARD8 depth;
+    };
+    static const struct tmpl_t templates[] = {
+	/* CAIRO_FORMAT_ARGB32 */
+	{
+	    {
+		16, 0xff,
+		8,  0xff,
+		0,  0xff,
+		24, 0xff
+	    },
+	    32
+	},
+	/* CAIRO_FORMAT_RGB24 */
+	{
+	    {
+		16, 0xff,
+		8,  0xff,
+		0,  0xff,
+		0,  0x00
+	    },
+	    24
+	},
+	/* CAIRO_FORMAT_A8 */
+	{
+	    {
+		0,  0x00,
+		0,  0x00,
+		0,  0x00,
+		0,  0xff
+	    },
+	    8
+	},
+	/* CAIRO_FORMAT_A1 */
+	{
+	    {
+		0,  0x00,
+		0,  0x00,
+		0,  0x00,
+		0,  0x01
+	    },
+	    1
+	},
+    };
+    const struct tmpl_t *tmpl;
+    XCBRenderQueryPictFormatsRep *r;
+    XCBRenderPICTFORMINFOIter fi;
+
+    if(fmt < 0 || fmt >= (sizeof(templates) / sizeof(*templates)))
+	return ret;
+    tmpl = templates + fmt;
+
+    r = XCBRenderQueryPictFormatsReply(c, XCBRenderQueryPictFormats(c), 0);
+    if(!r)
+	return ret;
+
+    for(fi = XCBRenderQueryPictFormatsFormatsIter(r); fi.rem; XCBRenderPICTFORMINFONext(&fi))
+    {
+	const XCBRenderDIRECTFORMAT *t, *f;
+	if(fi.data->type != XCBRenderPictTypeDirect)
+	    continue;
+	if(fi.data->depth != tmpl->depth)
+	    continue;
+	t = &tmpl->direct;
+	f = &fi.data->direct;
+	if(t->red_mask && (t->red_mask != f->red_mask || t->red_shift != f->red_shift))
+	    continue;
+	if(t->green_mask && (t->green_mask != f->green_mask || t->green_shift != f->green_shift))
+	    continue;
+	if(t->blue_mask && (t->blue_mask != f->blue_mask || t->blue_shift != f->blue_shift))
+	    continue;
+	if(t->alpha_mask && (t->alpha_mask != f->alpha_mask || t->alpha_shift != f->alpha_shift))
+	    continue;
+
+	ret = *fi.data;
+    }
+
+    free(r);
+    return ret;
+}
+
 static cairo_surface_t *
 create_xcb_surface (int width, int height, void **closure)
 {
@@ -207,6 +296,7 @@
     xcb_target_closure_t *xtc;
     cairo_surface_t *surface;
     XCBConnection *c;
+    XCBRenderPICTFORMINFO render_format;
 
     *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));
 
@@ -216,24 +306,27 @@
 	height = 1;
 
     xtc->c = c = XCBConnectBasic();
-    root = XCBConnSetupSuccessRepRootsIter(XCBGetSetup(c)).data;
-
     if (c == NULL) {
 	cairo_test_log ("Failed to connect to X server through XCB\n");
 	return NULL;
     }
 
-    xtc->pixmap = XCBPIXMAPNew (c);
-    /* XXX: What in the world is the drawable argument to XCBCreatePixmap ? */
+    root = XCBConnSetupSuccessRepRootsIter(XCBGetSetup(c)).data;
+
+    xtc->drawable.pixmap = XCBPIXMAPNew (c);
     {
 	XCBDRAWABLE root_drawable;
 	root_drawable.window = root->root;
-	XCBCreatePixmap (c, 32, xtc->pixmap, root_drawable, width, height);
+	XCBCreatePixmap (c, 32, xtc->drawable.pixmap, root_drawable,
+			 width, height);
     }
 
-    surface = cairo_xcb_surface_create_for_pixmap (c, xtc->pixmap,
-						   CAIRO_FORMAT_ARGB32);
-    cairo_xcb_surface_set_size (surface, width, height);
+    render_format = _format_from_cairo (c, CAIRO_FORMAT_ARGB32);
+    if (render_format.id.xid == 0)
+	return NULL;
+    surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->drawable,
+							    &render_format,
+							    width, height);
 
     return surface;
 }
@@ -243,7 +336,7 @@
 {
     xcb_target_closure_t *xtc = closure;
 
-    XCBFreePixmap (xtc->c, xtc->pixmap);
+    XCBFreePixmap (xtc->c, xtc->drawable.pixmap);
     XCBDisconnect (xtc->c);
 }
 #endif




More information about the cairo-commit mailing list