XRender Debugging and Programming

There is very little detailed information on how to use XRender extension.

In this case the following is helpful:
The specification for Xrender is a bit lacking:
In a previous post I was looking at a BadMatch error returned by a call to XRenderCreatePicture.

The issue is that the drawable and Xrender format is likely to not match (you can look at the Xserver and client libraries source code to see what can cause a BadMatch).

The Xrender implementation in the XServer can be found here.

The file that implements the RenderCreatePicture is called render.c.

In this case the following two parameters must match:
  • Drawable depth
  • Visual depth
Basically this means that the XRenderPictFormat must match the Visual depth and that this must match the Drawable depth.

You can get the Visual information in the client application from:

int nitems = 0;
int vmask = VisualIDMask | VisualScreenMask;
XVisualInfo *visInfo = XGetVisualInfo(display, vmask, &vinfo, &nitems);

You can get the depth of the drawable using:

Window    root;
int       x, y;
unsigned int  awidth, aheight, border, adepth;
if ( !XGetGeometry( display, drawable, &root, &x, &y, &awidth, &aheight,
                          &border, &adepth ) )

You can get the correct format for the Visual using:

XRenderPictFormat *drawableFormat = XRenderFindVisualFormat( display, visual );