diff options
author | Pierre Ossman <ossman@cendio.se> | 2014-02-13 14:37:25 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2014-07-14 16:00:20 +0200 |
commit | d4f718ddd02d50cb538ccd1e356a545aca119c2f (patch) | |
tree | 7c03a01fd7473961dbb51b0f2b1981a16e9c2177 | |
parent | 6ea6e1aebcd29cd8b950179f0df52768d5ddbdaf (diff) | |
download | tigervnc-d4f718ddd02d50cb538ccd1e356a545aca119c2f.tar.gz tigervnc-d4f718ddd02d50cb538ccd1e356a545aca119c2f.zip |
Allow PixelBuffers to be const
-rw-r--r-- | common/rfb/Cursor.cxx | 4 | ||||
-rw-r--r-- | common/rfb/Cursor.h | 6 | ||||
-rw-r--r-- | common/rfb/PixelBuffer.cxx | 10 | ||||
-rw-r--r-- | common/rfb/PixelBuffer.h | 12 |
4 files changed, 17 insertions, 15 deletions
diff --git a/common/rfb/Cursor.cxx b/common/rfb/Cursor.cxx index 62b767fa..8ef8b171 100644 --- a/common/rfb/Cursor.cxx +++ b/common/rfb/Cursor.cxx @@ -82,7 +82,7 @@ void Cursor::drawOutline(const Pixel& c) mask.buf = outlined.mask.buf; outlined.mask.buf = 0; } -rdr::U8* Cursor::getBitmap(Pixel* pix0, Pixel* pix1) +rdr::U8* Cursor::getBitmap(Pixel* pix0, Pixel* pix1) const { bool gotPix0 = false; bool gotPix1 = false; @@ -182,7 +182,7 @@ RenderedCursor::RenderedCursor() { } -const rdr::U8* RenderedCursor::getBuffer(const Rect& _r, int* stride) +const rdr::U8* RenderedCursor::getBuffer(const Rect& _r, int* stride) const { Rect r; diff --git a/common/rfb/Cursor.h b/common/rfb/Cursor.h index 5d4623d6..560e4d81 100644 --- a/common/rfb/Cursor.h +++ b/common/rfb/Cursor.h @@ -34,7 +34,7 @@ namespace rfb { rdr::U8Array mask; Point hotspot; - int maskLen() { return (width() + 7) / 8 * height(); } + int maskLen() const { return (width() + 7) / 8 * height(); } // setSize() resizes the cursor. The contents of the data and mask are // undefined after this call. @@ -46,7 +46,7 @@ namespace rfb { // getBitmap() tests whether the cursor is monochrome, and if so returns a // bitmap together with background and foreground colours. The size and // layout of the bitmap are the same as the mask. - rdr::U8* getBitmap(Pixel* pix0, Pixel* pix1); + rdr::U8* getBitmap(Pixel* pix0, Pixel* pix1) const; // crop() crops the cursor down to the smallest possible size, based on the // mask. @@ -59,7 +59,7 @@ namespace rfb { Rect getEffectiveRect() const { return buffer.getRect(offset); } - virtual const rdr::U8* getBuffer(const Rect& r, int* stride); + virtual const rdr::U8* getBuffer(const Rect& r, int* stride) const; void update(PixelBuffer* framebuffer, Cursor* cursor, const Point& pos); diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index 3f7f3019..b1359c2e 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -42,7 +42,7 @@ PixelBuffer::~PixelBuffer() {} void -PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) { +PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) const { int inStride; const U8* data = getBuffer(r, &inStride); // We assume that the specified rectangle is pre-clipped to the buffer @@ -61,7 +61,7 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) { } void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, - const Rect& r, int stride) + const Rect& r, int stride) const { const rdr::U8* srcBuffer; int srcStride; @@ -332,6 +332,12 @@ void FullFramePixelBuffer::commitBufferRW(const Rect& r) { } +const rdr::U8* FullFramePixelBuffer::getBuffer(const Rect& r, int* stride_) const +{ + *stride_ = stride; + return &data[(r.tl.x + (r.tl.y * stride)) * format.bpp/8]; +} + // -=- 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 5bc06c29..b0db6eb5 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -65,18 +65,18 @@ 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 rdr::U8* getBuffer(const Rect& r, int* stride) = 0; + virtual const rdr::U8* getBuffer(const 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); + void getImage(void* imageBuf, const 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 Rect& r, int stride=0) const; /////////////////////////////////////////////// // Framebuffer update methods @@ -114,11 +114,6 @@ namespace rfb { // 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); - } - /////////////////////////////////////////////// // Basic rendering operations // These operations DO NOT clip to the pixelbuffer area, or trap overruns. @@ -162,6 +157,7 @@ namespace rfb { virtual ~FullFramePixelBuffer(); public: + virtual const rdr::U8* getBuffer(const Rect& r, int* stride) const; virtual rdr::U8* getBufferRW(const Rect& r, int* stride); virtual void commitBufferRW(const Rect& r); |