15 static void keyb(int key, int pressed, void *cls);
16 static int parse_args(int argc, char **argv);
21 int main(int argc, char **argv)
24 struct timeval tv, tv0;
25 struct fbgfx_vmode *vm;
27 read_config("rbench.cfg");
29 if(parse_args(argc, argv) == -1) {
33 fbgfx_save_video_mode();
34 if(!(fbmem = fbgfx_set_video_mode(opt.width, opt.height, opt.bpp))) {
35 fprintf(stderr, "failed to set video mode: %dx%d %dbpp\n", opt.width,
39 vm = fbgfx_video_mode_info();
42 fb_height = vm->height;
48 fb_rshift = vm->rshift;
49 fb_gshift = vm->gshift;
50 fb_bshift = vm->bshift;
52 if(!(framebuf = malloc(fb_pitch * fb_height))) {
53 fprintf(stderr, "failed to allocate %dx%d (%d bpp) framebuffer\n",
54 fb_width, fb_height, fb_bpp);
58 if(fbev_init() == -1) {
61 fbev_keyboard(keyb, 0);
67 gettimeofday(&tv0, 0);
74 time_msec = (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
78 memcpy(fbmem, framebuf, fb_pitch * fb_height);
84 fbgfx_restore_video_mode();
87 printf("avg framerate: %.1f fps\n", (10000 * num_frames / time_msec) / 10.0f);
92 static void keyb(int key, int pressed, void *cls)
96 if(key == 27 || key == 'q' || key == 'Q') {
102 static const char *usage_str =
103 "Usage: %s [options]\n"
105 " -s <WxH>: resolution\n"
106 " -b <bpp>: color depth\n"
107 " -h: print usage and exit\n";
109 static int parse_args(int argc, char **argv)
113 for(i=1; i<argc; i++) {
114 if(argv[i][0] == '-') {
120 if(!argv[++i] || sscanf(argv[i], "%dx%d", &opt.width, &opt.height) != 2) {
121 fprintf(stderr, "-s must be followed by WxH\n");
127 if(!argv[++i] || !(opt.bpp = atoi(argv[i]))) {
128 fprintf(stderr, "-b must be followed by the color depth\n");
134 printf(usage_str, argv[0]);
141 inval_arg: fprintf(stderr, "invalid argument: %s\n", argv[i]);