14 static int init_fbdev(int xsz, int ysz, int bpp);
15 static void close_fbdev(void);
16 static int parse_args(int argc, char **argv);
23 int main(int argc, char **argv)
26 struct timeval tv, tv0;
28 read_config("rbench.cfg");
30 if(parse_args(argc, argv) == -1) {
34 if(init_fbdev(opt.width, opt.height, opt.bpp) == -1) {
39 fb_height = opt.height;
41 fb_pitch = opt.width * opt.bpp / 8;
43 if(!(framebuf = malloc(fb_pitch * fb_height))) {
44 fprintf(stderr, "failed to allocate %dx%d (%d bpp) framebuffer\n",
45 fb_width, fb_height, fb_bpp);
49 fb_rmask = ximg->red_mask;
50 fb_gmask = ximg->green_mask;
51 fb_bmask = ximg->blue_mask;
52 fb_rshift = mask_to_shift(fb_rmask);
53 fb_gshift = mask_to_shift(fb_gmask);
54 fb_bshift = mask_to_shift(fb_bmask);
61 /* TODO: set terminal raw and disable cursor */
63 gettimeofday(&tv0, 0);
69 time_msec = (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
82 printf("avg framerate: %.1f fps\n", (10000 * num_frames / time_msec) / 10.0f);
87 int init_fbdev(int xsz, int ysz, int bpp)
89 if((fbfd = open("/dev/fb0", O_RDWR)) == -1) {
90 perror("failed to open framebuffer device");
94 /* TODO modeset ioctl */
96 fbsz = xsz * ysz * bpp / 8; /* XXX */
98 if((fbmem = mmap(0, fbsz, PROT_WRITE, MAP_SHARED, fbfd, 0)) == (void*)-1) {
99 perror("failed to map framebuffer");
106 void close_fbdev(void)
116 static const char *usage_str =
117 "Usage: %s [options]\n"
119 " -s <WxH>: resolution\n"
120 " -b <bpp>: color depth\n"
121 " -h: print usage and exit\n";
123 static int parse_args(int argc, char **argv)
127 for(i=1; i<argc; i++) {
128 if(argv[i][0] == '-') {
134 if(!argv[++i] || sscanf(argv[i], "%dx%d", &opt.width, &opt.height) != 2) {
135 fprintf(stderr, "-s must be followed by WxH\n");
141 if(!argv[++i] || !(opt.bpp = atoi(argv[i]))) {
142 fprintf(stderr, "-b must be followed by the color depth\n");
148 printf(usage_str, argv[0]);
155 inval_arg: fprintf(stderr, "invalid argument: %s\n", argv[i]);