2000-07-25 14:34:29 +02:00
|
|
|
/*
|
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
|
|
|
Cache routines
|
2002-09-26 16:26:46 +02:00
|
|
|
Copyright (C) Matthew Chapman 1999-2002
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
#include "rdesktop.h"
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
|
|
|
|
|
|
|
|
|
|
|
|
/* BITMAP CACHE */
|
|
|
|
static HBITMAP bmpcache[3][600];
|
|
|
|
|
|
|
|
/* Retrieve a bitmap from the cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
HBITMAP
|
|
|
|
cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
HBITMAP bitmap;
|
|
|
|
|
2002-07-30 09:18:48 +02:00
|
|
|
if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
bitmap = bmpcache[cache_id][cache_idx];
|
2000-07-25 14:34:29 +02:00
|
|
|
if (bitmap != NULL)
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2001-09-14 15:51:38 +02:00
|
|
|
error("get bitmap %d:%d\n", cache_id, cache_idx);
|
2000-07-25 14:34:29 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Store a bitmap in the cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
void
|
|
|
|
cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
HBITMAP old;
|
|
|
|
|
2002-07-30 09:18:48 +02:00
|
|
|
if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
old = bmpcache[cache_id][cache_idx];
|
2000-07-25 14:34:29 +02:00
|
|
|
if (old != NULL)
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_destroy_bitmap(old);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
bmpcache[cache_id][cache_idx] = bitmap;
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-14 15:51:38 +02:00
|
|
|
error("put bitmap %d:%d\n", cache_id, cache_idx);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
|
|
|
|
/* FONT CACHE */
|
|
|
|
static FONTGLYPH fontcache[12][256];
|
|
|
|
|
|
|
|
/* Retrieve a glyph from the font cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
FONTGLYPH *
|
|
|
|
cache_get_font(uint8 font, uint16 character)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
FONTGLYPH *glyph;
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2002-07-30 09:18:48 +02:00
|
|
|
if ((font < NUM_ELEMENTS(fontcache)) && (character < NUM_ELEMENTS(fontcache[0])))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
glyph = &fontcache[font][character];
|
2000-07-25 14:34:29 +02:00
|
|
|
if (glyph->pixmap != NULL)
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
2001-09-14 15:51:38 +02:00
|
|
|
error("get font %d:%d\n", font, character);
|
2000-07-25 14:34:29 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Store a glyph in the font cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
void
|
|
|
|
cache_put_font(uint8 font, uint16 character, uint16 offset,
|
|
|
|
uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
FONTGLYPH *glyph;
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2002-07-30 09:18:48 +02:00
|
|
|
if ((font < NUM_ELEMENTS(fontcache)) && (character < NUM_ELEMENTS(fontcache[0])))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
glyph = &fontcache[font][character];
|
2000-07-25 14:34:29 +02:00
|
|
|
if (glyph->pixmap != NULL)
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_destroy_glyph(glyph->pixmap);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-10-16 09:37:52 +02:00
|
|
|
glyph->offset = offset;
|
2000-07-25 14:34:29 +02:00
|
|
|
glyph->baseline = baseline;
|
|
|
|
glyph->width = width;
|
|
|
|
glyph->height = height;
|
|
|
|
glyph->pixmap = pixmap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-14 15:51:38 +02:00
|
|
|
error("put font %d:%d\n", font, character);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
|
|
|
|
/* TEXT CACHE */
|
|
|
|
static DATABLOB textcache[256];
|
|
|
|
|
|
|
|
/* Retrieve a text item from the cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
DATABLOB *
|
|
|
|
cache_get_text(uint8 cache_id)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
DATABLOB *text;
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
if (cache_id < NUM_ELEMENTS(textcache))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
text = &textcache[cache_id];
|
2000-07-25 14:34:29 +02:00
|
|
|
if (text->data != NULL)
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2001-09-14 15:51:38 +02:00
|
|
|
error("get text %d\n", cache_id);
|
2000-07-25 14:34:29 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
/* Store a text item in the cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
void
|
|
|
|
cache_put_text(uint8 cache_id, void *data, int length)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
DATABLOB *text;
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
if (cache_id < NUM_ELEMENTS(textcache))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
text = &textcache[cache_id];
|
2000-07-25 14:34:29 +02:00
|
|
|
if (text->data != NULL)
|
2000-08-15 12:23:24 +02:00
|
|
|
xfree(text->data);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
text->data = xmalloc(length);
|
2000-07-25 14:34:29 +02:00
|
|
|
text->size = length;
|
|
|
|
memcpy(text->data, data, length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-14 15:51:38 +02:00
|
|
|
error("put text %d\n", cache_id);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
2000-08-15 12:23:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* DESKTOP CACHE */
|
2001-06-20 15:54:48 +02:00
|
|
|
static uint8 deskcache[0x38400 * 4];
|
2000-08-15 12:23:24 +02:00
|
|
|
|
|
|
|
/* Retrieve desktop data from the cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
uint8 *
|
2001-06-20 15:54:48 +02:00
|
|
|
cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
|
2000-08-15 12:23:24 +02:00
|
|
|
{
|
2001-06-20 15:54:48 +02:00
|
|
|
int length = cx * cy * bytes_per_pixel;
|
2000-09-28 09:04:14 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
if ((offset + length) <= sizeof(deskcache))
|
|
|
|
{
|
|
|
|
return &deskcache[offset];
|
|
|
|
}
|
|
|
|
|
2001-09-14 15:51:38 +02:00
|
|
|
error("get desktop %d:%d\n", offset, length);
|
2000-08-15 12:23:24 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store desktop data in the cache */
|
2001-01-06 04:47:04 +01:00
|
|
|
void
|
2002-07-30 09:18:48 +02:00
|
|
|
cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
|
2000-08-15 12:23:24 +02:00
|
|
|
{
|
2001-06-20 15:54:48 +02:00
|
|
|
int length = cx * cy * bytes_per_pixel;
|
2000-09-28 09:04:14 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
if ((offset + length) <= sizeof(deskcache))
|
|
|
|
{
|
2001-06-20 15:54:48 +02:00
|
|
|
cx *= bytes_per_pixel;
|
2000-09-28 09:04:14 +02:00
|
|
|
while (cy--)
|
|
|
|
{
|
|
|
|
memcpy(&deskcache[offset], data, cx);
|
|
|
|
data += scanline;
|
|
|
|
offset += cx;
|
|
|
|
}
|
2000-08-15 12:23:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-14 15:51:38 +02:00
|
|
|
error("put desktop %d:%d\n", offset, length);
|
2000-08-15 12:23:24 +02:00
|
|
|
}
|
|
|
|
}
|
2001-06-20 15:54:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* CURSOR CACHE */
|
|
|
|
static HCURSOR cursorcache[0x20];
|
|
|
|
|
|
|
|
/* Retrieve cursor from cache */
|
2002-07-18 18:38:31 +02:00
|
|
|
HCURSOR
|
|
|
|
cache_get_cursor(uint16 cache_idx)
|
2001-06-20 15:54:48 +02:00
|
|
|
{
|
|
|
|
HCURSOR cursor;
|
|
|
|
|
|
|
|
if (cache_idx < NUM_ELEMENTS(cursorcache))
|
|
|
|
{
|
|
|
|
cursor = cursorcache[cache_idx];
|
|
|
|
if (cursor != NULL)
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2001-09-14 15:51:38 +02:00
|
|
|
error("get cursor %d\n", cache_idx);
|
2001-06-20 15:54:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store cursor in cache */
|
|
|
|
void
|
|
|
|
cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
|
|
|
|
{
|
|
|
|
HCURSOR old;
|
|
|
|
|
|
|
|
if (cache_idx < NUM_ELEMENTS(cursorcache))
|
|
|
|
{
|
|
|
|
old = cursorcache[cache_idx];
|
|
|
|
if (old != NULL)
|
|
|
|
ui_destroy_cursor(old);
|
|
|
|
|
|
|
|
cursorcache[cache_idx] = cursor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-14 15:51:38 +02:00
|
|
|
error("put cursor %d\n", cache_idx);
|
2001-06-20 15:54:48 +02:00
|
|
|
}
|
|
|
|
}
|