]> source.dussan.org Git - tigervnc.git/commitdiff
Let CMsgHandler::serverInit() handle initial set up
authorPierre Ossman <ossman@cendio.se>
Wed, 31 Oct 2018 16:08:59 +0000 (17:08 +0100)
committerPierre Ossman <ossman@cendio.se>
Thu, 1 Nov 2018 15:11:42 +0000 (16:11 +0100)
Avoid using the callbacks used for runtime changes for the initial
setup. They weren't really useful anyway as you could not allocate
a framebuffer without also knowing the pixel format. So make things
more clear by letting serverInit() get the initial settings.

common/rfb/CConnection.cxx
common/rfb/CConnection.h
common/rfb/CMsgHandler.cxx
common/rfb/CMsgHandler.h
common/rfb/CMsgReader.cxx
tests/decperf.cxx
tests/encperf.cxx
vncviewer/CConn.cxx

index 805c8c31498012b427947ef37f2867218c10f561..14ef221f084ae29cfc4105a7b0651022d53aaac6 100644 (file)
@@ -16,6 +16,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  * USA.
  */
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -335,12 +336,19 @@ void CConnection::setExtendedDesktopSize(unsigned reason,
   CMsgHandler::setExtendedDesktopSize(reason, result, w, h, layout);
 }
 
