From 21d237fda9d909bb9588d877f244431989917af7 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 17 May 2021 08:44:49 +0300 Subject: [PATCH] override redirect, obey ximage rgb masks, restore completion event --- GNUmakefile | 4 ++-- src/rbench.c | 23 +++++++++++------------ src/rbench.h | 2 ++ src/util.c | 13 +++++++++++++ src/util.h | 6 ++++++ src/x11/main.c | 44 +++++++++++++++++++++++++++++++++----------- 6 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 src/util.c create mode 100644 src/util.h diff --git a/GNUmakefile b/GNUmakefile index 450b272..d2c211c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -5,11 +5,11 @@ bin = rbench warn = -pedantic -Wall -Wno-deprecated-declarations dbg = -g -#opt = -O3 -ffast-math +opt = -O3 -ffast-math inc = -Isrc CFLAGS = -pedantic $(warn) $(dbg) $(opt) $(inc) -MMD -LDFLAGS = -lX11 -lXext -lm +LDFLAGS = -L/usr/X11R6/lib -lX11 -lXext -lm $(bin): $(obj) $(CC) -o $@ $(obj) $(LDFLAGS) diff --git a/src/rbench.c b/src/rbench.c index 005013c..3d8eace 100644 --- a/src/rbench.c +++ b/src/rbench.c @@ -14,11 +14,16 @@ struct options opt = { }; int fb_width, fb_height, fb_bpp, fb_pitch; +int fb_rshift, fb_gshift, fb_bshift; +unsigned int fb_rmask, fb_gmask, fb_bmask; void *framebuf; unsigned int time_msec; int init(void) { + printf("initialized graphics %dx%d %dbpp\n", fb_width, fb_height, fb_bpp); + printf(" rgb mask: %x %x %x\n", fb_rmask, fb_gmask, fb_bmask); + printf(" rgb shift: %d %d %d\n", fb_rshift, fb_gshift, fb_bshift); return 0; } @@ -48,22 +53,14 @@ void redraw(void) switch(fb_bpp) { case 15: - fbptr16 = framebuf; - for(i=0; i> 1) - fb_width; - } - break; - case 16: fbptr16 = framebuf; for(i=0; i> 3) << fb_rshift) & fb_rmask) | + (((g >> 2) << fb_gshift) & fb_gmask) | + (((b >> 3) << fb_bshift) & fb_bmask); } fbptr16 += (fb_pitch >> 1) - fb_width; } @@ -87,7 +84,9 @@ void redraw(void) for(i=0; i> 2) - fb_width; } diff --git a/src/rbench.h b/src/rbench.h index 8efb0d1..c48d6f1 100644 --- a/src/rbench.h +++ b/src/rbench.h @@ -7,6 +7,8 @@ struct options { extern struct options opt; extern int fb_width, fb_height, fb_bpp, fb_pitch; +extern int fb_rshift, fb_gshift, fb_bshift; +extern unsigned int fb_rmask, fb_gmask, fb_bmask; extern void *framebuf; extern unsigned int time_msec; diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..82a8bfc --- /dev/null +++ b/src/util.c @@ -0,0 +1,13 @@ +#include "util.h" + +int mask_to_shift(unsigned int mask) +{ + int s = 0; + if(mask) { + while(!(mask & 1)) { + mask >>= 1; + s++; + } + } + return s; +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..001aedc --- /dev/null +++ b/src/util.h @@ -0,0 +1,6 @@ +#ifndef UTIL_H_ +#define UTIL_H_ + +int mask_to_shift(unsigned int mask); + +#endif /* UTIL_H_ */ diff --git a/src/x11/main.c b/src/x11/main.c index 036e765..c1f4b87 100644 --- a/src/x11/main.c +++ b/src/x11/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include "rbench.h" +#include "util.h" enum { QUIT = 1, REDRAW = 2 }; @@ -16,6 +18,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; @@ -33,13 +36,15 @@ static int xshm_ev_completion; int main(int argc, char **argv) { - int num_frames; + int num_frames = 0; XEvent ev; struct timeval tv, tv0; shm.shmid = -1; shm.shmaddr = (void*)-1; + signal(SIGINT, sig); + read_config("rbench.cfg"); if(parse_args(argc, argv) == -1) { @@ -86,18 +91,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 +119,16 @@ 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, True); + wait_putimg = 1; + } } else { XNextEvent(dpy, &ev); handle_event(&ev); @@ -174,8 +190,9 @@ static Window create_win(int width, int height, int bpp) xattr.background_pixel = BlackPixel(dpy, scr); xattr.colormap = cmap; + xattr.override_redirect = True; 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 +323,8 @@ inval_arg: fprintf(stderr, "invalid argument: %s\n", argv[i]); } return 0; } + +static void sig(int s) +{ + pending |= QUIT; +} -- 1.7.10.4