ReactOS 0.4.16-dev-197-g92996da
cache.c File Reference
#include "precomp.h"
Include dependency graph for cache.c:

Go to the source code of this file.

Classes

struct  bmpcache_entry
 

Macros

#define NUM_ELEMENTS(array)   (sizeof(array) / sizeof(array[0]))
 
#define TO_TOP   -1
 
#define NOT_SET   -1
 
#define IS_SET(idx)   (idx >= 0)
 
#define BUMP_COUNT   40
 

Functions

void cache_rebuild_bmpcache_linked_list (uint8 id, sint16 *idx, int count)
 
void cache_bump_bitmap (uint8 id, uint16 idx, int bump)
 
void cache_evict_bitmap (uint8 id)
 
RD_HBITMAP cache_get_bitmap (uint8 id, uint16 idx)
 
void cache_put_bitmap (uint8 id, uint16 idx, RD_HBITMAP bitmap)
 
void cache_save_state (void)
 
FONTGLYPHcache_get_font (uint8 font, uint16 character)
 
void cache_put_font (uint8 font, uint16 character, uint16 offset, uint16 baseline, uint16 width, uint16 height, RD_HGLYPH pixmap)
 
DATABLOBcache_get_text (uint8 cache_id)
 
void cache_put_text (uint8 cache_id, void *data, int length)
 
uint8cache_get_desktop (uint32 offset, int cx, int cy, int bytes_per_pixel)
 
void cache_put_desktop (uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 *data)
 
RD_HCURSOR cache_get_cursor (uint16 cache_idx)
 
void cache_put_cursor (uint16 cache_idx, RD_HCURSOR cursor)
 
BRUSHDATAcache_get_brush_data (uint8 colour_code, uint8 idx)
 
void cache_put_brush_data (uint8 colour_code, uint8 idx, BRUSHDATA *brush_data)
 

Variables

int g_pstcache_fd []
 
static struct bmpcache_entry g_bmpcache [3][0xa00]
 
static RD_HBITMAP g_volatile_bc [3]
 
static int g_bmpcache_lru [3] = { NOT_SET, NOT_SET, NOT_SET }
 
static int g_bmpcache_mru [3] = { NOT_SET, NOT_SET, NOT_SET }
 
static int g_bmpcache_count [3]
 
static FONTGLYPH g_fontcache [12][256]
 
static DATABLOB g_textcache [256]
 
static uint8 g_deskcache [0x38400 *4]
 
static RD_HCURSOR g_cursorcache [0x20]
 
static BRUSHDATA g_brushcache [2][64]
 

Macro Definition Documentation

◆ BUMP_COUNT

#define BUMP_COUNT   40

Definition at line 39 of file cache.c.

◆ IS_SET

#define IS_SET (   idx)    (idx >= 0)

Definition at line 31 of file cache.c.

◆ NOT_SET

#define NOT_SET   -1

Definition at line 30 of file cache.c.

◆ NUM_ELEMENTS

#define NUM_ELEMENTS (   array)    (sizeof(array) / sizeof(array[0]))

Definition at line 27 of file cache.c.

◆ TO_TOP

#define TO_TOP   -1

Definition at line 29 of file cache.c.

Function Documentation

◆ cache_bump_bitmap()

void cache_bump_bitmap ( uint8  id,
uint16  idx,
int  bump 
)

Definition at line 104 of file cache.c.

