if (0) fprintf(stderr, "  dfc---- dt: %.4f", dt);
if (db) fprintf(stderr, "  dfc---- dt: %.4f", dt);
int push_scr_ev(double max_age, int type, int bdpush, int bdx, int bdy,    int bdskinny) {	Window frame, win, win0;	int x, y, w, h, wx, wy, ww, wh, dx, dy;	int x0, y0, w0, h0;	int nx, ny, nw, nh;	int dret = 1, do_fb_push = 0, obscured;	int ev, ev_tot = scr_ev_cnt;	double tm, dt, st, dnow, waittime = 0.125;	int db = debug_scroll, rrate = get_read_rate();	sraRegionPtr backfill, whole, tmpregion, tmpregion2;	int link, latency, netrate;	int ypad = 0;	if (ev_tot == 0) {		return dret;	}	link = link_rate(&latency, &netrate);	if (link == LR_DIALUP) {		waittime *= 5;	} else if (link == LR_BROADBAND) {		waittime *= 3;	} else if (latency > 80 || netrate < 40) {		waittime *= 3;	}	dtime0(&dnow);	backfill = sraRgnCreate();	whole = sraRgnCreateRect(0, 0, dpy_x, dpy_y);	win0 = scr_ev[0].win;	x0 = scr_ev[0].win_x;	y0 = scr_ev[0].win_y;	w0 = scr_ev[0].win_w;	h0 = scr_ev[0].win_h;	ypad = set_ypad();if (db) fprintf(stderr, "ypad: %d  dy[0]: %d\n", ypad, scr_ev[0].dy);	for (ev=0; ev < ev_tot; ev++) {			x   = scr_ev[ev].x;		y   = scr_ev[ev].y;		w   = scr_ev[ev].w;		h   = scr_ev[ev].h;		dx  = scr_ev[ev].dx;		dy  = scr_ev[ev].dy;		win = scr_ev[ev].win;		wx  = scr_ev[ev].win_x;		wy  = scr_ev[ev].win_y;		ww  = scr_ev[ev].win_w;		wh  = scr_ev[ev].win_h;		nx  = scr_ev[ev].new_x;		ny  = scr_ev[ev].new_y;		nw  = scr_ev[ev].new_w;		nh  = scr_ev[ev].new_h;		st  = scr_ev[ev].t;		if (dabs((dnow - servertime_diff) - st) > max_age) {if (db) fprintf(stderr, "push_scr_ev: TOO OLD: %.4f :: (%.4f - %.4f) - %.4f \n", (dnow - servertime_diff) - st, dnow, servertime_diff, st);							dret = 0;			break;		} else {if (db) fprintf(stderr, "push_scr_ev: AGE:     %.4f\n", (dnow - servertime_diff) - st);						}		if (win != win0) {if (db) fprintf(stderr, "push_scr_ev: DIFF WIN: 0x%lx != 0x%lx\n", win, win0);			dret = 0;			break;		}		if (wx != x0 || wy != y0) {if (db) fprintf(stderr, "push_scr_ev: WIN SHIFT: %d %d, %d %d", wx, x0, wy, y0);			dret = 0;			break;		}		if (ww != w0 || wh != h0) {if (db) fprintf(stderr, "push_scr_ev: WIN RESIZE: %d %d, %d %d", ww, w0, wh, h0);			dret = 0;			break;		}		if (w < 1 || h < 1 || ww < 1 || wh < 1) {if (db) fprintf(stderr, "push_scr_ev: NEGATIVE h/w: %d %d %d %d\n", w, h, ww, wh);			dret = 0;			break;		}if (db > 1) fprintf(stderr, "push_scr_ev: got: %d x: %4d y: %3d"    " w: %4d h: %3d  dx: %d dy: %d %dx%d+%d+%d   win: 0x%lx\n",    ev, x, y, w, h, dx, dy, w, h, x, y, win);if (db > 1) fprintf(stderr, "------------ got: %d x: %4d y: %3d"    " w: %4d h: %3d %dx%d+%d+%d\n",    ev, wx, wy, ww, wh, ww, wh, wx, wy);if (db > 1) fprintf(stderr, "------------ got: %d x: %4d y: %3d"    " w: %4d h: %3d %dx%d+%d+%d\n",    ev, nx, ny, nw, nh, nw, nh, nx, ny);		frame = None;		if (xrecord_wm_window) {			frame = xrecord_wm_window;		}		if (! frame) {			X_LOCK;			frame = query_pointer(rootwin);			X_UNLOCK;		}		if (! frame) {			frame = win;		}		dtime0(&tm);		tmpregion = sraRgnCreateRect(0, 0, dpy_x, dpy_y);		tmpregion2 = sraRgnCreateRect(wx, wy, wx+ww, wy+wh);		sraRgnAnd(tmpregion2, whole);		sraRgnSubtract(tmpregion, tmpregion2);		sraRgnDestroy(tmpregion2);		/* do the wm frame just incase the above is bogus too. */		if (frame && frame != win) {			int k, gotk = -1;			for (k = stack_list_num - 1; k >= 0; k--) {				if (stack_list[k].win == frame &&				    stack_list[k].fetched && 				    stack_list[k].valid && 				    stack_list[k].map_state == IsViewable) {					gotk = k;					break;				}			}			if (gotk != -1) {				int tx1, ty1, tx2, ty2;				tx1 = stack_list[gotk].x;				ty1 = stack_list[gotk].y;				tx2 = tx1 + stack_list[gotk].width;				ty2 = ty1 + stack_list[gotk].height;				tmpregion2 = sraRgnCreateRect(tx1,ty1,tx2,ty2);				sraRgnAnd(tmpregion2, whole);				sraRgnSubtract(tmpregion, tmpregion2);				sraRgnDestroy(tmpregion2);			}		}		/*		 * XXX Need to also clip:		 *	children of win		 *	siblings of win higher in stacking order.		 * ignore for now... probably will make some apps		 * act very strangely.		 */if (ypad) {	if (ypad < 0) {		if (h > -ypad) {			h += ypad;		} else {			ypad = 0;		}	} else {		if (h > ypad) {			y += ypad;		} else {			ypad = 0;		}	}}				if (try_copyrect(frame, x, y, w, h, dx, dy, &obscured,		    tmpregion, waittime)) {			last_scroll_type = type;			dtime0(&last_scroll_event);			do_fb_push++;			urgent_update = 1;			sraRgnDestroy(tmpregion);			PUSH_TEST(0);		} else {			dret = 0;			sraRgnDestroy(tmpregion);			break;			}		dt = dtime(&tm);if (0) fprintf(stderr, "  try_copyrect dt: %.4f\n", dt);		if (ev > 0) {			sraRgnOffset(backfill, dx, dy);			sraRgnAnd(backfill, whole);		}if (ypad) {	if (ypad < 0) {		ny += ypad;			nh -= ypad;	} else {		;	}}		tmpregion = sraRgnCreateRect(nx, ny, nx + nw, ny + nh);		sraRgnAnd(tmpregion, whole);		sraRgnOr(backfill, tmpregion);		sraRgnDestroy(tmpregion);	}	/* try to update the backfill region (new window contents) */	if (dret != 0) {		double est, win_area = 0.0, area = 0.0;		sraRectangleIterator *iter;		sraRect rect;		int tx1, ty1, tx2, ty2;		tmpregion = sraRgnCreateRect(x0, y0, x0 + w0, y0 + h0);		sraRgnAnd(tmpregion, whole);		sraRgnAnd(backfill, tmpregion);		iter = sraRgnGetIterator(tmpregion);		while (sraRgnIteratorNext(iter, &rect)) {			tx1 = rect.x1;			ty1 = rect.y1;			tx2 = rect.x2;			ty2 = rect.y2;			win_area += (tx2 - tx1)*(ty2 - ty1);		}		sraRgnReleaseIterator(iter);		sraRgnDestroy(tmpregion);		iter = sraRgnGetIterator(backfill);		while (sraRgnIteratorNext(iter, &rect)) {			tx1 = rect.x1;			ty1 = rect.y1;			tx2 = rect.x2;			ty2 = rect.y2;			area += (tx2 - tx1)*(ty2 - ty1);		}		sraRgnReleaseIterator(iter);		est = (area * (bpp/8)) / (1000000.0 * rrate);if (db) fprintf(stderr, "  area %.1f win_area %.1f est: %.4f", area, win_area, est);		if (area > 0.90 * win_area) {if (db) fprintf(stderr, "  AREA_TOO_MUCH");			dret = 0;		} else if (est > 0.6) {if (db) fprintf(stderr, "  EST_TOO_LARGE");			dret = 0;		} else if (area <= 0.0) {			;		} else {			dtime0(&tm);			iter = sraRgnGetIterator(backfill);			while (sraRgnIteratorNext(iter, &rect)) {				tx1 = rect.x1;				ty1 = rect.y1;				tx2 = rect.x2;				ty2 = rect.y2;				tx1 = nfix(tx1, dpy_x);				ty1 = nfix(ty1, dpy_y);				tx2 = nfix(tx2, dpy_x+1);				ty2 = nfix(ty2, dpy_y+1);				dtime(&tm);if (db) fprintf(stderr, "  DFC(%d,%d-%d,%d)", tx1, ty1, tx2, ty2);				direct_fb_copy(tx1, ty1, tx2, ty2, 1);				do_fb_push++;PUSH_TEST(0);			}			sraRgnReleaseIterator(iter);			dt = dtime(&tm);if (0) fprintf(stderr, "  dfc---- dt: %.4f", dt);		}if (db &&  dret) fprintf(stderr, " **** dret=%d", dret);if (db && !dret) fprintf(stderr, " ---- dret=%d", dret);if (db) fprintf(stderr, "\n");	}if (db && bdpush) fprintf(stderr, "BDPUSH-TIME:  0x%lx\n", xrecord_wm_window);	if (bdpush && xrecord_wm_window != None) {		int x, y, w, h;		x = scr_ev[0].x;		y = scr_ev[0].y;		w = scr_ev[0].w;		h = scr_ev[0].h;		do_fb_push += do_bdpush(xrecord_wm_window, x, y, w, h,		    bdx, bdy, bdskinny); 	}	if (do_fb_push) {		dtime0(&tm);		fb_push();		dt = dtime(&tm);if (0) fprintf(stderr, "  fb_push dt: %.4f", dt);	}	sraRgnDestroy(backfill);	sraRgnDestroy(whole);	return dret;}