From 018e90db5918a75ceaf3835be084e2387f31a47e Mon Sep 17 00:00:00 2001
From: dscho <dscho>
Date: Fri, 5 Oct 2001 21:41:16 +0000
Subject: changed cursor functions to use screen info, not cursor fixed copy
 rect.

---
 CHANGES     |  8 +++++++-
 TODO        |  2 +-
 cursor.c    | 16 +++-------------
 example.c   |  6 +++---
 main.c      | 30 ++++++++++++++++++------------
 rfb.h       |  4 ++--
 rfbserver.c |  8 ++++----
 7 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/CHANGES b/CHANGES
index 6632674..c507bfb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,11 @@
 0.2
-   flag backgroundLoop in rfbScreenInfo
+   fixed CopyRect (was using the wrong order of rectangles...)
+   	 should also work with pthreads, because copyrects are
+	 always sent immediately (so that two consecutive copy rects
+	 cannot conflict).
+   changed rfbUndrawCursor(rfbClientPtr) to (rfbScreenInfoPtr), because
+   	   this makes more sense!
+   flag backgroundLoop in rfbScreenInfo (if having pthreads)
    rfbCopyRect & rfbCopyRegion (really copies rectangle in frameBuffer)
    added flag to optionally not send XCursor updates.
    fixed java viewer on server side:
diff --git a/TODO b/TODO
index 28562e4..50926ab 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,7 @@
 immediate:
 ----------
 
-copyRect and pthreads possible problem.
+test copyRect and pthreads.
 authentification schemes (secure vnc)
 udp
 documentation
diff --git a/cursor.c b/cursor.c
index 6e678d5..f04dc84 100644
--- a/cursor.c
+++ b/cursor.c
@@ -331,9 +331,8 @@ void MakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor)
 
 /* functions to draw/hide cursor directly in the frame buffer */
 
-void rfbUndrawCursor(rfbClientPtr cl)
+void rfbUndrawCursor(rfbScreenInfoPtr s)
 {
-   rfbScreenInfoPtr s=cl->screen;
    rfbCursorPtr c=s->cursor;
    int j,x1,x2,y1,y2,bpp=s->rfbServerFormat.bitsPerPixel/8,
      rowstride=s->paddedWidthInBytes;
@@ -372,9 +371,8 @@ void rfbUndrawCursor(rfbClientPtr cl)
    UNLOCK(s->cursorMutex);
 }
 