105{
106 int p_idx, n_idx, n;
107
108 if (!IS_PERSISTENT(id))
109 return;
110
111 if (g_bmpcache_mru[id] == idx)
112 return;
113
114 DEBUG_RDP5(("bump bitmap: id=%d, idx=%d, bump=%d\n", id, idx, bump));
115
116 n_idx = g_bmpcache[id][idx].next;
117 p_idx = g_bmpcache[id][idx].previous;
118
119 if (IS_SET(n_idx))
120 {
121 /* remove */
123 if (IS_SET(p_idx))
124 g_bmpcache[id][p_idx].next = n_idx;
125 else
126 g_bmpcache_lru[id] = n_idx;
127 if (IS_SET(n_idx))
128 g_bmpcache[id][n_idx].previous = p_idx;
129 else
130 g_bmpcache_mru[id] = p_idx;
131 }
132 else
133 {
134 p_idx = NOT_SET;
135 n_idx = g_bmpcache_lru[id];
136 }
137
138 if (bump >= 0)
139 {
140 for (n = 0; n < bump && IS_SET(n_idx); n++)
141 {
142 p_idx = n_idx;
143 n_idx = g_bmpcache[id][p_idx].next;
144 }
145 }
146 else
147 {
148 p_idx = g_bmpcache_mru[id];
149 n_idx = NOT_SET;
150 }
151
152 /* insert */
154 g_bmpcache[id][idx].previous = p_idx;
155 g_bmpcache[id][idx].next = n_idx;
156
157 if (p_idx >= 0)
158 g_bmpcache[id][p_idx].next = idx;
159 else
161
162 if (n_idx >= 0)
163 g_bmpcache[id][n_idx].previous = idx;
164 else
166}
#define IS_SET(idx)
Definition: cache.c:31
static struct bmpcache_entry g_bmpcache[3][0xa00]
Definition: cache.c:48
#define NOT_SET
Definition: cache.c:30
static int g_bmpcache_count[3]
Definition: cache.c:54
static int g_bmpcache_mru[3]
Definition: cache.c:52
static int g_bmpcache_lru[3]
Definition: cache.c:51
#define IS_PERSISTENT(id)
Definition: precomp.h:26
#define DEBUG_RDP5(args)
Definition: rdesktop.h:141
unsigned int idx
Definition: utils.c:41
GLdouble n
Definition: glext.h:7729
GLuint id
Definition: glext.h:5910

Referenced by cache_get_bitmap(), and cache_put_bitmap().

◆ cache_evict_bitmap()

void cache_evict_bitmap ( uint8  id)

Definition at line 170 of file cache.c.

171{
172 uint16 idx;
173 int n_idx;
174
175 if (!IS_PERSISTENT(id))
176 return;
177
179 n_idx = g_bmpcache[id][idx].next;
180 DEBUG_RDP5(("evict bitmap: id=%d idx=%d n_idx=%d bmp=%p\n", id, idx, n_idx,
181 g_bmpcache[id][idx].bitmap));
182
185 g_bmpcache[id][idx].bitmap = 0;
186
187 g_bmpcache_lru[id] = n_idx;
188 g_bmpcache[id][n_idx].previous = NOT_SET;
189
191}
void ui_destroy_bitmap(RD_HBITMAP bmp)
void pstcache_touch_bitmap(uint8 cache_id, uint16 cache_idx, uint32 stamp)
Definition: pstcache.c:39
unsigned short uint16
Definition: types.h:30
Definition: uimain.c:89

Referenced by cache_put_bitmap().

◆ cache_get_bitmap()

RD_HBITMAP cache_get_bitmap ( uint8  id,
uint16  idx 
)

Definition at line 195 of file cache.c.

196{
197 if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0])))
198 {
200 {
201 if (IS_PERSISTENT(id))
203
204 return g_bmpcache[id][idx].bitmap;
205 }
206 }
207 else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff))
208 {
209 return g_volatile_bc[id];
210 }
211
212 error("get bitmap %d:%d\n", id, idx);
213 return NULL;
214}
#define BUMP_COUNT
Definition: cache.c:39
static RD_HBITMAP g_volatile_bc[3]
Definition: cache.c:49
void cache_bump_bitmap(uint8 id, uint16 idx, int bump)
Definition: cache.c:104
#define NUM_ELEMENTS(array)
Definition: cache.c:27
RD_BOOL pstcache_load_bitmap(uint8 cache_id, uint16 cache_idx)
Definition: pstcache.c:53
#define NULL
Definition: types.h:112
#define error(str)
Definition: mkdosfs.c:1605

Referenced by process_memblt(), and process_triblt().

