summaryrefslogtreecommitdiffstats
path: root/xrdp/xrdp_bitmap.c
diff options
context:
space:
mode:
authorJay Sorg <jay.sorg@gmail.com>2014-03-14 11:48:07 -0700
committerJay Sorg <jay.sorg@gmail.com>2014-03-14 11:48:07 -0700
commitf94f5bec1c0563954924d7e036d0f70970236b16 (patch)
treea1cfb79b1d0cc3f0422ea3252fe443120c4dde8a /xrdp/xrdp_bitmap.c
parentc34ba69ad81776210da17b6bbb3db82be29b8624 (diff)
downloadxrdp-proprietary-f94f5bec1c0563954924d7e036d0f70970236b16.tar.gz
xrdp-proprietary-f94f5bec1c0563954924d7e036d0f70970236b16.zip
xrdp: speed up bitmap cache lookup using hash table
Diffstat (limited to 'xrdp/xrdp_bitmap.c')
-rw-r--r--xrdp/xrdp_bitmap.c134
1 files changed, 62 insertions, 72 deletions
diff --git a/xrdp/xrdp_bitmap.c b/xrdp/xrdp_bitmap.c
index 46fb6401..2fe87c4c 100644
--- a/xrdp/xrdp_bitmap.c
+++ b/xrdp/xrdp_bitmap.c
@@ -23,9 +23,22 @@
#include "xrdp.h"
#include "log.h"
-
-static int g_crc_seed = 0xffffffff;
-static int g_crc_table[256] =
+#include "crc16.h"
+
+#define LLOG_LEVEL 1
+#define LLOGLN(_level, _args) \
+ do \
+ { \
+ if (_level < LLOG_LEVEL) \
+ { \
+ g_write("xrdp:xrdp_bitmap [%10.10u]: ", g_time3()); \
+ g_writeln _args ; \
+ } \
+ } \
+ while (0)
+
+
+static const int g_crc_table[256] =
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -72,10 +85,10 @@ static int g_crc_table[256] =
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
-#define CRC_START(in_crc) (in_crc) = g_crc_seed
+#define CRC_START(in_crc) (in_crc) = 0xFFFFFFFF
#define CRC_PASS(in_pixel, in_crc) \
(in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)
-#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ g_crc_seed)
+#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ 0xFFFFFFFF)
/*****************************************************************************/
struct xrdp_bitmap *APP_CC
@@ -809,20 +822,20 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
struct xrdp_bitmap *dest,
int x, int y, int cx, int cy)
{
- int i = 0;
- int j = 0;
- int destx = 0;
- int desty = 0;
- int pixel = 0;
- int crc = 0;
- int incs = 0;
- int incd = 0;
- unsigned char *s8 = (unsigned char *)NULL;
- unsigned char *d8 = (unsigned char *)NULL;
- unsigned short *s16 = (unsigned short *)NULL;
- unsigned short *d16 = (unsigned short *)NULL;
- unsigned int *s32;
- unsigned int *d32;
+ int i;
+ int j;
+ int destx;
+ int desty;
+ int pixel;
+ int crc;
+ int incs;
+ int incd;
+ tui8 *s8;
+ tui8 *d8;
+ tui16 *s16;
+ tui16 *d16;
+ tui32 *s32;
+ tui32 *d32;
if (self == 0)
{
@@ -864,47 +877,54 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
CRC_START(crc);
+ CRC_PASS(self->width, crc);
+ CRC_PASS(self->width >> 8, crc);
+
+ CRC_PASS(self->height, crc);
+ CRC_PASS(self->height >> 8, crc);
+
if (self->bpp == 24)
{
- s32 = ((unsigned int *)(self->data)) + (self->width * y + x);
- d32 = ((unsigned int *)(dest->data)) + (dest->width * desty + destx);
+ s32 = ((tui32 *)(self->data)) + (self->width * y + x);
+ d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
for (i = 0; i < cy; i++)
{
j = 0;
+
while (j < cx - 4)
{
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
@@ -913,10 +933,10 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
while (j < cx)
{
pixel = *s32;
+ *d32 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc);
- *d32 = pixel;
s32++;
d32++;
@@ -929,8 +949,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
}
else if (self->bpp == 15 || self->bpp == 16)
{
- s16 = ((unsigned short *)(self->data)) + (self->width * y + x);
- d16 = ((unsigned short *)(dest->data)) + (dest->width * desty + destx);
+ s16 = ((tui16 *)(self->data)) + (self->width * y + x);
+ d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
@@ -939,9 +959,9 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
for (j = 0; j < cx; j++)
{
pixel = *s16;
+ *d16 = pixel;
CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc);
- *d16 = pixel;
s16++;
d16++;
}
@@ -952,8 +972,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
}
else if (self->bpp == 8)
{
- s8 = ((unsigned char *)(self->data)) + (self->width * y + x);
- d8 = ((unsigned char *)(dest->data)) + (dest->width * desty + destx);
+ s8 = ((tui8 *)(self->data)) + (self->width * y + x);
+ d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
@@ -962,8 +982,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
for (j = 0; j < cx; j++)
{
pixel = *s8;
- CRC_PASS(pixel, crc);
*d8 = pixel;
+ CRC_PASS(pixel, crc);
s8++;
d8++;
}
@@ -978,7 +998,14 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
}
CRC_END(crc);
- dest->crc = crc;
+ dest->crc32 = crc;
+ dest->crc16 = dest->crc32 & 0xffff;
+
+ LLOGLN(10, ("xrdp_bitmap_copy_box_with_crc: crc16 0x%4.4x",
+ dest->crc16));
+ LLOGLN(10, ("xrdp_bitmap_copy_box_with_crc: width %d height %d",
+ dest->width, dest->height));
+
return 0;
}
@@ -988,45 +1015,8 @@ int APP_CC
xrdp_bitmap_compare(struct xrdp_bitmap *self,
struct xrdp_bitmap *b)
{
- if (self == 0)
- {
- return 0;
- }
+ LLOGLN(10, ("xrdp_bitmap_compare:"));
- if (b == 0)
- {
- return 0;
- }
-
- if (self->bpp != b->bpp)
- {
- return 0;
- }
-
- if (self->width != b->width)
- {
- return 0;
- }
-
- if (self->height != b->height)
- {
- return 0;
- }
-
- if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
- {
- return 1;
- }
-
- return 0;
-}
-
-/*****************************************************************************/
-/* returns true if they are the same, else returns false */
-int APP_CC
-xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
- struct xrdp_bitmap *b)
-{
if (self == 0)
{
return 0;
@@ -1052,7 +1042,7 @@ xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
return 0;
}
- if (self->crc == b->crc)
+ if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
{
return 1;
}