1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <time.h>
#define BLACK XBlackPixel(display,*(int*)screen)
#define WHITE XWhitePixel(display,*(int*)screen)
#define ROOT XDefaultRootWindow(display)
#define HEIGHT DisplayHeight(display,*(int*)screen)
#define WIDTH DisplayWidth(display,*(int*)screen)
int main(void)
{
sleep(3);
Display* display;
Window win2;
XImage* img;
XEvent ev;
GC gc;
Screen* screen;
clock_t t1,t2,t3,t4;
display = XOpenDisplay(NULL);
if (display == NULL)
{
printf ("!Open Display \n");
exit -1;
}
XSynchronize (display, True);
XSync (display, False);
screen = DefaultScreenOfDisplay(display);
gc=DefaultGC(display,*(int*)screen);
t1 = clock();
img = XGetImage(display,ROOT,0,0,WIDTH,HEIGHT,AllPlanes,XYPixmap);
t2 = clock();
win2 = XCreateSimpleWindow(display,ROOT,0,0,WIDTH,HEIGHT,0,BLACK,WHITE);
XSelectInput(display,win2,ExposureMask);
XMapWindow(display,win2);
while(1)
{
XNextEvent(display,&ev);
if (ev.type == Expose)
break;
}
t3 = clock();
XPutImage(display,win2,gc,img,0,0,0,0,WIDTH,HEIGHT);
t4 = clock();
printf ("GET : %f | PUT : %f \n",(t2-t1)/(double)CLOCKS_PER_SEC, (t4-t3)/(double)CLOCKS_PER_SEC);
XSynchronize (display, False);
XDestroyImage(img);
XDestroyWindow(display,win2);
XCloseDisplay(display);
return 0;
} |
Partager