From f350545337cd45b238cd4193bd4295e0ce16c3ed Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 15 Jul 2011 08:11:55 +0000 Subject: [PATCH] The new viewer stores the framebuffer in a native format, instead of converting it on each render like the old one. That means we have to change how we deal with colour maps and make sure it is updated before any changes to the framebuffer. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4589 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- vncviewer/Viewport.cxx | 28 ++++++++++++++-------------- vncviewer/Viewport.h | 13 ++++++++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 2d197fcc..dcadd0ef 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -63,7 +63,8 @@ enum { ID_EXIT, ID_FULLSCREEN, ID_CTRL, ID_ALT, ID_MENUKEY, ID_CTRLALTDEL, Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_) : Fl_Widget(0, 0, w, h), cc(cc_), frameBuffer(NULL), pixelTrans(NULL), - lastPointerPos(0, 0), lastButtonMask(0), cursor(NULL) + colourMapChange(false), lastPointerPos(0, 0), lastButtonMask(0), + cursor(NULL) { // FLTK STR #2599 must be fixed for proper dead keys support #ifdef HAVE_FLTK_DEAD_KEYS @@ -103,7 +104,6 @@ Viewport::~Viewport() // Unregister all timeouts in case they get a change tro trigger // again later when this object is already gone. Fl::remove_timeout(handleUpdateTimeout, this); - Fl::remove_timeout(handleColourMap, this); Fl::remove_timeout(handlePointerTimeout, this); #ifdef HAVE_FLTK_CLIPBOARD @@ -149,17 +149,17 @@ const rfb::PixelFormat &Viewport::getPreferredPF() // setColourMapEntries() changes some of the entries in the colourmap. -// Unfortunately these messages are often sent one at a time, so we delay the -// settings taking effect by 100ms. This is because recalculating the internal -// translation table can be expensive. +// We don't actually act on these changes until we need to. This is +// because recalculating the internal translation table can be expensive. +// This also solves the issue of silly servers sending colour maps in +// multiple pieces. void Viewport::setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs) { for (int i = 0; i < nColours; i++) colourMap.set(firstColour+i, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]); - if (!Fl::has_timeout(handleColourMap, this)) - Fl::add_timeout(0.100, handleColourMap, this); + colourMapChange = true; } @@ -431,16 +431,16 @@ void Viewport::handleUpdateTimeout(void *data) } -void Viewport::handleColourMap(void *data) +void Viewport::commitColourMap() { - Viewport *self = (Viewport *)data; - - assert(self); + if (pixelTrans == NULL) + return; + if (!colourMapChange) + return; - if (self->pixelTrans != NULL) - self->pixelTrans->setColourMapEntries(0, 0); + colourMapChange = false; - self->Fl_Widget::damage(FL_DAMAGE_ALL); + pixelTrans->setColourMapEntries(0, 0); } diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index 9eb3b73c..c9a3cf3a 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -70,6 +70,8 @@ public: void fillRect(const rfb::Rect& r, rfb::Pixel pix) { if (pixelTrans) { rfb::Pixel pix2; + if (colourMapChange) + commitColourMap(); pixelTrans->translatePixels(&pix, &pix2, 1); pix = pix2; } @@ -78,13 +80,16 @@ public: damageRect(r); } void imageRect(const rfb::Rect& r, void* pixels) { - if (pixelTrans) + if (pixelTrans) { + if (colourMapChange) + commitColourMap(); pixelTrans->translateRect(pixels, r.width(), rfb::Rect(0, 0, r.width(), r.height()), frameBuffer->data, frameBuffer->getStride(), r.tl); - else + } else { frameBuffer->imageRect(r, pixels); + } damageRect(r); } void copyRect(const rfb::Rect& r, int srcX, int srcY) { @@ -112,7 +117,8 @@ private: }; static void handleUpdateTimeout(void *data); - static void handleColourMap(void *data); + + void commitColourMap(); static void handleClipboardChange(int source, void *data); @@ -136,6 +142,7 @@ private: rfb::PixelTransformer *pixelTrans; rfb::SimpleColourMap colourMap; + bool colourMapChange; rfb::Region damage; -- 2.39.5