18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
*/ |
20 |
|
|
21 |
#include "includes.h" |
#include "rdesktop.h" |
22 |
|
|
23 |
HBITMAP cache_get_bitmap(HCONN conn, uint8 cache_id, uint16 cache_idx) |
#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; |
HBITMAP bitmap; |
33 |
|
|
34 |
if ((cache_id < NUM_ELEMENTS(conn->bmpcache)) |
if ((cache_id < NUM_ELEMENTS(bmpcache)) |
35 |
&& (cache_idx < NUM_ELEMENTS(conn->bmpcache[0]))) |
&& (cache_idx < NUM_ELEMENTS(bmpcache[0]))) |
36 |
{ |
{ |
37 |
bitmap = conn->bmpcache[cache_id][cache_idx]; |
bitmap = bmpcache[cache_id][cache_idx]; |
38 |
if (bitmap != NULL) |
if (bitmap != NULL) |
39 |
return bitmap; |
return bitmap; |
40 |
} |
} |
41 |
|
|
42 |
ERROR("Bitmap %d:%d not found\n", cache_id, cache_idx); |
ERROR("get bitmap %d:%d\n", cache_id, cache_idx); |
43 |
return NULL; |
return NULL; |
44 |
} |
} |
45 |
|
|
46 |
void cache_put_bitmap(HCONN conn, uint8 cache_id, uint16 cache_idx, HBITMAP bitmap) |
/* Store a bitmap in the cache */ |
47 |
|
void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap) |
48 |
{ |
{ |
49 |
HBITMAP old; |
HBITMAP old; |
50 |
|
|
51 |
if ((cache_id < NUM_ELEMENTS(conn->bmpcache)) |
if ((cache_id < NUM_ELEMENTS(bmpcache)) |
52 |
&& (cache_idx < NUM_ELEMENTS(conn->bmpcache[0]))) |
&& (cache_idx < NUM_ELEMENTS(bmpcache[0]))) |
53 |
{ |
{ |
54 |
old = conn->bmpcache[cache_id][cache_idx]; |
old = bmpcache[cache_id][cache_idx]; |
55 |
if (old != NULL) |
if (old != NULL) |
56 |
ui_destroy_bitmap(conn->wnd, old); |
ui_destroy_bitmap(old); |
57 |
|
|
58 |
conn->bmpcache[cache_id][cache_idx] = bitmap; |
bmpcache[cache_id][cache_idx] = bitmap; |
59 |
} |
} |
60 |
else |
else |
61 |
{ |
{ |
62 |
ERROR("Bitmap %d:%d past end of cache\n", cache_id, cache_idx); |
ERROR("put bitmap %d:%d\n", cache_id, cache_idx); |
63 |
} |
} |
64 |
} |
} |
65 |
|
|
66 |
FONT_GLYPH *cache_get_font(HCONN conn, uint8 font, uint16 character) |
|
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 |
FONT_GLYPH *glyph; |
FONTGLYPH *glyph; |
74 |
|
|
75 |
if ((font < NUM_ELEMENTS(conn->fontcache)) |
if ((font < NUM_ELEMENTS(fontcache)) |
76 |
&& (character < NUM_ELEMENTS(conn->fontcache[0]))) |
&& (character < NUM_ELEMENTS(fontcache[0]))) |
77 |
{ |
{ |
78 |
glyph = &conn->fontcache[font][character]; |
glyph = &fontcache[font][character]; |
79 |
if (glyph->pixmap != NULL) |
if (glyph->pixmap != NULL) |
80 |
return glyph; |
return glyph; |
81 |
} |
} |
82 |
|
|
83 |
ERROR("Font %d character %d not found\n", font, character); |
ERROR("get font %d:%d\n", font, character); |
84 |
return NULL; |
return NULL; |
85 |
} |
} |
86 |
|
|
87 |
void cache_put_font(HCONN conn, uint8 font, uint32 character, uint16 baseline, |
/* Store a glyph in the font cache */ |
88 |
uint16 width, uint16 height, HGLYPH pixmap) |
void cache_put_font(uint8 font, uint16 character, uint16 offset, |
89 |
|
uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap) |
90 |
{ |
{ |
91 |
FONT_GLYPH *glyph; |
FONTGLYPH *glyph; |
92 |
|
|
93 |
if ((font < NUM_ELEMENTS(conn->fontcache)) |
if ((font < NUM_ELEMENTS(fontcache)) |
94 |
&& (character < NUM_ELEMENTS(conn->fontcache[0]))) |
&& (character < NUM_ELEMENTS(fontcache[0]))) |
95 |
{ |
{ |
96 |
glyph = &conn->fontcache[font][character]; |
glyph = &fontcache[font][character]; |
97 |
if (glyph->pixmap != NULL) |
if (glyph->pixmap != NULL) |
98 |
ui_destroy_glyph(conn->wnd, glyph->pixmap); |
ui_destroy_glyph(glyph->pixmap); |
99 |
|
|
100 |
|
glyph->offset = offset; |
101 |
glyph->baseline = baseline; |
glyph->baseline = baseline; |
102 |
glyph->width = width; |
glyph->width = width; |
103 |
glyph->height = height; |
glyph->height = height; |
105 |
} |
} |
106 |
else |
else |
107 |
{ |
{ |
108 |
ERROR("Font %d character %d past end of cache\n", |
ERROR("put font %d:%d\n", font, character); |
|
font, character); |
|
109 |
} |
} |
110 |
} |
} |
111 |
|
|
112 |
BLOB *cache_get_text(HCONN conn, uint8 cache_id) |
|
113 |
|
/* TEXT CACHE */ |
114 |
|
static DATABLOB textcache[256]; |
115 |
|
|
116 |
|
/* Retrieve a text item from the cache */ |
117 |
|
DATABLOB *cache_get_text(uint8 cache_id) |
118 |
{ |
{ |
119 |
BLOB *text; |
DATABLOB *text; |
120 |
|
|
121 |
if (cache_id < NUM_ELEMENTS(conn->textcache)) |
if (cache_id < NUM_ELEMENTS(textcache)) |
122 |
{ |
{ |
123 |
text = &conn->textcache[cache_id]; |
text = &textcache[cache_id]; |
124 |
if (text->data != NULL) |
if (text->data != NULL) |
125 |
return text; |
return text; |
126 |
} |
} |
127 |
|
|
128 |
ERROR("Text cache id %d not found\n", cache_id); |
ERROR("get text %d\n", cache_id); |
129 |
return NULL; |
return NULL; |
130 |
} |
} |
131 |
|
|
132 |
void cache_put_text(HCONN conn, uint8 cache_id, void *data, int length) |
/* Store a text item in the cache */ |
133 |
|
void cache_put_text(uint8 cache_id, void *data, int length) |
134 |
{ |
{ |
135 |
BLOB *text; |
DATABLOB *text; |
136 |
|
|
137 |
if (cache_id < NUM_ELEMENTS(conn->textcache)) |
if (cache_id < NUM_ELEMENTS(textcache)) |
138 |
{ |
{ |
139 |
text = &conn->textcache[cache_id]; |
text = &textcache[cache_id]; |
140 |
if (text->data != NULL) |
if (text->data != NULL) |
141 |
free(text->data); |
xfree(text->data); |
142 |
|
|
143 |
text->data = malloc(length); |
text->data = xmalloc(length); |
144 |
text->size = length; |
text->size = length; |
145 |
memcpy(text->data, data, length); |
memcpy(text->data, data, length); |
146 |
} |
} |
147 |
else |
else |
148 |
{ |
{ |
149 |
ERROR("Text cache id %d past end of cache\n", cache_id); |
ERROR("put text %d\n", cache_id); |
150 |
} |
} |
151 |
} |
} |
152 |
|
|
153 |
|
|
154 |
|
/* DESKTOP CACHE */ |
155 |
|
static uint8 deskcache[0x38400]; |
156 |
|
|
157 |
|
/* Retrieve desktop data from the cache */ |
158 |
|
uint8 *cache_get_desktop(uint32 offset, int cx, int cy) |
159 |
|
{ |
160 |
|
int length = cx * cy; |
161 |
|
|
162 |
|
if ((offset + length) <= sizeof(deskcache)) |
163 |
|
{ |
164 |
|
return &deskcache[offset]; |
165 |
|
} |
166 |
|
|
167 |
|
ERROR("get desktop %d:%d\n", offset, length); |
168 |
|
return NULL; |
169 |
|
} |
170 |
|
|
171 |
|
/* Store desktop data in the cache */ |
172 |
|
void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, uint8 *data) |
173 |
|
{ |
174 |
|
int length = cx * cy; |
175 |
|
|
176 |
|
if ((offset + length) <= sizeof(deskcache)) |
177 |
|
{ |
178 |
|
while (cy--) |
179 |
|
{ |
180 |
|
memcpy(&deskcache[offset], data, cx); |
181 |
|
data += scanline; |
182 |
|
offset += cx; |
183 |
|
} |
184 |
|
} |
185 |
|
else |
186 |
|
{ |
187 |
|
ERROR("put desktop %d:%d\n", offset, length); |
188 |
|
} |
189 |
|
} |
190 |
|
|