rendered paste body#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <X11/Xlib.h>#include <X11/keysymdef.h>#include <X11/extensions/Xrender.h>#define KERNEL_SIZE 6/* create_a8_picture is heavily based (99%) on code** from cairo/src/cairo-xlib-surface.c */Picturecreate_a8_picture (Display* pDisplay, Drawable drawable, XRenderColor* pColor, int iWidth, int iHeight, Bool bRepeat){ XRenderPictureAttributes pa; unsigned long ulMask = 0; Picture picture; Pixmap pixmap; pixmap = XCreatePixmap (pDisplay, drawable, iWidth <= 0 ? 1 : iWidth, iHeight <= 0 ? 1 : iHeight, 8); if (bRepeat) { pa.repeat = True; ulMask = CPRepeat; } picture = XRenderCreatePicture (pDisplay, pixmap, XRenderFindStandardFormat (pDisplay, PictStandardA8), ulMask, &pa); XRenderFillRectangle (pDisplay, PictOpSrc, picture, pColor, 0, 0, iWidth, iHeight); XFreePixmap (pDisplay, pixmap); return picture;}intmain (int argc, char** argv){ Display* pDisplay = NULL; XEvent event; Bool bKeepGoing = True; Bool bGotEvent = False; int iEventBase; int iErrorBase; int iMajorVersion; int iMinorVersion; XSetWindowAttributes values; Window window; Visual* pVisual = NULL; XRenderPictFormat* pPictFormatDefault = NULL; XRenderPictFormat* pPictFormatA8 = NULL; XRenderPictFormat* pPictFormatRGB24 = NULL; XRenderPictFormat* pPictFormatARGB32 = NULL; XRenderPictureAttributes pictAttribs; XRenderColor colorTrans = {0x0000, 0x0000, 0x0000, 0x0000}; XRenderColor colorWhite = {0xffff, 0xffff, 0xffff, 0xffff}; XRenderColor colorRed = {0xffff, 0x0000, 0x0000, 0x7fff}; XRenderColor colorGreen = {0x0000, 0xffff, 0x0000, 0xffff}; XRenderColor colorBlue = {0x0000, 0x0000, 0xffff, 0xffff}; Picture redFillPict; Picture greenFillPict; Picture blueFillPict; Picture maskPict; Picture solidPict; Picture destPict; int iWindowAttribsMask; XTrapezoid trapezoid; XTriangle triangle; XFixed convolutionKernel[KERNEL_SIZE] = { XDoubleToFixed (1.0f), XDoubleToFixed (7.0f), XDoubleToFixed (10.0f), XDoubleToFixed (10.0f), XDoubleToFixed (7.0f), XDoubleToFixed (1.0f) }; trapezoid.top = XDoubleToFixed (20.0f); trapezoid.bottom = XDoubleToFixed (200.0f); trapezoid.left.p1.x = XDoubleToFixed (140.0f); trapezoid.left.p1.y = XDoubleToFixed (20.0f); trapezoid.left.p2.x = XDoubleToFixed (120.0f); trapezoid.left.p2.y = XDoubleToFixed (200.0f); trapezoid.right.p1.x = XDoubleToFixed (180.0f); trapezoid.right.p1.y = XDoubleToFixed (20.0f); trapezoid.right.p2.x = XDoubleToFixed (250.0f); trapezoid.right.p2.y = XDoubleToFixed (200.0f); triangle.p1.x = XDoubleToFixed (225.0f); triangle.p1.y = XDoubleToFixed (110.0f); triangle.p2.x = XDoubleToFixed (275.0f); triangle.p2.y = XDoubleToFixed (210.0f); triangle.p3.x = XDoubleToFixed (175.0f); triangle.p3.y = XDoubleToFixed (210.0f); /* connect to display */ pDisplay = XOpenDisplay (NULL); if (!pDisplay) { printf ("Could not open display\n"); return 1; } /* check for Xrender-extension */ if (!XRenderQueryExtension (pDisplay, &iEventBase, &iErrorBase)) { XCloseDisplay (pDisplay); printf ("Xrender-extension not found\n"); return 2; } /* see which version is available */ XRenderQueryVersion (pDisplay, &iMajorVersion, &iMinorVersion); printf ("Found Xrender %d.%d\n", iMajorVersion, iMinorVersion); /* make behaviour synchronous */ XSynchronize (pDisplay, True); /* get the default visual for this display */ pVisual = DefaultVisual (pDisplay, 0); /* create and open window */ values.background_pixel = WhitePixel (pDisplay, 0); values.event_mask = KeyPressMask; iWindowAttribsMask = CWEventMask | CWBackPixel; window = XCreateWindow (pDisplay, RootWindow (pDisplay, 0), 50, 50, 400, 400, 0, DefaultDepth (pDisplay, 0), InputOutput, pVisual, iWindowAttribsMask, &values); XMapWindow (pDisplay, window); /* now the guessing work starts, ** because Xrender is so "thoroughly" documented :-( */ pPictFormatDefault = XRenderFindVisualFormat (pDisplay, pVisual); pPictFormatA8 = XRenderFindStandardFormat (pDisplay, PictStandardA8); pPictFormatRGB24 = XRenderFindStandardFormat (pDisplay, PictStandardRGB24); pPictFormatARGB32 = XRenderFindStandardFormat (pDisplay, PictStandardARGB32); printf ("default PictFormat-depth %d\n", pPictFormatDefault->depth); printf ("A8 PictFormat-depth %d\n", pPictFormatA8->depth); printf ("RGB24 PictFormat-depth %d\n", pPictFormatRGB24->depth); printf ("ARGB32 PictFormat-depth %d\n", pPictFormatARGB32->depth); /* as far as I get it this should give ** me three colored "infinite pictures" */ redFillPict = XRenderCreateSolidFill (pDisplay, &colorRed); greenFillPict = XRenderCreateSolidFill (pDisplay, &colorGreen); blueFillPict = XRenderCreateSolidFill (pDisplay, &colorBlue); /* this is my target- or destination-drawable derived from the window... ** at least I think so */ /*pictAttribs.repeat = True;*/ destPict = XRenderCreatePicture (pDisplay, window, pPictFormatDefault, 0, &pictAttribs); maskPict = create_a8_picture (pDisplay, window, &colorTrans, 400, 400, False); solidPict = create_a8_picture (pDisplay, window, &colorWhite, 400, 400, True); /*XRenderSetPictureFilter (pDisplay, maskPict, "convolution", convolutionKernel, KERNEL_SIZE);*/ /* this trapezoid show up too now */ XRenderCompositeTrapezoids (pDisplay, PictOpAdd, solidPict, maskPict, pPictFormatA8, 0, 0, &trapezoid, 1); XRenderComposite (pDisplay, PictOpOver, blueFillPict, maskPict, destPict, 0, 0, 0, 0, 0, 0, 400, 400); XRenderFreePicture (pDisplay, maskPict); XRenderFreePicture (pDisplay, solidPict); maskPict = create_a8_picture (pDisplay, window, &colorTrans, 400, 400, False); solidPict = create_a8_picture (pDisplay, window, &colorWhite, 400, 400, True); XRenderCompositeTriangles (pDisplay, PictOpAdd, solidPict, maskPict, pPictFormatA8, 0, 0, &triangle, 1); XRenderComposite (pDisplay, PictOpOver, redFillPict, maskPict, destPict, 0, 0, 0, 0, 0, 0, 400, 400); while (bKeepGoing) { bGotEvent = XCheckWindowEvent (pDisplay, window, KeyPressMask, &event); if (bGotEvent) { switch (event.type) { case KeyPress : if (XLookupKeysym (&event.xkey, 0) == XK_Escape) bKeepGoing = False; break; } } else usleep (10000); } XRenderFreePicture (pDisplay, redFillPict); XRenderFreePicture (pDisplay, greenFillPict); XRenderFreePicture (pDisplay, blueFillPict); XRenderFreePicture (pDisplay, destPict); XRenderFreePicture (pDisplay, maskPict); XRenderFreePicture (pDisplay, solidPict); XUnmapWindow (pDisplay, window); XDestroyWindow (pDisplay, window); XCloseDisplay (pDisplay); return 0;}