Make sure all methods only write what is given as arguments, and avoid side effects by getting data from parameter objects. This keeps things readable in the calling code.tags/v1.9.90
@@ -25,6 +25,7 @@ | |||
#include <rfb/CMsgReader.h> | |||
#include <rfb/CMsgWriter.h> | |||
#include <rfb/CSecurity.h> | |||
#include <rfb/Decoder.h> | |||
#include <rfb/Security.h> | |||
#include <rfb/SecurityClient.h> | |||
#include <rfb/CConnection.h> | |||
@@ -547,7 +548,7 @@ void CConnection::requestNewUpdate() | |||
} | |||
if (encodingChange) { | |||
writer()->writeSetEncodings(preferredEncoding, true); | |||
updateEncodings(); | |||
encodingChange = false; | |||
} | |||
@@ -561,3 +562,77 @@ void CConnection::requestNewUpdate() | |||
forceNonincremental = false; | |||
} | |||
// Ask for encodings based on which decoders are supported. Assumes higher | |||
// encoding numbers are more desirable. | |||
void CConnection::updateEncodings() | |||
{ | |||
int nEncodings = 0; | |||
rdr::U32 encodings[encodingMax+3]; | |||
if (server.supportsLocalCursor) { | |||
encodings[nEncodings++] = pseudoEncodingCursorWithAlpha; | |||
encodings[nEncodings++] = pseudoEncodingCursor; | |||
encodings[nEncodings++] = pseudoEncodingXCursor; | |||
} | |||
if (server.supportsDesktopResize) | |||
encodings[nEncodings++] = pseudoEncodingDesktopSize; | |||
if (server.supportsExtendedDesktopSize) | |||
encodings[nEncodings++] = pseudoEncodingExtendedDesktopSize; | |||
if (server.supportsDesktopRename) | |||
encodings[nEncodings++] = pseudoEncodingDesktopName; | |||
if (server.supportsLEDState) | |||
encodings[nEncodings++] = pseudoEncodingLEDState; | |||
encodings[nEncodings++] = pseudoEncodingLastRect; | |||
encodings[nEncodings++] = pseudoEncodingContinuousUpdates; | |||
encodings[nEncodings++] = pseudoEncodingFence; | |||
encodings[nEncodings++] = pseudoEncodingQEMUKeyEvent; | |||
if (Decoder::supported(preferredEncoding)) { | |||
encodings[nEncodings++] = preferredEncoding; | |||
} | |||
encodings[nEncodings++] = encodingCopyRect; | |||
/* | |||
* Prefer encodings in this order: | |||
* | |||
* Tight, ZRLE, Hextile, * | |||
*/ | |||
if ((preferredEncoding != encodingTight) && | |||
Decoder::supported(encodingTight)) | |||
encodings[nEncodings++] = encodingTight; | |||
if ((preferredEncoding != encodingZRLE) && | |||
Decoder::supported(encodingZRLE)) | |||
encodings[nEncodings++] = encodingZRLE; | |||
if ((preferredEncoding != encodingHextile) && | |||
Decoder::supported(encodingHextile)) | |||
encodings[nEncodings++] = encodingHextile; | |||
// Remaining encodings | |||
for (int i = encodingMax; i >= 0; i--) { | |||
switch (i) { | |||
case encodingCopyRect: | |||
case encodingTight: | |||
case encodingZRLE: | |||
case encodingHextile: | |||
/* These have already been sent earlier */ | |||
break; | |||
default: | |||
if ((i != preferredEncoding) && Decoder::supported(i)) | |||
encodings[nEncodings++] = i; | |||
} | |||
} | |||
if (server.compressLevel >= 0 && server.compressLevel <= 9) | |||
encodings[nEncodings++] = pseudoEncodingCompressLevel0 + server.compressLevel; | |||
if (server.qualityLevel >= 0 && server.qualityLevel <= 9) | |||
encodings[nEncodings++] = pseudoEncodingQualityLevel0 + server.qualityLevel; | |||
writer()->writeSetEncodings(nEncodings, encodings); | |||
} |
@@ -201,6 +201,7 @@ namespace rfb { | |||
void securityCompleted(); | |||
void requestNewUpdate(); | |||
void updateEncodings(); | |||
rdr::InStream* is; | |||
rdr::OutStream* os; |
@@ -20,13 +20,11 @@ | |||
#include <rdr/OutStream.h> | |||
#include <rfb/msgTypes.h> | |||
#include <rfb/fenceTypes.h> | |||
#include <rfb/encodings.h> | |||
#include <rfb/qemuTypes.h> | |||
#include <rfb/Exception.h> | |||
#include <rfb/PixelFormat.h> | |||
#include <rfb/Rect.h> | |||
#include <rfb/ServerParams.h> | |||
#include <rfb/Decoder.h> | |||
#include <rfb/CMsgWriter.h> | |||
using namespace rfb; | |||
@@ -64,82 +62,6 @@ void CMsgWriter::writeSetEncodings(int nEncodings, rdr::U32* encodings) | |||
endMsg(); | |||
} | |||
// Ask for encodings based on which decoders are supported. Assumes higher | |||
// encoding numbers are more desirable. | |||
void CMsgWriter::writeSetEncodings(int preferredEncoding, bool useCopyRect) | |||
{ | |||
int nEncodings = 0; | |||
rdr::U32 encodings[encodingMax+3]; | |||
if (server->supportsLocalCursor) { | |||
encodings[nEncodings++] = pseudoEncodingCursorWithAlpha; | |||
encodings[nEncodings++] = pseudoEncodingCursor; | |||
encodings[nEncodings++] = pseudoEncodingXCursor; | |||
} | |||
if (server->supportsDesktopResize) | |||
encodings[nEncodings++] = pseudoEncodingDesktopSize; | |||
if (server->supportsExtendedDesktopSize) | |||
encodings[nEncodings++] = pseudoEncodingExtendedDesktopSize; | |||
if (server->supportsDesktopRename) | |||
encodings[nEncodings++] = pseudoEncodingDesktopName; | |||
if (server->supportsLEDState) | |||
encodings[nEncodings++] = pseudoEncodingLEDState; | |||
encodings[nEncodings++] = pseudoEncodingLastRect; | |||
encodings[nEncodings++] = pseudoEncodingContinuousUpdates; | |||
encodings[nEncodings++] = pseudoEncodingFence; | |||
encodings[nEncodings++] = pseudoEncodingQEMUKeyEvent; | |||
if (Decoder::supported(preferredEncoding)) { | |||
encodings[nEncodings++] = preferredEncoding; | |||
} | |||
if (useCopyRect) { | |||
encodings[nEncodings++] = encodingCopyRect; | |||
} | |||
/* | |||
* Prefer encodings in this order: | |||
* | |||
* Tight, ZRLE, Hextile, * | |||
*/ | |||
if ((preferredEncoding != encodingTight) && | |||
Decoder::supported(encodingTight)) | |||
encodings[nEncodings++] = encodingTight; | |||
if ((preferredEncoding != encodingZRLE) && | |||
Decoder::supported(encodingZRLE)) | |||
encodings[nEncodings++] = encodingZRLE; | |||
if ((preferredEncoding != encodingHextile) && | |||
Decoder::supported(encodingHextile)) | |||
encodings[nEncodings++] = encodingHextile; | |||
// Remaining encodings | |||
for (int i = encodingMax; i >= 0; i--) { | |||
switch (i) { | |||
case encodingCopyRect: | |||
case encodingTight: | |||
case encodingZRLE: | |||
case encodingHextile: | |||
/* These have already been sent earlier */ | |||
break; | |||
default: | |||
if ((i != preferredEncoding) && Decoder::supported(i)) | |||
encodings[nEncodings++] = i; | |||
} | |||
} | |||
if (server->compressLevel >= 0 && server->compressLevel <= 9) | |||
encodings[nEncodings++] = pseudoEncodingCompressLevel0 + server->compressLevel; | |||
if (server->qualityLevel >= 0 && server->qualityLevel <= 9) | |||
encodings[nEncodings++] = pseudoEncodingQualityLevel0 + server->qualityLevel; | |||
writeSetEncodings(nEncodings, encodings); | |||
} | |||
void CMsgWriter::writeSetDesktopSize(int width, int height, | |||
const ScreenSet& layout) | |||
{ |
@@ -44,7 +44,6 @@ namespace rfb { | |||
void writeSetPixelFormat(const PixelFormat& pf); | |||
void writeSetEncodings(int nEncodings, rdr::U32* encodings); | |||
void writeSetEncodings(int preferredEncoding, bool useCopyRect); | |||
void writeSetDesktopSize(int width, int height, const ScreenSet& layout); | |||
void writeFramebufferUpdateRequest(const Rect& r,bool incremental); |
@@ -355,7 +355,8 @@ void SConnection::approveConnection(bool accept, const char* reason) | |||
void SConnection::clientInit(bool shared) | |||
{ | |||
writer_->writeServerInit(); | |||
writer_->writeServerInit(client.width(), client.height(), | |||
client.pf(), client.name()); | |||
state_ = RFBSTATE_NORMAL; | |||
} | |||
@@ -47,12 +47,13 @@ SMsgWriter::~SMsgWriter() | |||
{ | |||
} | |||
void SMsgWriter::writeServerInit() | |||
void SMsgWriter::writeServerInit(rdr::U16 width, rdr::U16 height, | |||
const PixelFormat& pf, const char* name) | |||
{ | |||
os->writeU16(client->width()); | |||
os->writeU16(client->height()); | |||
client->pf().write(os); | |||
os->writeString(client->name()); | |||
os->writeU16(width); | |||
os->writeU16(height); | |||
pf.write(os); | |||
os->writeString(name); | |||
endMsg(); | |||
} | |||
@@ -32,6 +32,7 @@ namespace rdr { class OutStream; } | |||
namespace rfb { | |||
class ClientParams; | |||
class PixelFormat; | |||
struct ScreenSet; | |||
class SMsgWriter { | |||
@@ -41,7 +42,8 @@ namespace rfb { | |||
// writeServerInit() must only be called at the appropriate time in the | |||
// protocol initialisation. | |||
void writeServerInit(); | |||
void writeServerInit(rdr::U16 width, rdr::U16 height, | |||
const PixelFormat& pf, const char* name); | |||
// Methods to write normal protocol messages | |||