◆ cache_get_brush_data()

BRUSHDATA * cache_get_brush_data ( uint8  colour_code,
uint8  idx 
)

Definition at line 441 of file cache.c.

442{
443 colour_code = colour_code == 1 ? 0 : 1;
444 if (idx < NUM_ELEMENTS(g_brushcache[0]))
445 {
446 return &g_brushcache[colour_code][idx];
447 }
448 error("get brush %d %d\n", colour_code, idx);
449 return NULL;
450}
static BRUSHDATA g_brushcache[2][64]
Definition: cache.c:437

Referenced by setup_brush().

◆ cache_get_cursor()

RD_HCURSOR cache_get_cursor ( uint16  cache_idx)

Definition at line 400 of file cache.c.

401{
403
404 if (cache_idx < NUM_ELEMENTS(g_cursorcache))
405 {
406 cursor = g_cursorcache[cache_idx];
407 if (cursor != NULL)
408 return cursor;
409 }
410
411 error("get cursor %d\n", cache_idx);
412 return NULL;
413}
static RD_HCURSOR g_cursorcache[0x20]
Definition: cache.c:396
const char cursor[]
Definition: icontest.c:13

Referenced by process_cached_pointer_pdu().

◆ cache_get_desktop()

uint8 * cache_get_desktop ( uint32  offset,
int  cx,
int  cy,
int  bytes_per_pixel 
)

Definition at line 353 of file cache.c.

354{
355 int length = cx * cy * bytes_per_pixel;
356
357 if (offset > sizeof(g_deskcache))
358 offset = 0;
359
360 if ((offset + length) <= sizeof(g_deskcache))
361 {
362 return &g_deskcache[offset];
363 }
364
365 error("get desktop %d:%d\n", offset, length);
366 return NULL;
367}
static uint8 g_deskcache[0x38400 *4]
Definition: cache.c:349
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLintptr offset
Definition: glext.h:5920
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585

Referenced by RdpClientUI::Display_RestoreDesktop(), and ui_desktop_restore().

◆ cache_get_font()

FONTGLYPH * cache_get_font ( uint8  font,
uint16  character 
)

Definition at line 279 of file cache.c.

280{
281 FONTGLYPH *glyph;
282
283 if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
284 {
285 glyph = &g_fontcache[font][character];
286 if (glyph->pixmap != NULL)
287 return glyph;
288 }
289
290 error("get font %d:%d\n", font, character);
291 return NULL;
292}
static FONTGLYPH g_fontcache[12][256]
Definition: cache.c:275
Definition: mk_font.cpp:20
RD_HBITMAP pixmap
Definition: types.h:116

Referenced by RdpClientUI::Display_DoGlyph().

◆ cache_get_text()

DATABLOB * cache_get_text ( uint8  cache_id)

Definition at line 325 of file cache.c.

326{
327 DATABLOB *text;
328
329 text = &g_textcache[cache_id];
330 return text;
331}
static DATABLOB g_textcache[256]
Definition: cache.c:321
const WCHAR * text
Definition: package.c:1794

Referenced by RdpClientUI::Display_DrawText(), and ui_draw_text().

◆ cache_put_bitmap()

void cache_put_bitmap ( uint8  id,
uint16  idx,
RD_HBITMAP  bitmap 
)

Definition at line 218 of file cache.c.

219{
220 RD_HBITMAP old;
221
222 if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0])))
223 {
224 old = g_bmpcache[id][idx].bitmap;
225 if (old != NULL)
227 g_bmpcache[id][idx].bitmap = bitmap;
228
229 if (IS_PERSISTENT(id))
230 {
231 if (old == NULL)
232 g_bmpcache[id][idx].previous = g_bmpcache[id][idx].next = NOT_SET;
233
237 }
238 }
239 else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff))
240 {
241 old = g_volatile_bc[id];
242 if (old != NULL)
245 }
246 else
247 {
248 error("put bitmap %d:%d\n", id, idx);
249 }
250}
#define TO_TOP
Definition: cache.c:29
void cache_evict_bitmap(uint8 id)
Definition: cache.c:170
#define BMPCACHE2_C2_CELLS
Definition: constants.h:284

