X/Render, rotation transform, Src PICTOP: can I ignore pixels in the bounding box but outside the polygon?

Nigel Tao nigeltao at golang.org
Fri Oct 9 21:38:11 PDT 2015

I'm using X Render, and want to draw a playing card image onto my
window, rotated (e.g. as part of a fan of cards in hand).

For simplicity, suppose that playing cards are square and the rotation
is by 45 degrees. The result is a diamond shape, so that in its
bounding box, the pixels in (1) and out of (0) that diamond looks


Labeling the interesting points on the edges of that bounding box as:


with the center point as X, that means that the bounding box is ACEG
and the playing card is BDFH.

For a fully opaque source image, the result is the same inside the
diamond BDFH, for the Src and Over Render PICTOPs.

I am also guessing that, in general, the Src operator is faster than
Over, since it does not have to read and blend the destination pixels
at all. Thus, I'd like to use the Src operator if possible.

The thing is, outside the diamond, in the '0' pixels above, the
resultant pixels are black with Src, and unchanged, obviously, with

In contrast, in OpenGL say, if my (transformed) vertices are BDFH,
then the pixel shader only touches the '1' pixels and leaves the '0'
pixels alone, regardless of whether I use the equivalent of Src or
Over in my pixel shader.

Is there a way I can use the Src operator, in Render, and touch only
the '1' pixels? I've tried a mixture of the Composite and TriStrip
requests, with SetPictureTransform, and setting a clip (but
SetPictureClipRectangles takes a union of axis-aligned rects, AFAICT),
but I haven't been able to make it do what I want. Am I missing
something obvious?

Sure, technically, I could calculate the diamond client-side, and send
a series of one-pixel-high strips to the server, but that feels
inelegant at best.

For this particular card-playing app, an easy, practical solution is
to just use the Over operator instead of Src. I'm not really writing a
card-playing app, though. I'm writing a graphics library, for which
there'll be both OpenGL-based and X11/Render-based backends, and I'd
like 'draw this texture with this affine transform and this
Porter-Duff operator' to work the same on both backends.

I had a quick skim through the cairo xlib render source code, but
nothing leapt out as specifically looking at this case.

More information about the xorg mailing list