diff options
author | Pierre Ossman <ossman@cendio.se> | 2014-02-06 16:31:10 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2014-07-07 14:55:27 +0200 |
commit | a32040d7c9972f70272218effbc0242416d417d2 (patch) | |
tree | b6ef6c797262da99af6907154b014a65acb15b60 /common/rfb | |
parent | 2e5a10608394186fd1324c97b17d7f08e0c0aaf6 (diff) | |
download | tigervnc-a32040d7c9972f70272218effbc0242416d417d2.tar.gz tigervnc-a32040d7c9972f70272218effbc0242416d417d2.zip |
Provide a better R/W base PixelBuffer class
Clearly separates the read API from the write API
and also from actual implementation.
Diffstat (limited to 'common/rfb')
-rw-r--r-- | common/rfb/ComparingUpdateTracker.cxx | 2 | ||||
-rw-r--r-- | common/rfb/PixelBuffer.cxx | 67 | ||||
-rw-r--r-- | common/rfb/PixelBuffer.h | 46 |
3 files changed, 89 insertions, 26 deletions
diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx index 8d4311a1..1d27f3c4 100644 --- a/common/rfb/ComparingUpdateTracker.cxx +++ b/common/rfb/ComparingUpdateTracker.cxx @@ -157,6 +157,8 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged) oldData += oldStrideBytes * BLOCK_SIZE; } + oldFb.commitBufferRW(r); + if (!changedBlocks.empty()) { Region temp; temp.setOrderedRects(changedBlocks); diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index ea19d183..bcffa791 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -60,26 +60,24 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) { } } +// -=- Modifiable generic pixel buffer class -FullFramePixelBuffer::FullFramePixelBuffer(const PixelFormat& pf, int w, int h, - rdr::U8* data_, int stride_) - : PixelBuffer(pf, w, h), data(data_), stride(stride_) +ModifiablePixelBuffer::ModifiablePixelBuffer(const PixelFormat& pf, + int w, int h) + : PixelBuffer(pf, w, h) { } -FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {} - -FullFramePixelBuffer::~FullFramePixelBuffer() {} - - -rdr::U8* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) +ModifiablePixelBuffer::ModifiablePixelBuffer() { - *stride_ = stride; - return &data[(r.tl.x + (r.tl.y * stride)) * format.bpp/8]; } +ModifiablePixelBuffer::~ModifiablePixelBuffer() +{ +} -void FullFramePixelBuffer::fillRect(const Rect& r, Pixel pix) { +void ModifiablePixelBuffer::fillRect(const Rect& r, Pixel pix) +{ int stride; U8 *buf, pixbuf[4]; int w, h, b; @@ -99,9 +97,13 @@ void FullFramePixelBuffer::fillRect(const Rect& r, Pixel pix) { } buf += (stride - w) * b; } + + commitBufferRW(r); } -void FullFramePixelBuffer::imageRect(const Rect& r, const void* pixels, int srcStride) { +void ModifiablePixelBuffer::imageRect(const Rect& r, + const void* pixels, int srcStride) +{ int bytesPerPixel = getPF().bpp/8; int destStride; U8* dest = getBufferRW(r, &destStride); @@ -116,9 +118,12 @@ void FullFramePixelBuffer::imageRect(const Rect& r, const void* pixels, int srcS dest += bytesPerDestRow; src += bytesPerSrcRow; } + commitBufferRW(r); } -void FullFramePixelBuffer::maskRect(const Rect& r, const void* pixels, const void* mask_) { +void ModifiablePixelBuffer::maskRect(const Rect& r, + const void* pixels, const void* mask_) +{ Rect cr = getRect().intersect(r); if (cr.is_empty()) return; int stride; @@ -154,9 +159,13 @@ void FullFramePixelBuffer::maskRect(const Rect& r, const void* pixels, const voi } mask += maskStride; } + + commitBufferRW(cr); } -void FullFramePixelBuffer::maskRect(const Rect& r, Pixel pixel, const void* mask_) { +void ModifiablePixelBuffer::maskRect(const Rect& r, + Pixel pixel, const void* mask_) +{ Rect cr = getRect().intersect(r); if (cr.is_empty()) return; int stride; @@ -190,9 +199,13 @@ void FullFramePixelBuffer::maskRect(const Rect& r, Pixel pixel, const void* mask } mask += maskStride; } + + commitBufferRW(cr); } -void FullFramePixelBuffer::copyRect(const Rect &rect, const Point &move_by_delta) { +void ModifiablePixelBuffer::copyRect(const Rect &rect, + const Point &move_by_delta) +{ int stride; U8* data; unsigned int bytesPerPixel, bytesPerRow, bytesPerMemCpy; @@ -241,8 +254,30 @@ void FullFramePixelBuffer::copyRect(const Rect &rect, const Point &move_by_delta src -= bytesPerRow; } } + commitBufferRW(getRect()); +} + +// -=- Simple pixel buffer with a continuous block of memory + +FullFramePixelBuffer::FullFramePixelBuffer(const PixelFormat& pf, int w, int h, + rdr::U8* data_, int stride_) + : ModifiablePixelBuffer(pf, w, h), data(data_), stride(stride_) +{ } +FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {} + +FullFramePixelBuffer::~FullFramePixelBuffer() {} + +rdr::U8* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) +{ + *stride_ = stride; + return &data[(r.tl.x + (r.tl.y * stride)) * format.bpp/8]; +} + +void FullFramePixelBuffer::commitBufferRW(const Rect& r) +{ +} // -=- Managed pixel buffer class // Automatically allocates enough space for the specified format & area diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h index 59d71c79..e2cc3e92 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -66,7 +66,6 @@ namespace rfb { // The pointer is to the top-left pixel of the specified Rect. // The buffer stride (in pixels) is returned. virtual const rdr::U8* getBuffer(const Rect& r, int* stride) = 0; - virtual rdr::U8* getBufferRW(const Rect& r, int* stride) = 0; // Get pixel data for a given part of the buffer // Data is copied into the supplied buffer, with the specified @@ -89,20 +88,31 @@ namespace rfb { int width_, height_; }; - // FullFramePixelBuffer - - class FullFramePixelBuffer : public PixelBuffer { + // ModifiablePixelBuffer + class ModifiablePixelBuffer : public PixelBuffer { public: - FullFramePixelBuffer(const PixelFormat& pf, int width, int height, - rdr::U8* data, int stride); - virtual ~FullFramePixelBuffer(); + ModifiablePixelBuffer(const PixelFormat& pf, int width, int height); + virtual ~ModifiablePixelBuffer(); - public: - // Get a pointer to specified pixel data + /////////////////////////////////////////////// + // Access to pixel data + // + + // 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 rdr::U8* getBufferRW(const 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; + + // Default trivial handling of read-only access virtual const rdr::U8* getBuffer(const Rect& r, int* stride) { return getBufferRW(r, stride); } - virtual rdr::U8* getBufferRW(const Rect& r, int* stride); /////////////////////////////////////////////// // Basic rendering operations @@ -128,6 +138,22 @@ namespace rfb { void maskRect(const Rect& r, Pixel pixel, const void* mask_); protected: + ModifiablePixelBuffer(); + }; + + // FullFramePixelBuffer + + class FullFramePixelBuffer : public ModifiablePixelBuffer { + public: + FullFramePixelBuffer(const PixelFormat& pf, int width, int height, + rdr::U8* data_, int stride); + virtual ~FullFramePixelBuffer(); + + public: + virtual rdr::U8* getBufferRW(const Rect& r, int* stride); + virtual void commitBufferRW(const Rect& r); + + protected: FullFramePixelBuffer(); rdr::U8* data; |