Referenced by process_bmpcache(), process_bmpcache2(), process_raw_bmpcache(), and pstcache_load_bitmap().

◆ cache_put_brush_data()

void cache_put_brush_data ( uint8  colour_code,
uint8  idx,
BRUSHDATA brush_data 
)

Definition at line 455 of file cache.c.

456{
457 BRUSHDATA *bd;
458
459 colour_code = colour_code == 1 ? 0 : 1;
460 if (idx < NUM_ELEMENTS(g_brushcache[0]))
461 {
462 bd = &g_brushcache[colour_code][idx];
463 if (bd->data != 0)
464 {
465 xfree(bd->data);
466 }
467 memcpy(bd, brush_data, sizeof(BRUSHDATA));
468 }
469 else
470 {
471 error("put brush %d %d\n", colour_code, idx);
472 }
473}
void xfree(void *mem)
Definition: uimain.c:758
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint8 * data
Definition: types.h:96

Referenced by process_brushcache().

◆ cache_put_cursor()

void cache_put_cursor ( uint16  cache_idx,
RD_HCURSOR  cursor 
)

Definition at line 417 of file cache.c.

418{
419 RD_HCURSOR old;
420
421 if (cache_idx < NUM_ELEMENTS(g_cursorcache))
422 {
423 old = g_cursorcache[cache_idx];
424 if (old != NULL)
426
427 g_cursorcache[cache_idx] = cursor;
428 }
429 else
430 {
431 error("put cursor %d\n", cache_idx);
432 }
433}
void ui_destroy_cursor(RD_HCURSOR cursor)

Referenced by process_colour_pointer_common(), and process_colour_pointer_pdu().

◆ cache_put_desktop()

void cache_put_desktop ( uint32  offset,
int  cx,
int  cy,
int  scanline,
int  bytes_per_pixel,
uint8 data 
)

Definition at line 371 of file cache.c.

372{
373 int length = cx * cy * bytes_per_pixel;
374
375 if (offset > sizeof(g_deskcache))
376 offset = 0;
377
378 if ((offset + length) <= sizeof(g_deskcache))
379 {
380 cx *= bytes_per_pixel;
381 while (cy--)
382 {
384 data += scanline;
385 offset += cx;
386 }
387 }
388 else
389 {
390 error("put desktop %d:%d\n", offset, length);
391 }
392}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by RdpClientUI::Display_SaveDesktop(), and ui_desktop_save().

◆ cache_put_font()

void cache_put_font ( uint8  font,
uint16  character,
uint16  offset,
uint16  baseline,
uint16  width,
uint16  height,
RD_HGLYPH  pixmap 
)

Definition at line 296 of file cache.c.

298{
299 FONTGLYPH *glyph;
300
301 if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
302 {
303 glyph = &g_fontcache[font][character];
304 if (glyph->pixmap != NULL)
305 ui_destroy_glyph(glyph->pixmap);
306
307 glyph->offset = offset;
308 glyph->baseline = baseline;
309 glyph->width = width;
310 glyph->height = height;
311 glyph->pixmap = pixmap;
312 }
313 else
314 {
315 error("put font %d:%d\n", font, character);
316 }
317}
void ui_destroy_glyph(RD_HGLYPH glyph)
Definition: qtewin.cpp:1424
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
uint16 width
Definition: types.h:114
sint16 baseline
Definition: types.h:113
uint16 height
Definition: types.h:115
sint16 offset
Definition: types.h:112

Referenced by process_fontcache().

◆ cache_put_text()

void cache_put_text ( uint8  cache_id,
void data,
int  length 
)

Definition at line 335 of file cache.c.

336{
337 DATABLOB *text;
338
339 text = &g_textcache[cache_id];
340 if (text->data != NULL)
341 xfree(text->data);
342 text->data = xmalloc(length);
343 text->size = length;
344 memcpy(text->data, data, length);
345}
void * xmalloc(int size)
Definition: uimain.c:747

