From: Pierre Ossman Date: Fri, 31 Jan 2014 10:21:51 +0000 (+0100) Subject: Handle CopyRect like any other encoding X-Git-Tag: v1.3.90~45^2~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d704e4ae77724abca7835f53390dacbfe1b09f9f;p=tigervnc.git Handle CopyRect like any other encoding Avoids having to special case things. Keeps the code simpler. --- 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 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 +#include +#include +#include +#include + +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 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 + +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 #include #include +#include #include #include #include @@ -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: