remove uirdesktop

ulab-original
jsorg71 18 years ago
parent 451f7a1c0f
commit c569c09a5c

File diff suppressed because it is too large Load Diff

@ -1,833 +0,0 @@
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Generics backingstore operations
Copyright (C) Jay Sorg 2005-2006
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <string.h>
#include "bsops.h"
/* externals */
extern int g_width;
extern int g_height;
extern int g_bs_bpp;
extern int g_bs_Bpp;
extern char * g_bs;
/* globals */
static int g_clip_left = 0;
static int g_clip_top = 0;
static int g_clip_right = 800;
static int g_clip_bottom = 600;
/* for bs_patblt */
static unsigned char g_hatch_patterns[] =
{
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0 - bsHorizontal */
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 1 - bsVertical */
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, /* 2 - bsFDiagonal */
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, /* 3 - bsBDiagonal */
0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, /* 4 - bsCross */
0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 /* 5 - bsDiagCross */
};
/*****************************************************************************/
/* do a raster op */
int
bs_do_rop(int rop, int src, int dst)
{
switch (rop)
{
case 0x0: return 0;
case 0x1: return ~(src | dst);
case 0x2: return (~src) & dst;
case 0x3: return ~src;
case 0x4: return src & (~dst);
case 0x5: return ~(dst);
case 0x6: return src ^ dst;
case 0x7: return ~(src & dst);
case 0x8: return src & dst;
case 0x9: return ~(src) ^ dst;
case 0xa: return dst;
case 0xb: return (~src) | dst;
case 0xc: return src;
case 0xd: return src | (~dst);
case 0xe: return src | dst;
case 0xf: return ~0;
}
return dst;
}
/*****************************************************************************/
/* get a pixel from the in memory copy of whats on the screen */
int
bs_get_pixel(int x, int y)
{
char * p;
if (x >= 0 && x < g_width && y >= 0 && y < g_height)
{
p = g_bs + (y * g_width * g_bs_Bpp) + (x * g_bs_Bpp);
if (g_bs_Bpp == 1)
{
return *((unsigned char *) p);
}
else if (g_bs_Bpp == 2)
{
return *((unsigned short *) p);
}
else
{
return *((unsigned int *) p);
}
}
else
{
return 0;
}
}
/*****************************************************************************/
/* set a pixel on the screen using the clip */
void
bs_set_pixel(int x, int y, int pixel, int rop, int use_clip)
{
char * p;
if (!use_clip ||
(x >= g_clip_left && x < g_clip_right &&
y >= g_clip_top && y < g_clip_bottom))
{
if (x >= 0 && x < g_width && y >= 0 && y < g_height)
{
p = g_bs + (y * g_width * g_bs_Bpp) + (x * g_bs_Bpp);
if (rop != 12)
{
pixel = bs_do_rop(rop, pixel, bs_get_pixel(x, y));
}
if (g_bs_Bpp == 1)
{
*((unsigned char *) p) = pixel;
}
else if (g_bs_Bpp == 2)
{
*((unsigned short *) p) = pixel;
}
else
{
*((unsigned int *) p) = pixel;
}
}
}
}
/*****************************************************************************/
static char *
get_bs_ptr(int x, int y)
{
char * p;
if (x >= 0 && x < g_width && y >= 0 && y < g_height)
{
p = g_bs + (y * g_width * g_bs_Bpp) + (x * g_bs_Bpp);
return p;
}
else
{
return 0;
}
}
/*****************************************************************************/
void
bs_init(void)
{
g_clip_left = 0;
g_clip_top = 0;
g_clip_right = g_width;
g_clip_bottom = g_height;
}
/*****************************************************************************/
void
bs_exit(void)
{
}
/*****************************************************************************/
void
bs_set_clip(int x, int y, int cx, int cy)
{
g_clip_left = x;
g_clip_top = y;
g_clip_right = x + cx;
g_clip_bottom = y + cy;
}
/*****************************************************************************/
void
bs_reset_clip(void)
{
g_clip_left = 0;
g_clip_top = 0;
g_clip_right = g_width;
g_clip_bottom = g_height;
}
/*****************************************************************************/
/* check if a certain pixel is set in a bitmap */
int
bs_is_pixel_on(char * data, int x, int y, int width, int bpp)
{
int start;
int shift;
if (bpp == 1)
{
width = (width + 7) / 8;
start = (y * width) + x / 8;
shift = x % 8;
return (data[start] & (0x80 >> shift)) != 0;
}
else if (bpp == 8)
{
return data[y * width + x] != 0;
}
else if (bpp == 24)
{
return data[(y * 3) * width + (x * 3)] != 0 &&
data[(y * 3) * width + (x * 3) + 1] != 0 &&
data[(y * 3) * width + (x * 3) + 2] != 0;
}
else
{
return 0;
}
}
/*****************************************************************************/
void
bs_set_pixel_on(char * data, int x, int y, int width, int bpp,
int pixel)
{
int start;
int shift;
if (bpp == 1)
{
width = (width + 7) / 8;
start = (y * width) + x / 8;
shift = x % 8;
if (pixel != 0)
{
data[start] = data[start] | (0x80 >> shift);
}
else
{
data[start] = data[start] & ~(0x80 >> shift);
}
}
else if (bpp == 8)
{
data[y * width + x] = pixel;
}
else if (bpp == 15 || bpp == 16)
{
((unsigned short *) data)[y * width + x] = pixel;
}
}
/*****************************************************************************/
void
bs_copy_mem(char * d, char * s, int n)
{
while (n & (~7))
{
*(d++) = *(s++);
*(d++) = *(s++);
*(d++) = *(s++);
*(d++) = *(s++);
*(d++) = *(s++);
*(d++) = *(s++);
*(d++) = *(s++);
*(d++) = *(s++);
n = n - 8;
}
while (n > 0)
{
*(d++) = *(s++);
n--;
}
}
/*****************************************************************************/
void
bs_copy_memb(char * d, char * s, int n)
{
d = (d + n) - 1;
s = (s + n) - 1;
while (n & (~7))
{
*(d--) = *(s--);
*(d--) = *(s--);
*(d--) = *(s--);
*(d--) = *(s--);
*(d--) = *(s--);
*(d--) = *(s--);
*(d--) = *(s--);
*(d--) = *(s--);
n = n - 8;
}
while (n > 0)
{
*(d--) = *(s--);
n--;
}
}
/*****************************************************************************/
/* return true is the is something to draw */
int
bs_warp_coords(int * x, int * y, int * cx, int * cy,
int * srcx, int * srcy)
{
int dx;
int dy;
if (g_clip_left > *x)
{
dx = g_clip_left - *x;
}
else
{
dx = 0;
}
if (g_clip_top > *y)
{
dy = g_clip_top - *y;
}
else
{
dy = 0;
}
if (*x + *cx > g_clip_right)
{
*cx = (*cx - ((*x + *cx) - g_clip_right));
}
if (*y + *cy > g_clip_bottom)
{
*cy = (*cy - ((*y + *cy) - g_clip_bottom));
}
*cx = *cx - dx;
*cy = *cy - dy;
if (*cx <= 0)
{
return 0;
}
if (*cy <= 0)
{
return 0;
}
*x = *x + dx;
*y = *y + dy;
if (srcx != 0)
{
*srcx = *srcx + dx;
}
if (srcy != 0)
{
*srcy = *srcy + dy;
}
return 1;
}
/*****************************************************************************/
void
bs_rect(int x, int y, int cx, int cy, int colour, int rop)
{
int i;
int j;
unsigned char * p8;
unsigned short * p16;
unsigned int * p32;
if (bs_warp_coords(&x, &y, &cx, &cy, 0, 0))
{
if (rop == 0) /* black */
{
rop = 12;
colour = 0;
}
else if (rop == 15) /* white */
{
rop = 12;
colour = 0xffffff;
}
if (rop == 12) /* copy */
{
if (g_bs_Bpp == 1)
{
for (i = 0; i < cy; i++)
{
p8 = (unsigned char *) get_bs_ptr(x, y + i);
if (p8 != 0)
{
for (j = 0; j < cx; j++)
{
*p8 = colour;
p8++;
}
}
}
}
else if (g_bs_Bpp == 2)
{
for (i = 0; i < cy; i++)
{
p16 = (unsigned short *) get_bs_ptr(x, y + i);
if (p16 != 0)
{
for (j = 0; j < cx; j++)
{
*p16 = colour;
p16++;
}
}
}
}
else
{
for (i = 0; i < cy; i++)
{
p32 = (unsigned int *) get_bs_ptr(x, y + i);
if (p32 != 0)
{
for (j = 0; j < cx; j++)
{
*p32 = colour;
p32++;
}
}
}
}
}
else /* slow */
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
bs_set_pixel(j + x, i + y, colour, rop, 0);
}
}
}
}
}
/*****************************************************************************/
void
bs_screenblt(int rop, int x, int y, int cx, int cy,
int srcx, int srcy)
{
int p;
int i;
int j;
char * src;
char * dst;
if (bs_warp_coords(&x, &y, &cx, &cy, &srcx, &srcy))
{
if (rop == 12) /* copy */
{
if (srcy < y) /* copy down - bottom to top */
{
for (i = cy - 1; i >= 0; i--)
{
src = get_bs_ptr(srcx, srcy + i);
dst = get_bs_ptr(x, y + i);
if (src != 0 && dst != 0)
{
bs_copy_mem(dst, src, cx * g_bs_Bpp);
}
}
}
else if (srcy > y || srcx > x) /* copy up or left - top to bottom */
{
for (i = 0; i < cy; i++)
{
src = get_bs_ptr(srcx, srcy + i);
dst = get_bs_ptr(x, y + i);
if (src != 0 && dst != 0)
{
bs_copy_mem(dst, src, cx * g_bs_Bpp);
}
}
}
else /* copy straight right */
{
for (i = 0; i < cy; i++)
{
src = get_bs_ptr(srcx, srcy + i);
dst = get_bs_ptr(x, y + i);
if (src != 0 && dst != 0)
{
bs_copy_memb(dst, src, cx * g_bs_Bpp);
}
}
}
}
else /* slow */
{
if (srcy < y) /* copy down - bottom to top */
{
for (i = cy - 1; i >= 0; i--)
{
for (j = 0; j < cx; j++)
{
p = bs_get_pixel(srcx + j, srcy + i);
bs_set_pixel(x + j, y + i, p, rop, 0);
}
}
}
else if (srcy > y || srcx > x) /* copy up or left - top to bottom */
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
p = bs_get_pixel(srcx + j, srcy + i);
bs_set_pixel(x + j, y + i, p, rop, 0);
}
}
}
else /* copy straight right */
{
for (i = 0; i < cy; i++)
{
for (j = cx - 1; j >= 0; j--)
{
p = bs_get_pixel(srcx + j, srcy + i);
bs_set_pixel(x + j, y + i, p, rop, 0);
}
}
}
}
}
}
/*****************************************************************************/
int
bs_memblt(int opcode, int x, int y, int cx, int cy,
void * srcdata, int srcwidth, int srcheight,
int srcx, int srcy)
{
int i;
int j;
int p;
int rv;
char * dst;
char * src;
rv = 1;
if (bs_warp_coords(&x, &y, &cx, &cy, &srcx, &srcy))
{
if (opcode == 12) /* copy */
{
rv = 0;
if (g_bs_Bpp == 1)
{
src = (char *) (((unsigned char *) srcdata) + srcy * srcwidth + srcx);
}
else if (g_bs_Bpp == 2)
{
src = (char *) (((unsigned short *) srcdata) + srcy * srcwidth + srcx);
}
else
{
src = (char *) (((unsigned int *) srcdata) + srcy * srcwidth + srcx);
}
for (i = 0; i < cy; i++)
{
dst = get_bs_ptr(x, y + i);
if (dst != 0)
{
if (!rv)
{
if (memcmp(dst, src, cx * g_bs_Bpp) != 0)
{
rv = 1;
}
}
bs_copy_mem(dst, src, cx * g_bs_Bpp);
src += srcwidth * g_bs_Bpp;
}
}
}
else /* slow */
{
if (g_bs_Bpp == 1)
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
p = *(((unsigned char *) srcdata) +
((i + srcy) * srcwidth + (j + srcx)));
bs_set_pixel(x + j, y + i, p, opcode, 0);
}
}
}
else if (g_bs_Bpp == 2)
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
p = *(((unsigned short *) srcdata) +
((i + srcy) * srcwidth + (j + srcx)));
bs_set_pixel(x + j, y + i, p, opcode, 0);
}
}
}
else
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
p = *(((unsigned int *) srcdata) +
((i + srcy) * srcwidth + (j + srcx)));
bs_set_pixel(x + j, y + i, p, opcode, 0);
}
}
}
}
}
return rv;
}
/*****************************************************************************/
void
bs_draw_glyph(int x, int y, char * glyph_data, int glyph_width,
int glyph_height, int fgcolour)
{
int i;
int j;
for (i = 0; i < glyph_height; i++)
{
for (j = 0; j < glyph_width; j++)
{
if (bs_is_pixel_on(glyph_data, j, i, glyph_width, 8))
{
bs_set_pixel(x + j, y + i, fgcolour, 12, 1);
}
}
}
}
/*****************************************************************************/
/* Bresenham's line drawing algorithm */
void
bs_line(int opcode, int startx, int starty, int endx, int endy,
int pen_width, int pen_style, int pen_colour)
{
int dx;
int dy;
int incx;
int incy;
int dpr;
int dpru;
int p;
if (startx > endx)
{
dx = startx - endx;
incx = -1;
}
else
{
dx = endx - startx;
incx = 1;
}
if (starty > endy)
{
dy = starty - endy;
incy = -1;
}
else
{
dy = endy - starty;
incy = 1;
}
if (dx >= dy)
{
dpr = dy << 1;
dpru = dpr - (dx << 1);
p = dpr - dx;
for (; dx >= 0; dx--)
{
if (startx != endx || starty != endy)
{
bs_set_pixel(startx, starty, pen_colour, opcode, 1);
}
if (p > 0)
{
startx += incx;
starty += incy;
p += dpru;
}
else
{
startx += incx;
p += dpr;
}
}
}
else
{
dpr = dx << 1;
dpru = dpr - (dy << 1);
p = dpr - dy;
for (; dy >= 0; dy--)
{
if (startx != endx || starty != endy)
{
bs_set_pixel(startx, starty, pen_colour, opcode, 1);
}
if (p > 0)
{
startx += incx;
starty += incy;
p += dpru;
}
else
{
starty += incy;
p += dpr;
}
}
}
}
/*****************************************************************************/
void
bs_patblt(int opcode, int x, int y, int cx, int cy,
int brush_style, char * brush_pattern,
int brush_x_org, int brush_y_org,
int bgcolour, int fgcolour)
{
int i;
int j;
char ipattern[8];
char * b;
b = 0;
switch (brush_style)
{
case 0:
bs_rect(x, y, cx, cy, fgcolour, opcode);
break;
case 2: /* Hatch */
b = g_hatch_patterns + brush_pattern[0] * 8;
break;
case 3:
for (i = 0; i < 8; i++)
{
ipattern[i] = ~brush_pattern[7 - i];
}
b = ipattern;
break;
}
if (b != 0)
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
if (bs_is_pixel_on(b, (x + j + brush_x_org) % 8,
(y + i + brush_y_org) % 8, 8, 1))
{
bs_set_pixel(x + j, y + i, fgcolour, opcode, 1);
}
else
{
bs_set_pixel(x + j, y + i, bgcolour, opcode, 1);
}
}
}
}
}
/*****************************************************************************/
void
bs_copy_box(char * dst, int x, int y, int cx, int cy, int line_size)
{
char * src;
int i;
/* shouldn't happen */
if (cx < 1 || cy < 1)
{
return;
}
/* nothing to draw, memset and leave */
if (x + cx < 0 || y + cy < 0 || x >= g_width || y >= g_height)
{
memset(dst, 0, cx * cy * g_bs_Bpp);
return;
}
/* check if it goes over an edge */
if (x < 0 || y < 0 || x + cx > g_width || y + cy > g_height)
{
memset(dst, 0, cx * cy * g_bs_Bpp);
if (x < 0)
{
cx += x;
dst += -x * g_bs_Bpp;
x = 0;
}
if (x + cx > g_width)
{
cx = g_width - x;
}
for (i = 0; i < cy; i++)
{
src = get_bs_ptr(x, y + i);
if (src != 0)
{
bs_copy_mem(dst, src, cx * g_bs_Bpp);
}
dst += line_size;
}
}
else /* whole box is within */
{
for (i = 0; i < cy; i++)
{
src = get_bs_ptr(x, y + i);
if (src != 0)
{
bs_copy_mem(dst, src, cx * g_bs_Bpp);
}
dst += line_size;
}
}
}