-void CConnection::serverInit()
+void CConnection::serverInit(int width, int height,
+                             const PixelFormat& pf,
+                             const char* name)
 {
+  CMsgHandler::serverInit(width, height, pf, name);
+
   state_ = RFBSTATE_NORMAL;
   vlog.debug("initialisation done");
 
   initDone();
+  assert(framebuffer != NULL);
+  assert(framebuffer->width() == server.width());
+  assert(framebuffer->height() == server.height());
 }
 
 void CConnection::readAndDecodeRect(const Rect& r, int encoding,
index c996ecf4b7b8451eeef0d628f08f389425a2613f..7623c02eace8c39f26afd329f1aa0194b4ba6478 100644 (file)
@@ -100,7 +100,9 @@ namespace rfb {
                                         int w, int h,
                                         const ScreenSet& layout);
 
-    virtual void serverInit();
+    virtual void serverInit(int width, int height,
+                            const PixelFormat& pf,
+                            const char* name);
 
     virtual void readAndDecodeRect(const Rect& r, int encoding,
                                    ModifiablePixelBuffer* pb);
@@ -118,8 +120,10 @@ namespace rfb {
     // initDone() is called when the connection is fully established
     // and standard messages can be sent. This is called before the
     // initial FramebufferUpdateRequest giving a derived class the
-    // chance to modify pixel format and settings.
-    virtual void initDone();
+    // chance to modify pixel format and settings. The derived class
+    // must also make sure it has provided a valid framebuffer before
+    // returning.
+    virtual void initDone() = 0;
 
 
     // Other methods
index 4289cbf137f6db9bf3db051290d345b61c501674..4fe50414e7e0ba59cc7b6d75d5968613fe757926 100644 (file)
@@ -74,6 +74,15 @@ void CMsgHandler::supportsQEMUKeyEvent()
   server.supportsQEMUKeyEvent = true;
 }
 
+void CMsgHandler::serverInit(int width, int height,
+                             const PixelFormat& pf,
+                             const char* name)
+{
+  server.setDimensions(width, height);
+  server.setPF(pf);
+  server.setName(name);
+}
+
 void CMsgHandler::framebufferUpdateStart()
 {
 }
index 55241dac9ea207874ce0f85a75f5a89363b70fc8..effdaabff0fd370af744298278ee5d53edfae866 100644 (file)
@@ -41,9 +41,9 @@ namespace rfb {
 
     // The following methods are called as corresponding messages are read.  A
     // derived class should override these methods as desired.  Note that for
-    // the setDesktopSize(), setExtendedDesktopSize(), setPixelFormat() and
-    // setName() methods, a derived class should call on to CMsgHandler's
-    // methods to set the members of "server" appropriately.
+    // the setDesktopSize(), setExtendedDesktopSize(), setPixelFormat(),
+    // setName() and serverInit() methods, a derived class should call on to
+    // CMsgHandler's methods to set the members of "server" appropriately.
 
     virtual void setDesktopSize(int w, int h);
     virtual void setExtendedDesktopSize(unsigned reason, unsigned result,
@@ -56,7 +56,9 @@ namespace rfb {
     virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
     virtual void endOfContinuousUpdates();
     virtual void supportsQEMUKeyEvent();
-    virtual void serverInit() = 0;
+    virtual void serverInit(int width, int height,
+                            const PixelFormat& pf,
+                            const char* name) = 0;
 
     virtual void readAndDecodeRect(const Rect& r, int encoding,
                                    ModifiablePixelBuffer* pb) = 0;
index 3ce74731af4512e74fd462d24f55468b316c5368..17152ab71164ba205fa603b114af5c267442ea25 100644 (file)
@@ -43,13 +43,10 @@ void CMsgReader::readServerInit()
 {
   int width = is->readU16();
   int height = is->readU16();
-  handler->setDesktopSize(width, height);
   PixelFormat pf;
   pf.read(is);
-  handler->setPixelFormat(pf);
   CharArray name(is->readString());
-  handler->setName(name.buf);
-  handler->serverInit();
+  handler->serverInit(width, height, pf, name.buf);
 }
 
 void CMsgReader::readMsg()
index 056848aec16892adeb293dc0a05f0dc07b10a084..301e45e025514c3a65e78b4223cad4e12277d71d 100644 (file)
@@ -47,7 +47,7 @@ public:
   CConn(const char *filename);
   ~CConn();
 
-  virtual void setDesktopSize(int w, int h);
+  virtual void initDone();
   virtual void setPixelFormat(const rfb::PixelFormat& pf);
   virtual void setCursor(int, int, const rfb::Point&, const rdr::U8*);
   virtual void framebufferUpdateStart();
@@ -81,10 +81,8 @@ CConn::~CConn()
   delete in;
 }
 
-void CConn::setDesktopSize(int w, int h)
+void CConn::initDone()
 {
-  CConnection::setDesktopSize(w, h);
-
   setFramebuffer(new rfb::ManagedPixelBuffer(filePF,
                                              server.width(),
                                              server.height()));
index f8b2555f85ae7b6098d7e62e08385547d13d7a81..6f9283b83045e54a378b7dc6999372df0fd3ac85 100644 (file)
@@ -89,7 +89,7 @@ public:
   void getStats(double& ratio, unsigned long long& bytes,
                 unsigned long long& rawEquivalent);
 
-  virtual void setDesktopSize(int w, int h);
+  virtual void initDone();
   virtual void setCursor(int, int, const rfb::Point&, const rdr::U8*);
   virtual void framebufferUpdateStart();
   virtual void framebufferUpdateEnd();
@@ -196,12 +196,10 @@ void CConn::getStats(double& ratio, unsigned long long& bytes,
   sc->getStats(ratio, bytes, rawEquivalent);
 }
 
-void CConn::setDesktopSize(int w, int h)
+void CConn::initDone()
 {
   rfb::ModifiablePixelBuffer *pb;
 
-  CConnection::setDesktopSize(w, h);
-
   pb = new rfb::ManagedPixelBuffer((bool)translate ? fbPF : server.pf(),
                                    server.width(), server.height());
   setFramebuffer(pb);
index 23257ee6f8378a8aa41c99776d8296dd3e60e0e6..3e156ad60c755925ddba6f8ecf6245466fb53a3f 100644 (file)
@@ -363,8 +363,7 @@ void CConn::setExtendedDesktopSize(unsigned reason, unsigned result,
 void CConn::setName(const char* name)
 {
   CConnection::setName(name);
-  if (desktop)
-    desktop->setName(name);
+  desktop->setName(name);
 }
 
 // framebufferUpdateStart() is called at the beginning of an update.
@@ -495,9 +494,6 @@ void CConn::setLEDState(unsigned int state)
 
 void CConn::resizeFramebuffer()
 {
-  if (!desktop)
-    return;
-
   if (continuousUpdates)
     writer()->writeEnableContinuousUpdates(true, 0, 0,
                                            server.width(),