1 |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
Cache routines |
4 |
Copyright (C) Matthew Chapman 1999-2000 |
5 |
|
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. |
10 |
|
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. |
15 |
|
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. |
19 |
*/ |
20 |
|
21 |
#include "rdesktop.h" |
22 |
|
23 |
#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0])) |
24 |
|
25 |
|
26 |
/* BITMAP CACHE */ |
27 |
static HBITMAP bmpcache[3][600]; |
28 |
|
29 |
/* Retrieve a bitmap from the cache */ |
30 |
HBITMAP cache_get_bitmap(uint8 cache_id, uint16 cache_idx) |
31 |
{ |
32 |
HBITMAP bitmap; |
33 |
|
34 |
if ((cache_id < NUM_ELEMENTS(bmpcache)) |
35 |
&& (cache_idx < NUM_ELEMENTS(bmpcache[0]))) |
36 |
{ |
37 |
bitmap = bmpcache[cache_id][cache_idx]; |
38 |
if (bitmap != NULL) |
39 |
return bitmap; |
40 |
} |
41 |
|
42 |
ERROR("get bitmap %d:%d\n", cache_id, cache_idx); |
43 |
return NULL; |
44 |
} |
45 |
|
46 |
/* Store a bitmap in the cache */ |
47 |
void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap) |
48 |
{ |
49 |
HBITMAP old; |
50 |
|
51 |
if ((cache_id < NUM_ELEMENTS(bmpcache)) |
52 |
&& (cache_idx < NUM_ELEMENTS(bmpcache[0]))) |
53 |
{ |
54 |
old = bmpcache[cache_id][cache_idx]; |
55 |
if (old != NULL) |
56 |
ui_destroy_bitmap(old); |
57 |
|
58 |
bmpcache[cache_id][cache_idx] = bitmap; |
59 |
} |
60 |
else |
61 |
{ |
62 |
ERROR("put bitmap %d:%d\n", cache_id, cache_idx); |
63 |
} |
64 |
} |
65 |
|
66 |
|
67 |
/* FONT CACHE */ |
68 |
static FONTGLYPH fontcache[12][256]; |
69 |
|
70 |
/* Retrieve a glyph from the font cache */ |
71 |
FONTGLYPH *cache_get_font(uint8 font, uint16 character) |
72 |
{ |
73 |
FONTGLYPH *glyph; |
74 |
|
75 |
if ((font < NUM_ELEMENTS(fontcache)) |
76 |
&& (character < NUM_ELEMENTS(fontcache[0]))) |
77 |
{ |
78 |
glyph = &fontcache[font][character]; |
79 |
if (glyph->pixmap != NULL) |
80 |
return glyph; |
81 |
} |
82 |
|
83 |
ERROR("get font %d:%d\n", font, character); |
84 |
return NULL; |
85 |
} |
86 |
|
87 |
/* Store a glyph in the font cache */ |
88 |
void cache_put_font(uint8 font, uint32 character, uint16 baseline, |
89 |
uint16 width, uint16 height, HGLYPH pixmap) |
90 |
{ |
91 |
FONTGLYPH *glyph; |
92 |
|
93 |
if ((font < NUM_ELEMENTS(fontcache)) |
94 |
&& (character < NUM_ELEMENTS(fontcache[0]))) |
95 |
{ |
96 |
glyph = &fontcache[font][character]; |
97 |
if (glyph->pixmap != NULL) |
98 |
ui_destroy_glyph(glyph->pixmap); |
99 |
|
100 |
glyph->baseline = baseline; |
101 |
glyph->width = width; |
102 |
glyph->height = height; |
103 |
glyph->pixmap = pixmap; |
104 |
} |
105 |
else |
106 |
{ |
107 |
ERROR("put font %d:%d\n", font, character); |
108 |
} |
109 |
} |
110 |
|
111 |
|
112 |
/* TEXT CACHE */ |
113 |
static DATABLOB textcache[256]; |
114 |
|
115 |
/* Retrieve a text item from the cache */ |
116 |
DATABLOB *cache_get_text(uint8 cache_id) |
117 |
{ |
118 |
DATABLOB *text; |
119 |
|
120 |
if (cache_id < NUM_ELEMENTS(textcache)) |
121 |
{ |
122 |
text = &textcache[cache_id]; |
123 |
if (text->data != NULL) |
124 |
return text; |
125 |
} |
126 |
|
127 |
ERROR("get text %d\n", cache_id); |
128 |
return NULL; |
129 |
} |
130 |
|
131 |
/* Store a text item in the cache */ |
132 |
void cache_put_text(uint8 cache_id, void *data, int length) |
133 |
{ |
134 |
DATABLOB *text; |
135 |
|
136 |
if (cache_id < NUM_ELEMENTS(textcache)) |
137 |
{ |
138 |
text = &textcache[cache_id]; |
139 |
if (text->data != NULL) |
140 |
xfree(text->data); |
141 |
|
142 |
text->data = xmalloc(length); |
143 |
text->size = length; |
144 |
memcpy(text->data, data, length); |
145 |
} |
146 |
else |
147 |
{ |
148 |
ERROR("put text %d\n", cache_id); |
149 |
} |
150 |
} |
151 |
|
152 |
|
153 |
/* DESKTOP CACHE */ |
154 |
static uint8 deskcache[0x38400]; |
155 |
|
156 |
/* Retrieve desktop data from the cache */ |
157 |
uint8 *cache_get_desktop(uint32 offset, uint32 length) |
158 |
{ |
159 |
if ((offset + length) <= sizeof(deskcache)) |
160 |
{ |
161 |
return &deskcache[offset]; |
162 |
} |
163 |
|
164 |
ERROR("get desktop %d:%d\n", offset, length); |
165 |
return NULL; |
166 |
} |
167 |
|
168 |
/* Store desktop data in the cache */ |
169 |
void cache_put_desktop(uint32 offset, uint32 length, uint8 *data) |
170 |
{ |
171 |
if ((offset + length) <= sizeof(deskcache)) |
172 |
{ |
173 |
memcpy(&deskcache[offset], data, length); |
174 |
} |
175 |
else |
176 |
{ |
177 |
ERROR("put desktop %d:%d\n", offset, length); |
178 |
} |
179 |
} |
180 |
|