@ -1,49 +0,0 @@
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Generics backingstore operations
Copyright (C) Jay Sorg 2005-2006
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
int bs_get_pixel(int x, int y);
void bs_set_pixel(int x, int y, int pixel, int rop, int use_clip);
int bs_do_rop(int rop, int src, int dst);
void bs_init(void);
void bs_exit(void);
void bs_set_clip(int x, int y, int cx, int cy);
void bs_reset_clip(void);
void bs_set_pixel_on(char * data, int x, int y, int width, int bpp,
int pixel);
int bs_is_pixel_on(char * data, int x, int y, int width, int bpp);
void bs_copy_mem(char * d, char * s, int n);
void bs_copy_memb(char * d, char * s, int n);
int bs_warp_coords(int * x, int * y, int * cx, int * cy,
int * srcx, int * srcy);
void bs_rect(int x, int y, int cx, int cy, int colour, int rop);
void bs_screenblt(int opcode, int x, int y, int cx, int cy,
int srcx, int srcy);
int bs_memblt(int opcode, int x, int y, int cx, int cy,
void * srcdata, int srcwidth, int srcheight,
int srcx, int srcy);
void bs_copy_box(char * dst, int x, int y, int cx, int cy, int line_size);
void bs_draw_glyph(int x, int y, char * glyph_data, int glyph_width,
int glyph_height, int fgcolour);
void bs_line(int opcode, int startx, int starty, int endx, int endy,
int pen_width, int pen_style, int pen_colour);
void bs_patblt(int opcode, int x, int y, int cx, int cy,
int brush_style, char * brush_pattern,
int brush_x_org, int brush_y_org,
int bgcolour, int fgcolour);

