+ gc = XCreateGC(dpy, win, 0, 0);
+
+ if(!(ximg = XShmCreateImage(dpy, vis, opt.bpp, ZPixmap, 0, &shm, opt.width, opt.height))) {
+ fprintf(stderr, "failed to create shared memory image\n");
+ goto end;
+ }
+ if((shm.shmid = shmget(IPC_PRIVATE, ximg->bytes_per_line * ximg->height, IPC_CREAT | 0777)) == -1) {
+ fprintf(stderr, "failed to create shared memory block\n");
+ goto end;
+ }
+ if((shm.shmaddr = ximg->data = shmat(shm.shmid, 0, 0)) == (void*)-1) {
+ fprintf(stderr, "failed to attach shared memory block\n");
+ goto end;
+ }
+ shm.readOnly = True;
+ if(!XShmAttach(dpy, &shm)) {
+ fprintf(stderr, "XShmAttach failed");
+ goto end;
+ }
+
+ fb_width = opt.width;
+ fb_height = opt.height;
+ fb_bpp = opt.bpp >= 24 ? 32 : opt.bpp;
+ framebuf = ximg->data;
+ fb_pitch = ximg->bytes_per_line;
+
+ if(init() == -1) {
+ goto end;
+ }
+
+ gettimeofday(&tv0, 0);
+ num_frames = 0;