00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "rdesktop.h"
00022
00023 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
00024
00025
00026
00027 static HBITMAP bmpcache[3][600];
00028
00029
00030 HBITMAP
00031 cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
00032 {
00033 HBITMAP bitmap;
00034
00035 if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
00036 {
00037 bitmap = bmpcache[cache_id][cache_idx];
00038 if (bitmap != NULL)
00039 return bitmap;
00040 }
00041
00042 error("get bitmap %d:%d\n", cache_id, cache_idx);
00043 return NULL;
00044 }
00045
00046
00047 void
00048 cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
00049 {
00050 HBITMAP old;
00051
00052 if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
00053 {
00054 old = bmpcache[cache_id][cache_idx];
00055 if (old != NULL)
00056 ui_destroy_bitmap(old);
00057
00058 bmpcache[cache_id][cache_idx] = bitmap;
00059 }
00060 else
00061 {
00062 error("put bitmap %d:%d\n", cache_id, cache_idx);
00063 }
00064 }
00065
00066
00067
00068 static FONTGLYPH fontcache[12][256];
00069
00070
00071 FONTGLYPH *
00072 cache_get_font(uint8 font, uint16 character)
00073 {
00074 FONTGLYPH *glyph;
00075
00076 if ((font < NUM_ELEMENTS(fontcache)) && (character < NUM_ELEMENTS(fontcache[0])))
00077 {
00078 glyph = &fontcache[font][character];
00079 if (glyph->pixmap != NULL)
00080 return glyph;
00081 }
00082
00083 error("get font %d:%d\n", font, character);
00084 return NULL;
00085 }
00086
00087
00088 void
00089 cache_put_font(uint8 font, uint16 character, uint16 offset,
00090 uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
00091 {
00092 FONTGLYPH *glyph;
00093
00094 if ((font < NUM_ELEMENTS(fontcache)) && (character < NUM_ELEMENTS(fontcache[0])))
00095 {
00096 glyph = &fontcache[font][character];
00097 if (glyph->pixmap != NULL)
00098 ui_destroy_glyph(glyph->pixmap);
00099
00100 glyph->offset = offset;
00101 glyph->baseline = baseline;
00102 glyph->width = width;
00103 glyph->height = height;
00104 glyph->pixmap = pixmap;
00105 }
00106 else
00107 {
00108 error("put font %d:%d\n", font, character);
00109 }
00110 }
00111
00112
00113
00114 static DATABLOB textcache[256];
00115
00116
00117 DATABLOB *
00118 cache_get_text(uint8 cache_id)
00119 {
00120 DATABLOB *text;
00121
00122 if (cache_id < NUM_ELEMENTS(textcache))
00123 {
00124 text = &textcache[cache_id];
00125 if (text->data != NULL)
00126 return text;
00127 }
00128
00129 error("get text %d\n", cache_id);
00130 return NULL;
00131 }
00132
00133
00134 void
00135 cache_put_text(uint8 cache_id, void *data, int length)
00136 {
00137 DATABLOB *text;
00138
00139 if (cache_id < NUM_ELEMENTS(textcache))
00140 {
00141 text = &textcache[cache_id];
00142 if (text->data != NULL)
00143 xfree(text->data);
00144
00145 text->data = xmalloc(length);
00146 text->size = length;
00147 memcpy(text->data, data, length);
00148 }
00149 else
00150 {
00151 error("put text %d\n", cache_id);
00152 }
00153 }
00154
00155
00156
00157 static uint8 deskcache[0x38400];
00158
00159
00160 uint8 *
00161 cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
00162 {
00163 int length = cx * cy * bytes_per_pixel;
00164
00165 if ((offset + length) <= sizeof(deskcache))
00166 {
00167 return &deskcache[offset];
00168 }
00169
00170 error("get desktop %d:%d\n", offset, length);
00171 return NULL;
00172 }
00173
00174
00175 void
00176 cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
00177 {
00178 int length = cx * cy * bytes_per_pixel;
00179
00180 if ((offset + length) <= sizeof(deskcache))
00181 {
00182 cx *= bytes_per_pixel;
00183 while (cy--)
00184 {
00185 memcpy(&deskcache[offset], data, cx);
00186 data += scanline;
00187 offset += cx;
00188 }
00189 }
00190 else
00191 {
00192 error("put desktop %d:%d\n", offset, length);
00193 }
00194 }
00195
00196
00197
00198 static HCURSOR cursorcache[0x20];
00199
00200
00201 HCURSOR
00202 cache_get_cursor(uint16 cache_idx)
00203 {
00204 HCURSOR cursor;
00205
00206 if (cache_idx < NUM_ELEMENTS(cursorcache))
00207 {
00208 cursor = cursorcache[cache_idx];
00209 if (cursor != NULL)
00210 return cursor;
00211 }
00212
00213 error("get cursor %d\n", cache_idx);
00214 return NULL;
00215 }
00216
00217
00218 void
00219 cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
00220 {
00221 HCURSOR old;
00222
00223 if (cache_idx < NUM_ELEMENTS(cursorcache))
00224 {
00225 old = cursorcache[cache_idx];
00226 if (old != NULL)
00227 ui_destroy_cursor(old);
00228
00229 cursorcache[cache_idx] = cursor;
00230 }
00231 else
00232 {
00233 error("put cursor %d\n", cache_idx);
00234 }
00235 }