Make sure the fill function pointer gets updated if the
managed pixel buffer changes format. Also add a bit more
protection for switching pixel format as the base classes
aren't really designed for that. Fixes a crash with the
mouse pointer in WinVNC.
Based on work done by Daniel Wyatt (dewyatt).


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5152 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx
index 106b42b..60957a2 100644
--- a/common/rfb/PixelBuffer.cxx
+++ b/common/rfb/PixelBuffer.cxx
@@ -133,6 +133,22 @@
                                            rdr::U8* data_, ColourMap* cm)
   : PixelBuffer(pf, w, h, cm), data(data_)
 {
+  // Called again to configure the fill function
+  setPF(pf);
+}
+
+FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {}
+
+FullFramePixelBuffer::~FullFramePixelBuffer() {}
+
+
+void FullFramePixelBuffer::setPF(const PixelFormat &pf) {
+  // We have this as a separate method for ManagedPixelBuffer's
+  // sake. Direct users of FullFramePixelBuffer aren't allowed
+  // to call it.
+
+  PixelBuffer::setPF(pf);
+
   switch(pf.bpp) {
   case 8:
     fillRectFn = fillRect8;
@@ -148,10 +164,6 @@
   }
 }
 
-FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {}
-
-FullFramePixelBuffer::~FullFramePixelBuffer() {}
-
 
 int FullFramePixelBuffer::getStride() const { return width(); }
 
@@ -334,7 +346,7 @@
 
 void
 ManagedPixelBuffer::setPF(const PixelFormat &pf) {
-  format = pf; checkDataSize();
+  FullFramePixelBuffer::setPF(pf); checkDataSize();
 };
 void
 ManagedPixelBuffer::setSize(int w, int h) {
diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h
index d721fa2..e870622 100644
--- a/common/rfb/PixelBuffer.h
+++ b/common/rfb/PixelBuffer.h
@@ -44,7 +44,10 @@
     //
 
     // Set/get pixel format & colourmap
+  protected:
+    // Only for subclasses that support changing parameters
     virtual void setPF(const PixelFormat &pf);
+  public:
     virtual const PixelFormat &getPF() const;
     virtual ColourMap* getColourMap() const;
 
@@ -103,6 +106,10 @@
                          rdr::U8* data_, ColourMap* cm);
     virtual ~FullFramePixelBuffer();
 
+  protected:
+    virtual void setPF(const PixelFormat &pf);
+
+  public:
     // - Get the number of pixels per row in the actual pixel buffer data area
     //   This may in some cases NOT be the same as width().
     virtual int getStride() const;