From 73014910f56278a91e796ad8eed620196e289f47 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 3 Jan 2020 13:10:20 +0100 Subject: [PATCH] Clean up initialization of DIBSectionBuffer We had an unintentional conflict with PixelBuffer::setSize() here. But we can simplify this further as this initialization is only used by the subclass DeviceFrameBuffer, and only once. --- win/rfb_win32/DIBSectionBuffer.cxx | 18 ++++++------------ win/rfb_win32/DIBSectionBuffer.h | 6 +----- win/rfb_win32/DeviceFrameBuffer.cxx | 14 +------------- win/rfb_win32/DeviceFrameBuffer.h | 5 ----- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/win/rfb_win32/DIBSectionBuffer.cxx b/win/rfb_win32/DIBSectionBuffer.cxx index e00cf233..57bef2dc 100644 --- a/win/rfb_win32/DIBSectionBuffer.cxx +++ b/win/rfb_win32/DIBSectionBuffer.cxx @@ -44,26 +44,20 @@ DIBSectionBuffer::~DIBSectionBuffer() { } -void DIBSectionBuffer::setPF(const PixelFormat& pf) { - if (memcmp(&getPF(), &pf, sizeof(pf)) == 0) { - vlog.debug("pixel format unchanged by setPF()"); - return; - } - if (!pf.trueColour) - throw rfb::Exception("palette format not supported"); - format = pf; - setSize(width(), height()); -} - inline void initMaxAndShift(DWORD mask, int* max, int* shift) { for ((*shift) = 0; (mask & 1) == 0; (*shift)++) mask >>= 1; (*max) = (rdr::U16)mask; } -void DIBSectionBuffer::setSize(int w, int h) { +void DIBSectionBuffer::initBuffer(const PixelFormat& pf, int w, int h) { HBITMAP new_bitmap = 0; rdr::U8* new_data = 0; + if (!pf.trueColour) + throw rfb::Exception("palette format not supported"); + + format = pf; + if (w && h && (format.depth != 0)) { BitmapInfo bi; memset(&bi, 0, sizeof(bi)); diff --git a/win/rfb_win32/DIBSectionBuffer.h b/win/rfb_win32/DIBSectionBuffer.h index cf9e7bc1..2f099f39 100644 --- a/win/rfb_win32/DIBSectionBuffer.h +++ b/win/rfb_win32/DIBSectionBuffer.h @@ -44,14 +44,10 @@ namespace rfb { DIBSectionBuffer(HDC device); virtual ~DIBSectionBuffer(); - virtual void setPF(const PixelFormat &pf); - virtual void setSize(int w, int h); - - // *** virtual void copyRect(const Rect &dest, const Point &move_by_delta); public: HBITMAP bitmap; protected: - void recreateBuffer(); + void initBuffer(const PixelFormat& pf, int w, int h); HWND window; HDC device; }; diff --git a/win/rfb_win32/DeviceFrameBuffer.cxx b/win/rfb_win32/DeviceFrameBuffer.cxx index 3138cce2..14c0ae34 100644 --- a/win/rfb_win32/DeviceFrameBuffer.cxx +++ b/win/rfb_win32/DeviceFrameBuffer.cxx @@ -74,25 +74,13 @@ DeviceFrameBuffer::DeviceFrameBuffer(HDC deviceContext, const Rect& wRect) if (w % 2) w--; // Configure the underlying DIB to match the device - DIBSectionBuffer::setPF(DeviceContext::getPF(device)); - DIBSectionBuffer::setSize(w, h); + initBuffer(DeviceContext::getPF(device), w, h); } DeviceFrameBuffer::~DeviceFrameBuffer() { } -void -DeviceFrameBuffer::setPF(const PixelFormat &pf) { - throw Exception("setPF not supported"); -} - -void -DeviceFrameBuffer::setSize(int w, int h) { - throw Exception("setSize not supported"); -} - - #ifndef CAPTUREBLT #define CAPTUREBLT 0x40000000 #endif diff --git a/win/rfb_win32/DeviceFrameBuffer.h b/win/rfb_win32/DeviceFrameBuffer.h index 6fccf9fa..c8715724 100644 --- a/win/rfb_win32/DeviceFrameBuffer.h +++ b/win/rfb_win32/DeviceFrameBuffer.h @@ -71,11 +71,6 @@ namespace rfb { virtual void grabRect(const Rect &rect); virtual void grabRegion(const Region ®ion); - // - DIBSectionBuffer overrides - - virtual void setPF(const PixelFormat& pf); - virtual void setSize(int w, int h); - // - DeviceFrameBuffer specific methods void setCursor(HCURSOR c, VNCServer* server); -- 2.39.5