x11vnc: add -8to24 option for some multi-depth displays.

pull/1/head
runge 19 years ago
parent 60918e6664
commit 5993dd757e

@ -1,3 +1,6 @@
2006-01-14 Karl Runge <runge@karlrunge.com>
* x11vnc: add -8to24 option for some multi-depth displays.
2006-01-12 Karl Runge <runge@karlrunge.com>
* configure.ac: add switches for most X extensions.

@ -0,0 +1,797 @@
/* -- 8to24.c -- */
#include "x11vnc.h"
#include "cleanup.h"
#include "scan.h"
#include "util.h"
#include "win_utils.h"
int multivis_count = 0;
void check_for_multivis(void);
void bpp8to24(int, int, int, int);
void mark_8bpp(void);
static int check_depth(Window win, Window top, int doall);
static int check_depth_win(Window win, Window top, XWindowAttributes attr);
/* struct for keeping info about the 8bpp windows: */
typedef struct window8 {
Window win;
Window top;
int depth;
int x, y;
int w, h;
int map_state;
Colormap cmap;
Bool map_installed;
int fetched;
} window8bpp_t;
/* fixed size array. Will primarily hold visable 8bpp windows */
#define MAX_8BPP_WINDOWS 64
static window8bpp_t windows_8bpp[MAX_8BPP_WINDOWS];
static int db24 = 0;
void check_for_multivis(void) {
XWindowAttributes attr;
int doall = 0;
int k, i, cnt, diff;
static int first = 1;
static double last_update = 0.0;
static double last_clear = 0.0;
double now = dnow();
static Window *stack_old = NULL;
static int stack_old_len = 0;
if (first) {
int i;
/* initialize 8bpp window table: */
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
windows_8bpp[i].win = None;
windows_8bpp[i].top = None;
windows_8bpp[i].map_state = IsUnmapped;
windows_8bpp[i].cmap = (Colormap) 0;
windows_8bpp[i].fetched = 0;
}
first = 0;
doall = 1; /* fetch everything first time */
}
/*
* allocate an "old stack" list of all toplevels. we compare
* this to the current stack to guess stacking order changes.
*/
if (!stack_old || stack_old_len < stack_list_len) {
int n = stack_list_len;
if (n < 256) {
n = 256;
}
if (stack_old) {
free(stack_old);
}
stack_old = (Window *) malloc(n*sizeof(Window));
stack_old_len = n;
}
/* fill the old stack with visable windows: */
cnt = 0;
for (k=0; k < stack_list_num; k++) {
if (stack_list[k].valid &&
stack_list[k].map_state == IsViewable) {
stack_old[cnt++] = stack_list[k].win;
}
}
/* snapshot + update the current stacking order: */
snapshot_stack_list(0, 0.25);
if (doall || now > last_update + 0.25) {
update_stack_list();
last_update = now;
}
/* look for differences in the visable toplevels: */
diff = 0;
cnt = 0;
for (k=0; k < stack_list_num; k++) {
if (stack_list[k].valid && stack_list[k].map_state == IsViewable) {
if (stack_old[cnt] != stack_list[k].win) {
diff = 1;
break;
}
cnt++;
}
}
/*
* if there are 8bpp visable and a stacking order change
* refresh vnc with coverage of the 8bpp regions:
*/
if (diff && multivis_count) {
if (db24 || 0) fprintf(stderr, "check_for_multivis stack diff: mark_all %f\n", now - x11vnc_start);
if (0) mark_rect_as_modified(0, 0, dpy_x, dpy_y, 0);
if (1) mark_8bpp();
}
multivis_count = 0;
/*
* every 10 seconds we try to clean out and also refresh the window
* info in the the 8bpp window table:
*/
if (now > last_clear + 10) {
last_clear = now;
X_LOCK;
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
Window w = windows_8bpp[i].win;
if ((db24 || 0) && w != None) fprintf(stderr, " windows_8bpp: 0x%lx i=%02d ms: %d\n", windows_8bpp[i].win, i, windows_8bpp[i].map_state);
if (w == None || ! valid_window(w, &attr, 1)) {
/* catch windows that went away: */
windows_8bpp[i].win = None;
windows_8bpp[i].top = None;
windows_8bpp[i].map_state = IsUnmapped;
windows_8bpp[i].cmap = (Colormap) 0;
windows_8bpp[i].fetched = 0;
}
}
X_UNLOCK;
}
/* loop over all toplevels, both 8 and 24 depths: */
for (k=0; k < stack_list_num; k++) {
Window r, parent;
Window *list0;
Status rc;
unsigned int nc0;
int i1;
Window win = stack_list[k].win;
if (win == None) {
continue;
}
if (stack_list[k].map_state != IsViewable) {
int i;
/*
* if the toplevel became unmapped, mark it
* for the children as well...
*/
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
if (windows_8bpp[i].top == win) {
windows_8bpp[i].map_state =
stack_list[k].map_state;
}
}
}
if (check_depth(win, win, doall)) {
/*
* returns 1 if no need to recurse down e.g. IT
* is 8bpp and we assume all lower one are too.
*/
continue;
}
/* we recurse up to two levels down from stack_list windows */
X_LOCK;
rc = XQueryTree(dpy, win, &r, &parent, &list0, &nc0);
X_UNLOCK;
if (! rc) {
continue;
}
/* loop over grandchildren of rootwin: */
for (i1=0; i1 < (int) nc0; i1++) {
Window win1 = list0[i1];
Window *list1;
unsigned int nc1;
int i2;
if (check_depth(win1, win, doall)) {
continue;
}
X_LOCK;
rc = XQueryTree(dpy, win1, &r, &parent, &list1, &nc1);
X_UNLOCK;
if (! rc) {
continue;
}
/* loop over great-grandchildren of rootwin: */
for (i2=0; i2< (int) nc1; i2++) {
Window win2 = list1[i2];
if (check_depth(win2, win, doall)) {
continue;
}
/* more? Which wm does this? */
}
if (nc1) {
X_LOCK;
XFree(list1);
X_UNLOCK;
}
}
if (nc0) {
X_LOCK;
XFree(list0);
X_UNLOCK;
}
}
}
static int check_depth(Window win, Window top, int doall) {
XWindowAttributes attr;
X_LOCK;
/* first see if it is (still) a valid window: */
if (! valid_window(win, &attr, 1)) {
X_UNLOCK;
return 1; /* indicate done */
}
X_UNLOCK;
if (! doall && attr.map_state != IsViewable) {
/*
* store results anyway... this may lead to table filling up,
* but currently this allows us to update state of onetime mapped
* windows.
*/
check_depth_win(win, top, attr);
return 1; /* indicate done */
} else if (check_depth_win(win, top, attr)) {
return 1; /* indicate done */
} else {
return 0; /* indicate not done */
}
}
static int check_depth_win(Window win, Window top, XWindowAttributes attr) {
/*
* only store windows with depth not equal to the default visual's depth
* note some windows can have depth == 0 ... (skip them).
*/
if (attr.depth != depth && attr.depth > 0) {
int i, j = -1, none = -1, nomap = -1;
int new = 0;
if (attr.map_state == IsViewable) {
/* count the visable ones: */
multivis_count++;
if (db24 || 0) fprintf(stderr, "multivis: 0x%lx %d\n", win, attr.depth);
}
/* try to find a table slot for this window: */
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
if (none < 0 && windows_8bpp[i].win == None) {
/* found first None */
none = i;
}
if (windows_8bpp[i].win == win) {
/* found myself */
j = i;
break;
}
if (nomap < 0 && windows_8bpp[i].win != None &&
windows_8bpp[i].map_state != IsViewable) {
/* found first unmapped */
nomap = i;
}
}
if (j < 0) {
if (attr.map_state != IsViewable) {
/* no slot and not visable: not worth keeping */
return 1;
} else if (none >= 0) {
/* put it in the first None slot */
j = none;
new = 1;
} else if (nomap >=0) {
/* put it in the first unmapped slot */
j = nomap;
}
/* otherwise we cannot store it... */
}
if (db24 || 0) fprintf(stderr, "multivis: 0x%lx ms: %d j: %d no: %d nm: %d\n", win, attr.map_state, j, none, nomap);
/* store if if we found a slot j: */
if (j >= 0) {
Window w;
int x, y;
if (db24 || 0) fprintf(stderr, "multivis: STORE 0x%lx j: %3d ms: %d\n", win, j, attr.map_state);
windows_8bpp[j].win = win;
windows_8bpp[j].top = top;
windows_8bpp[j].depth = attr.depth;
windows_8bpp[j].map_state = attr.map_state;
windows_8bpp[j].cmap = attr.colormap;
windows_8bpp[j].map_installed = attr.map_installed;
windows_8bpp[j].w = attr.width;
windows_8bpp[j].h = attr.height;
/* translate x y to be WRT the root window (not parent) */
xtranslate(win, window, 0, 0, &x, &y, &w, 1);
windows_8bpp[j].x = x;
windows_8bpp[j].y = y;
windows_8bpp[j].fetched = 1;
if (new) {
if (db24) fprintf(stderr, "new: 0x%lx\n", win);
/* mark it immediately if a new one: */
mark_rect_as_modified(x, y, x + attr.width,
y + attr.height, 0);
}
} else {
/*
* Error: could not find a slot.
* perhaps keep age and expire old ones??
*/
if (db24 || 1) fprintf(stderr, "multivis: CANNOT STORE 0x%lx j=%d\n", win, j);
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
if (db24 || 0) fprintf(stderr, " ------------ 0x%lx i=%d\n", windows_8bpp[i].win, i);
}
}
return 1;
}
return 0;
}
void bpp8to24(int x1, int y1, int x2, int y2) {
char *src;
char *dst;
int pixelsize = bpp/8;
int line, i, h, k, w;
# define CMAPMAX 64
Colormap cmaps[CMAPMAX];
int ncmaps, cmap_max = CMAPMAX;
sraRegionPtr rect, disp, region8bpp;
XWindowAttributes attr;
static int last_map_count = 0, call_count = 0;
static double last_validate = 0.0;
int validate = 1;
if (! cmap8to24 || !cmap8to24_fb) {
/* hmmm, why were we called? */
return;
}
call_count++;
/* initialize color map list */
ncmaps = 0;
for (i=0; i < cmap_max; i++) {
cmaps[i] = (Colormap) 0;
}
/* create regions for finding overlap, etc. */
disp = sraRgnCreateRect(0, 0, dpy_x, dpy_y);
rect = sraRgnCreateRect(x1, y1, x2, y2);
region8bpp = sraRgnCreate();
X_LOCK;
XFlush(dpy); /* make sure X server is up to date WRT input, etc */
X_UNLOCK;
if (last_map_count > MAX_8BPP_WINDOWS/4) {
/* table is filling up... skip validating sometimes: */
int skip = 3;
if (last_map_count > MAX_8BPP_WINDOWS/2) {
skip = 6;
}
if (last_map_count > 3*MAX_8BPP_WINDOWS/4) {
skip = 12;
}
if (call_count % skip != 0) {
validate = 0;
fprintf(stderr, " bpp8to24: No validate: %d -- %d\n", skip, last_map_count);
} else {
fprintf(stderr, " bpp8to24: yesvalidate: %d -- %d\n", skip, last_map_count);
}
}
last_map_count = 0;
/* loop over the table of 8bpp windows: */
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
sraRegionPtr tmp_reg, tmp_reg2;
Window w = windows_8bpp[i].win;
Window c;
int x, y;
if (wireframe_in_progress) {
break; /* skip updates during wireframe drag */
}
if (w == None) {
continue;
}
if (db24 || 0) fprintf(stderr, "bpp8to24: 0x%lx ms=%d i=%d\n", w, windows_8bpp[i].map_state, i);
if (validate) {
/*
* this could be slow: validating 8bpp windows each
* time...
*/
last_validate = dnow();
X_LOCK;
if (! valid_window(w, &attr, 1)) {
X_UNLOCK;
windows_8bpp[i].win = None;
windows_8bpp[i].top = None;
windows_8bpp[i].map_state = IsUnmapped;
windows_8bpp[i].cmap = (Colormap) 0;
windows_8bpp[i].fetched = 0;
continue;
}
X_UNLOCK;
if (attr.map_state != IsViewable) {
continue;
}
X_LOCK;
xtranslate(w, window, 0, 0, &x, &y, &c, 1);
X_UNLOCK;
} else {
/* this would be faster: no call to X server: */
if (windows_8bpp[i].map_state != IsViewable) {
continue;
}
x = windows_8bpp[i].x;
y = windows_8bpp[i].y;
attr.width = windows_8bpp[i].w;
attr.height = windows_8bpp[i].h;
attr.map_state = windows_8bpp[i].map_state;
attr.colormap = windows_8bpp[i].cmap;
}
last_map_count++;
/* tmp region for this 8bpp rectangle: */
tmp_reg = sraRgnCreateRect(x, y, x + attr.width,
y + attr.height);
/* clip to display screen: */
sraRgnAnd(tmp_reg, disp);
/* find overlap with mark region in rect: */
sraRgnAnd(tmp_reg, rect);
if (sraRgnEmpty(tmp_reg)) {
/* skip if no overlap: */
sraRgnDestroy(tmp_reg);
continue;
}
/* loop over all toplevels, top to bottom clipping: */
for (k = stack_list_num - 1; k >= 0; k--) {
Window swin = stack_list[k].win;
int sx, sy, sw, sh;
if (db24) fprintf(stderr, "Stack win: 0x%lx %d iv=%d\n", swin, k, stack_list[k].map_state);
if (swin == windows_8bpp[i].top) {
/* found our top level: we clip the rest. */
if (db24) fprintf(stderr, "found top: 0x%lx %d iv=%d\n", swin, k, stack_list[k].map_state);
break;
}
if (stack_list[k].map_state != IsViewable) {
/* skip unmapped ones: */
continue;
}
/* make a temp rect for this toplevel: */
sx = stack_list[k].x;
sy = stack_list[k].y;
sw = stack_list[k].width;
sh = stack_list[k].height;
tmp_reg2 = sraRgnCreateRect(sx, sy, sx + sw, sy + sh);
sraRgnAnd(tmp_reg2, disp);
/* subtrace it from the 8bpp window region */
sraRgnSubtract(tmp_reg, tmp_reg2);
sraRgnDestroy(tmp_reg2);
}
if (sraRgnEmpty(tmp_reg)) {
/* skip this 8bpp if completely clipped away: */
sraRgnDestroy(tmp_reg);
if (db24) fprintf(stderr, "Empty tmp_reg\n");
continue;
}
/* otherwise, store any new colormaps: */
if (ncmaps < cmap_max && attr.colormap != (Colormap) 0) {
int m, sawit = 0;
for (m=0; m < ncmaps; m++) {
if (cmaps[m] == attr.colormap) {
sawit = 1;
break;
}
}
if (! sawit) {
/* store only new ones: */
cmaps[ncmaps++] = attr.colormap;
}
}
/* now include this region with the full 8bpp region: */
sraRgnOr(region8bpp, tmp_reg);
sraRgnDestroy(tmp_reg);
}
/* copy from main_fb to cmap8to24_fb regardless of 8bpp windows: */
src = main_fb + main_bytes_per_line * y1 + pixelsize * x1;
dst = cmap8to24_fb + main_bytes_per_line * y1 + pixelsize * x1;
h = y2 - y1;
w = x2 - x1;
for (line = 0; line < h; line++) {
memcpy(dst, src, w * pixelsize);
src += main_bytes_per_line;
dst += main_bytes_per_line;
}
if (db24) fprintf(stderr, "bpp8to24 w=%d h=%d m=%p c=%p r=%p \n", w, h, main_fb, cmap8to24_fb, rfb_fb);
/*
* now go back and tranform and 8bpp regions to TrueColor in
* cmap8to24_fb. we have to guess the best colormap to use if
* there is more than one...
*/
#define NCOLOR 256
if (! sraRgnEmpty(region8bpp) && ncmaps) {
sraRectangleIterator *iter;
sraRect rect;
int i, j, ncells;
int cmap_failed[CMAPMAX];
static XColor color[CMAPMAX][NCOLOR];
static unsigned int rgb[CMAPMAX][NCOLOR];
XErrorHandler old_handler;
#if 0
/* not working properly for depth 24... */
X_LOCK;
ncells = CellsOfScreen(ScreenOfDisplay(dpy, scr));
X_UNLOCK;
#else
ncells = NCOLOR;
#endif
/* ncells should "always" be 256. */
if (ncells > NCOLOR) {
ncells = NCOLOR;
} else if (ncells == 8) {
/* hmmm. see set_colormap() */
ncells = NCOLOR;
}
/*
* first, grab all of the associated colormaps from the
* X server. Hopefully just 1 or 2...
*/
for (j=0; j<ncmaps; j++) {
if (db24) fprintf(stderr, "cmap %d\n", (int) cmaps[j]);
/* initialize XColor array: */
for (i=0; i < ncells; i++) {
color[j][i].pixel = i;
color[j][i].pad = 0;
}
/* try to query the colormap, trap errors */
X_LOCK;
trapped_xerror = 0;
old_handler = XSetErrorHandler(trap_xerror);
XQueryColors(dpy, cmaps[j], color[j], ncells);
XSetErrorHandler(old_handler);
X_UNLOCK;
if (trapped_xerror) {
/*
* results below will be indefinite...
* need to exclude this one.
*/
trapped_xerror = 0;
cmap_failed[j] = 1;
continue;
}
trapped_xerror = 0;
cmap_failed[j] = 0;
/* now map each index to depth 24 RGB */
for (i=0; i < ncells; i++) {
unsigned int red, green, blue;
/* strip out highest 8 bits of values: */
red = (color[j][i].red & 0xff00) >> 8;
green = (color[j][i].green & 0xff00) >> 8;
blue = (color[j][i].blue & 0xff00) >> 8;
/*
* the maxes should be at 255 already,
* but just in case...
*/
red = (main_red_max * red )/255;
green = (main_green_max * green)/255;
blue = (main_blue_max * blue )/255;
/* shift them over and or together for value */
red = red << main_red_shift;
green = green << main_green_shift;
blue = blue << main_blue_shift;
rgb[j][i] = red | green | blue;
}
}
/* loop over the rectangles making up region8bpp */
iter = sraRgnGetIterator(region8bpp);
while (sraRgnIteratorNext(iter, &rect)) {
double score, max_score = -1.0;
int n, m, best;
if (rect.x1 > rect.x2) {
int tmp = rect.x2;
rect.x2 = rect.x1;
rect.x1 = tmp;
}
if (rect.y1 > rect.y2) {
int tmp = rect.y2;
rect.y2 = rect.y1;
rect.y1 = tmp;
}
if (db24 || 0) fprintf(stderr, "ncmaps: %d\n", ncmaps);
/*
* try to pick the "best" colormap to use for
* this rectangle (often wrong... let them
* iconify or move the trouble windows, etc.)
*/
best = -1;
for (m=0; m < MAX_8BPP_WINDOWS; m++) {
int mx1, my1, mx2, my2;
int k, failed = 0;
if (windows_8bpp[m].win == None) {
continue;
}
if (windows_8bpp[m].map_state != IsViewable) {
continue;
}
/* see if XQueryColors failed: */
for (k=0; k<ncmaps; k++) {
if (windows_8bpp[m].cmap == cmaps[k]
&& cmap_failed[k]) {
failed = 1;
}
}
if (failed) {
continue;
}
/* rectangle coords for this 8bpp win: */
mx1 = windows_8bpp[m].x;
my1 = windows_8bpp[m].y;
mx2 = windows_8bpp[m].x + windows_8bpp[m].w;
my2 = windows_8bpp[m].y + windows_8bpp[m].h;
/* use overlap as score: */
score = rect_overlap(mx1, my1, mx2, my2,
rect.x1, rect.y1, rect.x2, rect.y2);
if (score > max_score) {
max_score = score;
best = m;
}
if (db24 || 0) fprintf(stderr, "cmap_score: 0x%x %.3f %.3f\n", (int) windows_8bpp[m].cmap, score, max_score);
}
if (best < 0) {
/* hmmm, use the first one then... */
best = 0;
} else {
int ok = 0;
/*
* find the cmap corresponding to best window
* note we reset best from the windows_8bpp
* index to the cmaps[].
*/
for (m=0; m < ncmaps; m++) {
if (cmaps[m] == windows_8bpp[best].cmap) {
ok = 1;
best = m;
}
}
if (! ok) {
best = 0;
}
}
if (db24) fprintf(stderr, "transform %d %d %d %d\n", rect.x1, rect.y1, rect.x2, rect.y2);
/* now tranform the pixels in this rectangle: */
n = main_bytes_per_line * rect.y1 + pixelsize * rect.x1;
src = cmap8to24_fb + n;
h = rect.y2 - rect.y1;
w = rect.x2 - rect.x1;
for (line = 0; line < h; line++) {
/* line by line ... */
for (j = 0; j < w; j++) {
/* pixel by pixel... */
unsigned int *ui;
unsigned int hi, idx;
/* grab 32 bit value */
ui = (unsigned int *) (src + pixelsize * j);
/* extract top 8 bits (FIXME: masks?) */
hi = (*ui) & 0xff000000;
/* map to lookup index; rewrite pixel: */
idx = hi >> 24;
*ui = hi | rgb[best][idx];
}
src += main_bytes_per_line;
}
}
sraRgnReleaseIterator(iter);
}
/* cleanup */
sraRgnDestroy(disp);
sraRgnDestroy(rect);
sraRgnDestroy(region8bpp);
}
void mark_8bpp(void) {
int i, cnt = 0;
if (! cmap8to24 || !cmap8to24_fb) {
return;
}
/* for each mapped 8bpp window, mark it changed: */
for (i=0; i < MAX_8BPP_WINDOWS; i++) {
int x1, y1, x2, y2, w, h, f = 32;
f = 0; /* skip fuzz, may bring in other windows... */
if (windows_8bpp[i].win == None) {
continue;
}
if (windows_8bpp[i].map_state != IsViewable) {
continue;
}
x1 = windows_8bpp[i].x;
y1 = windows_8bpp[i].y;
w = windows_8bpp[i].w;
h = windows_8bpp[i].h;
/* apply a fuzz f around each one... constrain to screen */
x2 = x1 + w;
y2 = y1 + h;
x1 = nfix(x1 - f, dpy_x);
y1 = nfix(y1 - f, dpy_y);
x2 = nfix(x2 + f, dpy_x);
y2 = nfix(y2 + f, dpy_y);
if (db24 || 0) fprintf(stderr, "mark_8bpp: 0x%lx %d %d %d %d\n", windows_8bpp[i].win, x1, y1, x2, y2);
mark_rect_as_modified(x1, y1, x2, y2, 0);
cnt++;
}
if (cnt) {
/* push it to viewers if possible. */
rfbPE(-1);
}
}

