From dd45b4490100f70e21000c5181540c224e0f3c41 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 31 Oct 2018 17:08:59 +0100 Subject: [PATCH] Let CMsgHandler::serverInit() handle initial set up 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 | 10 +++++++++- common/rfb/CConnection.h | 10 +++++++--- common/rfb/CMsgHandler.cxx | 9 +++++++++ common/rfb/CMsgHandler.h | 10 ++++++---- common/rfb/CMsgReader.cxx | 5 +---- tests/decperf.cxx | 6 ++---- tests/encperf.cxx | 6 ++---- vncviewer/CConn.cxx | 6 +----- 8 files changed, 37 insertions(+), 25 deletions(-) diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 805c8c31..14ef221f 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ +#include #include #include @@ -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, diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h index c996ecf4..7623c02e 100644 --- a/common/rfb/CConnection.h +++ b/common/rfb/CConnection.h @@ -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 diff --git a/common/rfb/CMsgHandler.cxx b/common/rfb/CMsgHandler.cxx index 4289cbf1..4fe50414 100644 --- a/common/rfb/CMsgHandler.cxx +++ b/common/rfb/CMsgHandler.cxx @@ -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() { } diff --git a/common/rfb/CMsgHandler.h b/common/rfb/CMsgHandler.h index 55241dac..effdaabf 100644 --- a/common/rfb/CMsgHandler.h +++ b/common/rfb/CMsgHandler.h @@ -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; diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 3ce74731..17152ab7 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -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() diff --git a/tests/decperf.cxx b/tests/decperf.cxx index 056848ae..301e45e0 100644 --- a/tests/decperf.cxx +++ b/tests/decperf.cxx @@ -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())); diff --git a/tests/encperf.cxx b/tests/encperf.cxx index f8b2555f..6f9283b8 100644 --- a/tests/encperf.cxx +++ b/tests/encperf.cxx @@ -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); diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 23257ee6..3e156ad6 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -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(), -- 2.39.5