#include #include #include #include Display *display; int screen; Window root, window; XEvent event; char* alphaData; XRenderPictFormat *fmt_a8; GlyphSet gs12a8; Picture sourcePicture; Picture picture; #define GLYPH_BATCH 5 void memleak() { XGlyphInfo xginfo[GLYPH_BATCH]; Glyph gid[GLYPH_BATCH]; int i=0; for(; i < GLYPH_BATCH; i++) { gid[i] = i + 100; xginfo[i].width = 100; xginfo[i].height = 100; xginfo[i].x = 0; xginfo[i].y = 0; xginfo[i].xOff = 100; xginfo[i].yOff = 0; } XRenderAddGlyphs(display, gs12a8, &gid[0], &xginfo[0], GLYPH_BATCH, alphaData, 100*100*GLYPH_BATCH); XGlyphElt32 elt = {.glyphset=gs12a8, .chars= (unsigned int*) &gid, GLYPH_BATCH, 100, 100}; XRenderCompositeText32 (display, PictOpOver, sourcePicture, screen, fmt_a8, 0, 0, 100, 100, &elt, 1); XRenderFreeGlyphs (display, gs12a8, &gid[0], GLYPH_BATCH); } Picture create_pen(int red, int green, int blue, int alpha, int width, int height, int depth, char* sm) { XRenderColor color={.red=red, .green=green, .blue=blue, .alpha=alpha}; XRenderPictFormat *fmt; if(depth == 24) { fmt = XRenderFindStandardFormat(display, PictStandardRGB24); }else { fmt = XRenderFindStandardFormat(display, PictStandardARGB32); } Pixmap pm = XCreatePixmap(display, window, width, height, depth); XRenderPictureAttributes pict_attr; pict_attr.repeat=RepeatNormal; Picture picture = XRenderCreatePicture(display, pm, fmt, CPRepeat, &pict_attr); XRenderFillRectangle(display, PictOpSrc, picture, &color, 0, 0, width, height); return picture; } int main(int argc, char *argv[]) { alphaData = malloc(1024*1024); //Open display and check that it actually opens display=XOpenDisplay(NULL); if ( display == NULL ) { printf("Unable to open display, is X running? Set DISPLAY enviorment variable.\n"); return 1; } 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(); } //Check version of xrender extension, v0.10 is needed. int render_version_major, render_version_minor; if ( XRenderQueryVersion(display, &render_version_major, &render_version_minor) != 0 ) { if( render_version_minor < 10 ){ printf("RENDER Version %d.%d is too old! Requires 0.10\n",render_version_major,render_version_minor); return 1; } }else{ return 1; abort(); } /* obtain a few parameters */ XRenderPictFormat *fmt=XRenderFindStandardFormat(display, PictStandardRGB24); screen=DefaultScreen(display); root=DefaultRootWindow(display); /* create window and all related resources */ window = XCreateWindow(display, root, 0, 0, 640, 480, 0, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), 0, NULL); XRenderPictureAttributes pict_attr; picture=XRenderCreatePicture(display, window, fmt, 0, &pict_attr); XSelectInput(display, window, KeyPressMask|KeyReleaseMask|ExposureMask |ButtonPressMask|StructureNotifyMask); sourcePicture = create_pen(0,0,0xffff,0xdfff, 1, 1, 32, NULL); /* now make the window visible */ XMapWindow(display, window); fmt_a8 = XRenderFindStandardFormat(display, PictStandardA8); gs12a8 = XRenderCreateGlyphSet(display, fmt_a8); while(1) { XNextEvent(display, &event); switch(event.type) { case Expose: { while(1) { memleak(); } } break; case DestroyNotify: return 0; } } return 0; } /* XGlyphInfo xginfo[GLYPH_BATCH]; Glyph gid[GLYPH_BATCH]; int i=0; for(; i < GLYPH_BATCH; i++) { gid[i] = i + 100; xginfo[i].width = area; xginfo[i].height = area; xginfo[i].x = 0; xginfo[i].y = 0; xginfo[i].xOff = area; xginfo[i].yOff = 0; } XRenderAddGlyphs(display, gs12a8, &gid[0], &xginfo[0], GLYPH_BATCH, alphaData, area*area*GLYPH_BATCH); XGlyphElt32 elt = {.glyphset=gs12a8, .chars= (unsigned int*) &gid, GLYPH_BATCH, area, area}; XRenderCompositeText32 (display, PictOpOver, sourcePicture, backBuffer, fmt_a8, 0, 0, 100, 100, &elt, 1); XRenderFreeGlyphs (display, gs12a8, &gid[0], GLYPH_BATCH);*/