@ -0,0 +1,12 @@
#ifndef _X11VNC_8TO24_H
#define _X11VNC_8TO24_H
/* -- 8to24.h -- */
extern int multivis_count;
extern void check_for_multivis(void);
extern void bpp8to24(int, int, int, int);
extern void mark_8bpp(void);
#endif /* _X11VNC_8TO24_H */

@ -1,3 +1,7 @@
2006-01-14 Karl Runge <runge@karlrunge.com>
* x11vnc: add -8to24 option for some multi-depth displays (but use
of -overlay is preferred is supported).
2006-01-12 Karl Runge <runge@karlrunge.com>
* fix -DSMALL_FOOTPRINT=N builds.

@ -13,7 +13,7 @@ endif
if HAVE_X
bin_PROGRAMS=x11vnc
x11vnc_SOURCES = cleanup.c connections.c cursor.c gui.c help.c inet.c keyboard.c options.c pointer.c rates.c remote.c scan.c screen.c selection.c solid.c user.c userinput.c util.c win_utils.c x11vnc.c x11vnc_defs.c xdamage.c xevents.c xinerama.c xkb_bell.c xrandr.c xrecord.c xwrappers.c allowed_input_t.h blackout_t.h cleanup.h connections.h cursor.h enums.h gui.h help.h inet.h keyboard.h options.h params.h pointer.h rates.h remote.h scan.h screen.h scrollevent_t.h selection.h solid.h tkx11vnc.h user.h userinput.h util.h win_utils.h winattr_t.h x11vnc.h xdamage.h xevents.h xinerama.h xkb_bell.h xrandr.h xrecord.h xwrappers.h
x11vnc_SOURCES = 8to24.c cleanup.c connections.c cursor.c gui.c help.c inet.c keyboard.c options.c pointer.c rates.c remote.c scan.c screen.c selection.c solid.c user.c userinput.c util.c win_utils.c x11vnc.c x11vnc_defs.c xdamage.c xevents.c xinerama.c xkb_bell.c xrandr.c xrecord.c xwrappers.c 8to24.h allowed_input_t.h blackout_t.h cleanup.h connections.h cursor.h enums.h gui.h help.h inet.h keyboard.h options.h params.h pointer.h rates.h remote.h scan.h screen.h scrollevent_t.h selection.h solid.h tkx11vnc.h user.h userinput.h util.h win_utils.h winattr_t.h x11vnc.h xdamage.h xevents.h xinerama.h xkb_bell.h xrandr.h xrecord.h xwrappers.h
INCLUDES=@X_CFLAGS@
x11vnc_LDADD=@X_LIBS@ $(LD_CYGIPC) $(LDADD)
endif