@ -1,432 +0,0 @@
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Cache routines
Copyright (C) Matthew Chapman 1999-2005
Copyright (C) Jeroen Meijer 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "rdesktop.h"
/* BITMAP CACHE */
extern int g_pstcache_fd[];
#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
#define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0)
#define TO_TOP -1
#define NOT_SET -1
#define IS_SET(idx) (idx >= 0)
/*
* TODO: Test for optimal value of BUMP_COUNT. TO_TOP gives lowest cpu utilisation but using
* a positive value will hopefully result in less frequently used bitmaps having a greater chance
* of being evicted from the cache, and therby reducing the need to load bitmaps from disk.
* (Jeroen)
*/
#define BUMP_COUNT 40
struct bmpcache_entry
{
RD_HBITMAP bitmap;
sint16 previous;
sint16 next;
};
static struct bmpcache_entry g_bmpcache[3][0xa00];
static RD_HBITMAP g_volatile_bc[3];
static int g_bmpcache_lru[3] = { NOT_SET, NOT_SET, NOT_SET };
static int g_bmpcache_mru[3] = { NOT_SET, NOT_SET, NOT_SET };
static int g_bmpcache_count[3];
/* Setup the bitmap cache lru/mru linked list */
void
cache_rebuild_bmpcache_linked_list(uint8 id, sint16 * idx, int count)
{
int n = count, c = 0;
sint16 n_idx;
/* find top, skip evicted bitmaps */
while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL);
if (n < 0)
{
g_bmpcache_mru[id] = g_bmpcache_lru[id] = NOT_SET;
return;
}
g_bmpcache_mru[id] = idx[n];
g_bmpcache[id][idx[n]].next = NOT_SET;
n_idx = idx[n];
c++;
/* link list */
while (n >= 0)
{
/* skip evicted bitmaps */
while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL);
if (n < 0)
break;
g_bmpcache[id][n_idx].previous = idx[n];
g_bmpcache[id][idx[n]].next = n_idx;
n_idx = idx[n];
c++;
}
g_bmpcache[id][n_idx].previous = NOT_SET;
g_bmpcache_lru[id] = n_idx;
if (c != g_bmpcache_count[id])
{
error("Oops. %d in bitmap cache linked list, %d in ui cache...\n", c,
g_bmpcache_count[id]);
exit(1);
}
}
/* Move a bitmap to a new position in the linked list. */
void
cache_bump_bitmap(uint8 id, uint16 idx, int bump)
{
int p_idx, n_idx, n;
if (!IS_PERSISTENT(id))
return;
if (g_bmpcache_mru[id] == idx)
return;
DEBUG_RDP5(("bump bitmap: id=%d, idx=%d, bump=%d\n", id, idx, bump));
n_idx = g_bmpcache[id][idx].next;
p_idx = g_bmpcache[id][idx].previous;
if (IS_SET(n_idx))
{
/* remove */
--g_bmpcache_count[id];
if (IS_SET(p_idx))
g_bmpcache[id][p_idx].next = n_idx;
else
g_bmpcache_lru[id] = n_idx;
if (IS_SET(n_idx))
g_bmpcache[id][n_idx].previous = p_idx;
else
g_bmpcache_mru[id] = p_idx;
}
else
{
p_idx = NOT_SET;
n_idx = g_bmpcache_lru[id];
}
if (bump >= 0)
{
for (n = 0; n < bump && IS_SET(n_idx); n++)
{
p_idx = n_idx;
n_idx = g_bmpcache[id][p_idx].next;
}
}
else
{
p_idx = g_bmpcache_mru[id];
n_idx = NOT_SET;
}
/* insert */
++g_bmpcache_count[id];
g_bmpcache[id][idx].previous = p_idx;
g_bmpcache[id][idx].next = n_idx;
if (p_idx >= 0)
g_bmpcache[id][p_idx].next = idx;
else
g_bmpcache_lru[id] = idx;
if (n_idx >= 0)
g_bmpcache[id][n_idx].previous = idx;
else
g_bmpcache_mru[id] = idx;
}
/* Evict the least-recently used bitmap from the cache */
void
cache_evict_bitmap(uint8 id)
{
uint16 idx;
int n_idx;
if (!IS_PERSISTENT(id))
return;
idx = g_bmpcache_lru[id];
n_idx = g_bmpcache[id][idx].next;
DEBUG_RDP5(("evict bitmap: id=%d idx=%d n_idx=%d bmp=0x%x\n", id, idx, n_idx,
g_bmpcache[id][idx].bitmap));
ui_destroy_bitmap(g_bmpcache[id][idx].bitmap);
--g_bmpcache_count[id];
g_bmpcache[id][idx].bitmap = 0;
g_bmpcache_lru[id] = n_idx;
g_bmpcache[id][n_idx].previous = NOT_SET;
pstcache_touch_bitmap(id, idx, 0);
}
/* Retrieve a bitmap from the cache */
RD_HBITMAP
cache_get_bitmap(uint8 id, uint16 idx)
{
if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0])))
{
if (g_bmpcache[id][idx].bitmap || pstcache_load_bitmap(id, idx))
{
if (IS_PERSISTENT(id))
cache_bump_bitmap(id, idx, BUMP_COUNT);
return g_bmpcache[id][idx].bitmap;
}
}
else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff))
{
return g_volatile_bc[id];
}
error("get bitmap %d:%d\n", id, idx);
return NULL;
}
/* Store a bitmap in the cache */
void
cache_put_bitmap(uint8 id, uint16 idx, RD_HBITMAP bitmap)
{
RD_HBITMAP old;
if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0])))
{
old = g_bmpcache[id][idx].bitmap;
if (old != NULL)
ui_destroy_bitmap(old);
g_bmpcache[id][idx].bitmap = bitmap;
if (IS_PERSISTENT(id))
{
if (old == NULL)
g_bmpcache[id][idx].previous = g_bmpcache[id][idx].next = NOT_SET;
cache_bump_bitmap(id, idx, TO_TOP);
if (g_bmpcache_count[id] > BMPCACHE2_C2_CELLS)
cache_evict_bitmap(id);
}
}
else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff))
{
old = g_volatile_bc[id];
if (old != NULL)
ui_destroy_bitmap(old);
g_volatile_bc[id] = bitmap;
}
else
{
error("put bitmap %d:%d\n", id, idx);
}
}
/* Updates the persistent bitmap cache MRU information on exit */
void
cache_save_state(void)
{
uint32 id = 0, t = 0;
int idx;
for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++)
if (IS_PERSISTENT(id))
{
DEBUG_RDP5(("Saving cache state for bitmap cache %d...", id));
idx = g_bmpcache_lru[id];
while (idx >= 0)
{
pstcache_touch_bitmap((uint8) id, (uint16) idx, ++t);
idx = g_bmpcache[id][idx].next;
}
DEBUG_RDP5((" %d stamps written.\n", t));
}
}
/* FONT CACHE */
static FONTGLYPH g_fontcache[12][256];
/* Retrieve a glyph from the font cache */
FONTGLYPH *
cache_get_font(uint8 font, uint16 character)
{
FONTGLYPH *glyph;
if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
{
glyph = &g_fontcache[font][character];
if (glyph->pixmap != NULL)
return glyph;
}
error("get font %d:%d\n", font, character);
return NULL;
}
/* Store a glyph in the font cache */
void
cache_put_font(uint8 font, uint16 character, uint16 offset,
uint16 baseline, uint16 width, uint16 height, RD_HGLYPH pixmap)
{
FONTGLYPH *glyph;
if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
{
glyph = &g_fontcache[font][character];
if (glyph->pixmap != NULL)
ui_destroy_glyph(glyph->pixmap);
glyph->offset = offset;
glyph->baseline = baseline;
glyph->width = width;
glyph->height = height;
glyph->pixmap = pixmap;
}
else
{
error("put font %d:%d\n", font, character);
}
}
/* TEXT CACHE */
static DATABLOB g_textcache[256];
/* Retrieve a text item from the cache */
DATABLOB *
cache_get_text(uint8 cache_id)
{
DATABLOB *text;
text = &g_textcache[cache_id];
return text;
}
/* Store a text item in the cache */
void
cache_put_text(uint8 cache_id, void *data, int length)
{
DATABLOB *text;
text = &g_textcache[cache_id];
if (text->data != NULL)
xfree(text->data);
text->data = xmalloc(length);
text->size = length;
memcpy(text->data, data, length);
}
/* DESKTOP CACHE */
static uint8 g_deskcache[0x38400 * 4];
/* Retrieve desktop data from the cache */
uint8 *
cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
{
int length = cx * cy * bytes_per_pixel;
if (offset > sizeof(g_deskcache))
offset = 0;
if ((offset + length) <= sizeof(g_deskcache))
{
return &g_deskcache[offset];
}
error("get desktop %d:%d\n", offset, length);
return NULL;
}
/* Store desktop data in the cache */
void
cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
{
int length = cx * cy * bytes_per_pixel;
if (offset > sizeof(g_deskcache))
offset = 0;
if ((offset + length) <= sizeof(g_deskcache))
{
cx *= bytes_per_pixel;
while (cy--)
{
memcpy(&g_deskcache[offset], data, cx);
data += scanline;
offset += cx;
}
}
else
{
error("put desktop %d:%d\n", offset, length);
}
}
/* CURSOR CACHE */
static RD_HCURSOR g_cursorcache[0x20];
/* Retrieve cursor from cache */
RD_HCURSOR
cache_get_cursor(uint16 cache_idx)
{
RD_HCURSOR cursor;
if (cache_idx < NUM_ELEMENTS(g_cursorcache))
{
cursor = g_cursorcache[cache_idx];
if (cursor != NULL)
return cursor;
}
error("get cursor %d\n", cache_idx);
return NULL;
}
/* Store cursor in cache */
void
cache_put_cursor(uint16 cache_idx, RD_HCURSOR cursor)
{
RD_HCURSOR old;
if (cache_idx < NUM_ELEMENTS(g_cursorcache))
{
old = g_cursorcache[cache_idx];
if (old != NULL)
ui_destroy_cursor(old);
g_cursorcache[cache_idx] = cursor;
}
else
{
error("put cursor %d\n", cache_idx);
}
}
Loading…
Cancel
Save