fprintf(stderr, " Visual*:    0x%x\n", (int) vinfo->visual);
fprintf(stderr, " Visual*:    0x%p\n", vinfo->visual);
XImage *initialize_xdisplay_fb(void) {	XImage *fb;	char *vis_str = visual_str;	int try = 0, subwin_tries = 3;	XErrorHandler old_handler;	int subwin_bs;	X_LOCK;	if (subwin && !valid_window((Window) subwin)) {		rfbLog("invalid sub-window: 0x%lx\n", subwin);		X_UNLOCK;		clean_up_exit(1);	}		if (overlay) {		/* 		 * ideally we'd like to not have to cook up the		 * visual variables but rather let it all come out		 * of XReadScreen(), however there is no way to get		 * a default visual out of it, so we pretend -visual		 * TrueColor:NN was supplied with NN usually 24.		 */		char str[32];		Window twin = subwin ? subwin : rootwin;		XImage *xi;		xi = xreadscreen(dpy, twin, 0, 0, 8, 8, False);		sprintf(str, "TrueColor:%d", xi->depth);		if (xi->depth != 24 && ! quiet) {			rfbLog("warning: overlay image has depth %d "			    "instead of 24.\n", xi->depth);		}		XDestroyImage(xi);		if (visual_str != NULL && ! quiet) {			rfbLog("warning: replacing '-visual %s' by '%s' "			    "for use with -overlay\n", visual_str, str);		}		vis_str = strdup(str);	}	if (vis_str != NULL) {		set_visual(vis_str);		if (vis_str != visual_str) {			free(vis_str);		}	}	/* set up parameters for subwin or non-subwin cases: */	if (! subwin) {		/* full screen */		window = rootwin;		dpy_x = DisplayWidth(dpy, scr);		dpy_y = DisplayHeight(dpy, scr);		off_x = 0;		off_y = 0;		/* this may be overridden via visual_id below */		default_visual = DefaultVisual(dpy, scr);	} else {		/* single window */		XWindowAttributes attr;		window = (Window) subwin;		if (! XGetWindowAttributes(dpy, window, &attr)) {			rfbLog("invalid window: 0x%lx\n", window);			X_UNLOCK;			clean_up_exit(1);		}		dpy_x = attr.width;		dpy_y = attr.height;		subwin_bs = attr.backing_store;		/* this may be overridden via visual_id below */		default_visual = attr.visual;		X_UNLOCK;		set_offset();		X_LOCK;	}	/* initialize depth to reasonable value, visual_id may override */	depth = DefaultDepth(dpy, scr);	if (visual_id) {		int n;		XVisualInfo vinfo_tmpl, *vinfo;		/*		 * we are in here from -visual or -overlay options		 * visual_id and visual_depth were set in set_visual().		 */		vinfo_tmpl.visualid = visual_id; 		vinfo = XGetVisualInfo(dpy, VisualIDMask, &vinfo_tmpl, &n);		if (vinfo == NULL || n == 0) {			rfbLog("could not match visual_id: 0x%x\n",			    (int) visual_id);			X_UNLOCK;			clean_up_exit(1);		}		default_visual = vinfo->visual;		depth = vinfo->depth;		if (visual_depth) {			/* force it from -visual MooColor:NN */			depth = visual_depth;		}		if (! quiet) {			fprintf(stderr, " initialize_xdisplay_fb()\n");			fprintf(stderr, " Visual*:    0x%x\n",			    (int) vinfo->visual);			fprintf(stderr, " visualid:   0x%x\n",			    (int) vinfo->visualid);			fprintf(stderr, " screen:     %d\n", vinfo->screen);			fprintf(stderr, " depth:      %d\n", vinfo->depth);			fprintf(stderr, " class:      %d\n", vinfo->class);			fprintf(stderr, " red_mask:   0x%08lx  %s\n",			    vinfo->red_mask, bitprint(vinfo->red_mask, 32));			fprintf(stderr, " green_mask: 0x%08lx  %s\n",			    vinfo->green_mask, bitprint(vinfo->green_mask, 32));			fprintf(stderr, " blue_mask:  0x%08lx  %s\n",			    vinfo->blue_mask, bitprint(vinfo->blue_mask, 32));			fprintf(stderr, " cmap_size:  %d\n",			    vinfo->colormap_size);			fprintf(stderr, " bits b/rgb: %d\n",			    vinfo->bits_per_rgb);			fprintf(stderr, "\n");		}		XFree(vinfo);	}	if (! quiet) {		rfbLog("default visual ID: 0x%x\n",		    (int) XVisualIDFromVisual(default_visual));	}	again:	if (subwin) {		int shift = 0;		int subwin_x, subwin_y;		int disp_x = DisplayWidth(dpy, scr);		int disp_y = DisplayHeight(dpy, scr);		Window twin;		/* subwins can be a dicey if they are changing size... */		XTranslateCoordinates(dpy, window, rootwin, 0, 0, &subwin_x,		    &subwin_y, &twin);		if (subwin_x + dpy_x > disp_x) {			shift = 1;			subwin_x = disp_x - dpy_x - 3;		}		if (subwin_y + dpy_y > disp_y) {			shift = 1;			subwin_y = disp_y - dpy_y - 3;		}		if (subwin_x < 0) {			shift = 1;			subwin_x = 1;		}		if (subwin_y < 0) {			shift = 1;			subwin_y = 1;		}		trapped_xerror = 0;		old_handler = XSetErrorHandler(trap_xerror);		if (shift) {			XMoveWindow(dpy, window, subwin_x, subwin_y);		}		XMapRaised(dpy, window);		XRaiseWindow(dpy, window);		XFlush(dpy);	}	try++;	if (nofb) {		/* 		 * For -nofb we do not allocate the framebuffer, so we		 * can save a few MB of memory. 		 */		fb = XCreateImage_wr(dpy, default_visual, depth, ZPixmap,		    0, NULL, dpy_x, dpy_y, BitmapPad(dpy), 0);	} else if (visual_id) {		/*		 * we need to call XCreateImage to supply the visual		 */		fb = XCreateImage_wr(dpy, default_visual, depth, ZPixmap,		    0, NULL, dpy_x, dpy_y, BitmapPad(dpy), 0);		fb->data = (char *) malloc(fb->bytes_per_line * fb->height);	} else {		fb = XGetImage_wr(dpy, window, 0, 0, dpy_x, dpy_y, AllPlanes,		    ZPixmap);		if (! quiet) {			rfbLog("Read initial data from X display into"			    " framebuffer.\n");		}	}	if (subwin) {		XSetErrorHandler(old_handler);		if (trapped_xerror) {			rfbLog("trapped GetImage at SUBWIN creation.\n");			if (try < subwin_tries) {				usleep(250 * 1000);				if (!get_window_size(window, &dpy_x, &dpy_y)) {					rfbLog("could not get size of subwin "					    "0x%lx\n", subwin);					X_UNLOCK;					clean_up_exit(1);				}				goto again;			}		}		trapped_xerror = 0;	} else if (! fb && try == 1) {		/* try once more */		usleep(250 * 1000);		goto again;	}	X_UNLOCK;	if (fb->bits_per_pixel == 24 && ! quiet) {		rfbLog("warning: 24 bpp may have poor performance.\n");	}	return fb;}