File diff suppressed because it is too large Load Diff

@ -1512,7 +1512,7 @@ void check_connect_inputs(void) {
}
void check_gui_inputs(void) {
int i, nmax = 0, n = 0, nfds;
int i, gnmax = 0, n = 0, nfds;
int socks[ICON_MODE_SOCKS];
fd_set fds;
struct timeval tv;
@ -1522,8 +1522,8 @@ void check_gui_inputs(void) {
for (i=0; i<ICON_MODE_SOCKS; i++) {
if (icon_mode_socks[i] >= 0) {
socks[n++] = i;
if (icon_mode_socks[i] > nmax) {
nmax = icon_mode_socks[i];
if (icon_mode_socks[i] > gnmax) {
gnmax = icon_mode_socks[i];
}
}
}
@ -1539,7 +1539,7 @@ void check_gui_inputs(void) {
tv.tv_sec = 0;
tv.tv_usec = 0;
nfds = select(nmax+1, &fds, NULL, NULL, &tv);
nfds = select(gnmax+1, &fds, NULL, NULL, &tv);
if (nfds <= 0) {
return;
}

@ -1783,4 +1783,3 @@ int check_x11_pointer(void) {
return set_cursor(x, y, get_which_cursor());
}

@ -147,6 +147,38 @@ void print_help(int mode) {
"-overlay_nocursor Sets -overlay, but does not try to draw the exact mouse\n"
" cursor shape using the overlay mechanism.\n"
"\n"
"-8to24 If -overlay is not supported on your OS, and you have a\n"
" legacy 8bpp app that you want to view on a multi-depth\n"
" display with default depth 24 (and is 32 bpp), try\n"
" this option. This option may not work on all X servers\n"
" and hardware (tested on XFree86/Xorg mga driver).\n"
"\n"
" It enables a hack where x11vnc monitors windows within 3\n"
" levels from the root window. If it finds any that are\n"
" 8bpp it will apply a transformation for pixel data in\n"
" these regions where it extracts the 8bpp index color\n"
" value from bits 25-32 and maps them on to TrueColor\n"
" values and inserts them into bits 1-24 (i.e. overwrites\n"
" bits 1-24). This method appears to work, but may still\n"
" have bugs and note that it does hog resources. If there\n"
" are multiple 8bpp windows using different colormaps,\n"
" one may have to iconify all but one for the colors to\n"
" be correct.\n"
"\n"
" There may also be painting errors for clipping\n"
" and switching between windows of depths 8 and 24.\n"
" Heuristics are applied to try to minimize the painting\n"
" errors. One can also press 3 Alt_L's in a row to\n"
" refresh the screen if the error does not repair itself.\n"
" Also the option, say, -fixscreen V=3.0 may be use\n"
" to periodically refresh the screen (at the cost of\n"
" bandwidth).\n"
"\n"
" Note that -8to24 does not work on displays with 8bpp\n"
" default visual with depth 24 applications. The Xserver\n"
" -cc option can be used to switch the default depth on\n"
" multidepth setups.\n"
"\n"
"-scale fraction Scale the framebuffer by factor \"fraction\". Values\n"
" less than 1 shrink the fb, larger ones expand it. Note:\n"
" image may not be sharp and response may be slower.\n"
@ -1590,6 +1622,8 @@ void print_help(int mode) {
" overlay_cursor in -overlay mode, enable cursor drawing.\n"
" overlay_nocursor disable cursor drawing. same as\n"
" nooverlay_cursor.\n"
" 8to24 enable -8to24 mode (if applicable).\n"
" no8to24 disable -8to24 mode.\n"
" visual:vis set -visual to \"vis\"\n"
" scale:frac set -scale to \"frac\"\n"
" scale_cursor:f set -scale_cursor to \"f\"\n"
@ -1849,10 +1883,10 @@ void print_help(int mode) {
" nowaitmapped clip flashcmap noflashcmap shiftcmap\n"
" truecolor notruecolor overlay nooverlay overlay_cursor\n"
" overlay_yescursor nooverlay_nocursor nooverlay_cursor\n"
" nooverlay_yescursor overlay_nocursor visual scale\n"
" scale_cursor viewonly noviewonly shared noshared\n"
" forever noforever once timeout filexfer deny lock\n"
" nodeny unlock connect allowonce allow localhost\n"
" nooverlay_yescursor overlay_nocursor 8to24 no8to24\n"
" visual scale scale_cursor viewonly noviewonly shared\n"
" noshared forever noforever once timeout filexfer deny\n"
" lock nodeny unlock connect allowonce allow localhost\n"
" nolocalhost listen lookup nolookup accept afteraccept\n"
" gone shm noshm flipbyteorder noflipbyteorder onetile\n"
" noonetile solid_color solid nosolid blackout xinerama\n"

@ -88,6 +88,7 @@ int first_conn_timeout = 0; /* -timeout */
int flash_cmap = 0; /* follow installed colormaps */
int shift_cmap = 0; /* ncells < 256 and needs shift of pixel values */
int force_indexed_color = 0; /* whether to force indexed color for 8bpp */
int cmap8to24 = 0; /* -8to24 */
int launch_gui = 0; /* -gui */
int use_modifier_tweak = 1; /* use the shift/altgr modifier tweak */

@ -63,6 +63,7 @@ extern int first_conn_timeout;
extern int flash_cmap;
extern int shift_cmap;
extern int force_indexed_color;
extern int cmap8to24;
extern int launch_gui;
extern int use_modifier_tweak;

@ -979,6 +979,24 @@ char *process_remote_cmd(char *cmd, int stringonly) {
rfbLog(" -R cursor:... to re-enable any cursors.\n");
}
} else if (!strcmp(p, "8to24")) {
if (query) {
snprintf(buf, bufn, "ans=%s:%d", p, cmap8to24);
goto qry;
}
rfbLog("remote_cmd: turning on -8to24 mode.\n");
cmap8to24 = 1;
do_new_fb(0);
} else if (!strcmp(p, "no8to24")) {
if (query) {
snprintf(buf, bufn, "ans=%s:%d", p, !cmap8to24);
goto qry;
}
rfbLog("remote_cmd: turning off -8to24 mode.\n");
cmap8to24 = 0;
do_new_fb(0);
} else if (strstr(p, "visual") == p) {
COLON_CHECK("visual:")
if (query) {

@ -6,6 +6,7 @@
#include "xdamage.h"
#include "xrandr.h"
#include "win_utils.h"
#include "8to24.h"
#include "screen.h"
#include "pointer.h"
#include "cleanup.h"
@ -1158,6 +1159,7 @@ void scale_rect(double factor, int blend, int interpolate, int Bpp,
}
void scale_and_mark_rect(int X1, int Y1, int X2, int Y2) {
char *src_fb = main_fb;
if (!screen || !rfb_fb || !main_fb) {
return;
@ -1181,8 +1183,12 @@ void scale_and_mark_rect(int X1, int Y1, int X2, int Y2) {
}
}
if (cmap8to24 && cmap8to24_fb) {
src_fb = cmap8to24_fb;
}
scale_rect(scale_fac, scaling_blend, scaling_interpolate, bpp/8,
main_fb, main_bytes_per_line, rfb_fb, rfb_bytes_per_line,
src_fb, main_bytes_per_line, rfb_fb, rfb_bytes_per_line,
dpy_x, dpy_y, scaled_x, scaled_y, X1, Y1, X2, Y2, 1);
}
@ -1212,8 +1218,17 @@ void mark_rect_as_modified(int x1, int y1, int x2, int y2, int force) {
if (rfb_fb == main_fb || force) {
rfbMarkRectAsModified(screen, x1, y1, x2, y2);
} else if (scaling) {
return;
}
if (cmap8to24) {
bpp8to24(x1, y1, x2, y2);
}
if (scaling) {
scale_and_mark_rect(x1, y1, x2, y2);
} else {
rfbMarkRectAsModified(screen, x1, y1, x2, y2);
}
}
@ -2416,6 +2431,9 @@ int scan_for_updates(int count_only) {
/* check for changed colormap */
set_colormap(0);
}
if (cmap8to24 && scan_count % 4 == 0) {
check_for_multivis();
}
if (use_xdamage) {
/* first pass collecting DAMAGE events: */
collect_xdamage(scan_count, 0);

@ -544,8 +544,9 @@ static void nofb_hook(rfbClientPtr cl) {
void do_new_fb(int reset_mem) {
XImage *fb;
char *old_main = main_fb;
char *old_rfb = rfb_fb;
char *old_main = main_fb;
char *old_rfb = rfb_fb;
char *old_8to24 = cmap8to24_fb;
/* for threaded we really should lock libvncserver out. */
if (use_threads) {
@ -569,12 +570,15 @@ void do_new_fb(int reset_mem) {
initialize_polling_images();
}
if (old_main != old_rfb && old_main) {
if (old_main) {
free(old_main);
}
if (old_rfb) {
if (old_rfb && old_rfb != old_main) {
free(old_rfb);
}
if (old_8to24 && old_8to24 != old_main && old_8to24 != old_rfb) {
free(old_8to24);
}
fb0 = fb;
}
@ -1754,12 +1758,31 @@ void initialize_screen(int *argc, char **argv, XImage *fb) {
if (nofb) {
main_fb = NULL;
rfb_fb = main_fb;
cmap8to24_fb = NULL;
screen->displayHook = nofb_hook;
} else {
main_fb = fb->data;
rfb_fb = NULL;
cmap8to24_fb = NULL;
if (cmap8to24) {
if (screen->serverFormat.bitsPerPixel != 32 ||
screen->serverFormat.depth != 24) {
if (!quiet) rfbLog("disabling -8to24 mode:"
" bpp != 32 or depth != 24\n");
cmap8to24 = 0;
}
}
if (cmap8to24) {
int n = main_bytes_per_line * fb->height;
cmap8to24_fb = (char *) malloc(n);
memset(cmap8to24_fb, 0, n);
}
if (scaling) {
rfb_fb = (char *) malloc(rfb_bytes_per_line * height);
memset(rfb_fb, 0, rfb_bytes_per_line * height);
} else if (cmap8to24) {
rfb_fb = cmap8to24_fb;
} else {
rfb_fb = main_fb;
}
@ -1768,6 +1791,7 @@ void initialize_screen(int *argc, char **argv, XImage *fb) {
if (!quiet) {
fprintf(stderr, " main_fb: %p\n", main_fb);
fprintf(stderr, " rfb_fb: %p\n", rfb_fb);
fprintf(stderr, " 8to24_fb: %p\n", cmap8to24_fb);
fprintf(stderr, "\n");
}
@ -1780,7 +1804,7 @@ void initialize_screen(int *argc, char **argv, XImage *fb) {
setup_cursors_and_push();
if (scaling) {
if (scaling || cmap8to24) {
mark_rect_as_modified(0, 0, dpy_x, dpy_y, 0);
}

@ -121,6 +121,7 @@ Screen
=GAL OverlayVisuals::
overlay
overlay_nocursor
8to24
=GAL LOFF
=GAL 8-Bit-Color::
flashcmap
@ -1446,7 +1447,7 @@ proc parse_help {} {
if {! $sawopts} {
continue;
}
if {[regexp {^-([A-z_][A-z_]*)} $line match name]} {
if {[regexp {^-([0-9A-z_][0-9A-z_]*)} $line match name]} {
set allnames($name) 1;
if {"$curropt" != "no$name" && "no$curropt" != "$name"} {
set curropt $name;
@ -1525,7 +1526,7 @@ proc parse_remote_help {} {
if {! $sawopts} {
continue;
}
if {[regexp {^([A-z_][A-z_:]*)} $line match name]} {
if {[regexp {^([0-9A-z_][0-9A-z_:]*)} $line match name]} {
regsub {:.*$} $name "" popt
lappend possopts $popt
if {"$curropt" != "no$name" && "no$curropt" != "$name"} {

@ -132,6 +132,7 @@ char gui_code[] = "";
" =GAL OverlayVisuals::\n"
" overlay\n"
" overlay_nocursor\n"
" 8to24\n"
" =GAL LOFF\n"
" =GAL 8-Bit-Color::\n"
" flashcmap\n"
@ -1457,7 +1458,7 @@ char gui_code[] = "";
" if {! $sawopts} {\n"
" continue;\n"
" }\n"
" if {[regexp {^-([A-z_][A-z_]*)} $line match name]} {\n"
" if {[regexp {^-([0-9A-z_][0-9A-z_]*)} $line match name]} {\n"
" set allnames($name) 1;\n"
" if {\"$curropt\" != \"no$name\" && \"no$curropt\" != \"$name\"} {\n"
" set curropt $name;\n"
@ -1536,7 +1537,7 @@ char gui_code[] = "";
" if {! $sawopts} {\n"
" continue;\n"
" }\n"
" if {[regexp {^([A-z_][A-z_:]*)} $line match name]} {\n"
" if {[regexp {^([0-9A-z_][0-9A-z_:]*)} $line match name]} {\n"
" regsub {:.*$} $name \"\" popt\n"
" lappend possopts $popt\n"
" if {\"$curropt\" != \"no$name\" && \"no$curropt\" != \"$name\"} {\n"

@ -14,6 +14,7 @@
#include "keyboard.h"
#include "solid.h"
#include "xrandr.h"
#include "8to24.h"
/*
* user input handling heuristics
@ -241,7 +242,7 @@ WIREFRAME_PARMS "0xff,2,0,30+6+6+6,Alt,0.05+0.3+2.0,8"
shade,linewidth,percent,T+B+L+R,mods,t1+t2+t3+t4
*/
#define LW_MAX 8
static unsigned long wireframe_shade;
static unsigned long wireframe_shade = 0xff;
static int wireframe_lw;
static double wireframe_frac;
static int wireframe_top, wireframe_bot, wireframe_left, wireframe_right;
@ -3694,6 +3695,25 @@ if (db) fprintf(stderr, "send_copyrect: %d\n", sent_copyrect);
/* final push (for -nowirecopyrect) */
rfbPE(1000);
wireframe_in_progress = 0;
if (frame_changed && cmap8to24 && multivis_count) {
/* handle -8to24 tweak, mark area and check 8bpp... */
int x1, x2, y1, y2, f = 16;
x1 = nmin(box_x, orig_x) - f;
y1 = nmin(box_y, orig_y) - f;
x2 = nmax(box_x + box_w, orig_x + orig_w) + f;
y2 = nmax(box_y + box_h, orig_y + orig_h) + f;
x1 = nfix(x1, dpy_x);
x2 = nfix(x2, dpy_x);
y1 = nfix(y1, dpy_y);
y2 = nfix(y2, dpy_y);
if (0) fprintf(stderr, "wireframe_in_progress over: %d %d %d %d\n", x1, y1, x2, y2);
check_for_multivis();
if (1) mark_rect_as_modified(x1, y1, x2, y2, 0);
if (0) mark_rect_as_modified(0, 0, dpy_x, dpy_y, 0);
if (0) rfbPE(-1);
}
urgent_update = 1;
if (use_xdamage) {
/* DAMAGE can queue ~1000 rectangles for a move */

@ -14,6 +14,8 @@ MUTEX(scrollMutex);
#endif
int nfix(int i, int n);
int nmin(int n, int m);
int nmax(int n, int m);
int nabs(int n);
double dabs(double x);
void lowercase(char *str);
@ -42,6 +44,9 @@ double rfac(void);
void rfbPE(long usec);
void rfbCFD(long usec);
double rect_overlap(int x1, int y1, int x2, int y2, int X1, int Y1,
int X2, int Y2);
/*
* routine to keep 0 <= i < n, should use in more places...
@ -55,6 +60,22 @@ int nfix(int i, int n) {
return i;
}
int nmin(int n, int m) {
if (n < m) {
return n;
} else {
return m;
}
}
int nmax(int n, int m) {
if (n > m) {
return n;
} else {
return m;
}
}
int nabs(int n) {
if (n < 0) {
return -n;
@ -394,4 +415,39 @@ void rfbCFD(long usec) {
}
}
double rect_overlap(int x1, int y1, int x2, int y2, int X1, int Y1,
int X2, int Y2) {
double a, A, o;
sraRegionPtr r, R, overlap;
sraRectangleIterator *iter;
sraRect rt;
a = nabs((x2 - x1) * (y2 - y1));
A = nabs((X2 - X1) * (Y2 - Y1));
r = sraRgnCreateRect(x1, y1, x2, y2);
R = sraRgnCreateRect(X1, Y1, X2, Y2);
overlap = sraRgnCreateRect(x1, y1, x2, y2);
sraRgnAnd(overlap, R);
o = 0.0;
iter = sraRgnGetIterator(overlap);
while (sraRgnIteratorNext(iter, &rt)) {
o += nabs( (rt.x2 - rt.x1) * (rt.y2 - rt.y1) );
}
sraRgnReleaseIterator(iter);
sraRgnDestroy(r);
sraRgnDestroy(R);
sraRgnDestroy(overlap);
if (a < A) {
o = o/a;
} else {
o = o/A;
}
return o;
}

@ -4,6 +4,8 @@
/* -- util.h -- */
extern int nfix(int i, int n);
extern int nmin(int n, int m);
extern int nmax(int n, int m);
extern int nabs(int n);
extern double dabs(double x);
extern void lowercase(char *str);
@ -31,6 +33,8 @@ extern double rfac(void);
extern void rfbPE(long usec);
extern void rfbCFD(long usec);
extern double rect_overlap(int x1, int y1, int x2, int y2, int X1, int Y1,
int X2, int Y2);
#define NONUL(x) ((x) ? (x) : "")

@ -2,7 +2,7 @@
.TH X11VNC "1" "January 2006" "x11vnc " "User Commands"
.SH NAME
x11vnc - allow VNC connections to real X11 displays
version: 0.8, lastmod: 2006-01-11
version: 0.8, lastmod: 2006-01-14
.SH SYNOPSIS
.B x11vnc
[OPTION]...
@ -177,6 +177,40 @@ visual (e.g. some apps have \fB-use24\fR or \fB-visual\fR options).
Sets \fB-overlay,\fR but does not try to draw the exact mouse
cursor shape using the overlay mechanism.
.PP
\fB-8to24\fR
.IP
If \fB-overlay\fR is not supported on your OS, and you have a
legacy 8bpp app that you want to view on a multi-depth
display with default depth 24 (and is 32 bpp), try
this option. This option may not work on all X servers
and hardware (tested on XFree86/Xorg mga driver).
.IP
It enables a hack where x11vnc monitors windows within 3
levels from the root window. If it finds any that are
8bpp it will apply a transformation for pixel data in
these regions where it extracts the 8bpp index color
value from bits 25-32 and maps them on to TrueColor
values and inserts them into bits 1-24 (i.e. overwrites
bits 1-24). This method appears to work, but may still
have bugs and note that it does hog resources. If there
are multiple 8bpp windows using different colormaps,
one may have to iconify all but one for the colors to
be correct.
.IP
There may also be painting errors for clipping
and switching between windows of depths 8 and 24.
Heuristics are applied to try to minimize the painting
errors. One can also press 3 Alt_L's in a row to
refresh the screen if the error does not repair itself.
Also the option, say, \fB-fixscreen\fR V=3.0 may be use
to periodically refresh the screen (at the cost of
bandwidth).
.IP
Note that \fB-8to24\fR does not work on displays with 8bpp
default visual with depth 24 applications. The Xserver
\fB-cc\fR option can be used to switch the default depth on
multidepth setups.
.PP
\fB-scale\fR \fIfraction\fR
.IP
Scale the framebuffer by factor \fIfraction\fR. Values
@ -1979,6 +2013,10 @@ overlay_cursor in \fB-overlay\fR mode, enable cursor drawing.
overlay_nocursor disable cursor drawing. same as
nooverlay_cursor.
.IP
8to24 enable \fB-8to24\fR mode (if applicable).
.IP
no8to24 disable \fB-8to24\fR mode.
.IP
visual:vis set \fB-visual\fR to "vis"
.IP
scale:frac set \fB-scale\fR to "frac"
@ -2417,10 +2455,10 @@ refresh reset close disconnect id sid waitmapped
nowaitmapped clip flashcmap noflashcmap shiftcmap
truecolor notruecolor overlay nooverlay overlay_cursor
overlay_yescursor nooverlay_nocursor nooverlay_cursor
nooverlay_yescursor overlay_nocursor visual scale
scale_cursor viewonly noviewonly shared noshared
forever noforever once timeout filexfer deny lock
nodeny unlock connect allowonce allow localhost
nooverlay_yescursor overlay_nocursor 8to24 no8to24
visual scale scale_cursor viewonly noviewonly shared
noshared forever noforever once timeout filexfer deny
lock nodeny unlock connect allowonce allow localhost
nolocalhost listen lookup nolookup accept afteraccept
gone shm noshm flipbyteorder noflipbyteorder onetile
noonetile solid_color solid nosolid blackout xinerama

@ -907,6 +907,7 @@ static void print_settings(int try_http, int bg, char *gui_str) {
fprintf(stderr, " flashcmap: %d\n", flash_cmap);
fprintf(stderr, " shiftcmap: %d\n", shift_cmap);
fprintf(stderr, " force_idx: %d\n", force_indexed_color);
fprintf(stderr, " cmap8to24: %d\n", cmap8to24);
fprintf(stderr, " visual: %s\n", visual_str ? visual_str
: "null");
fprintf(stderr, " overlay: %d\n", overlay);
@ -1270,6 +1271,8 @@ int main(int argc, char* argv[]) {
} else if (!strcmp(arg, "-overlay_yescursor")) {
overlay = 1;
overlay_cursor = 2;
} else if (!strcmp(arg, "-8to24")) {
cmap8to24 = 1;
} else if (!strcmp(arg, "-visual")) {
CHECK_ARGC
visual_str = strdup(argv[++i]);

@ -315,6 +315,7 @@ extern char *main_fb; /* our copy of the X11 fb */
extern char *rfb_fb; /* same as main_fb unless transformation */
extern char *fake_fb; /* used under -padgeom */
extern char *snap_fb; /* used under -snapfb */
extern char *cmap8to24_fb; /* used under -8to24 */
extern char *raw_fb;
extern char *raw_fb_addr;
extern int raw_fb_offset;

@ -15,7 +15,7 @@ int xtrap_base_event_type = 0;
int xdamage_base_event_type = 0;
/* date +'lastmod: %Y-%m-%d' */
char lastmod[] = "0.8 lastmod: 2006-01-11";
char lastmod[] = "0.8 lastmod: 2006-01-14";
/* X display info */
@ -57,6 +57,7 @@ char *main_fb = NULL; /* our copy of the X11 fb */
char *rfb_fb = NULL; /* same as main_fb unless transformation */
char *fake_fb = NULL; /* used under -padgeom */
char *snap_fb = NULL; /* used under -snapfb */
char *cmap8to24_fb = NULL; /* used under -8to24 */
char *raw_fb = NULL;
char *raw_fb_addr = NULL;
int raw_fb_offset = 0;

Loading…
Cancel
Save