summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDRC <dcommander@users.sourceforge.net>2011-11-03 23:56:10 +0000
committerDRC <dcommander@users.sourceforge.net>2011-11-03 23:56:10 +0000
commit4f24c1a731dd812d14dac0a504a8033f6247a2fe (patch)
tree93d9180c7013fe02763766091b7c6cca17a5044d /common
parent3461d590b7c13e03a01bf5ffec59d035b2d6de4e (diff)
downloadtigervnc-4f24c1a731dd812d14dac0a504a8033f6247a2fe.tar.gz
tigervnc-4f24c1a731dd812d14dac0a504a8033f6247a2fe.zip
Since fillRect() operates directly on the framebuffer, optimize it and remove the separate version in TightDecoder.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4762 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common')
-rw-r--r--common/rfb/PixelBuffer.cxx96
-rw-r--r--common/rfb/PixelBuffer.h1
-rw-r--r--common/rfb/tightDecode.h34
3 files changed, 68 insertions, 63 deletions
diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx
index a48e735a..106b42bc 100644
--- a/common/rfb/PixelBuffer.cxx
+++ b/common/rfb/PixelBuffer.cxx
@@ -78,10 +78,74 @@ Pixel PixelBuffer::getPixel(const Point& p) {
*/
+static void fillRect8(U8 *buf, int stride, const Rect& r, Pixel pix)
+{
+ U8* ptr = buf;
+ int w = r.width(), h = r.height();
+
+ while (h > 0) {
+ memset(ptr, pix, w);
+ ptr += stride;
+ h--;
+ }
+}
+
+static void fillRect16(U8 *buf, int stride, const Rect& r, Pixel pix)
+{
+ U16* ptr = (U16 *)buf;
+ int w = r.width(), h = r.height(), wBytes = w * 2;
+
+ while (w > 0) {
+ *ptr++ = pix; w--;
+ }
+ h--;
+
+ ptr = (U16 *)buf;
+
+ while (h > 0) {
+ U16 *oldptr = ptr;
+ memcpy(ptr += stride, oldptr, wBytes);
+ h--;
+ }
+}
+
+static void fillRect32(U8 *buf, int stride, const Rect& r, Pixel pix)
+{
+ U32* ptr = (U32 *)buf;
+ int w = r.width(), h = r.height(), wBytes = w * 4;
+
+ while (w > 0) {
+ *ptr++ = pix; w--;
+ }
+ h--;
+
+ ptr = (U32 *)buf;
+
+ while (h > 0) {
+ U32 *oldptr = ptr;
+ memcpy(ptr += stride, oldptr, wBytes);
+ h--;
+ }
+}
+
+
FullFramePixelBuffer::FullFramePixelBuffer(const PixelFormat& pf, int w, int h,
rdr::U8* data_, ColourMap* cm)
: PixelBuffer(pf, w, h, cm), data(data_)
{
+ switch(pf.bpp) {
+ case 8:
+ fillRectFn = fillRect8;
+ break;
+ case 16:
+ fillRectFn = fillRect16;
+ break;
+ case 32:
+ fillRectFn = fillRect32;
+ break;
+ default:
+ throw Exception("rfb::FullFramePixelBuffer - Unsupported pixel format");
+ }
}
FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {}
@@ -100,36 +164,8 @@ rdr::U8* FullFramePixelBuffer::getPixelsRW(const Rect& r, int* stride)
void FullFramePixelBuffer::fillRect(const Rect& r, Pixel pix) {
int stride;
- U8* data = getPixelsRW(r, &stride);
- int bytesPerPixel = getPF().bpp/8;
- int bytesPerRow = bytesPerPixel * stride;
- int bytesPerFill = bytesPerPixel * r.width();
-
- U8* end = data + (bytesPerRow * r.height());
- while (data < end) {
- switch (bytesPerPixel) {
- case 1:
- memset(data, pix, bytesPerFill);
- break;
- case 2:
- {
- U16* optr = (U16*)data;
- U16* eol = optr + r.width();
- while (optr < eol)
- *optr++ = pix;
- }
- break;
- case 4:
- {
- U32* optr = (U32*)data;
- U32* eol = optr + r.width();
- while (optr < eol)
- *optr++ = pix;
- }
- break;
- }
- data += bytesPerRow;
- }
+ U8 *buf = getPixelsRW(r, &stride);
+ fillRectFn(buf, stride, r, pix);
}
void FullFramePixelBuffer::imageRect(const Rect& r, const void* pixels, int srcStride) {
diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h
index fc35a7d7..d721fa29 100644
--- a/common/rfb/PixelBuffer.h
+++ b/common/rfb/PixelBuffer.h
@@ -141,6 +141,7 @@ namespace rfb {
protected:
FullFramePixelBuffer();
+ void (*fillRectFn)(rdr::U8 *, int, const Rect&, Pixel);
};
// -=- Managed pixel buffer class
diff --git a/common/rfb/tightDecode.h b/common/rfb/tightDecode.h
index 4ea18a97..32bb4f15 100644
--- a/common/rfb/tightDecode.h
+++ b/common/rfb/tightDecode.h
@@ -46,7 +46,6 @@ namespace rfb {
#define TIGHT_DECODE TightDecoder::CONCAT2E(tightDecode,BPP)
#define DECOMPRESS_JPEG_RECT TightDecoder::CONCAT2E(DecompressJpegRect,BPP)
#define FILTER_GRADIENT TightDecoder::CONCAT2E(FilterGradient,BPP)
-#define DIRECT_FILL_RECT TightDecoder::CONCAT2E(directFillRect,BPP)
#define TIGHT_MIN_TO_COMPRESS 12
@@ -81,8 +80,7 @@ void TIGHT_DECODE (const Rect& r)
} else {
pix = is->READ_PIXEL();
}
- if (directDecode) DIRECT_FILL_RECT(r, pix);
- else FILL_RECT(r, pix);
+ FILL_RECT(r, pix);
return;
}
@@ -377,37 +375,7 @@ FILTER_GRADIENT(rdr::InStream* is, PIXEL_T* buf, int stride, const Rect& r,
delete [] netbuf;
}
-void
-DIRECT_FILL_RECT(const Rect& r, Pixel pix) {
-
- int stride;
- PIXEL_T *buf = (PIXEL_T *)handler->getRawPixelsRW(r, &stride);
-
- int w = r.width(), h = r.height();
- PIXEL_T *ptr = buf;
-#if BPP != 8
- int pad = stride - w;
-#endif
-
- while (h > 0) {
-#if BPP == 8
- memset(ptr, pix, w);
- ptr += stride;
-#else
- PIXEL_T *endOfRow = ptr + w;
- while (ptr < endOfRow) {
- *ptr++ = pix;
- }
- ptr += pad;
-#endif
- h--;
- }
-
- handler->releaseRawPixels(r);
-}
-
#undef TIGHT_MIN_TO_COMPRESS
-#undef DIRECT_FILL_RECT
#undef FILTER_GRADIENT
#undef DECOMPRESS_JPEG_RECT
#undef TIGHT_DECODE