summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2014-01-31 11:21:51 +0100
committerPierre Ossman <ossman@cendio.se>2014-07-07 14:42:08 +0200
commitd704e4ae77724abca7835f53390dacbfe1b09f9f (patch)
treeafeeea0cb8e54240ce7fc8648f92f12599af81f7
parent4aba19e287b0105bb47777762ce14b3786d91019 (diff)
downloadtigervnc-d704e4ae77724abca7835f53390dacbfe1b09f9f.tar.gz
tigervnc-d704e4ae77724abca7835f53390dacbfe1b09f9f.zip
Handle CopyRect like any other encoding
Avoids having to special case things. Keeps the code simpler.
-rw-r--r--common/rfb/CMakeLists.txt1
-rw-r--r--common/rfb/CMsgReader.cxx28
-rw-r--r--common/rfb/CMsgReader.h1
-rw-r--r--common/rfb/CMsgWriter.cxx2
-rw-r--r--common/rfb/CopyRectDecoder.cxx39
-rw-r--r--common/rfb/CopyRectDecoder.h32
-rw-r--r--common/rfb/Decoder.cxx4
7 files changed, 86 insertions, 21 deletions
diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt
index da68a278..590aea77 100644
--- a/common/rfb/CMakeLists.txt
+++ b/common/rfb/CMakeLists.txt
@@ -13,6 +13,7 @@ set(RFB_SOURCES
ComparingUpdateTracker.cxx
Configuration.cxx
ConnParams.cxx
+ CopyRectDecoder.cxx
Cursor.cxx
Decoder.cxx
d3des.c
diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx
index 8466c68c..b39fd099 100644
--- a/common/rfb/CMsgReader.cxx
+++ b/common/rfb/CMsgReader.cxx
@@ -198,35 +198,23 @@ void CMsgReader::readRect(const Rect& r, int encoding)
handler->beginRect(r, encoding);
- if (encoding == encodingCopyRect) {
- readCopyRect(r);
- } else {
+ if (!Decoder::supported(encoding)) {
+ fprintf(stderr, "Unknown rect encoding %d\n", encoding);
+ throw Exception("Unknown rect encoding");
+ }
- if (!Decoder::supported(encoding)) {
+ if (!decoders[encoding]) {
+ decoders[encoding] = Decoder::createDecoder(encoding, this);
+ if (!decoders[encoding]) {
fprintf(stderr, "Unknown rect encoding %d\n", encoding);
throw Exception("Unknown rect encoding");
}
-
- if (!decoders[encoding]) {
- decoders[encoding] = Decoder::createDecoder(encoding, this);
- if (!decoders[encoding]) {
- fprintf(stderr, "Unknown rect encoding %d\n", encoding);
- throw Exception("Unknown rect encoding");
- }
- }
- decoders[encoding]->readRect(r, handler);
}
+ decoders[encoding]->readRect(r, handler);
handler->endRect(r, encoding);
}
-void CMsgReader::readCopyRect(const Rect& r)
-{
- int srcX = is->readU16();
- int srcY = is->readU16();
- handler->copyRect(r, srcX, srcY);
-}
-
void CMsgReader::readSetCursor(int width, int height, const Point& hotspot)
{
int data_len = width * height * (handler->cp.pf().bpp/8);
diff --git a/common/rfb/CMsgReader.h b/common/rfb/CMsgReader.h
index 650f1642..12846678 100644
--- a/common/rfb/CMsgReader.h
+++ b/common/rfb/CMsgReader.h
@@ -62,7 +62,6 @@ namespace rfb {
void readFramebufferUpdate();
void readRect(const Rect& r, int encoding);
- void readCopyRect(const Rect& r);
void readSetCursor(int width, int height, const Point& hotspot);
void readSetDesktopName(int x, int y, int w, int h);
diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx
index 3d51060f..6536eaf2 100644
--- a/common/rfb/CMsgWriter.cxx
+++ b/common/rfb/CMsgWriter.cxx
@@ -113,9 +113,11 @@ void CMsgWriter::writeSetEncodings(int preferredEncoding, bool useCopyRect)
// 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))
diff --git a/common/rfb/CopyRectDecoder.cxx b/common/rfb/CopyRectDecoder.cxx
new file mode 100644
index 00000000..4c835832
--- /dev/null
+++ b/common/rfb/CopyRectDecoder.cxx
@@ -0,0 +1,39 @@
+/* Copyright 2014 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+#include <rdr/InStream.h>
+#include <rfb/CMsgReader.h>
+#include <rfb/CMsgHandler.h>
+#include <rfb/PixelBuffer.h>
+#include <rfb/CopyRectDecoder.h>
+
+using namespace rfb;
+
+CopyRectDecoder::CopyRectDecoder(CMsgReader* reader) : Decoder(reader)
+{
+}
+
+CopyRectDecoder::~CopyRectDecoder()
+{
+}
+
+void CopyRectDecoder::readRect(const Rect& r, CMsgHandler* handler)
+{
+ int srcX = reader->getInStream()->readU16();
+ int srcY = reader->getInStream()->readU16();
+ handler->copyRect(r, srcX, srcY);
+}
diff --git a/common/rfb/CopyRectDecoder.h b/common/rfb/CopyRectDecoder.h
new file mode 100644
index 00000000..e265ee42
--- /dev/null
+++ b/common/rfb/CopyRectDecoder.h
@@ -0,0 +1,32 @@
+/* Copyright 2014 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+#ifndef __RFB_COPYRECTDECODER_H__
+#define __RFB_COPYRECTDECODER_H__
+
+#include <rfb/Decoder.h>
+
+namespace rfb {
+
+ class CopyRectDecoder : public Decoder {
+ public:
+ CopyRectDecoder(CMsgReader* reader);
+ virtual ~CopyRectDecoder();
+ virtual void readRect(const Rect& r, CMsgHandler* handler);
+ };
+}
+#endif
diff --git a/common/rfb/Decoder.cxx b/common/rfb/Decoder.cxx
index 9982c932..f774f28c 100644
--- a/common/rfb/Decoder.cxx
+++ b/common/rfb/Decoder.cxx
@@ -20,6 +20,7 @@
#include <rfb/encodings.h>
#include <rfb/Decoder.h>
#include <rfb/RawDecoder.h>
+#include <rfb/CopyRectDecoder.h>
#include <rfb/RREDecoder.h>
#include <rfb/HextileDecoder.h>
#include <rfb/ZRLEDecoder.h>
@@ -39,6 +40,7 @@ bool Decoder::supported(int encoding)
{
switch (encoding) {
case encodingRaw:
+ case encodingCopyRect:
case encodingRRE:
case encodingHextile:
case encodingZRLE:
@@ -54,6 +56,8 @@ Decoder* Decoder::createDecoder(int encoding, CMsgReader* reader)
switch (encoding) {
case encodingRaw:
return new RawDecoder(reader);
+ case encodingCopyRect:
+ return new CopyRectDecoder(reader);
case encodingRRE:
return new RREDecoder(reader);
case encodingHextile: