#include #include #include #include #include #include #include Display *display; int screen; Window root, window; XEvent event; Pixmap maskPixmap; Picture sourcePicture; Picture createPicture() { XRenderPictFormat *fmt = XRenderFindStandardFormat(display, PictStandardRGB24); maskPixmap = XCreatePixmap(display, window, 2, 2, 24); XRenderPictureAttributes pict_attr; pict_attr.repeat=RepeatNone; Picture picture = XRenderCreatePicture(display, maskPixmap, fmt, CPRepeat, &pict_attr); XRenderColor yellow={.red=0xffff, .green=0xffff, .blue=0, .alpha=0xffff}; XRenderFillRectangle (display, PictOpSrc, picture, &yellow, 0, 0, 1, 1); XRenderColor red={.red=0xffff, .green=0, .blue=0, .alpha=0xffff}; XRenderFillRectangle (display, PictOpSrc, picture, &red, 0, 1, 1, 1); XRenderColor green={.red=0, .green=0xffff, .blue=0, .alpha=0xffff}; XRenderFillRectangle (display, PictOpSrc, picture, &green, 1, 0, 1, 1); XRenderColor blue={.red=0, .green=0, .blue=0xffff, .alpha=0xffff}; XRenderFillRectangle (display, PictOpSrc, picture, &blue, 1, 1, 1, 1); return picture; } int usec() { struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); localtime(&tv.tv_sec); return tv.tv_usec; } int main(int argc, char *argv[]) { /*Bosing initialization stuff*/ display=XOpenDisplay(NULL); int render_event_base, render_error_base; int render_present=XRenderQueryExtension(display, &render_event_base, &render_error_base); if (!render_present) { fprintf(stderr, "RENDER extension missing!\n"); abort(); } XRenderPictFormat *fmt=XRenderFindStandardFormat(display, PictStandardRGB24); screen=DefaultScreen(display); root=DefaultRootWindow(display); window = XCreateWindow(display, root, 0, 0, 640, 480, 0, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), 0, NULL); XRenderPictureAttributes pict_attr; pict_attr.poly_edge=PolyEdgeSmooth; pict_attr.poly_mode=PolyModeImprecise; Picture picture=XRenderCreatePicture(display, window, fmt, CPPolyEdge|CPPolyMode, &pict_attr); XSelectInput(display, window, KeyPressMask|KeyReleaseMask|ExposureMask |ButtonPressMask|StructureNotifyMask); /* now make the window visible */ XMapWindow(display, window); XRenderColor color_white = {.red=0xffff, .green=0xffff, .blue=0xffff, .alpha=0xffff}; sourcePicture = createPicture(); XRenderSetPictureFilter(display, sourcePicture, "good", NULL, 0); XRenderPictFormat *maskFmt = XRenderFindStandardFormat(display, PictStandardA8); Pixmap maskPM = XCreatePixmap(display, window, 512, 512, 8); XRenderPictureAttributes pict_attr2; Picture maskPic = XRenderCreatePicture(display, maskPM, maskFmt, 0, &pict_attr2); XRenderSetPictureFilter(display, maskPic, "fast", NULL, 0); XRenderFillRectangle (display, PictOpSrc, maskPic, &color_white, 0, 0, 512, 512); XRectangle clip; clip.x = 20; clip.y = 20; clip.width = 50; clip.height = 30; XRenderSetPictureClipRectangles(display, maskPic, 0, 0, &clip, 1); /*Set source scaling*/ XTransform xf; xf.matrix[0][0] = XDoubleToFixed(0.01); //scalex xf.matrix[0][1] = XDoubleToFixed(0); xf.matrix[0][2] = 0; xf.matrix[1][0] = XDoubleToFixed(0); xf.matrix[1][1] = XDoubleToFixed(0.01); //scaley xf.matrix[1][2] = 0; xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 1<<16; XRenderSetPictureTransform (display, sourcePicture, &xf); xf.matrix[0][0] = XDoubleToFixed(0.5); //scalex xf.matrix[0][1] = XDoubleToFixed(0); xf.matrix[0][2] = 0; xf.matrix[1][0] = XDoubleToFixed(0); xf.matrix[1][1] = XDoubleToFixed(1); //scaley xf.matrix[1][2] = 0; xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 1<<16; XRenderSetPictureTransform (display, maskPic, &xf); int i=0; while(1) { XNextEvent(display, &event); switch(event.type) { case Expose: { XRenderFillRectangle(display, PictOpOver, picture, &color_white, 0, 0, 1000, 1000); XSync(display, 0); int stime = usec(); //for(i=0; i < 50; i++) { XRenderComposite (display, PictOpOver, sourcePicture, maskPic, picture, -50, -20, -100,-100, 0, 0, 500, 500); } XSync(display, 0); int etime = usec(); printf("Msecs elapsed: %d\n", ((etime-stime)/1000));fflush(stdout); break; case DestroyNotify: return 0; } } } return 0; }