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)
};
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;
}
switch(fb_bpp) {
case 15:
- fbptr16 = framebuf;
- for(i=0; i<fb_height; i++) {
- for(j=0; j<fb_width; j++) {
- XORRGB(j + xoffs, i + yoffs, zoom, r, g, b);
- *fbptr16++ = ((r & 0x1f) << 10) | ((g & 0x1f) << 5) | (b & 0x1f);
- }
- fbptr16 += (fb_pitch >> 1) - fb_width;
- }
- break;
-
case 16:
fbptr16 = framebuf;
for(i=0; i<fb_height; i++) {
for(j=0; j<fb_width; j++) {
XORRGB(j + xoffs, i + yoffs, zoom, r, g, b);
- *fbptr16++ = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f);
+ *fbptr16++ = (((r >> 3) << fb_rshift) & fb_rmask) |
+ (((g >> 2) << fb_gshift) & fb_gmask) |
+ (((b >> 3) << fb_bshift) & fb_bmask);
}
fbptr16 += (fb_pitch >> 1) - fb_width;
}
for(i=0; i<fb_height; i++) {
for(j=0; j<fb_width; j++) {
XORRGB(j + xoffs, i + yoffs, zoom, r, g, b);
- *fbptr32++ = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
+ *fbptr32++ = (((r) << fb_rshift) & fb_rmask) |
+ (((g) << fb_gshift) & fb_gmask) |
+ (((b) << fb_bshift) & fb_bmask);
}
fbptr32 += (fb_pitch >> 2) - fb_width;
}
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;
--- /dev/null
+#include "util.h"
+
+int mask_to_shift(unsigned int mask)
+{
+ int s = 0;
+ if(mask) {
+ while(!(mask & 1)) {
+ mask >>= 1;
+ s++;
+ }
+ }
+ return s;
+}
--- /dev/null
+#ifndef UTIL_H_
+#define UTIL_H_
+
+int mask_to_shift(unsigned int mask);
+
+#endif /* UTIL_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <signal.h>
#include <sys/time.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include "rbench.h"
+#include "util.h"
enum { QUIT = 1, REDRAW = 2 };
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;
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) {
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);
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);
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 |
}
return 0;
}
+
+static void sig(int s)
+{
+ pending |= QUIT;
+}