Help for beginner. XCreatePixmap
mike
flame-mike at zeelandnet.nl
Mon Oct 22 03:03:23 PDT 2007
Hi, all.
When I create a lot of pixmaps I can't freed memory,
Wat I doe wrong?
Before start program.
mike at mike-desktop:~$ ps aux | grep /X11/X
root 3708 6.0 2.0 12672 9152 tty7 Ss+ 11:19 0:01
/usr/bin/X11/X -dpi 100 -nolisten tcp -ld 0 -ls 0 -lf 0 -bs -su -br
-maxbigreqsize 1
After
mike at mike-desktop:~$ ps aux | grep /X11/X
root 3708 1.1 2.9 51984 13324 tty7 Ss+ 11:19 0:02
/usr/bin/X11/X -dpi 100 -nolisten tcp -ld 0 -ls 0 -lf 0 -bs -su -br
-maxbigreqsize 1
#include <X11/cursorfont.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <stdio.h>
Display *display;
Window win1;
XSetWindowAttributes attributes;
XFontStruct *fontinfo;
GC gr_context1;
XArc arcs[10];
Pixmap pixmap, pix[1024];
Visual *visual;
int screen;
int depth;
int i;
main (argc, argv)
char *argv[];
int argc;
{
XGCValues gr_values;
XEvent event;
setbuf (stdout, NULL);
setbuf (stderr, NULL);
display = XOpenDisplay(NULL);
screen = DefaultScreen(display);
visual = DefaultVisual(display,screen);
depth = DefaultDepth(display,screen);
attributes.background_pixel = XWhitePixel(display,screen);
attributes.border_pixel = XBlackPixel(display,screen);
attributes.override_redirect = 0;
for(i=0;i<10;i++){
arcs[i].x = 100;arcs[i].y = 50;
arcs[i].width = 100;arcs[i].height = 50;
}
for(i=0;i<5;i++){
arcs[i].angle1 = 72*64*i;
arcs[i].angle2 = 35*64;
}
for(i=5;i<10;i++){
arcs[i].angle1 = 72*64*i + 36*64;
arcs[i].angle2 = 35*64;
}
win1= XCreateWindow(display, XRootWindow(display,screen),
200,200, 300,200,5, depth, InputOutput, visual,
CWBackPixel | CWBorderPixel |
CWOverrideRedirect,&attributes);
XSelectInput(display,win1,ExposureMask | ButtonPressMask |
KeyPressMask);
FILE *test;
test = fopen("test.pix", "w");
pixmap = XCreatePixmap(display,win1,200,100,depth);
for (i=0; i<1024; i++){
pix[i] = XCreatePixmap(display,win1,200,100,depth);
fprintf(test, "%lu\n", pix[i]);
}
fclose(test);
fontinfo = XLoadQueryFont(display,"6x10");
gr_values.font = fontinfo->fid;
gr_values.function = GXcopy;
gr_values.plane_mask = AllPlanes;
gr_values.foreground = BlackPixel(display,screen);
gr_values.background = WhitePixel(display,screen);
gr_context1=XCreateGC(display,win1,
GCFont | GCFunction | GCPlaneMask | GCForeground |
GCBackground,
&gr_values);
XDefineCursor(display,win1,XCreateFontCursor(display,XC_heart));
XMapWindow(display,win1);
do{
XNextEvent(display,&event);
if (event.type == Expose){
draw_ellipse();
XCopyArea(display,win1,pixmap,gr_context1,50,25,200,100,0,0);
XSetFunction(display,gr_context1,GXinvert);
XDrawImageString(display,pixmap,gr_context1,80,45,"pixmap",6);
XDrawImageString(display,pixmap,gr_context1,90,60,"copy",4);
XSetFunction(display,gr_context1,GXcopy);
XDrawString(display,win1,gr_context1,10,20,
"Press a key in this window",26);
}
}while (event.type !=KeyPress);
XCopyArea(display,pixmap,win1,gr_context1,0,0,200,100,100,125);
XDrawString(display,win1,gr_context1,10,32,
"Now press a key to exit",23);
XFlush(display);
do{
XNextEvent(display,&event);
}while (event.type !=KeyPress);
printf("closing display\n");
for (i=0; i<1024; i++) XFreePixmap(display, pix[i]);
XFreePixmap(display, pixmap);
XCloseDisplay(display);
}
draw_ellipse()
{
XSetArcMode(display,gr_context1,ArcPieSlice);
XFillArcs(display,win1,gr_context1,arcs,5);
XSetArcMode(display,gr_context1,ArcChord);
XFillArcs(display,win1,gr_context1,arcs+5,5);
}
More information about the xorg
mailing list