Referenced by RdpClientUI::Display_DrawText(), and ui_draw_text().

◆ cache_rebuild_bmpcache_linked_list()

void cache_rebuild_bmpcache_linked_list ( uint8  id,
sint16 idx,
int  count 
)

Definition at line 58 of file cache.c.

59{
60 int n = count, c = 0;
61 sint16 n_idx;
62
63 /* find top, skip evicted bitmaps */
64 while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL);
65 if (n < 0)
66 {
68 return;
69 }
70
72 g_bmpcache[id][idx[n]].next = NOT_SET;
73 n_idx = idx[n];
74 c++;
75
76 /* link list */
77 while (n >= 0)
78 {
79 /* skip evicted bitmaps */
80 while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL);
81
82 if (n < 0)
83 break;
84
85 g_bmpcache[id][n_idx].previous = idx[n];
86 g_bmpcache[id][idx[n]].next = n_idx;
87 n_idx = idx[n];
88 c++;
89 }
90
91 g_bmpcache[id][n_idx].previous = NOT_SET;
92 g_bmpcache_lru[id] = n_idx;
93
94 if (c != g_bmpcache_count[id])
95 {
96 error("Oops. %d in bitmap cache linked list, %d in ui cache...\n", c,
99 }
100}
#define EX_SOFTWARE
Definition: rdesktop.h:70
signed short sint16
Definition: types.h:31
GLuint GLuint GLsizei count
Definition: gl.h:1545
const GLubyte * c
Definition: glext.h:8905
#define exit(n)
Definition: config.h:202

Referenced by pstcache_enumerate().

◆ cache_save_state()

void cache_save_state ( void  )

Definition at line 254 of file cache.c.

255{
256 uint32 id = 0, t = 0;
257 int idx;
258
259 for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++)
260 if (IS_PERSISTENT(id))
261 {
262 DEBUG_RDP5(("Saving cache state for bitmap cache %d...", id));
264 while (idx >= 0)
265 {
267 idx = g_bmpcache[id][idx].next;
268 }
269 DEBUG_RDP5((" %d stamps written.\n", t));
270 }
271}
unsigned int uint32
Definition: types.h:32
GLdouble GLdouble t
Definition: gl.h:2047

Referenced by main().

Variable Documentation

◆ g_bmpcache

◆ g_bmpcache_count

int g_bmpcache_count[3]
static

◆ g_bmpcache_lru

int g_bmpcache_lru[3] = { NOT_SET, NOT_SET, NOT_SET }
static

◆ g_bmpcache_mru

int g_bmpcache_mru[3] = { NOT_SET, NOT_SET, NOT_SET }
static

Definition at line 52 of file cache.c.

Referenced by cache_bump_bitmap(), and cache_rebuild_bmpcache_linked_list().

◆ g_brushcache

BRUSHDATA g_brushcache[2][64]
static

Definition at line 437 of file cache.c.

Referenced by cache_get_brush_data(), and cache_put_brush_data().

◆ g_cursorcache

RD_HCURSOR g_cursorcache[0x20]
static

Definition at line 396 of file cache.c.

Referenced by cache_get_cursor(), and cache_put_cursor().

◆ g_deskcache

uint8 g_deskcache[0x38400 *4]
static

Definition at line 349 of file cache.c.

Referenced by cache_get_desktop(), and cache_put_desktop().

◆ g_fontcache

FONTGLYPH g_fontcache[12][256]
static

Definition at line 275 of file cache.c.

Referenced by cache_get_font(), and cache_put_font().

◆ g_pstcache_fd

int g_pstcache_fd[]
extern

◆ g_textcache

DATABLOB g_textcache[256]
static

Definition at line 321 of file cache.c.

Referenced by cache_get_text(), and cache_put_text().

◆ g_volatile_bc

RD_HBITMAP g_volatile_bc[3]
static

Definition at line 49 of file cache.c.

Referenced by cache_get_bitmap(), and cache_put_bitmap().