X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fx11%2Fmain.c;h=8511a93bd1f8b21811d96517b1ff8c643972699f;hb=9a0d071a2bb88786abc90ff3f4f406e06a66f8e3;hp=036e765847cbdba46875747ab6711e7c56f66943;hpb=dee0f6aebe2faae7f5b05136beec802b20740514;p=retrobench diff --git a/src/x11/main.c b/src/x11/main.c index 036e765..8511a93 100644 --- a/src/x11/main.c +++ b/src/x11/main.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include @@ -9,6 +11,7 @@ #include #include #include "rbench.h" +#include "util.h" enum { QUIT = 1, REDRAW = 2 }; @@ -16,6 +19,7 @@ static Window create_win(int width, int height, int bpp); static void handle_event(XEvent *ev); static int translate_keysym(KeySym sym); static int parse_args(int argc, char **argv); +static void sig(int s); static int win_width, win_height; static int mapped; @@ -25,21 +29,34 @@ static Window win, root; static GC gc; static Visual *vis; static Atom xa_wm_proto, xa_wm_delwin; +static int no_wm; static XImage *ximg; static XShmSegmentInfo shm; static int wait_putimg; static int xshm_ev_completion; + int main(int argc, char **argv) { - int num_frames; + int num_frames = 0; XEvent ev; struct timeval tv, tv0; + char *env; + + if((env = getenv("RBENCH_NO_WM"))) { + if(isdigit(env[0])) { + no_wm = atoi(env); + } else { + no_wm = 1; + } + } shm.shmid = -1; shm.shmaddr = (void*)-1; + signal(SIGINT, sig); + read_config("rbench.cfg"); if(parse_args(argc, argv) == -1) { @@ -86,18 +103,27 @@ int main(int argc, char **argv) fb_width = opt.width; fb_height = opt.height; - fb_bpp = opt.bpp >= 24 ? 32 : opt.bpp; + if(opt.bpp >= 24) { + fb_bpp = ximg->bytes_per_line < fb_width * 4 ? 24 : 32; + } else { + fb_bpp = opt.bpp; + } framebuf = ximg->data; fb_pitch = ximg->bytes_per_line; + fb_rmask = ximg->red_mask; + fb_gmask = ximg->green_mask; + fb_bmask = ximg->blue_mask; + fb_rshift = mask_to_shift(fb_rmask); + fb_gshift = mask_to_shift(fb_gmask); + fb_bshift = mask_to_shift(fb_bmask); if(init() == -1) { goto end; } gettimeofday(&tv0, 0); - num_frames = 0; - for(;;) { + while(!(pending & QUIT)) { if(mapped) {/* && !wait_putimg) { */ while(XPending(dpy)) { XNextEvent(dpy, &ev); @@ -105,14 +131,17 @@ int main(int argc, char **argv) if(pending & QUIT) goto end; } - gettimeofday(&tv, 0); - time_msec = (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000; - num_frames++; + if(!wait_putimg) { + gettimeofday(&tv, 0); + time_msec = (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000; + num_frames++; - redraw(); + redraw(); - XShmPutImage(dpy, win, gc, ximg, 0, 0, 0, 0, ximg->width, ximg->height, False); - /*wait_putimg = 1;*/ + XShmPutImage(dpy, win, gc, ximg, 0, 0, 0, 0, ximg->width, ximg->height, False); + XSync(dpy, False); + /*wait_putimg = 1;*/ + } } else { XNextEvent(dpy, &ev); handle_event(&ev); @@ -174,8 +203,9 @@ static Window create_win(int width, int height, int bpp) xattr.background_pixel = BlackPixel(dpy, scr); xattr.colormap = cmap; + xattr.override_redirect = no_wm ? True : False; win = XCreateWindow(dpy, root, 0, 0, width, height, 0, vinf->depth, - InputOutput, vis, CWColormap | CWBackPixel, &xattr); + InputOutput, vis, CWColormap | CWBackPixel | CWOverrideRedirect, &xattr); if(!win) return 0; XSelectInput(dpy, win, StructureNotifyMask | ExposureMask | KeyPressMask | @@ -306,3 +336,8 @@ inval_arg: fprintf(stderr, "invalid argument: %s\n", argv[i]); } return 0; } + +static void sig(int s) +{ + pending |= QUIT; +}