diff options
author | Pierre Ossman <ossman@cendio.se> | 2022-11-16 19:23:38 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2025-02-13 11:12:56 +0100 |
commit | 1c512f7dcd75b413a339cc48eab92e748ca2d003 (patch) | |
tree | 76d48d3446c4251f34141b04763522e83de062ae /common/rfb | |
parent | 4846e7189ab38b0c841d184f0063fe19c1c9b9a9 (diff) | |
download | tigervnc-1c512f7dcd75b413a339cc48eab92e748ca2d003.tar.gz tigervnc-1c512f7dcd75b413a339cc48eab92e748ca2d003.zip |
Move basic data types to core library
Make it clearer what is protocol handling and what is just general
plumbing.
This is one step of several.
Diffstat (limited to 'common/rfb')
67 files changed, 464 insertions, 772 deletions
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 4b97d7ac..20e343c2 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -100,7 +100,7 @@ void CConnection::setFramebuffer(ModifiablePixelBuffer* fb) } if ((framebuffer != nullptr) && (fb != nullptr)) { - Rect rect; + core::Rect rect; const uint8_t* data; int stride; @@ -493,7 +493,7 @@ void CConnection::serverInit(int width, int height, } } -bool CConnection::readAndDecodeRect(const Rect& r, int encoding, +bool CConnection::readAndDecodeRect(const core::Rect& r, int encoding, ModifiablePixelBuffer* pb) { if (!decoder.decodeRect(r, encoding, pb)) @@ -540,7 +540,7 @@ void CConnection::framebufferUpdateEnd() } } -bool CConnection::dataRect(const Rect& r, int encoding) +bool CConnection::dataRect(const core::Rect& r, int encoding) { return decoder.decodeRect(r, encoding, framebuffer); } diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h index 37f19353..9ffbd2c5 100644 --- a/common/rfb/CConnection.h +++ b/common/rfb/CConnection.h @@ -120,12 +120,12 @@ namespace rfb { void serverInit(int width, int height, const PixelFormat& pf, const char* name) override; - bool readAndDecodeRect(const Rect& r, int encoding, + bool readAndDecodeRect(const core::Rect& r, int encoding, ModifiablePixelBuffer* pb) override; void framebufferUpdateStart() override; void framebufferUpdateEnd() override; - bool dataRect(const Rect& r, int encoding) override; + bool dataRect(const core::Rect& r, int encoding) override; void serverCutText(const char* str) override; diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 36535448..ae398cf0 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -36,7 +36,6 @@ add_library(rfb STATIC RREDecoder.cxx RawDecoder.cxx RawEncoder.cxx - Region.cxx SConnection.cxx SMsgHandler.cxx SMsgReader.cxx @@ -65,10 +64,8 @@ add_library(rfb STATIC target_include_directories(rfb PUBLIC ${CMAKE_SOURCE_DIR}/common) target_include_directories(rfb SYSTEM PUBLIC ${JPEG_INCLUDE_DIR}) -target_include_directories(rfb SYSTEM PUBLIC ${PIXMAN_INCLUDE_DIRS}) -target_link_libraries(rfb os rdr network) +target_link_libraries(rfb core os rdr network) target_link_libraries(rfb ${JPEG_LIBRARIES} ${PIXMAN_LIBRARIES}) -target_link_directories(rfb PUBLIC ${PIXMAN_LIBRARY_DIRS}) if(ENABLE_H264 AND NOT H264_LIBS STREQUAL "NONE") target_sources(rfb PRIVATE H264Decoder.cxx H264DecoderContext.cxx) diff --git a/common/rfb/CMsgHandler.h b/common/rfb/CMsgHandler.h index 33c87235..e7ba2abc 100644 --- a/common/rfb/CMsgHandler.h +++ b/common/rfb/CMsgHandler.h @@ -28,13 +28,16 @@ #include <rfb/ServerParams.h> +namespace core { + struct Point; + struct Rect; +} + namespace rdr { class InStream; } namespace rfb { class ModifiablePixelBuffer; - struct Point; - struct Rect; struct ScreenSet; class CMsgHandler { @@ -53,9 +56,10 @@ namespace rfb { virtual void setExtendedDesktopSize(unsigned reason, unsigned result, int w, int h, const ScreenSet& layout); - virtual void setCursor(int width, int height, const Point& hotspot, + virtual void setCursor(int width, int height, const + core::Point& hotspot, const uint8_t* data) = 0; - virtual void setCursorPos(const Point& pos) = 0; + virtual void setCursorPos(const core::Point& pos) = 0; virtual void setName(const char* name); virtual void fence(uint32_t flags, unsigned len, const uint8_t data[]); virtual void endOfContinuousUpdates(); @@ -65,12 +69,12 @@ namespace rfb { const PixelFormat& pf, const char* name) = 0; - virtual bool readAndDecodeRect(const Rect& r, int encoding, + virtual bool readAndDecodeRect(const core::Rect& r, int encoding, ModifiablePixelBuffer* pb) = 0; virtual void framebufferUpdateStart(); virtual void framebufferUpdateEnd(); - virtual bool dataRect(const Rect& r, int encoding) = 0; + virtual bool dataRect(const core::Rect& r, int encoding) = 0; virtual void setColourMapEntries(int firstColour, int nColours, uint16_t* rgbs) = 0; diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 1d20a6fc..0ee893c3 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -473,7 +473,7 @@ bool CMsgReader::readFramebufferUpdate() return true; } -bool CMsgReader::readRect(const Rect& r, int encoding) +bool CMsgReader::readRect(const core::Rect& r, int encoding) { if ((r.br.x > handler->server.width()) || (r.br.y > handler->server.height())) { @@ -489,7 +489,8 @@ bool CMsgReader::readRect(const Rect& r, int encoding) return handler->dataRect(r, encoding); } -bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) +bool CMsgReader::readSetXCursor(int width, int height, + const core::Point& hotspot) { if (width > maxCursorSize || height > maxCursorSize) throw protocol_error("Too big cursor"); @@ -553,7 +554,8 @@ bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) return true; } -bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot) +bool CMsgReader::readSetCursor(int width, int height, + const core::Point& hotspot) { if (width > maxCursorSize || height > maxCursorSize) throw protocol_error("Too big cursor"); @@ -599,7 +601,8 @@ bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot) return true; } -bool CMsgReader::readSetCursorWithAlpha(int width, int height, const Point& hotspot) +bool CMsgReader::readSetCursorWithAlpha(int width, int height, + const core::Point& hotspot) { if (width > maxCursorSize || height > maxCursorSize) throw protocol_error("Too big cursor"); @@ -660,7 +663,8 @@ bool CMsgReader::readSetCursorWithAlpha(int width, int height, const Point& hots return true; } -bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot) +bool CMsgReader::readSetVMwareCursor(int width, int height, + const core::Point& hotspot) { if (width > maxCursorSize || height > maxCursorSize) throw protocol_error("Too big cursor"); diff --git a/common/rfb/CMsgReader.h b/common/rfb/CMsgReader.h index 4fbed0ac..e33f701d 100644 --- a/common/rfb/CMsgReader.h +++ b/common/rfb/CMsgReader.h @@ -26,13 +26,13 @@ #include <stdint.h> -#include <rfb/Rect.h> +#include <core/Rect.h> namespace rdr { class InStream; } namespace rfb { + class CMsgHandler; - struct Rect; class CMsgReader { public: @@ -58,12 +58,16 @@ namespace rfb { bool readFramebufferUpdate(); - bool readRect(const Rect& r, int encoding); + bool readRect(const core::Rect& r, int encoding); - bool readSetXCursor(int width, int height, const Point& hotspot); - bool readSetCursor(int width, int height, const Point& hotspot); - bool readSetCursorWithAlpha(int width, int height, const Point& hotspot); - bool readSetVMwareCursor(int width, int height, const Point& hotspot); + bool readSetXCursor(int width, int height, + const core::Point& hotspot); + bool readSetCursor(int width, int height, + const core::Point& hotspot); + bool readSetCursorWithAlpha(int width, int height, + const core::Point& hotspot); + bool readSetVMwareCursor(int width, int height, + const core::Point& hotspot); bool readSetDesktopName(int x, int y, int w, int h); bool readExtendedDesktopSize(int x, int y, int w, int h); bool readLEDState(); @@ -84,12 +88,14 @@ namespace rfb { uint8_t currentMsgType; int nUpdateRectsLeft; - Rect dataRect; + core::Rect dataRect; int rectEncoding; int cursorEncoding; static const int maxCursorSize = 256; }; + } + #endif diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx index 6cd2cc19..0e5cd722 100644 --- a/common/rfb/CMsgWriter.cxx +++ b/common/rfb/CMsgWriter.cxx @@ -24,6 +24,8 @@ #include <stdio.h> #include <assert.h> +#include <core/Rect.h> + #include <rdr/OutStream.h> #include <rdr/MemOutStream.h> #include <rdr/ZlibOutStream.h> @@ -33,7 +35,6 @@ #include <rfb/qemuTypes.h> #include <rfb/clipboardTypes.h> #include <rfb/PixelFormat.h> -#include <rfb/Rect.h> #include <rfb/ScreenSet.h> #include <rfb/ServerParams.h> #include <rfb/CMsgWriter.h> @@ -102,7 +103,8 @@ void CMsgWriter::writeSetDesktopSize(int width, int height, endMsg(); } -void CMsgWriter::writeFramebufferUpdateRequest(const Rect& r, bool incremental) +void CMsgWriter::writeFramebufferUpdateRequest(const core::Rect& r, + bool incremental) { startMsg(msgTypeFramebufferUpdateRequest); os->writeU8(incremental); @@ -174,9 +176,10 @@ void CMsgWriter::writeKeyEvent(uint32_t keysym, uint32_t keycode, bool down) } -void CMsgWriter::writePointerEvent(const Point& pos, uint16_t buttonMask) +void CMsgWriter::writePointerEvent(const core::Point& pos, + uint16_t buttonMask) { - Point p(pos); + core::Point p(pos); bool extendedMouseButtons; if (p.x < 0) p.x = 0; diff --git a/common/rfb/CMsgWriter.h b/common/rfb/CMsgWriter.h index 9cb4adec..d0378e62 100644 --- a/common/rfb/CMsgWriter.h +++ b/common/rfb/CMsgWriter.h @@ -27,6 +27,11 @@ #include <stdint.h> +namespace core { + struct Point; + struct Rect; +} + namespace rdr { class OutStream; } namespace rfb { @@ -34,8 +39,6 @@ namespace rfb { class PixelFormat; class ServerParams; struct ScreenSet; - struct Point; - struct Rect; class CMsgWriter { public: @@ -48,13 +51,14 @@ namespace rfb { void writeSetEncodings(const std::list<uint32_t> encodings); void writeSetDesktopSize(int width, int height, const ScreenSet& layout); - void writeFramebufferUpdateRequest(const Rect& r,bool incremental); + void writeFramebufferUpdateRequest(const core::Rect& r, + bool incremental); void writeEnableContinuousUpdates(bool enable, int x, int y, int w, int h); void writeFence(uint32_t flags, unsigned len, const uint8_t data[]); void writeKeyEvent(uint32_t keysym, uint32_t keycode, bool down); - void writePointerEvent(const Point& pos, uint16_t buttonMask); + void writePointerEvent(const core::Point& pos, uint16_t buttonMask); void writeClientCutText(const char* str); diff --git a/common/rfb/ClientParams.cxx b/common/rfb/ClientParams.cxx index 02bcae87..1aaa54fa 100644 --- a/common/rfb/ClientParams.cxx +++ b/common/rfb/ClientParams.cxx @@ -100,7 +100,7 @@ void ClientParams::setCursor(const Cursor& other) cursor_ = new Cursor(other); } -void ClientParams::setCursorPos(const Point& pos) +void ClientParams::setCursorPos(const core::Point& pos) { cursorPos_ = pos; } diff --git a/common/rfb/ClientParams.h b/common/rfb/ClientParams.h index 05ae884c..0910181b 100644 --- a/common/rfb/ClientParams.h +++ b/common/rfb/ClientParams.h @@ -28,7 +28,7 @@ #include <stdint.h> -#include <rfb/Rect.h> +#include <core/Rect.h> namespace rfb { @@ -81,8 +81,8 @@ namespace rfb { const Cursor& cursor() const { return *cursor_; } void setCursor(const Cursor& cursor); - const Point& cursorPos() const { return cursorPos_; } - void setCursorPos(const Point& pos); + const core::Point& cursorPos() const { return cursorPos_; } + void setCursorPos(const core::Point& pos); bool supportsEncoding(int32_t encoding) const; @@ -119,7 +119,7 @@ namespace rfb { PixelFormat* pf_; std::string name_; Cursor* cursor_; - Point cursorPos_; + core::Point cursorPos_; std::set<int32_t> encodings_; unsigned int ledState_; uint32_t clipFlags; diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx index 3c7e94ad..2c026cfa 100644 --- a/common/rfb/ComparingUpdateTracker.cxx +++ b/common/rfb/ComparingUpdateTracker.cxx @@ -50,8 +50,8 @@ ComparingUpdateTracker::~ComparingUpdateTracker() bool ComparingUpdateTracker::compare() { - std::vector<Rect> rects; - std::vector<Rect>::iterator i; + std::vector<core::Rect> rects; + std::vector<core::Rect>::iterator i; if (!enabled) return false; @@ -62,7 +62,7 @@ bool ComparingUpdateTracker::compare() oldFb.setSize(fb->width(), fb->height()); for (int y=0; y<fb->height(); y+=BLOCK_SIZE) { - Rect pos(0, y, fb->width(), __rfbmin(fb->height(), y+BLOCK_SIZE)); + core::Rect pos(0, y, fb->width(), __rfbmin(fb->height(), y+BLOCK_SIZE)); int srcStride; const uint8_t* srcData = fb->getBuffer(pos, &srcStride); oldFb.imageRect(pos, srcData, srcStride); @@ -79,7 +79,7 @@ bool ComparingUpdateTracker::compare() changed.get_rects(&rects); - Region newChanged; + core::Region newChanged; for (i = rects.begin(); i != rects.end(); i++) compareRect(*i, &newChanged); @@ -111,10 +111,11 @@ void ComparingUpdateTracker::disable() firstCompare = true; } -void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged) +void ComparingUpdateTracker::compareRect(const core::Rect& r, + core::Region* newChanged) { if (!r.enclosed_by(fb->getRect())) { - Rect safe; + core::Rect safe; // Crop the rect and try again safe = r.intersect(fb->getRect()); if (!safe.is_empty()) @@ -134,7 +135,7 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged) for (int blockTop = r.tl.y; blockTop < r.br.y; blockTop += BLOCK_SIZE) { // Get a strip of the source buffer - Rect pos(r.tl.x, blockTop, r.br.x, __rfbmin(r.br.y, blockTop+BLOCK_SIZE)); + core::Rect pos(r.tl.x, blockTop, r.br.x, __rfbmin(r.br.y, blockTop+BLOCK_SIZE)); int fbStride; const uint8_t* newBlockPtr = fb->getBuffer(pos, &fbStride); int newStrideBytes = fbStride * bytesPerPixel; diff --git a/common/rfb/ComparingUpdateTracker.h b/common/rfb/ComparingUpdateTracker.h index 753c4140..dbe7a4ef 100644 --- a/common/rfb/ComparingUpdateTracker.h +++ b/common/rfb/ComparingUpdateTracker.h @@ -45,7 +45,7 @@ namespace rfb { void logStats(); private: - void compareRect(const Rect& r, Region* newchanged); + void compareRect(const core::Rect& r, core::Region* newchanged); PixelBuffer* fb; ManagedPixelBuffer oldFb; bool firstCompare; diff --git a/common/rfb/CopyRectDecoder.cxx b/common/rfb/CopyRectDecoder.cxx index f7c72123..efc77c99 100644 --- a/common/rfb/CopyRectDecoder.cxx +++ b/common/rfb/CopyRectDecoder.cxx @@ -20,10 +20,12 @@ #include <config.h> #endif +#include <core/Region.h> + #include <rdr/MemInStream.h> #include <rdr/OutStream.h> + #include <rfb/PixelBuffer.h> -#include <rfb/Region.h> #include <rfb/CopyRectDecoder.h> using namespace rfb; @@ -36,7 +38,7 @@ CopyRectDecoder::~CopyRectDecoder() { } -bool CopyRectDecoder::readRect(const Rect& /*r*/, +bool CopyRectDecoder::readRect(const core::Rect& /*r*/, rdr::InStream* is, const ServerParams& /*server*/, rdr::OutStream* os) @@ -48,11 +50,11 @@ bool CopyRectDecoder::readRect(const Rect& /*r*/, } -void CopyRectDecoder::getAffectedRegion(const Rect& rect, +void CopyRectDecoder::getAffectedRegion(const core::Rect& rect, const uint8_t* buffer, size_t buflen, const ServerParams& server, - Region* region) + core::Region* region) { rdr::MemInStream is(buffer, buflen); int srcX = is.readU16(); @@ -64,7 +66,8 @@ void CopyRectDecoder::getAffectedRegion(const Rect& rect, srcY-rect.tl.y})); } -void CopyRectDecoder::decodeRect(const Rect& r, const uint8_t* buffer, +void CopyRectDecoder::decodeRect(const core::Rect& r, + const uint8_t* buffer, size_t buflen, const ServerParams& /*server*/, ModifiablePixelBuffer* pb) diff --git a/common/rfb/CopyRectDecoder.h b/common/rfb/CopyRectDecoder.h index 51651196..b1d0d38d 100644 --- a/common/rfb/CopyRectDecoder.h +++ b/common/rfb/CopyRectDecoder.h @@ -26,13 +26,13 @@ namespace rfb { public: CopyRectDecoder(); virtual ~CopyRectDecoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - void getAffectedRegion(const Rect& rect, const uint8_t* buffer, + void getAffectedRegion(const core::Rect& rect, const uint8_t* buffer, size_t buflen, const ServerParams& server, - Region* region) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + core::Region* region) override; + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; }; diff --git a/common/rfb/Cursor.cxx b/common/rfb/Cursor.cxx index 0c75eb86..764c5b62 100644 --- a/common/rfb/Cursor.cxx +++ b/common/rfb/Cursor.cxx @@ -33,7 +33,7 @@ using namespace rfb; static LogWriter vlog("Cursor"); -Cursor::Cursor(int width, int height, const Point& hotspot, +Cursor::Cursor(int width, int height, const core::Point& hotspot, const uint8_t* data_) : width_(width), height_(height), hotspot_(hotspot) { @@ -215,7 +215,7 @@ std::vector<uint8_t> Cursor::getMask() const void Cursor::crop() { - Rect busy(0, 0, width_, height_); + core::Rect busy(0, 0, width_, height_); busy = busy.intersect({hotspot_.x, hotspot_.y, hotspot_.x+1, hotspot_.y+1}); int x, y; @@ -255,9 +255,10 @@ RenderedCursor::RenderedCursor() { } -const uint8_t* RenderedCursor::getBuffer(const Rect& _r, int* stride) const +const uint8_t* RenderedCursor::getBuffer(const core::Rect& _r, + int* stride) const { - Rect r; + core::Rect r; r = _r.translate(offset.negate()); if (!r.enclosed_by(buffer.getRect())) @@ -267,10 +268,10 @@ const uint8_t* RenderedCursor::getBuffer(const Rect& _r, int* stride) const } void RenderedCursor::update(PixelBuffer* framebuffer, - Cursor* cursor, const Point& pos) + Cursor* cursor, const core::Point& pos) { - Point rawOffset, diff; - Rect clippedRect; + core::Point rawOffset, diff; + core::Rect clippedRect; const uint8_t* data; int stride; @@ -282,7 +283,7 @@ void RenderedCursor::update(PixelBuffer* framebuffer, setSize(framebuffer->width(), framebuffer->height()); rawOffset = pos.subtract(cursor->hotspot()); - clippedRect = Rect(0, 0, cursor->width(), cursor->height()) + clippedRect = core::Rect(0, 0, cursor->width(), cursor->height()) .translate(rawOffset) .intersect(framebuffer->getRect()); offset = clippedRect.tl; diff --git a/common/rfb/Cursor.h b/common/rfb/Cursor.h index 7d75251a..ef3c1b80 100644 --- a/common/rfb/Cursor.h +++ b/common/rfb/Cursor.h @@ -26,20 +26,22 @@ #include <vector> +#include <core/Rect.h> + #include <rfb/PixelBuffer.h> -#include <rfb/Rect.h> namespace rfb { class Cursor { public: - Cursor(int width, int height, const Point& hotspot, const uint8_t* data); + Cursor(int width, int height, const core::Point& hotspot, + const uint8_t* data); Cursor(const Cursor& other); ~Cursor(); int width() const { return width_; }; int height() const { return height_; }; - const Point& hotspot() const { return hotspot_; }; + const core::Point& hotspot() const { return hotspot_; }; const uint8_t* getBuffer() const { return data; }; // getBitmap() returns a monochrome version of the cursor @@ -53,7 +55,7 @@ namespace rfb { protected: int width_, height_; - Point hotspot_; + core::Point hotspot_; uint8_t* data; }; @@ -61,15 +63,16 @@ namespace rfb { public: RenderedCursor(); - Rect getEffectiveRect() const { return buffer.getRect(offset); } + core::Rect getEffectiveRect() const { return buffer.getRect(offset); } - const uint8_t* getBuffer(const Rect& r, int* stride) const override; + const uint8_t* getBuffer(const core::Rect& r, int* stride) const override; - void update(PixelBuffer* framebuffer, Cursor* cursor, const Point& pos); + void update(PixelBuffer* framebuffer, Cursor* cursor, + const core::Point& pos); protected: ManagedPixelBuffer buffer; - Point offset; + core::Point offset; }; } diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index 4effe985..542577cd 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -23,11 +23,12 @@ #include <assert.h> #include <string.h> +#include <core/Region.h> + #include <rfb/CConnection.h> #include <rfb/DecodeManager.h> #include <rfb/Decoder.h> #include <rfb/Exception.h> -#include <rfb/Region.h> #include <rfb/LogWriter.h> #include <rfb/util.h> @@ -101,7 +102,7 @@ DecodeManager::~DecodeManager() delete decoder; } -bool DecodeManager::decodeRect(const Rect& r, int encoding, +bool DecodeManager::decodeRect(const core::Rect& r, int encoding, ModifiablePixelBuffer* pb) { Decoder *decoder; @@ -344,7 +345,7 @@ void DecodeManager::DecodeThread::worker() DecodeManager::QueueEntry* DecodeManager::DecodeThread::findEntry() { - Region lockedRegion; + core::Region lockedRegion; if (manager->workQueue.empty()) return nullptr; diff --git a/common/rfb/DecodeManager.h b/common/rfb/DecodeManager.h index b11b7044..1e450976 100644 --- a/common/rfb/DecodeManager.h +++ b/common/rfb/DecodeManager.h @@ -21,11 +21,14 @@ #include <list> +#include <core/Region.h> + #include <os/Thread.h> -#include <rfb/Region.h> #include <rfb/encodings.h> +namespace core { struct Rect; } + namespace os { class Condition; class Mutex; @@ -36,17 +39,17 @@ namespace rdr { } namespace rfb { + class CConnection; class Decoder; class ModifiablePixelBuffer; - struct Rect; class DecodeManager { public: DecodeManager(CConnection *conn); ~DecodeManager(); - bool decodeRect(const Rect& r, int encoding, + bool decodeRect(const core::Rect& r, int encoding, ModifiablePixelBuffer* pb); void flush(); @@ -72,13 +75,13 @@ namespace rfb { struct QueueEntry { bool active; - Rect rect; + core::Rect rect; int encoding; Decoder* decoder; const ServerParams* server; ModifiablePixelBuffer* pb; rdr::MemOutStream* bufferStream; - Region affectedRegion; + core::Region affectedRegion; }; std::list<rdr::MemOutStream*> freeBuffers; @@ -109,6 +112,7 @@ namespace rfb { std::list<DecodeThread*> threads; std::exception *threadException; }; + } #endif diff --git a/common/rfb/Decoder.cxx b/common/rfb/Decoder.cxx index e9bc9a4f..0f1cde89 100644 --- a/common/rfb/Decoder.cxx +++ b/common/rfb/Decoder.cxx @@ -22,8 +22,10 @@ #endif #include <stdio.h> + +#include <core/Region.h> + #include <rfb/encodings.h> -#include <rfb/Region.h> #include <rfb/Decoder.h> #include <rfb/RawDecoder.h> #include <rfb/CopyRectDecoder.h> @@ -45,19 +47,19 @@ Decoder::~Decoder() { } -void Decoder::getAffectedRegion(const Rect& rect, +void Decoder::getAffectedRegion(const core::Rect& rect, const uint8_t* /*buffer*/, size_t /*buflen*/, const ServerParams& /*server*/, - Region* region) + core::Region* region) { region->reset(rect); } -bool Decoder::doRectsConflict(const Rect& /*rectA*/, +bool Decoder::doRectsConflict(const core::Rect& /*rectA*/, const uint8_t* /*bufferA*/, size_t /*buflenA*/, - const Rect& /*rectB*/, + const core::Rect& /*rectB*/, const uint8_t* /*bufferB*/, size_t /*buflenB*/, const ServerParams& /*server*/) diff --git a/common/rfb/Decoder.h b/common/rfb/Decoder.h index a5c25398..17d5296b 100644 --- a/common/rfb/Decoder.h +++ b/common/rfb/Decoder.h @@ -22,17 +22,20 @@ #include <stddef.h> #include <stdint.h> +namespace core { + class Region; + struct Rect; +} + namespace rdr { class InStream; class OutStream; } namespace rfb { + class ServerParams; class ModifiablePixelBuffer; - class Region; - - struct Rect; enum DecoderFlags { // A constant for decoders that don't need anything special @@ -55,7 +58,7 @@ namespace rfb { // InStream to the OutStream, possibly changing it along the way to // make it easier to decode. This function will always be called in // a serial manner on the main thread. - virtual bool readRect(const Rect& r, rdr::InStream* is, + virtual bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os)=0; // These functions will be called from any of the worker threads. @@ -65,17 +68,17 @@ namespace rfb { // getAffectedRegion() returns the parts of the frame buffer will // be either read from or written do when decoding this rect. The // default implementation simply returns the given rectangle. - virtual void getAffectedRegion(const Rect& rect, const uint8_t* buffer, + virtual void getAffectedRegion(const core::Rect& rect, const uint8_t* buffer, size_t buflen, const ServerParams& server, - Region* region); + core::Region* region); // doesRectsConflict() determines if two rectangles must be decoded // in the order they were received. This will only be called if the // DecoderPartiallyOrdered flag has been set. - virtual bool doRectsConflict(const Rect& rectA, + virtual bool doRectsConflict(const core::Rect& rectA, const uint8_t* bufferA, size_t buflenA, - const Rect& rectB, + const core::Rect& rectB, const uint8_t* bufferB, size_t buflenB, const ServerParams& server); @@ -84,7 +87,7 @@ namespace rfb { // given buffer, onto the ModifiablePixelBuffer. The PixelFormat of // the PixelBuffer might not match the ConnParams and it is up to // the decoder to do any necessary conversion. - virtual void decodeRect(const Rect& r, const uint8_t* buffer, + virtual void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb)=0; @@ -95,6 +98,7 @@ namespace rfb { public: const enum DecoderFlags flags; }; + } #endif diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index e60e02b1..84686ab4 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -254,12 +254,12 @@ bool EncodeManager::supported(int encoding) } } -bool EncodeManager::needsLosslessRefresh(const Region& req) +bool EncodeManager::needsLosslessRefresh(const core::Region& req) { return !lossyRegion.intersect(req).is_empty(); } -int EncodeManager::getNextLosslessRefresh(const Region& req) +int EncodeManager::getNextLosslessRefresh(const core::Region& req) { // Do we have something we can send right away? if (!pendingRefreshRegion.intersect(req).is_empty()) @@ -271,7 +271,7 @@ int EncodeManager::getNextLosslessRefresh(const Region& req) return recentChangeTimer.getNextTimeout(); } -void EncodeManager::pruneLosslessRefresh(const Region& limits) +void EncodeManager::pruneLosslessRefresh(const core::Region& limits) { lossyRegion.assign_intersect(limits); pendingRefreshRegion.assign_intersect(limits); @@ -288,7 +288,8 @@ void EncodeManager::writeUpdate(const UpdateInfo& ui, const PixelBuffer* pb, recentChangeTimer.start(RecentChangeTimeout); } -void EncodeManager::writeLosslessRefresh(const Region& req, const PixelBuffer* pb, +void EncodeManager::writeLosslessRefresh(const core::Region& req, + const PixelBuffer* pb, const RenderedCursor* renderedCursor, size_t maxUpdateSize) { @@ -310,13 +311,15 @@ void EncodeManager::handleTimeout(Timer* t) } } -void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, - const Region& copied, const Point& copyDelta, +void EncodeManager::doUpdate(bool allowLossy, const + core::Region& changed_, + const core::Region& copied, + const core::Point& copyDelta, const PixelBuffer* pb, const RenderedCursor* renderedCursor) { int nRects; - Region changed, cursorRegion; + core::Region changed, cursorRegion; updates++; @@ -485,11 +488,11 @@ void EncodeManager::prepareEncoders(bool allowLossy) } } -Region EncodeManager::getLosslessRefresh(const Region& req, - size_t maxUpdateSize) +core::Region EncodeManager::getLosslessRefresh(const core::Region& req, + size_t maxUpdateSize) { - std::vector<Rect> rects; - Region refresh; + std::vector<core::Rect> rects; + core::Region refresh; size_t area; // We make a conservative guess at the compression ratio at 2:1 @@ -502,7 +505,7 @@ Region EncodeManager::getLosslessRefresh(const Region& req, pendingRefreshRegion.intersect(req).get_rects(&rects); while (!rects.empty()) { size_t idx; - Rect rect; + core::Rect rect; // Grab a random rect so we don't keep damaging and restoring the // same rect over and over @@ -534,11 +537,11 @@ Region EncodeManager::getLosslessRefresh(const Region& req, return refresh; } -int EncodeManager::computeNumRects(const Region& changed) +int EncodeManager::computeNumRects(const core::Region& changed) { int numRects; - std::vector<Rect> rects; - std::vector<Rect>::const_iterator rect; + std::vector<core::Rect> rects; + std::vector<core::Rect>::const_iterator rect; numRects = 0; changed.get_rects(&rects); @@ -568,7 +571,7 @@ int EncodeManager::computeNumRects(const Region& changed) return numRects; } -Encoder *EncodeManager::startRect(const Rect& rect, int type) +Encoder* EncodeManager::startRect(const core::Rect& rect, int type) { Encoder *encoder; int klass, equiv; @@ -613,12 +616,13 @@ void EncodeManager::endRect() stats[klass][activeType].bytes += length; } -void EncodeManager::writeCopyRects(const Region& copied, const Point& delta) +void EncodeManager::writeCopyRects(const core::Region& copied, + const core::Point& delta) { - std::vector<Rect> rects; - std::vector<Rect>::const_iterator rect; + std::vector<core::Rect> rects; + std::vector<core::Rect>::const_iterator rect; - Region lossyCopy; + core::Region lossyCopy; beforeLength = conn->getOutStream()->length(); @@ -647,20 +651,22 @@ void EncodeManager::writeCopyRects(const Region& copied, const Point& delta) pendingRefreshRegion.assign_subtract(copied); } -void EncodeManager::writeSolidRects(Region *changed, const PixelBuffer* pb) +void EncodeManager::writeSolidRects(core::Region* changed, + const PixelBuffer* pb) { - std::vector<Rect> rects; - std::vector<Rect>::const_iterator rect; + std::vector<core::Rect> rects; + std::vector<core::Rect>::const_iterator rect; changed->get_rects(&rects); for (rect = rects.begin(); rect != rects.end(); ++rect) findSolidRect(*rect, changed, pb); } -void EncodeManager::findSolidRect(const Rect& rect, Region *changed, +void EncodeManager::findSolidRect(const core::Rect& rect, + core::Region* changed, const PixelBuffer* pb) { - Rect sr; + core::Rect sr; int dx, dy, dw, dh; // We start by finding a solid 16x16 block @@ -683,7 +689,7 @@ void EncodeManager::findSolidRect(const Rect& rect, Region *changed, sr.setXYWH(dx, dy, dw, dh); if (checkSolidTile(sr, colourValue, pb)) { - Rect erb, erp; + core::Rect erb, erp; Encoder *encoder; @@ -754,15 +760,16 @@ void EncodeManager::findSolidRect(const Rect& rect, Region *changed, } } -void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb) +void EncodeManager::writeRects(const core::Region& changed, + const PixelBuffer* pb) { - std::vector<Rect> rects; - std::vector<Rect>::const_iterator rect; + std::vector<core::Rect> rects; + std::vector<core::Rect>::const_iterator rect; changed.get_rects(&rects); for (rect = rects.begin(); rect != rects.end(); ++rect) { int w, h, sw, sh; - Rect sr; + core::Rect sr; w = rect->width(); h = rect->height(); @@ -796,7 +803,8 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb) } } -void EncodeManager::writeSubRect(const Rect& rect, const PixelBuffer *pb) +void EncodeManager::writeSubRect(const core::Rect& rect, + const PixelBuffer* pb) { PixelBuffer *ppb; @@ -880,7 +888,8 @@ void EncodeManager::writeSubRect(const Rect& rect, const PixelBuffer *pb) endRect(); } -bool EncodeManager::checkSolidTile(const Rect& r, const uint8_t* colourValue, +bool EncodeManager::checkSolidTile(const core::Rect& r, + const uint8_t* colourValue, const PixelBuffer *pb) { const uint8_t* buffer; @@ -904,13 +913,14 @@ bool EncodeManager::checkSolidTile(const Rect& r, const uint8_t* colourValue, } } -void EncodeManager::extendSolidAreaByBlock(const Rect& r, +void EncodeManager::extendSolidAreaByBlock(const core::Rect& r, const uint8_t* colourValue, - const PixelBuffer *pb, Rect* er) + const PixelBuffer* pb, + core::Rect* er) { int dx, dy, dw, dh; int w_prev; - Rect sr; + core::Rect sr; int w_best = 0, h_best = 0; w_prev = r.width(); @@ -960,12 +970,14 @@ void EncodeManager::extendSolidAreaByBlock(const Rect& r, er->br.y = er->tl.y + h_best; } -void EncodeManager::extendSolidAreaByPixel(const Rect& r, const Rect& sr, +void EncodeManager::extendSolidAreaByPixel(const core::Rect& r, + const core::Rect& sr, const uint8_t* colourValue, - const PixelBuffer *pb, Rect* er) + const PixelBuffer* pb, + core::Rect* er) { int cx, cy; - Rect tr; + core::Rect tr; // Try to extend the area upwards. for (cy = sr.tl.y - 1; cy >= r.tl.y; cy--) { @@ -1000,7 +1012,7 @@ void EncodeManager::extendSolidAreaByPixel(const Rect& r, const Rect& sr, er->br.x = cx; } -PixelBuffer* EncodeManager::preparePixelBuffer(const Rect& rect, +PixelBuffer* EncodeManager::preparePixelBuffer(const core::Rect& rect, const PixelBuffer *pb, bool convert) { @@ -1065,7 +1077,7 @@ void EncodeManager::OffsetPixelBuffer::update(const PixelFormat& pf, setBuffer(width, height, (uint8_t*)data_, stride_); } -uint8_t* EncodeManager::OffsetPixelBuffer::getBufferRW(const Rect& /*r*/, int* /*stride*/) +uint8_t* EncodeManager::OffsetPixelBuffer::getBufferRW(const core::Rect& /*r*/, int* /*stride*/) { throw std::logic_error("Invalid write attempt to OffsetPixelBuffer"); } diff --git a/common/rfb/EncodeManager.h b/common/rfb/EncodeManager.h index 7ae9b5b8..1bc221aa 100644 --- a/common/rfb/EncodeManager.h +++ b/common/rfb/EncodeManager.h @@ -24,17 +24,18 @@ #include <stdint.h> +#include <core/Region.h> + #include <rfb/PixelBuffer.h> -#include <rfb/Region.h> #include <rfb/Timer.h> namespace rfb { + class SConnection; class Encoder; class UpdateInfo; class PixelBuffer; class RenderedCursor; - struct Rect; struct RectInfo; @@ -48,51 +49,58 @@ namespace rfb { // Hack to let ConnParams calculate the client's preferred encoding static bool supported(int encoding); - bool needsLosslessRefresh(const Region& req); - int getNextLosslessRefresh(const Region& req); + bool needsLosslessRefresh(const core::Region& req); + int getNextLosslessRefresh(const core::Region& req); - void pruneLosslessRefresh(const Region& limits); + void pruneLosslessRefresh(const core::Region& limits); void writeUpdate(const UpdateInfo& ui, const PixelBuffer* pb, const RenderedCursor* renderedCursor); - void writeLosslessRefresh(const Region& req, const PixelBuffer* pb, + void writeLosslessRefresh(const core::Region& req, + const PixelBuffer* pb, const RenderedCursor* renderedCursor, size_t maxUpdateSize); protected: void handleTimeout(Timer* t) override; - void doUpdate(bool allowLossy, const Region& changed, - const Region& copied, const Point& copy_delta, + void doUpdate(bool allowLossy, const core::Region& changed, + const core::Region& copied, + const core::Point& copy_delta, const PixelBuffer* pb, const RenderedCursor* renderedCursor); void prepareEncoders(bool allowLossy); - Region getLosslessRefresh(const Region& req, size_t maxUpdateSize); + core::Region getLosslessRefresh(const core::Region& req, + size_t maxUpdateSize); - int computeNumRects(const Region& changed); + int computeNumRects(const core::Region& changed); - Encoder *startRect(const Rect& rect, int type); + Encoder* startRect(const core::Rect& rect, int type); void endRect(); - void writeCopyRects(const Region& copied, const Point& delta); - void writeSolidRects(Region *changed, const PixelBuffer* pb); - void findSolidRect(const Rect& rect, Region *changed, const PixelBuffer* pb); - void writeRects(const Region& changed, const PixelBuffer* pb); + void writeCopyRects(const core::Region& copied, + const core::Point& delta); + void writeSolidRects(core::Region* changed, const PixelBuffer* pb); + void findSolidRect(const core::Rect& rect, core::Region* changed, + const PixelBuffer* pb); + void writeRects(const core::Region& changed, const PixelBuffer* pb); - void writeSubRect(const Rect& rect, const PixelBuffer *pb); + void writeSubRect(const core::Rect& rect, const PixelBuffer* pb); - bool checkSolidTile(const Rect& r, const uint8_t* colourValue, + bool checkSolidTile(const core::Rect& r, const uint8_t* colourValue, const PixelBuffer *pb); - void extendSolidAreaByBlock(const Rect& r, const uint8_t* colourValue, - const PixelBuffer *pb, Rect* er); - void extendSolidAreaByPixel(const Rect& r, const Rect& sr, + void extendSolidAreaByBlock(const core::Rect& r, const uint8_t* colourValue, - const PixelBuffer *pb, Rect* er); + const PixelBuffer* pb, core::Rect* er); + void extendSolidAreaByPixel(const core::Rect& r, + const core::Rect& sr, + const uint8_t* colourValue, + const PixelBuffer* pb, core::Rect* er); - PixelBuffer* preparePixelBuffer(const Rect& rect, - const PixelBuffer *pb, bool convert); + PixelBuffer* preparePixelBuffer(const core::Rect& rect, + const PixelBuffer* pb, bool convert); bool analyseRect(const PixelBuffer *pb, struct RectInfo *info, int maxColours); @@ -114,9 +122,9 @@ namespace rfb { std::vector<Encoder*> encoders; std::vector<int> activeEncoders; - Region lossyRegion; - Region recentlyChangedRegion; - Region pendingRefreshRegion; + core::Region lossyRegion; + core::Region recentlyChangedRegion; + core::Region pendingRefreshRegion; Timer recentChangeTimer; @@ -143,12 +151,13 @@ namespace rfb { const uint8_t* data_, int stride); private: - uint8_t* getBufferRW(const Rect& r, int* stride) override; + uint8_t* getBufferRW(const core::Rect& r, int* stride) override; }; OffsetPixelBuffer offsetPixelBuffer; ManagedPixelBuffer convertedPixelBuffer; }; + } #endif diff --git a/common/rfb/H264Decoder.cxx b/common/rfb/H264Decoder.cxx index bb07d8bf..d0d9b4df 100644 --- a/common/rfb/H264Decoder.cxx +++ b/common/rfb/H264Decoder.cxx @@ -55,7 +55,7 @@ void H264Decoder::resetContexts() contexts.clear(); } -H264DecoderContext* H264Decoder::findContext(const Rect& r) +H264DecoderContext* H264Decoder::findContext(const core::Rect& r) { for (H264DecoderContext* context : contexts) if (context->isEqualRect(r)) @@ -63,7 +63,7 @@ H264DecoderContext* H264Decoder::findContext(const Rect& r) return nullptr; } -bool H264Decoder::readRect(const Rect& /*r*/, +bool H264Decoder::readRect(const core::Rect& /*r*/, rdr::InStream* is, const ServerParams& /*server*/, rdr::OutStream* os) @@ -91,7 +91,7 @@ bool H264Decoder::readRect(const Rect& /*r*/, return true; } -void H264Decoder::decodeRect(const Rect& r, const uint8_t* buffer, +void H264Decoder::decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& /*server*/, ModifiablePixelBuffer* pb) diff --git a/common/rfb/H264Decoder.h b/common/rfb/H264Decoder.h index 6f2dabfb..bc1b9281 100644 --- a/common/rfb/H264Decoder.h +++ b/common/rfb/H264Decoder.h @@ -32,16 +32,16 @@ namespace rfb { public: H264Decoder(); virtual ~H264Decoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; private: void resetContexts(); - H264DecoderContext* findContext(const Rect& r); + H264DecoderContext* findContext(const core::Rect& r); std::list<H264DecoderContext*> contexts; }; diff --git a/common/rfb/H264DecoderContext.cxx b/common/rfb/H264DecoderContext.cxx index 4748abe0..3ad8c343 100644 --- a/common/rfb/H264DecoderContext.cxx +++ b/common/rfb/H264DecoderContext.cxx @@ -34,7 +34,7 @@ using namespace rfb; -H264DecoderContext *H264DecoderContext::createContext(const Rect &r) +H264DecoderContext *H264DecoderContext::createContext(const core::Rect &r) { return new H264DecoderContextType(r); } diff --git a/common/rfb/H264DecoderContext.h b/common/rfb/H264DecoderContext.h index c62b48c4..5ef46662 100644 --- a/common/rfb/H264DecoderContext.h +++ b/common/rfb/H264DecoderContext.h @@ -23,7 +23,7 @@ #include <stdint.h> -#include <rfb/Rect.h> +#include <core/Rect.h> namespace rfb { @@ -31,7 +31,7 @@ namespace rfb { class H264DecoderContext { public: - static H264DecoderContext *createContext(const Rect &r); + static H264DecoderContext* createContext(const core::Rect& r); virtual ~H264DecoderContext() = 0; @@ -39,12 +39,12 @@ namespace rfb { uint32_t /*len*/, ModifiablePixelBuffer* /*pb*/) {} - inline bool isEqualRect(const Rect &r) const { return r == rect; } + inline bool isEqualRect(const core::Rect &r) const { return r == rect; } protected: - rfb::Rect rect; + core::Rect rect; - H264DecoderContext(const Rect &r) : rect(r) {} + H264DecoderContext(const core::Rect &r) : rect(r) {} }; } diff --git a/common/rfb/H264LibavDecoderContext.cxx b/common/rfb/H264LibavDecoderContext.cxx index 22c537c2..ba1b1b6d 100644 --- a/common/rfb/H264LibavDecoderContext.cxx +++ b/common/rfb/H264LibavDecoderContext.cxx @@ -41,7 +41,7 @@ extern "C" { using namespace rfb; -H264LibavDecoderContext::H264LibavDecoderContext(const Rect& r) +H264LibavDecoderContext::H264LibavDecoderContext(const core::Rect& r) : H264DecoderContext(r) { sws = nullptr; diff --git a/common/rfb/H264LibavDecoderContext.h b/common/rfb/H264LibavDecoderContext.h index 3d2d5e76..c23fdf79 100644 --- a/common/rfb/H264LibavDecoderContext.h +++ b/common/rfb/H264LibavDecoderContext.h @@ -31,7 +31,7 @@ extern "C" { namespace rfb { class H264LibavDecoderContext : public H264DecoderContext { public: - H264LibavDecoderContext(const Rect &r); + H264LibavDecoderContext(const core::Rect &r); ~H264LibavDecoderContext(); void decode(const uint8_t* h264_buffer, uint32_t len, diff --git a/common/rfb/H264WinDecoderContext.cxx b/common/rfb/H264WinDecoderContext.cxx index b90b6d40..71086fad 100644 --- a/common/rfb/H264WinDecoderContext.cxx +++ b/common/rfb/H264WinDecoderContext.cxx @@ -39,7 +39,7 @@ using namespace rfb; static GUID CLSID_VideoProcessorMFT = { 0x88753b26, 0x5b24, 0x49bd, { 0xb2, 0xe7, 0xc, 0x44, 0x5c, 0x78, 0xc9, 0x82 } }; #endif -H264WinDecoderContext::H264WinDecoderContext(const Rect &r) +H264WinDecoderContext::H264WinDecoderContext(const core::Rect &r) : H264DecoderContext(r) { if (FAILED(MFStartup(MF_VERSION, MFSTARTUP_LITE))) diff --git a/common/rfb/H264WinDecoderContext.h b/common/rfb/H264WinDecoderContext.h index 7402ed58..b1dbf0e1 100644 --- a/common/rfb/H264WinDecoderContext.h +++ b/common/rfb/H264WinDecoderContext.h @@ -30,7 +30,7 @@ namespace rfb { class H264WinDecoderContext : public H264DecoderContext { public: - H264WinDecoderContext(const Rect &r); + H264WinDecoderContext(const core::Rect &r); ~H264WinDecoderContext(); void decode(const uint8_t* h264_buffer, uint32_t len, diff --git a/common/rfb/HextileDecoder.cxx b/common/rfb/HextileDecoder.cxx index 35ec7928..0adffd54 100644 --- a/common/rfb/HextileDecoder.cxx +++ b/common/rfb/HextileDecoder.cxx @@ -41,10 +41,10 @@ HextileDecoder::~HextileDecoder() { } -bool HextileDecoder::readRect(const Rect& r, rdr::InStream* is, +bool HextileDecoder::readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) { - Rect t; + core::Rect t; size_t bytesPerPixel; is->setRestorePoint(); @@ -113,7 +113,7 @@ bool HextileDecoder::readRect(const Rect& r, rdr::InStream* is, return true; } -void HextileDecoder::decodeRect(const Rect& r, const uint8_t* buffer, +void HextileDecoder::decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) { @@ -138,11 +138,11 @@ inline T HextileDecoder::readPixel(rdr::InStream* is) } template<class T> -void HextileDecoder::hextileDecode(const Rect& r, rdr::InStream* is, +void HextileDecoder::hextileDecode(const core::Rect& r, rdr::InStream* is, const PixelFormat& pf, ModifiablePixelBuffer* pb) { - Rect t; + core::Rect t; T bg = 0; T fg = 0; T buf[16 * 16]; diff --git a/common/rfb/HextileDecoder.h b/common/rfb/HextileDecoder.h index 38e8b776..6ff94a1f 100644 --- a/common/rfb/HextileDecoder.h +++ b/common/rfb/HextileDecoder.h @@ -29,17 +29,17 @@ namespace rfb { public: HextileDecoder(); virtual ~HextileDecoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; private: template<class T> inline T readPixel(rdr::InStream* is); template<class T> - void hextileDecode(const Rect& r, rdr::InStream* is, + void hextileDecode(const core::Rect& r, rdr::InStream* is, const PixelFormat& pf, ModifiablePixelBuffer* pb); }; diff --git a/common/rfb/HextileEncoder.cxx b/common/rfb/HextileEncoder.cxx index baf7b98b..11f9af72 100644 --- a/common/rfb/HextileEncoder.cxx +++ b/common/rfb/HextileEncoder.cxx @@ -117,7 +117,7 @@ template<class T> void HextileEncoder::hextileEncode(rdr::OutStream* os, const PixelBuffer* pb) { - Rect t; + core::Rect t; T buf[256]; T oldBg = 0, oldFg = 0; bool oldBgValid = false; @@ -534,7 +534,7 @@ template<class T> void HextileEncoder::hextileEncodeBetter(rdr::OutStream* os, const PixelBuffer* pb) { - Rect t; + core::Rect t; T buf[256]; T oldBg = 0, oldFg = 0; bool oldBgValid = false; diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx index 67a86cd9..d8216c99 100644 --- a/common/rfb/JpegCompressor.cxx +++ b/common/rfb/JpegCompressor.cxx @@ -24,8 +24,9 @@ #include <stdexcept> +#include <core/Rect.h> + #include <rfb/JpegCompressor.h> -#include <rfb/Rect.h> #include <rfb/PixelFormat.h> #include <rfb/ClientParams.h> @@ -157,7 +158,8 @@ JpegCompressor::~JpegCompressor(void) } void JpegCompressor::compress(const uint8_t *buf, volatile int stride, - const Rect& r, const PixelFormat& pf, + const core::Rect& r, + const PixelFormat& pf, int quality, int subsamp) { int w = r.width(); diff --git a/common/rfb/JpegCompressor.h b/common/rfb/JpegCompressor.h index 8ebbd310..2460f62b 100644 --- a/common/rfb/JpegCompressor.h +++ b/common/rfb/JpegCompressor.h @@ -25,6 +25,8 @@ #ifndef __RFB_JPEGCOMPRESSOR_H__ #define __RFB_JPEGCOMPRESSOR_H__ +#include <core/Rect.h> + #include <rdr/MemOutStream.h> struct jpeg_compress_struct; @@ -44,7 +46,8 @@ namespace rfb { JpegCompressor(int bufferLen = 128*1024); virtual ~JpegCompressor(); - void compress(const uint8_t *, int, const Rect&, const PixelFormat&, int, int); + void compress(const uint8_t*, int, const core::Rect&, + const PixelFormat&, int, int); void writeBytes(const uint8_t*, int); diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx index 10c9e49c..ef548be0 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -23,9 +23,10 @@ #include <config.h> #endif +#include <core/Rect.h> + #include <rfb/JpegDecompressor.h> #include <rfb/Exception.h> -#include <rfb/Rect.h> #include <rfb/PixelFormat.h> #include <stdio.h> @@ -153,7 +154,8 @@ JpegDecompressor::~JpegDecompressor(void) void JpegDecompressor::decompress(const uint8_t *jpegBuf, int jpegBufLen, uint8_t *buf, volatile int stride, - const Rect& r, const PixelFormat& pf) + const core::Rect& r, + const PixelFormat& pf) { int w = r.width(); int h = r.height(); diff --git a/common/rfb/JpegDecompressor.h b/common/rfb/JpegDecompressor.h index cbf0485a..8e651b1c 100644 --- a/common/rfb/JpegDecompressor.h +++ b/common/rfb/JpegDecompressor.h @@ -33,10 +33,11 @@ struct jpeg_decompress_struct; struct JPEG_ERROR_MGR; struct JPEG_SRC_MGR; +namespace core { struct Rect; } + namespace rfb { class PixelFormat; - struct Rect; class JpegDecompressor { @@ -45,8 +46,8 @@ namespace rfb { JpegDecompressor(void); virtual ~JpegDecompressor(); - void decompress(const uint8_t *, int, uint8_t *, int, const Rect&, - const PixelFormat&); + void decompress(const uint8_t*, int, uint8_t*, int, + const core::Rect&, const PixelFormat&); private: diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index 5590c214..fff4f8ba 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -63,7 +63,8 @@ PixelBuffer::~PixelBuffer() {} void -PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) const +PixelBuffer::getImage(void* imageBuf, const core::Rect& r, + int outStride) const { int inStride; const uint8_t* data; @@ -98,7 +99,7 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) const } void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, - const Rect& r, int stride) const + const core::Rect& r, int stride) const { const uint8_t* srcBuffer; int srcStride; @@ -150,7 +151,8 @@ ModifiablePixelBuffer::~ModifiablePixelBuffer() { } -void ModifiablePixelBuffer::fillRect(const Rect& r, const void* pix) +void ModifiablePixelBuffer::fillRect(const core::Rect& r, + const void* pix) { int stride; uint8_t *buf; @@ -199,7 +201,7 @@ void ModifiablePixelBuffer::fillRect(const Rect& r, const void* pix) commitBufferRW(r); } -void ModifiablePixelBuffer::imageRect(const Rect& r, +void ModifiablePixelBuffer::imageRect(const core::Rect& r, const void* pixels, int srcStride) { uint8_t* dest; @@ -237,15 +239,15 @@ void ModifiablePixelBuffer::imageRect(const Rect& r, commitBufferRW(r); } -void ModifiablePixelBuffer::copyRect(const Rect &rect, - const Point &move_by_delta) +void ModifiablePixelBuffer::copyRect(const core::Rect& rect, + const core::Point& move_by_delta) { int srcStride, dstStride; int bytesPerPixel; const uint8_t* srcData; uint8_t* dstData; - Rect drect, srect; + core::Rect drect, srect; drect = rect; if (!drect.enclosed_by(getRect())) @@ -297,7 +299,8 @@ void ModifiablePixelBuffer::copyRect(const Rect &rect, commitBufferRW(drect); } -void ModifiablePixelBuffer::fillRect(const PixelFormat& pf, const Rect &dest, +void ModifiablePixelBuffer::fillRect(const PixelFormat& pf, + const core::Rect& dest, const void* pix) { uint8_t buf[4]; @@ -305,7 +308,8 @@ void ModifiablePixelBuffer::fillRect(const PixelFormat& pf, const Rect &dest, fillRect(dest, buf); } -void ModifiablePixelBuffer::imageRect(const PixelFormat& pf, const Rect &dest, +void ModifiablePixelBuffer::imageRect(const PixelFormat& pf, + const core::Rect& dest, const void* pixels, int stride) { uint8_t* dstBuffer; @@ -339,7 +343,8 @@ FullFramePixelBuffer::FullFramePixelBuffer() : data(nullptr) {} FullFramePixelBuffer::~FullFramePixelBuffer() {} -uint8_t* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) +uint8_t* FullFramePixelBuffer::getBufferRW(const core::Rect& r, + int* stride_) { if (!r.enclosed_by(getRect())) throw std::out_of_range(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", @@ -351,11 +356,12 @@ uint8_t* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)]; } -void FullFramePixelBuffer::commitBufferRW(const Rect& /*r*/) +void FullFramePixelBuffer::commitBufferRW(const core::Rect& /*r*/) { } -const uint8_t* FullFramePixelBuffer::getBuffer(const Rect& r, int* stride_) const +const uint8_t* FullFramePixelBuffer::getBuffer(const core::Rect& r, + int* stride_) const { if (!r.enclosed_by(getRect())) throw std::out_of_range(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h index 4db91d14..9fbea611 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -25,12 +25,13 @@ #ifndef __RFB_PIXEL_BUFFER_H__ #define __RFB_PIXEL_BUFFER_H__ +#include <core/Rect.h> + #include <rfb/PixelFormat.h> -#include <rfb/Rect.h> -namespace rfb { +namespace core { class Region; } - class Region; +namespace rfb { class PixelBuffer { public: @@ -52,8 +53,8 @@ namespace rfb { // Get rectangle encompassing this buffer // Top-left of rectangle is either at (0,0), or the specified point. - Rect getRect() const { return {0, 0, width_, height_}; } - Rect getRect(const Point& pos) const { + core::Rect getRect() const { return {0, 0, width_, height_}; } + core::Rect getRect(const core::Point& pos) const { return {pos, pos.translate({width_, height_})}; } @@ -64,18 +65,20 @@ namespace rfb { // Get a pointer into the buffer // The pointer is to the top-left pixel of the specified Rect. // The buffer stride (in pixels) is returned. - virtual const uint8_t* getBuffer(const Rect& r, int* stride) const = 0; + virtual const uint8_t* getBuffer(const core::Rect& r, + int* stride) const = 0; // Get pixel data for a given part of the buffer // Data is copied into the supplied buffer, with the specified // stride. Try to avoid using this though as getBuffer() will in // most cases avoid the extra memory copy. - void getImage(void* imageBuf, const Rect& r, int stride=0) const; + void getImage(void* imageBuf, const core::Rect& r, + int stride=0) const; // Get pixel data in a given format // Works just the same as getImage(), but guaranteed to be in a // specific format. void getImage(const PixelFormat& pf, void* imageBuf, - const Rect& r, int stride=0) const; + const core::Rect& r, int stride=0) const; /////////////////////////////////////////////// // Framebuffer update methods @@ -84,7 +87,7 @@ namespace rfb { // Ensure that the specified rectangle of buffer is up to date. // Overridden by derived classes implementing framebuffer access // to copy the required display data into place. - virtual void grabRegion(const Region& /*region*/) {} + virtual void grabRegion(const core::Region& /*region*/) {} protected: PixelBuffer(); @@ -110,32 +113,35 @@ namespace rfb { // Get a writeable pointer into the buffer // Like getBuffer(), the pointer is to the top-left pixel of the // specified Rect and the stride in pixels is returned. - virtual uint8_t* getBufferRW(const Rect& r, int* stride) = 0; + virtual uint8_t* getBufferRW(const core::Rect& r, int* stride) = 0; // Commit the modified contents // Ensures that the changes to the specified Rect is properly // stored away and any temporary buffers are freed. The Rect given // here needs to match the Rect given to the earlier call to // getBufferRW(). - virtual void commitBufferRW(const Rect& r) = 0; + virtual void commitBufferRW(const core::Rect& r) = 0; /////////////////////////////////////////////// // Basic rendering operations // These operations DO NOT clip to the pixelbuffer area, or trap overruns. // Fill a rectangle - void fillRect(const Rect &dest, const void* pix); + void fillRect(const core::Rect& dest, const void* pix); // Copy pixel data to the buffer - void imageRect(const Rect &dest, const void* pixels, int stride=0); + void imageRect(const core::Rect& dest, const void* pixels, + int stride=0); // Copy pixel data from one PixelBuffer location to another - void copyRect(const Rect &dest, const Point& move_by_delta); + void copyRect(const core::Rect& dest, + const core::Point& move_by_delta); // Render in a specific format // Does the exact same thing as the above methods, but the given // pixel values are defined by the given PixelFormat. - void fillRect(const PixelFormat& pf, const Rect &dest, const void* pix); - void imageRect(const PixelFormat& pf, const Rect &dest, + void fillRect(const PixelFormat& pf, const core::Rect& dest, + const void* pix); + void imageRect(const PixelFormat& pf, const core::Rect& dest, const void* pixels, int stride=0); protected: @@ -151,9 +157,10 @@ namespace rfb { virtual ~FullFramePixelBuffer(); public: - const uint8_t* getBuffer(const Rect& r, int* stride) const override; - uint8_t* getBufferRW(const Rect& r, int* stride) override; - void commitBufferRW(const Rect& r) override; + const uint8_t* getBuffer(const core::Rect& r, + int* stride) const override; + uint8_t* getBufferRW(const core::Rect& r, int* stride) override; + void commitBufferRW(const core::Rect& r) override; protected: FullFramePixelBuffer(); diff --git a/common/rfb/RREDecoder.cxx b/common/rfb/RREDecoder.cxx index fb8681f5..d2c3d3e6 100644 --- a/common/rfb/RREDecoder.cxx +++ b/common/rfb/RREDecoder.cxx @@ -40,7 +40,7 @@ RREDecoder::~RREDecoder() { } -bool RREDecoder::readRect(const Rect& /*r*/, rdr::InStream* is, +bool RREDecoder::readRect(const core::Rect& /*r*/, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) { uint32_t numRects; @@ -66,7 +66,7 @@ bool RREDecoder::readRect(const Rect& /*r*/, rdr::InStream* is, return true; } -void RREDecoder::decodeRect(const Rect& r, const uint8_t* buffer, +void RREDecoder::decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) { @@ -91,7 +91,7 @@ inline T RREDecoder::readPixel(rdr::InStream* is) } template<class T> -void RREDecoder::rreDecode(const Rect& r, rdr::InStream* is, +void RREDecoder::rreDecode(const core::Rect& r, rdr::InStream* is, const PixelFormat& pf, ModifiablePixelBuffer* pb) { diff --git a/common/rfb/RREDecoder.h b/common/rfb/RREDecoder.h index 8490146c..3fdcdd85 100644 --- a/common/rfb/RREDecoder.h +++ b/common/rfb/RREDecoder.h @@ -29,17 +29,17 @@ namespace rfb { public: RREDecoder(); virtual ~RREDecoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; private: template<class T> inline T readPixel(rdr::InStream* is); template<class T> - void rreDecode(const Rect& r, rdr::InStream* is, + void rreDecode(const core::Rect& r, rdr::InStream* is, const PixelFormat& pf, ModifiablePixelBuffer* pb); }; } diff --git a/common/rfb/RawDecoder.cxx b/common/rfb/RawDecoder.cxx index f2ea586b..43ce15a4 100644 --- a/common/rfb/RawDecoder.cxx +++ b/common/rfb/RawDecoder.cxx @@ -37,7 +37,7 @@ RawDecoder::~RawDecoder() { } -bool RawDecoder::readRect(const Rect& r, rdr::InStream* is, +bool RawDecoder::readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) { if (!is->hasData(r.area() * (server.pf().bpp/8))) @@ -46,7 +46,7 @@ bool RawDecoder::readRect(const Rect& r, rdr::InStream* is, return true; } -void RawDecoder::decodeRect(const Rect& r, const uint8_t* buffer, +void RawDecoder::decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) { diff --git a/common/rfb/RawDecoder.h b/common/rfb/RawDecoder.h index 2ac8b0bd..6c3a6357 100644 --- a/common/rfb/RawDecoder.h +++ b/common/rfb/RawDecoder.h @@ -25,10 +25,10 @@ namespace rfb { public: RawDecoder(); virtual ~RawDecoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; }; diff --git a/common/rfb/Rect.h b/common/rfb/Rect.h deleted file mode 100644 index b82ed274..00000000 --- a/common/rfb/Rect.h +++ /dev/null @@ -1,130 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * - * 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. - */ - -// rfb::Rect and rfb::Point structures - -#ifndef __RFB_RECT_INCLUDED__ -#define __RFB_RECT_INCLUDED__ - -// Some platforms (e.g. Windows) include max() and min() macros in their -// standard headers, but they are also standard C++ template functions, so some -// C++ headers will undefine them. So we steer clear of the names min and max -// and define __rfbmin and __rfbmax instead. - -#ifndef __rfbmax -#define __rfbmax(a,b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef __rfbmin -#define __rfbmin(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -namespace rfb { - - // rfb::Point - // - // Represents a point in 2D space, by X and Y coordinates. - // Can also be used to represent a delta, or offset, between - // two Points. - // Functions are provided to allow Points to be compared for - // equality and translated by a supplied offset. - // Functions are also provided to negate offset Points. - - struct Point { - Point() : x(0), y(0) {} - Point(int x_, int y_) : x(x_), y(y_) {} - inline Point negate() const - __attribute__ ((warn_unused_result)) - {return Point(-x, -y);} - inline bool operator==(const Point &p) const {return x==p.x && y==p.y;} - inline bool operator!=(const Point &p) const {return x!=p.x || y!=p.y;} - inline Point translate(const Point &p) const - __attribute__ ((warn_unused_result)) - {return Point(x+p.x, y+p.y);} - inline Point subtract(const Point &p) const - __attribute__ ((warn_unused_result)) - {return Point(x-p.x, y-p.y);} - int x, y; - }; - - // rfb::Rect - // - // Represents a rectangular region defined by its top-left (tl) - // and bottom-right (br) Points. - // Rects may be compared for equality, checked to determine whether - // or not they are empty, cleared (made empty), or intersected with - // one another. The bounding rectangle of two existing Rects - // may be calculated, as may the area of a Rect. - // Rects may also be translated, in the same way as Points, by - // an offset specified in a Point structure. - - struct Rect { - Rect() {} - Rect(Point tl_, Point br_) : tl(tl_), br(br_) {} - Rect(int x1, int y1, int x2, int y2) : tl(x1, y1), br(x2, y2) {} - inline void setXYWH(int x, int y, int w, int h) { - tl.x = x; tl.y = y; br.x = x+w; br.y = y+h; - } - inline Rect intersect(const Rect &r) const - __attribute__ ((warn_unused_result)) - { - Rect result; - result.tl.x = __rfbmax(tl.x, r.tl.x); - result.tl.y = __rfbmax(tl.y, r.tl.y); - result.br.x = __rfbmax(__rfbmin(br.x, r.br.x), result.tl.x); - result.br.y = __rfbmax(__rfbmin(br.y, r.br.y), result.tl.y); - return result; - } - inline Rect union_boundary(const Rect &r) const - __attribute__ ((warn_unused_result)) - { - if (r.is_empty()) return *this; - if (is_empty()) return r; - Rect result; - result.tl.x = __rfbmin(tl.x, r.tl.x); - result.tl.y = __rfbmin(tl.y, r.tl.y); - result.br.x = __rfbmax(br.x, r.br.x); - result.br.y = __rfbmax(br.y, r.br.y); - return result; - } - inline Rect translate(const Point &p) const - __attribute__ ((warn_unused_result)) - { - return Rect(tl.translate(p), br.translate(p)); - } - inline bool operator==(const Rect &r) const {return r.tl == tl && r.br == br;} - inline bool operator!=(const Rect &r) const {return r.tl != tl || r.br != br;} - inline bool is_empty() const {return (tl.x >= br.x) || (tl.y >= br.y);} - inline void clear() {tl = Point(); br = Point();} - inline bool enclosed_by(const Rect &r) const { - return (tl.x>=r.tl.x) && (tl.y>=r.tl.y) && (br.x<=r.br.x) && (br.y<=r.br.y); - } - inline bool overlaps(const Rect &r) const { - return tl.x < r.br.x && tl.y < r.br.y && br.x > r.tl.x && br.y > r.tl.y; - } - inline int area() const {return is_empty() ? 0 : (br.x-tl.x)*(br.y-tl.y);} - inline Point dimensions() const {return Point(width(), height());} - inline int width() const {return br.x-tl.x;} - inline int height() const {return br.y-tl.y;} - inline bool contains(const Point &p) const { - return (tl.x<=p.x) && (tl.y<=p.y) && (br.x>p.x) && (br.y>p.y); - } - Point tl; - Point br; - }; -} -#endif // __RFB_RECT_INCLUDED__ diff --git a/common/rfb/Region.cxx b/common/rfb/Region.cxx deleted file mode 100644 index cf80fc6f..00000000 --- a/common/rfb/Region.cxx +++ /dev/null @@ -1,203 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2016-2020 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. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <rfb/Region.h> -#include <rfb/LogWriter.h> - -extern "C" { -#include <pixman.h> -} - -using namespace rfb; - -static LogWriter vlog("Region"); - -Region::Region() -{ - rgn = new struct pixman_region16; - pixman_region_init(rgn); -} - -Region::Region(const Rect& r) -{ - rgn = new struct pixman_region16; - pixman_region_init_rect(rgn, r.tl.x, r.tl.y, r.width(), r.height()); -} - -Region::Region(const Region& r) -{ - rgn = new struct pixman_region16; - pixman_region_init(rgn); - pixman_region_copy(rgn, r.rgn); -} - -Region::~Region() -{ - pixman_region_fini(rgn); - delete rgn; -} - -Region& Region::operator=(const Region& r) -{ - pixman_region_copy(rgn, r.rgn); - return *this; -} - -void Region::clear() -{ - // pixman_region_clear() isn't available on some older systems - pixman_region_fini(rgn); - pixman_region_init(rgn); -} - -void Region::reset(const Rect& r) -{ - pixman_region_fini(rgn); - pixman_region_init_rect(rgn, r.tl.x, r.tl.y, r.width(), r.height()); -} - -void Region::translate(const Point& delta) -{ - pixman_region_translate(rgn, delta.x, delta.y); -} - -void Region::assign_intersect(const Region& r) -{ - pixman_region_intersect(rgn, rgn, r.rgn); -} - -void Region::assign_union(const Region& r) -{ - pixman_region_union(rgn, rgn, r.rgn); -} - -void Region::assign_subtract(const Region& r) -{ - pixman_region_subtract(rgn, rgn, r.rgn); -} - -Region Region::intersect(const Region& r) const -{ - Region ret; - pixman_region_intersect(ret.rgn, rgn, r.rgn); - return ret; -} - -Region Region::union_(const Region& r) const -{ - Region ret; - pixman_region_union(ret.rgn, rgn, r.rgn); - return ret; -} - -Region Region::subtract(const Region& r) const -{ - Region ret; - pixman_region_subtract(ret.rgn, rgn, r.rgn); - return ret; -} - -bool Region::operator==(const Region& r) const -{ - return pixman_region_equal(rgn, r.rgn); -} - -bool Region::operator!=(const Region& r) const -{ - return !pixman_region_equal(rgn, r.rgn); -} - -int Region::numRects() const -{ - return pixman_region_n_rects(rgn); -} - -bool Region::get_rects(std::vector<Rect>* rects, - bool left2right, bool topdown) const -{ - int nRects; - const pixman_box16_t* boxes; - int xInc, yInc, i; - - boxes = pixman_region_rectangles(rgn, &nRects); - - rects->clear(); - rects->reserve(nRects); - - xInc = left2right ? 1 : -1; - yInc = topdown ? 1 : -1; - i = topdown ? 0 : nRects-1; - - while (nRects > 0) { - int firstInNextBand = i; - int nRectsInBand = 0; - - while (nRects > 0 && boxes[firstInNextBand].y1 == boxes[i].y1) - { - firstInNextBand += yInc; - nRects--; - nRectsInBand++; - } - - if (xInc != yInc) - i = firstInNextBand - yInc; - - while (nRectsInBand > 0) { - Rect r(boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2); - rects->push_back(r); - i += xInc; - nRectsInBand--; - } - - i = firstInNextBand; - } - - return !rects->empty(); -} - -Rect Region::get_bounding_rect() const -{ - const pixman_box16_t* extents; - extents = pixman_region_extents(rgn); - return Rect(extents->x1, extents->y1, extents->x2, extents->y2); -} - - -void Region::debug_print(const char* prefix) const -{ - Rect extents; - std::vector<Rect> rects; - std::vector<Rect>::const_iterator iter; - - extents = get_bounding_rect(); - get_rects(&rects); - - vlog.debug("%s num rects %3ld extents %3d,%3d %3dx%3d", - prefix, (long)rects.size(), extents.tl.x, extents.tl.y, - extents.width(), extents.height()); - - for (iter = rects.begin(); iter != rects.end(); ++iter) { - vlog.debug(" rect %3d,%3d %3dx%3d", - iter->tl.x, iter->tl.y, iter->width(), iter->height()); - } -} diff --git a/common/rfb/Region.h b/common/rfb/Region.h deleted file mode 100644 index 0927f763..00000000 --- a/common/rfb/Region.h +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2016-2020 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. - */ - -// Region class wrapper around pixman's region operations - -#ifndef __RFB_REGION_INCLUDED__ -#define __RFB_REGION_INCLUDED__ - -#include <rfb/Rect.h> -#include <vector> - -struct pixman_region16; - -namespace rfb { - - struct Point; - struct Rect; - - class Region { - public: - // Create an empty region - Region(); - // Create a rectangular region - Region(const Rect& r); - - Region(const Region& r); - Region &operator=(const Region& src); - - ~Region(); - - // the following methods alter the region in place: - - void clear(); - void reset(const Rect& r); - void translate(const rfb::Point& delta); - - void assign_intersect(const Region& r); - void assign_union(const Region& r); - void assign_subtract(const Region& r); - - // the following three operations return a new region: - - Region intersect(const Region& r) const - __attribute__ ((warn_unused_result)); - Region union_(const Region& r) const - __attribute__ ((warn_unused_result)); - Region subtract(const Region& r) const - __attribute__ ((warn_unused_result)); - - bool operator==(const Region& b) const; - bool operator!=(const Region& b) const; - int numRects() const; - bool is_empty() const { return numRects() == 0; } - - bool get_rects(std::vector<Rect>* rects, bool left2right=true, - bool topdown=true) const; - Rect get_bounding_rect() const; - - void debug_print(const char *prefix) const; - - protected: - - struct pixman_region16* rgn; - }; - -}; - -#endif // __RFB_REGION_INCLUDED__ diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 03219378..c65ef3e0 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -508,7 +508,7 @@ void SConnection::setPixelFormat(const PixelFormat& pf) writeFakeColourMap(); } -void SConnection::framebufferUpdateRequest(const Rect& /*r*/, +void SConnection::framebufferUpdateRequest(const core::Rect& /*r*/, bool /*incremental*/) { if (!readyForSetColourMapEntries) { diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index dcaa90de..df3dfe92 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -134,7 +134,7 @@ namespace rfb { // framebufferUpdateRequest() is called when a FramebufferUpdateRequest // message is received. The derived class must call on to // SConnection::framebufferUpdateRequest(). - void framebufferUpdateRequest(const Rect& r, bool incremental) override; + void framebufferUpdateRequest(const core::Rect& r, bool incremental) override; // fence() is called when we get a fence request or response. By default // it responds directly to requests (stating it doesn't support any diff --git a/common/rfb/SDesktop.h b/common/rfb/SDesktop.h index acccb914..402a13af 100644 --- a/common/rfb/SDesktop.h +++ b/common/rfb/SDesktop.h @@ -42,11 +42,12 @@ #include <rfb/screenTypes.h> +namespace core { struct Point; } + namespace network { class Socket; } namespace rfb { - struct Point; struct ScreenSet; class VNCServer; @@ -101,7 +102,7 @@ namespace rfb { // pointerEvent() is called whenever a client sends an event that // the pointer moved, or a button was pressed or released. - virtual void pointerEvent(const Point& /*pos*/, + virtual void pointerEvent(const core::Point& /*pos*/, uint16_t /*buttonMask*/) {}; // handleClipboardRequest() is called whenever a client requests diff --git a/common/rfb/SMsgHandler.cxx b/common/rfb/SMsgHandler.cxx index 1dce634d..148efdaa 100644 --- a/common/rfb/SMsgHandler.cxx +++ b/common/rfb/SMsgHandler.cxx @@ -82,7 +82,7 @@ void SMsgHandler::keyEvent(uint32_t /*keysym*/, uint32_t /*keycode*/, { } -void SMsgHandler::pointerEvent(const Point& /*pos*/, +void SMsgHandler::pointerEvent(const core::Point& /*pos*/, uint16_t /*buttonMask*/) { } diff --git a/common/rfb/SMsgHandler.h b/common/rfb/SMsgHandler.h index 3fee5703..f5f5b769 100644 --- a/common/rfb/SMsgHandler.h +++ b/common/rfb/SMsgHandler.h @@ -45,7 +45,8 @@ namespace rfb { virtual void setPixelFormat(const PixelFormat& pf); virtual void setEncodings(int nEncodings, const int32_t* encodings); - virtual void framebufferUpdateRequest(const Rect& r, bool incremental) = 0; + virtual void framebufferUpdateRequest(const core::Rect& r, + bool incremental) = 0; virtual void setDesktopSize(int fb_width, int fb_height, const ScreenSet& layout) = 0; virtual void fence(uint32_t flags, unsigned len, const uint8_t data[]) = 0; @@ -54,7 +55,7 @@ namespace rfb { virtual void keyEvent(uint32_t keysym, uint32_t keycode, bool down); - virtual void pointerEvent(const Point& pos, + virtual void pointerEvent(const core::Point& pos, uint16_t buttonMask); virtual void clientCutText(const char* str); diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx index 69f06cf5..0d6e7008 100644 --- a/common/rfb/SMsgWriter.cxx +++ b/common/rfb/SMsgWriter.cxx @@ -408,7 +408,7 @@ void SMsgWriter::writeFramebufferUpdateEnd() endMsg(); } -void SMsgWriter::writeCopyRect(const Rect& r, int srcX, int srcY) +void SMsgWriter::writeCopyRect(const core::Rect& r, int srcX, int srcY) { startRect(r,encodingCopyRect); os->writeU16(srcX); @@ -416,7 +416,7 @@ void SMsgWriter::writeCopyRect(const Rect& r, int srcX, int srcY) endRect(); } -void SMsgWriter::startRect(const Rect& r, int encoding) +void SMsgWriter::startRect(const core::Rect& r, int encoding) { if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) throw std::logic_error("SMsgWriter::startRect: nRects out of sync"); @@ -491,7 +491,7 @@ void SMsgWriter::writePseudoRects() } if (needCursorPos) { - const Point& cursorPos = client->cursorPos(); + const core::Point& cursorPos = client->cursorPos(); if (client->supportsEncoding(pseudoEncodingVMwareCursorPosition)) { writeSetVMwareCursorPositionRect(cursorPos.x, cursorPos.y); diff --git a/common/rfb/SMsgWriter.h b/common/rfb/SMsgWriter.h index 9bfe116b..113a9370 100644 --- a/common/rfb/SMsgWriter.h +++ b/common/rfb/SMsgWriter.h @@ -25,13 +25,14 @@ #include <stdint.h> +namespace core { struct Rect; } + namespace rdr { class OutStream; } namespace rfb { class ClientParams; class PixelFormat; - struct Rect; struct ScreenSet; class SMsgWriter { @@ -115,11 +116,11 @@ namespace rfb { void writeFramebufferUpdateEnd(); // There is no explicit encoder for CopyRect rects. - void writeCopyRect(const Rect& r, int srcX, int srcY); + void writeCopyRect(const core::Rect& r, int srcX, int srcY); // Encoders should call these to mark the start and stop of individual // rects. - void startRect(const Rect& r, int enc); + void startRect(const core::Rect& r, int enc); void endRect(); protected: diff --git a/common/rfb/ScreenSet.h b/common/rfb/ScreenSet.h index fb93e5c2..10753b17 100644 --- a/common/rfb/ScreenSet.h +++ b/common/rfb/ScreenSet.h @@ -25,10 +25,11 @@ #include <string.h> #include <stdint.h> -#include <rfb/Rect.h> #include <list> #include <set> +#include <core/Rect.h> + namespace rfb { // rfb::Screen @@ -52,7 +53,7 @@ namespace rfb { } uint32_t id; - Rect dimensions; + core::Rect dimensions; uint32_t flags; }; @@ -87,7 +88,7 @@ namespace rfb { inline bool validate(int fb_width, int fb_height) const { std::list<Screen>::const_iterator iter; std::set<uint32_t> seen_ids; - Rect fb_rect; + core::Rect fb_rect; if (screens.empty()) return false; diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index 8443f09f..fdbd3f40 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -52,7 +52,7 @@ TightDecoder::~TightDecoder() { } -bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, +bool TightDecoder::readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) { uint8_t comp_ctl; @@ -193,10 +193,10 @@ bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, return true; } -bool TightDecoder::doRectsConflict(const Rect& /*rectA*/, +bool TightDecoder::doRectsConflict(const core::Rect& /*rectA*/, const uint8_t* bufferA, size_t buflenA, - const Rect& /*rectB*/, + const core::Rect& /*rectB*/, const uint8_t* bufferB, size_t buflenB, const ServerParams& /*server*/) @@ -221,7 +221,7 @@ bool TightDecoder::doRectsConflict(const Rect& /*rectA*/, return false; } -void TightDecoder::decodeRect(const Rect& r, const uint8_t* buffer, +void TightDecoder::decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) { @@ -507,7 +507,7 @@ uint32_t TightDecoder::readCompact(rdr::InStream* is) void TightDecoder::FilterGradient24(const uint8_t *inbuf, const PixelFormat& pf, uint32_t* outbuf, - int stride, const Rect& r) + int stride, const core::Rect& r) { int x, y, c; uint8_t prevRow[TIGHT_MAX_WIDTH*3]; @@ -553,7 +553,7 @@ TightDecoder::FilterGradient24(const uint8_t *inbuf, template<class T> void TightDecoder::FilterGradient(const uint8_t* inbuf, const PixelFormat& pf, T* outbuf, - int stride, const Rect& r) + int stride, const core::Rect& r) { int x, y, c; static uint8_t prevRow[TIGHT_MAX_WIDTH*3]; @@ -607,7 +607,7 @@ void TightDecoder::FilterGradient(const uint8_t* inbuf, template<class T> void TightDecoder::FilterPalette(const T* palette, int palSize, const uint8_t* inbuf, T* outbuf, - int stride, const Rect& r) + int stride, const core::Rect& r) { // Indexed color int x, h = r.height(), w = r.width(), b, pad = stride - w; diff --git a/common/rfb/TightDecoder.h b/common/rfb/TightDecoder.h index cb94ca73..a75fc7da 100644 --- a/common/rfb/TightDecoder.h +++ b/common/rfb/TightDecoder.h @@ -30,15 +30,15 @@ namespace rfb { public: TightDecoder(); virtual ~TightDecoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - bool doRectsConflict(const Rect& rectA, + bool doRectsConflict(const core::Rect& rectA, const uint8_t* bufferA, size_t buflenA, - const Rect& rectB, + const core::Rect& rectB, const uint8_t* bufferB, size_t buflenB, const ServerParams& server) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; @@ -46,16 +46,16 @@ namespace rfb { uint32_t readCompact(rdr::InStream* is); void FilterGradient24(const uint8_t* inbuf, const PixelFormat& pf, - uint32_t* outbuf, int stride, const Rect& r); + uint32_t* outbuf, int stride, const core::Rect& r); template<class T> void FilterGradient(const uint8_t* inbuf, const PixelFormat& pf, - T* outbuf, int stride, const Rect& r); + T* outbuf, int stride, const core::Rect& r); template<class T> void FilterPalette(const T* palette, int palSize, const uint8_t* inbuf, T* outbuf, - int stride, const Rect& r); + int stride, const core::Rect& r); private: rdr::ZlibInStream zis[4]; diff --git a/common/rfb/UpdateTracker.cxx b/common/rfb/UpdateTracker.cxx index 7c97a6b8..b7a86e5f 100644 --- a/common/rfb/UpdateTracker.cxx +++ b/common/rfb/UpdateTracker.cxx @@ -35,17 +35,20 @@ static LogWriter vlog("UpdateTracker"); // -=- ClippingUpdateTracker -void ClippingUpdateTracker::add_changed(const Region ®ion) { +void ClippingUpdateTracker::add_changed(const core::Region& region) +{ ut->add_changed(region.intersect(clipRect)); } -void ClippingUpdateTracker::add_copied(const Region &dest, const Point &delta) { +void ClippingUpdateTracker::add_copied(const core::Region& dest, + const core::Point& delta) +{ // Clip the destination to the display area - Region clipdest = dest.intersect(clipRect); + core::Region clipdest = dest.intersect(clipRect); if (clipdest.is_empty()) return; // Clip the source to the screen - Region tmp = clipdest; + core::Region tmp = clipdest; tmp.translate(delta.negate()); tmp.assign_intersect(clipRect); if (!tmp.is_empty()) { @@ -70,25 +73,28 @@ SimpleUpdateTracker::SimpleUpdateTracker() { SimpleUpdateTracker::~SimpleUpdateTracker() { } -void SimpleUpdateTracker::add_changed(const Region ®ion) { +void SimpleUpdateTracker::add_changed(const core::Region& region) +{ changed.assign_union(region); } -void SimpleUpdateTracker::add_copied(const Region &dest, const Point &delta) { +void SimpleUpdateTracker::add_copied(const core::Region& dest, + const core::Point& delta) +{ // Is there anything to do? if (dest.is_empty()) return; // Calculate whether any of this copy can be treated as a continuation // of an earlier one - Region src = dest; + core::Region src = dest; src.translate(delta.negate()); - Region overlap = src.intersect(copied); + core::Region overlap = src.intersect(copied); if (overlap.is_empty()) { // There is no overlap - Rect newbr = dest.get_bounding_rect(); - Rect oldbr = copied.get_bounding_rect(); + core::Rect newbr = dest.get_bounding_rect(); + core::Rect oldbr = copied.get_bounding_rect(); if (oldbr.area() > newbr.area()) { // Old copyrect is (probably) bigger - use it changed.assign_union(dest); @@ -97,7 +103,7 @@ void SimpleUpdateTracker::add_copied(const Region &dest, const Point &delta) { // Use the new one // But be careful not to copy stuff that still needs // to be updated. - Region invalid_src = src.intersect(changed); + core::Region invalid_src = src.intersect(changed); invalid_src.translate(delta); changed.assign_union(invalid_src); changed.assign_union(copied); @@ -107,13 +113,13 @@ void SimpleUpdateTracker::add_copied(const Region &dest, const Point &delta) { return; } - Region invalid_src = overlap.intersect(changed); + core::Region invalid_src = overlap.intersect(changed); invalid_src.translate(delta); changed.assign_union(invalid_src); overlap.translate(delta); - Region nonoverlapped_copied = dest.union_(copied).subtract(overlap); + core::Region nonoverlapped_copied = dest.union_(copied).subtract(overlap); changed.assign_union(nonoverlapped_copied); copied = overlap; @@ -122,12 +128,14 @@ void SimpleUpdateTracker::add_copied(const Region &dest, const Point &delta) { return; } -void SimpleUpdateTracker::subtract(const Region& region) { +void SimpleUpdateTracker::subtract(const core::Region& region) +{ copied.assign_subtract(region); changed.assign_subtract(region); } -void SimpleUpdateTracker::getUpdateInfo(UpdateInfo* info, const Region& clip) +void SimpleUpdateTracker::getUpdateInfo(UpdateInfo* info, + const core::Region& clip) { copied.assign_subtract(changed); info->changed = changed.intersect(clip); diff --git a/common/rfb/UpdateTracker.h b/common/rfb/UpdateTracker.h index e6e98086..3d7a2fcd 100644 --- a/common/rfb/UpdateTracker.h +++ b/common/rfb/UpdateTracker.h @@ -19,16 +19,16 @@ #ifndef __RFB_UPDATETRACKER_INCLUDED__ #define __RFB_UPDATETRACKER_INCLUDED__ -#include <rfb/Rect.h> -#include <rfb/Region.h> +#include <core/Rect.h> +#include <core/Region.h> namespace rfb { class UpdateInfo { public: - Region changed; - Region copied; - Point copy_delta; + core::Region changed; + core::Region copied; + core::Point copy_delta; bool is_empty() const { return copied.is_empty() && changed.is_empty(); } @@ -46,23 +46,25 @@ namespace rfb { UpdateTracker() {}; virtual ~UpdateTracker() {}; - virtual void add_changed(const Region ®ion) = 0; - virtual void add_copied(const Region &dest, const Point &delta) = 0; + virtual void add_changed(const core::Region& region) = 0; + virtual void add_copied(const core::Region& dest, + const core::Point& delta) = 0; }; class ClippingUpdateTracker : public UpdateTracker { public: ClippingUpdateTracker() : ut(nullptr) {} - ClippingUpdateTracker(UpdateTracker* ut_, const Rect& r={}) : ut(ut_), clipRect(r) {} + ClippingUpdateTracker(UpdateTracker* ut_, const core::Rect& r={}) : ut(ut_), clipRect(r) {} void setUpdateTracker(UpdateTracker* ut_) {ut = ut_;} - void setClipRect(const Rect& cr) {clipRect = cr;} + void setClipRect(const core::Rect& cr) {clipRect = cr;} - void add_changed(const Region ®ion) override; - void add_copied(const Region &dest, const Point &delta) override; + void add_changed(const core::Region& region) override; + void add_copied(const core::Region& dest, + const core::Point& delta) override; protected: UpdateTracker* ut; - Rect clipRect; + core::Rect clipRect; }; class SimpleUpdateTracker : public UpdateTracker { @@ -70,27 +72,29 @@ namespace rfb { SimpleUpdateTracker(); virtual ~SimpleUpdateTracker(); - void add_changed(const Region ®ion) override; - void add_copied(const Region &dest, const Point &delta) override; - virtual void subtract(const Region& region); + void add_changed(const core::Region& region) override; + void add_copied(const core::Region& dest, + const core::Point& delta) override; + virtual void subtract(const core::Region& region); // Fill the supplied UpdateInfo structure with update information // FIXME: Provide getUpdateInfo() with no clipping, for better efficiency. - virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn); + virtual void getUpdateInfo(UpdateInfo* info, + const core::Region& cliprgn); // Copy the contained updates to another tracker virtual void copyTo(UpdateTracker* to) const; // Move the entire update region by an offset - void translate(const Point& p) {changed.translate(p); copied.translate(p);} + void translate(const core::Point& p) {changed.translate(p); copied.translate(p);} virtual bool is_empty() const {return changed.is_empty() && copied.is_empty();} virtual void clear() {changed.clear(); copied.clear();}; protected: - Region changed; - Region copied; - Point copy_delta; + core::Region changed; + core::Region copied; + core::Point copy_delta; }; } diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 1e7363c0..f8a1a025 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -469,7 +469,8 @@ void VNCSConnectionST::setPixelFormat(const PixelFormat& pf) setCursor(); } -void VNCSConnectionST::pointerEvent(const Point& pos, uint16_t buttonMask) +void VNCSConnectionST::pointerEvent(const core::Point& pos, + uint16_t buttonMask) { if (rfb::Server::idleTimeout) idleTimer.start(secsToMillis(rfb::Server::idleTimeout)); @@ -609,9 +610,10 @@ void VNCSConnectionST::keyEvent(uint32_t keysym, uint32_t keycode, bool down) { server->keyEvent(keysym, keycode, down); } -void VNCSConnectionST::framebufferUpdateRequest(const Rect& r,bool incremental) +void VNCSConnectionST::framebufferUpdateRequest(const core::Rect& r, + bool incremental) { - Rect safeRect; + core::Rect safeRect; if (!accessCheck(AccessView)) return; @@ -629,7 +631,7 @@ void VNCSConnectionST::framebufferUpdateRequest(const Rect& r,bool incremental) // Just update the requested region. // Framebuffer update will be sent a bit later, see processMessages(). - Region reqRgn(safeRect); + core::Region reqRgn(safeRect); if (!incremental || !continuousUpdates) requested.assign_union(reqRgn); @@ -720,7 +722,7 @@ void VNCSConnectionST::fence(uint32_t flags, unsigned len, const uint8_t data[]) void VNCSConnectionST::enableContinuousUpdates(bool enable, int x, int y, int w, int h) { - Rect rect; + core::Rect rect; if (!accessCheck(AccessView)) return; @@ -928,7 +930,7 @@ void VNCSConnectionST::writeNoDataUpdate() void VNCSConnectionST::writeDataUpdate() { - Region req; + core::Region req; UpdateInfo ui; bool needNewUpdateInfo; const RenderedCursor *cursor; @@ -953,7 +955,7 @@ void VNCSConnectionST::writeDataUpdate() // destination will be wrong, so add it to the changed region. if (!ui.copied.is_empty() && !damagedCursorRegion.is_empty()) { - Region bogusCopiedCursor; + core::Region bogusCopiedCursor; bogusCopiedCursor = damagedCursorRegion; bogusCopiedCursor.translate(ui.copy_delta); @@ -1000,7 +1002,7 @@ void VNCSConnectionST::writeDataUpdate() cursor = nullptr; if (needRenderedCursor()) { - Rect renderedCursorRect; + core::Rect renderedCursorRect; cursor = server->getRenderedCursor(); renderedCursorRect = cursor->getEffectiveRect(); @@ -1040,7 +1042,7 @@ void VNCSConnectionST::writeDataUpdate() void VNCSConnectionST::writeLosslessRefresh() { - Region req, pending; + core::Region req, pending; const RenderedCursor *cursor; int nextRefresh, nextUpdate; diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index 17de9d01..7335051a 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -108,8 +108,8 @@ namespace rfb { // Change tracking - void add_changed(const Region& region) { updates.add_changed(region); } - void add_copied(const Region& dest, const Point& delta) { + void add_changed(const core::Region& region) { updates.add_changed(region); } + void add_copied(const core::Region& dest, const core::Point& delta) { updates.add_copied(dest, delta); } @@ -123,10 +123,11 @@ namespace rfb { void queryConnection(const char* userName) override; void clientInit(bool shared) override; void setPixelFormat(const PixelFormat& pf) override; - void pointerEvent(const Point& pos, uint16_t buttonMask) override; + void pointerEvent(const core::Point& pos, + uint16_t buttonMask) override; void keyEvent(uint32_t keysym, uint32_t keycode, bool down) override; - void framebufferUpdateRequest(const Rect& r, + void framebufferUpdateRequest(const core::Rect& r, bool incremental) override; void setDesktopSize(int fb_width, int fb_height, const ScreenSet& layout) override; @@ -185,11 +186,11 @@ namespace rfb { VNCServerST* server; SimpleUpdateTracker updates; - Region requested; + core::Region requested; bool updateRenderedCursor, removeRenderedCursor; - Region damagedCursorRegion; + core::Region damagedCursorRegion; bool continuousUpdates; - Region cuRegion; + core::Region cuRegion; EncodeManager encodeManager; std::map<uint32_t, uint32_t> pressedKeys; @@ -197,7 +198,7 @@ namespace rfb { Timer idleTimer; time_t pointerEventTime; - Point pointerEventPos; + core::Point pointerEventPos; bool clientHasCursor; std::string closeReason; diff --git a/common/rfb/VNCServer.h b/common/rfb/VNCServer.h index 143ac1f4..4d9b31ed 100644 --- a/common/rfb/VNCServer.h +++ b/common/rfb/VNCServer.h @@ -133,13 +133,14 @@ namespace rfb { // setCursor() tells the server that the cursor has changed. The // cursorData argument contains width*height rgba quadruplets with // non-premultiplied alpha. - virtual void setCursor(int width, int height, const Point& hotspot, + virtual void setCursor(int width, int height, + const core::Point& hotspot, const uint8_t* cursorData) = 0; // setCursorPos() tells the server the current position of the cursor, and // whether the server initiated that change (e.g. through another X11 // client calling XWarpPointer()). - virtual void setCursorPos(const Point& p, bool warped) = 0; + virtual void setCursorPos(const core::Point& p, bool warped) = 0; // setName() tells the server what desktop title to supply to clients virtual void setName(const char* name) = 0; diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 6e327129..6b572b39 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -316,7 +316,7 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_) // Check that the screen layout is still valid if (pb_ && !layout.validate(pb_->width(), pb_->height())) { - Rect fbRect; + core::Rect fbRect; ScreenSet::iterator iter, iter_next; fbRect.setXYWH(0, 0, pb_->width(), pb_->height()); @@ -404,7 +404,7 @@ void VNCServerST::setName(const char* name_) (*ci)->setDesktopNameOrClose(name_); } -void VNCServerST::add_changed(const Region& region) +void VNCServerST::add_changed(const core::Region& region) { if (comparer == nullptr) return; @@ -413,7 +413,8 @@ void VNCServerST::add_changed(const Region& region) startFrameClock(); } -void VNCServerST::add_copied(const Region& dest, const Point& delta) +void VNCServerST::add_copied(const core::Region& dest, + const core::Point& delta) { if (comparer == nullptr) return; @@ -422,7 +423,8 @@ void VNCServerST::add_copied(const Region& dest, const Point& delta) startFrameClock(); } -void VNCServerST::setCursor(int width, int height, const Point& newHotspot, +void VNCServerST::setCursor(int width, int height, + const core::Point& newHotspot, const uint8_t* data) { delete cursor; @@ -438,7 +440,7 @@ void VNCServerST::setCursor(int width, int height, const Point& newHotspot, } } -void VNCServerST::setCursorPos(const Point& pos, bool warped) +void VNCServerST::setCursorPos(const core::Point& pos, bool warped) { if (cursorPos != pos) { cursorPos = pos; @@ -487,7 +489,8 @@ void VNCServerST::keyEvent(uint32_t keysym, uint32_t keycode, bool down) } void VNCServerST::pointerEvent(VNCSConnectionST* client, - const Point& pos, uint16_t buttonMask) + const core::Point& pos, + uint16_t buttonMask) { time_t now = time(nullptr); if (rfb::Server::maxIdleTime) @@ -825,7 +828,7 @@ int VNCServerST::msToNextUpdate() void VNCServerST::writeUpdate() { UpdateInfo ui; - Region toCheck; + core::Region toCheck; std::list<VNCSConnectionST*>::iterator ci; @@ -837,9 +840,9 @@ void VNCServerST::writeUpdate() toCheck = ui.changed.union_(ui.copied); if (needRenderedCursor()) { - Rect clippedCursorRect = Rect(0, 0, cursor->width(), cursor->height()) - .translate(cursorPos.subtract(cursor->hotspot())) - .intersect(pb->getRect()); + core::Rect clippedCursorRect = core::Rect(0, 0, cursor->width(), cursor->height()) + .translate(cursorPos.subtract(cursor->hotspot())) + .intersect(pb->getRect()); if (!toCheck.intersect(clippedCursorRect).is_empty()) renderedCursorInvalid = true; @@ -867,7 +870,7 @@ void VNCServerST::writeUpdate() // checkUpdate() is called by clients to see if it is safe to read from // the framebuffer at this time. -Region VNCServerST::getPendingRegion() +core::Region VNCServerST::getPendingRegion() { UpdateInfo ui; diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index 6c19e5be..3d6fbeee 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -95,11 +95,12 @@ namespace rfb { void closeClients(const char* reason) override {closeClients(reason, nullptr);} SConnection* getConnection(network::Socket* sock) override; - void add_changed(const Region ®ion) override; - void add_copied(const Region &dest, const Point &delta) override; - void setCursor(int width, int height, const Point& hotspot, + void add_changed(const core::Region& region) override; + void add_copied(const core::Region& dest, + const core::Point& delta) override; + void setCursor(int width, int height, const core::Point& hotspot, const uint8_t* data) override; - void setCursorPos(const Point& p, bool warped) override; + void setCursorPos(const core::Point& p, bool warped) override; void setName(const char* name_) override; void setLEDState(unsigned state) override; @@ -111,13 +112,14 @@ namespace rfb { const ScreenSet& getScreenLayout() const { return screenLayout; } const Cursor* getCursor() const { return cursor; } - const Point& getCursorPos() const { return cursorPos; } + const core::Point& getCursorPos() const { return cursorPos; } const char* getName() const { return name.c_str(); } unsigned getLEDState() const { return ledState; } // Event handlers void keyEvent(uint32_t keysym, uint32_t keycode, bool down); - void pointerEvent(VNCSConnectionST* client, const Point& pos, uint16_t buttonMask); + void pointerEvent(VNCSConnectionST* client, + const core::Point& pos, uint16_t buttonMask); void handleClipboardRequest(VNCSConnectionST* client); void handleClipboardAnnounce(VNCSConnectionST* client, bool available); @@ -146,7 +148,7 @@ namespace rfb { // Part of the framebuffer that has been modified but is not yet // ready to be sent to clients - Region getPendingRegion(); + core::Region getPendingRegion(); // getRenderedCursor() returns an up to date version of the server // side rendered cursor buffer @@ -195,7 +197,7 @@ namespace rfb { ComparingUpdateTracker* comparer; - Point cursorPos; + core::Point cursorPos; Cursor* cursor; RenderedCursor renderedCursor; bool renderedCursorInvalid; diff --git a/common/rfb/ZRLEDecoder.cxx b/common/rfb/ZRLEDecoder.cxx index 633d1c36..f149eca6 100644 --- a/common/rfb/ZRLEDecoder.cxx +++ b/common/rfb/ZRLEDecoder.cxx @@ -75,7 +75,7 @@ ZRLEDecoder::~ZRLEDecoder() { } -bool ZRLEDecoder::readRect(const Rect& /*r*/, rdr::InStream* is, +bool ZRLEDecoder::readRect(const core::Rect& /*r*/, rdr::InStream* is, const ServerParams& /*server*/, rdr::OutStream* os) { @@ -99,7 +99,7 @@ bool ZRLEDecoder::readRect(const Rect& /*r*/, rdr::InStream* is, return true; } -void ZRLEDecoder::decodeRect(const Rect& r, const uint8_t* buffer, +void ZRLEDecoder::decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) { @@ -113,13 +113,13 @@ void ZRLEDecoder::decodeRect(const Rect& r, const uint8_t* buffer, } template<class T> -void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, +void ZRLEDecoder::zrleDecode(const core::Rect& r, rdr::InStream* is, const PixelFormat& pf, ModifiablePixelBuffer* pb) { int length = is->readU32(); zis.setUnderlying(is, length); - Rect t; + core::Rect t; T buf[64 * 64]; Pixel maxPixel = pf.pixelFromRGB((uint16_t)-1, (uint16_t)-1, (uint16_t)-1); diff --git a/common/rfb/ZRLEDecoder.h b/common/rfb/ZRLEDecoder.h index facf0adc..b9ebf771 100644 --- a/common/rfb/ZRLEDecoder.h +++ b/common/rfb/ZRLEDecoder.h @@ -30,16 +30,16 @@ namespace rfb { public: ZRLEDecoder(); virtual ~ZRLEDecoder(); - bool readRect(const Rect& r, rdr::InStream* is, + bool readRect(const core::Rect& r, rdr::InStream* is, const ServerParams& server, rdr::OutStream* os) override; - void decodeRect(const Rect& r, const uint8_t* buffer, + void decodeRect(const core::Rect& r, const uint8_t* buffer, size_t buflen, const ServerParams& server, ModifiablePixelBuffer* pb) override; private: template<class T> - void zrleDecode(const Rect& r, rdr::InStream* is, + void zrleDecode(const core::Rect& r, rdr::InStream* is, const PixelFormat& pf, ModifiablePixelBuffer* pb); private: diff --git a/common/rfb/ZRLEEncoder.cxx b/common/rfb/ZRLEEncoder.cxx index 425c4d75..5f1081cf 100644 --- a/common/rfb/ZRLEEncoder.cxx +++ b/common/rfb/ZRLEEncoder.cxx @@ -67,7 +67,7 @@ void ZRLEEncoder::setCompressLevel(int level) void ZRLEEncoder::writeRect(const PixelBuffer* pb, const Palette& palette) { int x, y; - Rect tile; + core::Rect tile; rdr::OutStream* os; @@ -133,7 +133,8 @@ void ZRLEEncoder::writeSolidRect(int width, int height, mos.clear(); } -void ZRLEEncoder::writePaletteTile(const Rect& tile, const PixelBuffer* pb, +void ZRLEEncoder::writePaletteTile(const core::Rect& tile, + const PixelBuffer* pb, const Palette& palette) { const uint8_t* buffer; @@ -159,7 +160,8 @@ void ZRLEEncoder::writePaletteTile(const Rect& tile, const PixelBuffer* pb, } } -void ZRLEEncoder::writePaletteRLETile(const Rect& tile, const PixelBuffer* pb, +void ZRLEEncoder::writePaletteRLETile(const core::Rect& tile, + const PixelBuffer* pb, const Palette& palette) { const uint8_t* buffer; @@ -185,7 +187,8 @@ void ZRLEEncoder::writePaletteRLETile(const Rect& tile, const PixelBuffer* pb, } } -void ZRLEEncoder::writeRawTile(const Rect& tile, const PixelBuffer* pb) +void ZRLEEncoder::writeRawTile(const core::Rect& tile, + const PixelBuffer* pb) { const uint8_t* buffer; int stride; diff --git a/common/rfb/ZRLEEncoder.h b/common/rfb/ZRLEEncoder.h index 87d87e94..3be81ba3 100644 --- a/common/rfb/ZRLEEncoder.h +++ b/common/rfb/ZRLEEncoder.h @@ -40,11 +40,13 @@ namespace rfb { const uint8_t* colour) override; protected: - void writePaletteTile(const Rect& tile, const PixelBuffer* pb, + void writePaletteTile(const core::Rect& tile, + const PixelBuffer* pb, const Palette& palette); - void writePaletteRLETile(const Rect& tile, const PixelBuffer* pb, + void writePaletteRLETile(const core::Rect& tile, + const PixelBuffer* pb, const Palette& palette); - void writeRawTile(const Rect& tile, const PixelBuffer* pb); + void writeRawTile(const core::Rect& tile, const PixelBuffer* pb); void writePalette(const PixelFormat& pf, const Palette& palette); |