2
rdesktop: A Remote Desktop Protocol client.
4
Copyright (C) Matthew Chapman 1999-2002
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
27
static HBITMAP g_bmpcache[3][600];
29
/* Retrieve a bitmap from the cache */
31
cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
35
if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
37
bitmap = g_bmpcache[cache_id][cache_idx];
42
error("get bitmap %d:%d\n", cache_id, cache_idx);
46
/* Store a bitmap in the cache */
48
cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
52
if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
54
old = g_bmpcache[cache_id][cache_idx];
56
ui_destroy_bitmap(old);
58
g_bmpcache[cache_id][cache_idx] = bitmap;
62
error("put bitmap %d:%d\n", cache_id, cache_idx);
68
static FONTGLYPH g_fontcache[12][256];
70
/* Retrieve a glyph from the font cache */
72
cache_get_font(uint8 font, uint16 character)
76
if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
78
glyph = &g_fontcache[font][character];
79
if (glyph->pixmap != NULL)
83
error("get font %d:%d\n", font, character);
87
/* Store a glyph in the font cache */
89
cache_put_font(uint8 font, uint16 character, uint16 offset,
90
uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
94
if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
96
glyph = &g_fontcache[font][character];
97
if (glyph->pixmap != NULL)
98
ui_destroy_glyph(glyph->pixmap);
100
glyph->offset = offset;
101
glyph->baseline = baseline;
102
glyph->width = width;
103
glyph->height = height;
104
glyph->pixmap = pixmap;
108
error("put font %d:%d\n", font, character);
114
static DATABLOB g_textcache[256];
116
/* Retrieve a text item from the cache */
118
cache_get_text(uint8 cache_id)
122
if (cache_id < NUM_ELEMENTS(g_textcache))
124
text = &g_textcache[cache_id];
125
if (text->data != NULL)
129
error("get text %d\n", cache_id);
133
/* Store a text item in the cache */
135
cache_put_text(uint8 cache_id, void *data, int length)
139
if (cache_id < NUM_ELEMENTS(g_textcache))
141
text = &g_textcache[cache_id];
142
if (text->data != NULL)
145
text->data = xmalloc(length);
147
memcpy(text->data, data, length);
151
error("put text %d\n", cache_id);
157
static uint8 g_deskcache[0x38400 * 4];
159
/* Retrieve desktop data from the cache */
161
cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
163
int length = cx * cy * bytes_per_pixel;
165
if (offset > sizeof(g_deskcache))
168
if ((offset + length) <= sizeof(g_deskcache))
170
return &g_deskcache[offset];
173
error("get desktop %d:%d\n", offset, length);
177
/* Store desktop data in the cache */
179
cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
181
int length = cx * cy * bytes_per_pixel;
183
if (offset > sizeof(g_deskcache))
186
if ((offset + length) <= sizeof(g_deskcache))
188
cx *= bytes_per_pixel;
191
memcpy(&g_deskcache[offset], data, cx);
198
error("put desktop %d:%d\n", offset, length);
204
static HCURSOR g_cursorcache[0x20];
206
/* Retrieve cursor from cache */
208
cache_get_cursor(uint16 cache_idx)
212
if (cache_idx < NUM_ELEMENTS(g_cursorcache))
214
cursor = g_cursorcache[cache_idx];
219
error("get cursor %d\n", cache_idx);
223
/* Store cursor in cache */
225
cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
229
if (cache_idx < NUM_ELEMENTS(g_cursorcache))
231
old = g_cursorcache[cache_idx];
233
ui_destroy_cursor(old);
235
g_cursorcache[cache_idx] = cursor;
239
error("put cursor %d\n", cache_idx);