Restored the functionality of the VideoPriority parameter. This time, it
should work correctly even over slow networks, when update requests go less
frequently than polling cycles. This version does not give any special
meaning to the value 0, it is equivalent to 1.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2584 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx
index 750daae..19b8fee 100644
--- a/common/rfb/ServerCore.cxx
+++ b/common/rfb/ServerCore.cxx
@@ -92,3 +92,10 @@
 ("QueryConnect",
  "Prompt the local user to accept or reject incoming connections.",
  false);
+
+// TightVNC-specific parameters
+// FIXME: Disable special video handling when this parameter is 0.
+rfb::IntParameter rfb::Server::videoPriority
+("VideoPriority",
+ "Priority of sending updates for video area (0..8)",
+ 0, 0, 8);
diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h
index 68d7b74..85d4e90 100644
--- a/common/rfb/ServerCore.h
+++ b/common/rfb/ServerCore.h
@@ -48,6 +48,9 @@
     static BoolParameter sendCutText;
     static BoolParameter queryConnect;
 
+    // TightVNC-specific parameters
+    static IntParameter videoPriority;
+
   };
 
 };
diff --git a/common/rfb/UpdateTracker.h b/common/rfb/UpdateTracker.h
index b6a7d74..9cd99ab 100644
--- a/common/rfb/UpdateTracker.h
+++ b/common/rfb/UpdateTracker.h
@@ -85,6 +85,11 @@
     // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency.
     virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn);
 
+    // Get coordinates of the video rectangle
+    virtual const Rect& getVideoArea() const {
+      return video_area;
+    }
+
     // Copy the contained updates to another tracker
     virtual void copyTo(UpdateTracker* to) const;
 
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index 95b99fd..a9c59f3 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -541,7 +541,13 @@
 
   updates.enable_copyrect(cp.useCopyRect);
 
-  server->checkUpdate();
+  static int counter = 1;
+  if (--counter > 0) {
+    server->checkVideoUpdate();
+  } else {
+    counter = rfb::Server::videoPriority;
+    server->checkUpdate();
+  }
 
   // Get the lists of updates. Prior to exporting the data to the `ui' object,
   // getUpdateInfo() will normalize the `updates' object such way that its
diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx
index 93f947c..dc6c709 100644
--- a/common/rfb/VNCServerST.cxx
+++ b/common/rfb/VNCServerST.cxx
@@ -507,6 +507,22 @@
   comparer->clear();
 }
 
+void VNCServerST::checkVideoUpdate()
+{
+  const Rect &videoRect = comparer->getVideoArea();
+  Region videoRegion(videoRect);
+
+  if (!videoRegion.is_empty()) {
+    pb->grabRegion(videoRegion);
+
+    std::list<VNCSConnectionST*>::iterator ci, ci_next;
+    for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
+      ci_next = ci; ci_next++;
+      (*ci)->set_video_area(videoRect);
+    }
+  }
+}
+
 void VNCServerST::getConnInfo(ListConnInfo * listConn)
 {
   listConn->Clear();
diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h
index 81ad4ec..213f6b1 100644
--- a/common/rfb/VNCServerST.h
+++ b/common/rfb/VNCServerST.h
@@ -238,6 +238,7 @@
 
     bool needRenderedCursor();
     void checkUpdate();
+    void checkVideoUpdate();
 
     SSecurityFactory* securityFactory;
     QueryConnectionHandler* queryConnectionHandler;