summaryrefslogtreecommitdiffstats
path: root/x11vnc/userinput.c
diff options
context:
space:
mode:
Diffstat (limited to 'x11vnc/userinput.c')
-rw-r--r--x11vnc/userinput.c123
1 files changed, 60 insertions, 63 deletions
diff --git a/x11vnc/userinput.c b/x11vnc/userinput.c
index 56fadde..1a50a03 100644
--- a/x11vnc/userinput.c
+++ b/x11vnc/userinput.c
@@ -1842,10 +1842,12 @@ static void get_client_regions(int *req, int *mod, int *cpy, int *num) {
i = rfbGetClientIterator(screen);
while( (cl = rfbClientIteratorNext(i)) ) {
+ if (use_threads) LOCK(cl->updateMutex);
*req += sraRgnCountRects(cl->requestedRegion);
*mod += sraRgnCountRects(cl->modifiedRegion);
*cpy += sraRgnCountRects(cl->copyRegion);
*num += 1;
+ if (use_threads) UNLOCK(cl->updateMutex);
}
rfbReleaseClientIterator(i);
}
@@ -2024,7 +2026,9 @@ if (0) fprintf(stderr, "sb.. %d %d %d %d %d %d\n", sx1, sy1, sx2, sy2, sdx, sdy)
i = rfbGetClientIterator(screen);
while( (cl = rfbClientIteratorNext(i)) ) {
+ if (use_threads) LOCK(cl->updateMutex);
rfbSendCopyRegion(cl, r, sdx, sdy);
+ if (use_threads) UNLOCK(cl->updateMutex);
}
rfbReleaseClientIterator(i);
sraRgnDestroy(r);
@@ -2073,34 +2077,47 @@ void batch_copyregion(sraRegionPtr* region, int *dx, int *dy, int ncr, double de
if (delay < 0.0) {
delay = 0.1;
}
- fb_push_wait(delay, FB_COPY|FB_MOD);
+ if (!fb_push_wait(delay, FB_COPY|FB_MOD)) {
+ if (use_threads) usleep(100 * 1000);
+ fb_push_wait(0.75, FB_COPY|FB_MOD);
+ }
t1 = dnow();
-#if 0
+ bad = 0;
i = rfbGetClientIterator(screen);
while( (cl = rfbClientIteratorNext(i)) ) {
+
+ if (use_threads) LOCK(cl->updateMutex);
+
if (cl->ublen != 0) {
fprintf(stderr, "batch_copyregion: *** BAD ublen != 0: %d\n", cl->ublen);
bad++;
}
+
+ if (use_threads) UNLOCK(cl->updateMutex);
}
rfbReleaseClientIterator(i);
if (bad) {
return;
}
-#endif
i = rfbGetClientIterator(screen);
while( (cl = rfbClientIteratorNext(i)) ) {
- rfbFramebufferUpdateMsg *fu = (rfbFramebufferUpdateMsg *)cl->updateBuf;
+ rfbFramebufferUpdateMsg *fu;
+
+ if (use_threads) LOCK(cl->updateMutex);
+
+ fu = (rfbFramebufferUpdateMsg *)cl->updateBuf;
fu->nRects = Swap16IfLE((uint16_t)(nrects));
fu->type = rfbFramebufferUpdate;
- if (cl->ublen != 0) fprintf(stderr, "batch_copyregion: *** BAD ublen != 0: %d\n", cl->ublen);
+ if (cl->ublen != 0) fprintf(stderr, "batch_copyregion: *** BAD-2 ublen != 0: %d\n", cl->ublen);
cl->ublen = sz_rfbFramebufferUpdateMsg;
+
+ if (use_threads) UNLOCK(cl->updateMutex);
}
rfbReleaseClientIterator(i);
@@ -2119,12 +2136,17 @@ void batch_copyregion(sraRegionPtr* region, int *dx, int *dy, int ncr, double de
i = rfbGetClientIterator(screen);
while( (cl = rfbClientIteratorNext(i)) ) {
+
+ if (use_threads) LOCK(cl->updateMutex);
+
if (!direct) {
for (k=0; k < ncr; k++) {
rfbSendCopyRegion(cl, region[k], dx[k], dy[k]);
}
}
rfbSendUpdateBuf(cl);
+
+ if (use_threads) UNLOCK(cl->updateMutex);
}
rfbReleaseClientIterator(i);
@@ -2145,49 +2167,32 @@ void batch_push(int nreg, double delay) {
}
}
-void fb_push0(void) {
- char *httpdir = screen->httpDir;
- int defer = screen->deferUpdateTime;
- int req0, mod0, cpy0, req1, mod1, cpy1, ncli;
- int db = (debug_scroll || debug_wireframe);
-
- screen->httpDir = NULL;
- screen->deferUpdateTime = 0;
-
-if (db) get_client_regions(&req0, &mod0, &cpy0, &ncli);
-
- rfbPE(0);
-
- screen->httpDir = httpdir;
- screen->deferUpdateTime = defer;
-
-if (db) {
- get_client_regions(&req1, &mod1, &cpy1, &ncli);
- fprintf(stderr, "\nFB_push: req: %d/%d mod: %d/%d cpy: %d/%d %.4f\n",
- req0, req1, mod0, mod1, cpy0, cpy1, dnowx());
-}
-
-}
-
void fb_push(void) {
int req0, mod0, cpy0, req1, mod1, cpy1, ncli;
int db = (debug_scroll || debug_wireframe);
rfbClientIteratorPtr i;
rfbClientPtr cl;
+
+ if (use_threads) {
+ return;
+ }
if (db) get_client_regions(&req0, &mod0, &cpy0, &ncli);
i = rfbGetClientIterator(screen);
while( (cl = rfbClientIteratorNext(i)) ) {
+ if (use_threads) LOCK(cl->updateMutex);
if (cl->sock >= 0 && !cl->onHold && FB_UPDATE_PENDING(cl) &&
!sraRgnEmpty(cl->requestedRegion)) {
if (!rfbSendFramebufferUpdate(cl, cl->modifiedRegion)) {
fprintf(stderr, "*** rfbSendFramebufferUpdate *FAILED* #1\n");
if (cl->ublen) fprintf(stderr, "*** fb_push ublen not zero: %d\n", cl->ublen);
+ if (use_threads) UNLOCK(cl->updateMutex);
break;
}
if (cl->ublen) fprintf(stderr, "*** fb_push ublen NOT ZERO: %d\n", cl->ublen);
}
+ if (use_threads) UNLOCK(cl->updateMutex);
}
rfbReleaseClientIterator(i);
@@ -2199,37 +2204,6 @@ if (db) {
}
-int fb_push_wait0(double max_wait, int flags) {
- double tm, dt = 0.0;
- int req, mod, cpy, ncli;
- int ok = 0;
-
- dtime0(&tm);
- while (dt < max_wait) {
- int done = 1;
- rfbCFD(0);
- get_client_regions(&req, &mod, &cpy, &ncli);
- if (flags & FB_COPY && cpy) {
- done = 0;
- }
- if (flags & FB_MOD && mod) {
- done = 0;
- }
- if (flags & FB_REQ && req) {
- done = 0;
- }
- if (done) {
- ok = 1;
- break;
- }
-
- usleep(1000);
- fb_push();
- dt += dtime(&tm);
- }
- return ok;
-}
-
int fb_push_wait(double max_wait, int flags) {
double tm, dt = 0.0;
int req, mod, cpy, ncli;
@@ -3403,6 +3377,7 @@ if (db2 && saw_me) continue;
sraRgnSubtract(moved_win, tmp_win);
sraRgnDestroy(tmp_win);
}
+
X_UNLOCK;
if (extra_clip && ! sraRgnEmpty(extra_clip)) {
@@ -4597,6 +4572,9 @@ if (db) fprintf(stderr, "INTERIOR\n");
if (rotating) {
try_batch = 0;
}
+ if (use_threads && ncache > 0 && ncache_copyrect) {
+ try_batch = 0;
+ }
g = got_pointer_input;
gd = got_local_pointer_input;
@@ -4882,8 +4860,9 @@ if (0) fprintf(stderr, "*** NO GPI DRAW_BOX\n");
rfbPE(1000);
} else {
#ifndef NO_NCACHE
+ int tb = use_threads ? 0 : try_batch;
do_copyrect_drag_move(orig_frame, frame, &nidx,
- try_batch, now_x, now_y, orig_w, orig_h, x, y, w, h,
+ tb, now_x, now_y, orig_w, orig_h, x, y, w, h,
copyrect_drag_delay);
now_x = x;
now_y = y;
@@ -4940,8 +4919,9 @@ if (db || db2) fprintf(stderr, "NO button_mask\n");
draw_box(0, 0, 0, 0, 1);
fb_push(); /* XXX Y */
} else {
+ int tb = use_threads ? 0 : try_batch;
do_copyrect_drag_move(orig_frame, frame, &nidx,
- try_batch, now_x, now_y, orig_w, orig_h, x, y, w, h, -1.0);
+ tb, now_x, now_y, orig_w, orig_h, x, y, w, h, -1.0);
fb_push_wait(0.15, FB_COPY|FB_MOD);
}
@@ -4960,15 +4940,19 @@ if (db || db2) fprintf(stderr, "NO button_mask\n");
} else if (w != orig_w || h != orig_h) {
if (ncache > 0) {
try_to_fix_resize_su(orig_frame, orig_x, orig_y, orig_w, orig_h, x, y, w, h, try_batch);
+ X_LOCK;
clear_win_events(orig_frame, 1);
if (frame != orig_frame) {
clear_win_events(frame, 1);
}
+ X_UNLOCK;
}
} else if (dx == 0 && dy == 0) {
;
} else if (do_copyrect_drag > 0) {
+ X_LOCK;
clear_win_events(NPP_nwin, 0);
+ X_UNLOCK;
} else {
int spin_ms = (int) (spin * 1000 * 1000);
int obscured, sent_copyrect = 0;
@@ -5030,7 +5014,9 @@ if ((ncache || db) && ncdb) fprintf(stderr, "sent_copyrect: %d - obs: %d frame:
}
ncache_post_portions(nidx, use_batch,
orig_x, orig_y, orig_w, orig_h, x, y, w, h, -1.0, ntim);
+ X_LOCK;
clear_win_events(NPP_nwin, 0);
+ X_UNLOCK;
if (scaling && !use_batch) {
static double last_time = 0.0;
@@ -7598,6 +7584,7 @@ void block_stats(void) {
int h = cache_list[k].bs_h;
int rc = 0;
Window win = cache_list[k].win;
+
if (win == None) {
continue;
}
@@ -8790,7 +8777,11 @@ if (ncdb) fprintf(stderr, "*SCHED LOOKUP FAIL: i=%d 0x%lx\n", i, win);
}
/* XXX Y resp */
if (saw_desktop_change || freq % 5 == 0) {
- if (!valid_window(win, &attr, 1)) {
+ int vret = 0;
+ X_LOCK;
+ vret = valid_window(win, &attr, 1);
+ X_UNLOCK;
+ if (!vret) {
continue;
}
STORE(i, win, attr);
@@ -8948,6 +8939,9 @@ int check_ncache(int reset, int mode) {
if (reset && (first || cache_list_len == 0)) {
return -1;
}
+ if (use_threads) {
+ try_batch = 0;
+ }
if (ncache0) {
if (reset) {
@@ -9244,6 +9238,7 @@ if (ncdb) fprintf(stderr, "PRELOOP: RepartNotify: 0x%lx %d idx=%d\n", win2, n1,
break;
}
}
+
X_UNLOCK;
if (got_NET_CURRENT_DESKTOP > 0.0) {
@@ -9703,7 +9698,9 @@ if (ncdb) fprintf(stderr, "skip%02d: ** SpecialSkip 0x%lx/0x%lx type: %s\n", i
valid = 1;
su_save(idx, nbatch, &attr, 0, &valid, 1);
STORE(idx, win2, attr);
+
X_LOCK;
+
if (! desktop_change) {
SCHED(win2, 1)
}