-void rfbDrawCursor(rfbClientPtr cl)
+void rfbDrawCursor(rfbScreenInfoPtr s)
 {
-   rfbScreenInfoPtr s=cl->screen;
    rfbCursorPtr c=s->cursor;
    int i,j,x1,x2,y1,y2,i1,j1,bpp=s->rfbServerFormat.bitsPerPixel/8,
      rowstride=s->paddedWidthInBytes,
@@ -453,16 +451,8 @@ void rfbPrintXCursor(rfbCursorPtr cursor)
 
 extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c,Bool freeOld)
 {
-  rfbClientIteratorPtr i = rfbGetClientIterator(rfbScreen);
-  rfbClientPtr cl;
-
   LOCK(rfbScreen->cursorMutex);
-
-  while((cl=rfbClientIteratorNext(i))) {
-    LOCK(cl->updateMutex);
-    rfbUndrawCursor(cl);
-    UNLOCK(cl->updateMutex);
-    }
+  rfbUndrawCursor(rfbScreen);
 
   if(freeOld && rfbScreen->cursor)
     rfbFreeCursor(rfbScreen->cursor);
diff --git a/example.c b/example.c
index 64e4d6c..1348c49 100644
--- a/example.c
+++ b/example.c
@@ -102,7 +102,7 @@ void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
    ClientData* cd=cl->clientData;
 
    if(cl->screen->cursorIsDrawn)
-     rfbUndrawCursor(cl);
+     rfbUndrawCursor(cl->screen);
 
    if(x>=0 && y>=0 && x<maxx && y<maxy) {
       if(buttonMask) {
@@ -149,14 +149,14 @@ void dokey(Bool down,KeySym key,rfbClientPtr cl)
       rfbCloseClient(cl);
     else if(key==XK_Page_Up) {
       if(cl->screen->cursorIsDrawn)
-	rfbUndrawCursor(cl);
+	rfbUndrawCursor(cl->screen);
       initBuffer(cl->screen->frameBuffer);
       rfbMarkRectAsModified(cl->screen,0,0,maxx,maxy);
     } else if(key>=' ' && key<0x100) {
       ClientData* cd=cl->clientData;
       int x1=cd->oldx,y1=cd->oldy,x2,y2;
       if(cl->screen->cursorIsDrawn)
-	rfbUndrawCursor(cl);
+	rfbUndrawCursor(cl->screen);
       cd->oldx+=rfbDrawChar(cl->screen,&radonFont,cd->oldx,cd->oldy,key,0xffffff);
       rfbFontBBox(&radonFont,key,&x1,&y1,&x2,&y2);
       rfbMarkRectAsModified(cl->screen,x1,y1,x2-1,y2-1);
diff --git a/main.c b/main.c
index 372bdb9..305645e 100644
--- a/main.c
+++ b/main.c
@@ -67,23 +67,29 @@ void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,in
    rfbClientIteratorPtr iterator;
    rfbClientPtr cl;
 
-  iterator=rfbGetClientIterator(rfbScreen);
+   rfbUndrawCursor(rfbScreen);
+  
+   iterator=rfbGetClientIterator(rfbScreen);
    while((cl=rfbClientIteratorNext(iterator))) {
      LOCK(cl->updateMutex);
      if(cl->useCopyRect) {
-       while(!sraRgnEmpty(cl->copyRegion) && (cl->copyDX!=dx || cl->copyDY!=dy)) {
-#ifdef HAVE_PTHREADS
-	 if(cl->screen->backgroundLoop) {
-	   SIGNAL(cl->updateCond);
-	   UNLOCK(cl->updateMutex);
-	   LOCK(cl->updateMutex);
-	 } else
-#endif
-	   rfbSendFramebufferUpdate(cl,cl->copyRegion);
-       }
        sraRgnOr(cl->copyRegion,copyRegion);
        cl->copyDX = dx;
        cl->copyDY = dy;
+       
+#ifdef HAVE_PTHREADS
+       if(cl->screen->backgroundLoop) {
+	 SIGNAL(cl->updateCond);
+	 UNLOCK(cl->updateMutex);
+	 LOCK(cl->updateMutex);
+       } else
+#endif
+       {
+	 sraRegionPtr updateRegion = sraRgnCreateRgn(cl->modifiedRegion);
+	 sraRgnOr(updateRegion,cl->copyRegion);
+	 rfbSendFramebufferUpdate(cl,updateRegion);
+	 sraRgnDestroy(updateRegion);
+       }
      } else {
        sraRgnOr(cl->modifiedRegion,copyRegion);
      }
@@ -332,7 +338,7 @@ defaultPtrAddEvent(int buttonMask, int x, int y, rfbClientPtr cl)
 {
    if(x!=cl->screen->cursorX || y!=cl->screen->cursorY) {
       if(cl->screen->cursorIsDrawn)
-	rfbUndrawCursor(cl);
+	rfbUndrawCursor(cl->screen);
       LOCK(cl->screen->cursorMutex);
       if(!cl->screen->cursorIsDrawn) {
 	  cl->screen->cursorX = x;
diff --git a/rfb.h b/rfb.h
index 04bb9de..c0ca7a9 100644
--- a/rfb.h
+++ b/rfb.h
@@ -667,8 +667,8 @@ extern char* rfbMakeMaskForXCursor(int width,int height,char* cursorString);
 extern void MakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
 extern void MakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
 extern void rfbFreeCursor(rfbCursorPtr cursor);
-extern void rfbDrawCursor(rfbClientPtr cl);
-extern void rfbUndrawCursor(rfbClientPtr cl);
+extern void rfbDrawCursor(rfbScreenInfoPtr rfbScreen);
+extern void rfbUndrawCursor(rfbScreenInfoPtr rfbScreen);
 extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c,Bool freeOld);
 
 /* cursor handling for the pointer */
diff --git a/rfbserver.c b/rfbserver.c
index 5266e5a..2460130 100644
--- a/rfbserver.c
+++ b/rfbserver.c
@@ -857,14 +857,14 @@ rfbSendFramebufferUpdate(cl, givenUpdateRegion)
 
     if (cl->enableCursorShapeUpdates) {
       if (cl->screen->cursorIsDrawn) {
-	rfbUndrawCursor(cl);
+	rfbUndrawCursor(cl->screen);
       }
       if (!cl->screen->cursorIsDrawn && cl->cursorWasChanged &&
 	  cl->readyForSetColourMapEntries)
 	  sendCursorShape = TRUE;
     } else {
       if (!cl->screen->cursorIsDrawn) {
-	rfbDrawCursor(cl);
+	rfbDrawCursor(cl->screen);
       }
     }
 
@@ -1093,7 +1093,7 @@ rfbSendCopyRegion(cl, reg, dx, dy)
     sraRectangleIterator* i;
     sraRect rect1;
 
-    i = sraRgnGetReverseIterator(reg,dx<0,dy<0);
+    i = sraRgnGetReverseIterator(reg,dx>0,dy>0);
 
     while(sraRgnIteratorNext(i,&rect1)) {
       x = rect1.x1;
@@ -1113,7 +1113,7 @@ rfbSendCopyRegion(cl, reg, dx, dy)
 
       cr.srcX = Swap16IfLE(x - dx);
       cr.srcY = Swap16IfLE(y - dy);
-fprintf(stderr,"sent copyrect (%d,%d) (%d,%d) (%d,%d)\n",x,y,w,h,x-dx,y-dy);
+
       memcpy(&cl->updateBuf[cl->ublen], (char *)&cr, sz_rfbCopyRect);
       cl->ublen += sz_rfbCopyRect;
 
-- 
cgit v1.2.3

