#include #include #include #include #include #include #include Display *display; int screen; Window root, window; XEvent event; Pixmap maskPixmap; Picture alphaMask; Picture setAlphaPict; XRenderColor clearAlpha = {.red=0, .green=0, .blue=0, .alpha=0}; XRenderColor setAlpha = {.red=0, .green=0, .blue=0, .alpha=0x0aff}; Picture create_pen(int red, int green, int blue, int alpha) { XRenderColor color={.red=red, .green=green, .blue=blue, .alpha=alpha}; XRenderPictFormat *fmt=XRenderFindStandardFormat(display, PictStandardRGB24); Pixmap pm = XCreatePixmap(display, window, 1, 1, 24); XRenderPictureAttributes pict_attr; pict_attr.repeat=1; Picture picture = XRenderCreatePicture(display, pm, fmt, CPRepeat, &pict_attr); XRenderFillRectangle(display, PictOpSrc, picture, &color, 0, 0, 1, 1); return picture; } int usec() { struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); localtime(&tv.tv_sec); return tv.tv_usec; } Picture createPicture() { XRenderPictFormat *fmt = XRenderFindStandardFormat(display, PictStandardRGB24); maskPixmap = XCreatePixmap(display, window, 10, 1, 24); XRenderPictureAttributes pict_attr; pict_attr.repeat=RepeatNone; Picture picture = XRenderCreatePicture(display, maskPixmap, fmt, CPRepeat, &pict_attr); XRenderColor color_black={.red=0xffff, .green=0xffff, .blue=0, .alpha=0xffff}; XRenderFillRectangle (display, PictOpSrc, picture, &color_black, 0, 0, 1000, 1000); return picture; } 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}; XRenderColor color_red = {.red=0xffff, .green=0x0000, .blue=0x0000, .alpha=0x0fff}; XRenderColor color_black = {.red=0, .green=0, .blue=0, .alpha=0xffff}; Picture black = XRenderCreateSolidFill (display, &color_black); Picture red = XRenderCreateSolidFill (display, &color_red);//create_pen(0,0,0,0xffff); Picture black_pict = create_pen(0x0ffff,0x0ffff,0,0xffff); setAlphaPict = create_pen(0,0,0,0x00ff); alphaMask = createPicture(); XRenderSetPictureFilter(display, alphaMask, "good", NULL, 0); //XRenderSetPictureFilter(display, alphaMask, "fast", NULL, 0); XTransform xf; xf.matrix[0][0] = XDoubleToFixed(0.2); xf.matrix[0][1] = 0; xf.matrix[0][2] = 0; xf.matrix[1][0] = 0; xf.matrix[1][1] = XDoubleToFixed(1); xf.matrix[1][2] = 0; xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 1<<16; XRenderSetPictureTransform (display, alphaMask, &xf); while(1) { XNextEvent(display, &event); switch(event.type) { case Expose: { XRenderFillRectangle(display, PictOpOver, picture, &color_white, 0, 0, 1000, 1000); XRenderComposite (display, PictOpSrc, alphaMask, None, picture, -50, -50, 0, 0, 10, 10, 500, 500); break; case DestroyNotify: return 0; } } } return 0; } /* int cnt = 0; for(cnt=0; cnt < 25; cnt++) { //Fill the rect-array int trapCnt = 250; int i; //1. Clean the mask XRenderFillRectangle (display, PictOpSrc, alphaMask, &clearAlpha, 0, 0, 320, 200); //fillRectMaskTile(250); //fillTrapMaskTile(250); //fillPutImage(); //Composite XRenderComposite (display, PictOpOver, black_pict, alphaMask, picture, 0, 0, 0, 0, 0, 0, 320, 200); } */