ReactOS 0.4.16-dev-125-g798ea90
cache.c File Reference
#include "rdesktop.h"
Include dependency graph for cache.c:

Go to the source code of this file.

Macros

#define NUM_ELEMENTS(array)   (sizeof(array) / sizeof(array[0]))
 
#define IS_PERSISTENT(id)   (This->pstcache_fd[id] > 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 (RDPCLIENT *This, uint8 id, sint16 *idx, int count)
 
void cache_bump_bitmap (RDPCLIENT *This, uint8 id, uint16 idx, int bump)
 
void cache_evict_bitmap (RDPCLIENT *This, uint8 id)
 
HBITMAP cache_get_bitmap (RDPCLIENT *This, uint8 id, uint16 idx)
 
void cache_put_bitmap (RDPCLIENT *This, uint8 id, uint16 idx, HBITMAP bitmap)
 
void cache_save_state (RDPCLIENT *This)
 
FONTGLYPHcache_get_font (RDPCLIENT *This, uint8 font, uint16 character)
 
void cache_put_font (RDPCLIENT *This, uint8 font, uint16 character, uint16 offset, uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
 
DATABLOBcache_get_text (RDPCLIENT *This, uint8 cache_id)
 
void cache_put_text (RDPCLIENT *This, uint8 cache_id, void *data, int length)
 
uint8cache_get_desktop (RDPCLIENT *This, uint32 offset, int cx, int cy, int bytes_per_pixel)
 
void cache_put_desktop (RDPCLIENT *This, uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 *data)
 
HCURSOR cache_get_cursor (RDPCLIENT *This, uint16 cache_idx)
 
void cache_put_cursor (RDPCLIENT *This, uint16 cache_idx, HCURSOR cursor)
 

Macro Definition Documentation

◆ BUMP_COUNT

#define BUMP_COUNT   40

Definition at line 39 of file cache.c.

◆ IS_PERSISTENT

#define IS_PERSISTENT (   id)    (This->pstcache_fd[id] > 0)

Definition at line 28 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 ( RDPCLIENT This,
uint8  id,
uint16  idx,
int  bump 
)

Definition at line 89 of file cache.c.

90{
91 int p_idx, n_idx, n;
92
93 if (!IS_PERSISTENT(id))
94 return;
95
96 if (This->cache.bmpcache_mru[id] == idx)
97 return;
98
99 DEBUG_RDP5(("bump bitmap: id=%d, idx=%d, bump=%d\n", id, idx, bump));
100
101 n_idx = This->cache.bmpcache[id][idx].next;
102 p_idx = This->cache.bmpcache[id][idx].previous;
103
104 if (IS_SET(n_idx))
105 {
106 /* remove */
107 --This->cache.bmpcache_count[id];
108 if (IS_SET(p_idx))
109 This->cache.bmpcache[id][p_idx].next = n_idx;
110 else
111 This->cache.bmpcache_lru[id] = n_idx;
112 if (IS_SET(n_idx))
113 This->cache.bmpcache[id][n_idx].previous = p_idx;
114 else
115 This->cache.bmpcache_mru[id] = p_idx;
116 }
117 else
118 {
119 p_idx = NOT_SET;
120 n_idx = This->cache.bmpcache_lru[id];
121 }
122
123 if (bump >= 0)
124 {
125 for (n = 0; n < bump && IS_SET(n_idx); n++)
126 {
127 p_idx = n_idx;
128 n_idx = This->cache.bmpcache[id][p_idx].next;
129 }
130 }
131 else
132 {
133 p_idx = This->cache.bmpcache_mru[id];
134 n_idx = NOT_SET;
135 }
136
137 /* insert */
138 ++This->cache.bmpcache_count[id];
139 This->cache.bmpcache[id][idx].previous = p_idx;
140 This->cache.bmpcache[id][idx].next = n_idx;
141
142 if (p_idx >= 0)
143 This->cache.bmpcache[id][p_idx].next = idx;
144 else
145 This->cache.bmpcache_lru[id] = idx;
146
147 if (n_idx >= 0)
148 This->cache.bmpcache[id][n_idx].previous = idx;
149 else
150 This->cache.bmpcache_mru[id] = idx;
151}
#define IS_SET(idx)
Definition: cache.c:31
#define NOT_SET
Definition: cache.c:30
#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

◆ cache_evict_bitmap()

void cache_evict_bitmap ( RDPCLIENT This,
uint8  id 
)

Definition at line 155 of file cache.c.

156{
157 uint16 idx;
158 int n_idx;
159
160 if (!IS_PERSISTENT(id))
161 return;
162
163 idx = This->cache.bmpcache_lru[id];
164 n_idx = This->cache.bmpcache[id][idx].next;
165 DEBUG_RDP5(("evict bitmap: id=%d idx=%d n_idx=%d bmp=0x%x\n", id, idx, n_idx,
166 This->cache.bmpcache[id][idx].bitmap));
167
168 ui_destroy_bitmap(This, This->cache.bmpcache[id][idx].bitmap);
169 --This->cache.bmpcache_count[id];
170 This->cache.bmpcache[id][idx].bitmap = 0;
171
172 This->cache.bmpcache_lru[id] = n_idx;
173 This->cache.bmpcache[id][n_idx].previous = NOT_SET;
174
176}
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

◆ cache_get_bitmap()

HBITMAP cache_get_bitmap ( RDPCLIENT This,
uint8  id,
uint16  idx 
)

Definition at line 180 of file cache.c.

181{
182 if ((id < NUM_ELEMENTS(This->cache.bmpcache)) && (idx < NUM_ELEMENTS(This->cache.bmpcache[0])))
183 {
184 if (This->cache.bmpcache[id][idx].bitmap || pstcache_load_bitmap(This, id, idx))
185 {
186 if (IS_PERSISTENT(id))
188
189 return This->cache.bmpcache[id][idx].bitmap;
190 }
191 }
192 else if ((id < NUM_ELEMENTS(This->cache.volatile_bc)) && (idx == 0x7fff))
193 {
194 return This->cache.volatile_bc[id];
195 }
196
197 error("get bitmap %d:%d\n", id, idx);
198 return NULL;
199}
#define BUMP_COUNT
Definition: cache.c:39
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

◆ cache_get_cursor()

HCURSOR cache_get_cursor ( RDPCLIENT This,
uint16  cache_idx 
)

Definition at line 381 of file cache.c.

382{
384
385 if (cache_idx < NUM_ELEMENTS(This->cache.cursorcache))
386 {
387 cursor = This->cache.cursorcache[cache_idx];
388 if (cursor != NULL)
389 return cursor;
390 }
391
392 error("get cursor %d\n", cache_idx);
393 return NULL;
394}
const char cursor[]
Definition: icontest.c:13
HICON HCURSOR
Definition: windef.h:299

◆ cache_get_desktop()

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

Definition at line 336 of file cache.c.

337{
338 int length = cx * cy * bytes_per_pixel;
339
340 if (offset > sizeof(This->cache.deskcache))
341 offset = 0;
342
343 if ((offset + length) <= sizeof(This->cache.deskcache))
344 {
345 return &This->cache.deskcache[offset];
346 }
347
348 error("get desktop %d:%d\n", offset, length);
349 return NULL;
350}
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

◆ cache_get_font()

FONTGLYPH * cache_get_font ( RDPCLIENT This,
uint8  font,
uint16  character 
)

Definition at line 262 of file cache.c.

263{
264 FONTGLYPH *glyph;
265
266 if ((font < NUM_ELEMENTS(This->cache.fontcache)) && (character < NUM_ELEMENTS(This->cache.fontcache[0])))
267 {
268 glyph = &This->cache.fontcache[font][character];
269 if (glyph->pixmap != NULL)
270 return glyph;
271 }
272
273 error("get font %d:%d\n", font, character);
274 return NULL;
275}
Definition: mk_font.cpp:20
RD_HBITMAP pixmap
Definition: types.h:116

◆ cache_get_text()

DATABLOB * cache_get_text ( RDPCLIENT This,
uint8  cache_id 
)

Definition at line 306 of file cache.c.

307{
308 DATABLOB *text;
309
310 text = &This->cache.textcache[cache_id];
311 return text;
312}
const WCHAR * text
Definition: package.c:1794

◆ cache_put_bitmap()

void cache_put_bitmap ( RDPCLIENT This,
uint8  id,
uint16  idx,
HBITMAP  bitmap 
)

Definition at line 203 of file cache.c.

204{
205 HBITMAP old;
206
207 if ((id < NUM_ELEMENTS(This->cache.bmpcache)) && (idx < NUM_ELEMENTS(This->cache.bmpcache[0])))
208 {
209 old = This->cache.bmpcache[id][idx].bitmap;
210 if (old != NULL)
212 This->cache.bmpcache[id][idx].bitmap = bitmap;
213
214 if (IS_PERSISTENT(id))
215 {
216 if (old == NULL)
217 This->cache.bmpcache[id][idx].previous = This->cache.bmpcache[id][idx].next = NOT_SET;
218
220 if (This->cache.bmpcache_count[id] > BMPCACHE2_C2_CELLS)
222 }
223 }
224 else if ((id < NUM_ELEMENTS(This->cache.volatile_bc)) && (idx == 0x7fff))
225 {
226 old = This->cache.volatile_bc[id];
227 if (old != NULL)
229 This->cache.volatile_bc[id] = bitmap;
230 }
231 else
232 {
233 error("put bitmap %d:%d\n", id, idx);
234 }
235}
#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
static HBITMAP
Definition: button.c:44
Definition: uimain.c:89

◆ cache_put_cursor()

void cache_put_cursor ( RDPCLIENT This,
uint16  cache_idx,
HCURSOR  cursor 
)

Definition at line 398 of file cache.c.

399{
400 HCURSOR old;
401
402 if (cache_idx < NUM_ELEMENTS(This->cache.cursorcache))
403 {
404 old = This->cache.cursorcache[cache_idx];
405 if (old != NULL)
407
408 This->cache.cursorcache[cache_idx] = cursor;
409 }
410 else
411 {
412 error("put cursor %d\n", cache_idx);
413 }
414}
void ui_destroy_cursor(RD_HCURSOR cursor)

◆ cache_put_desktop()

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

Definition at line 354 of file cache.c.

355{
356 int length = cx * cy * bytes_per_pixel;
357
358 if (offset > sizeof(This->cache.deskcache))
359 offset = 0;
360
361 if ((offset + length) <= sizeof(This->cache.deskcache))
362 {
363 cx *= bytes_per_pixel;
364 while (cy--)
365 {
366 memcpy(&This->cache.deskcache[offset], data, cx);
367 data += scanline;
368 offset += cx;
369 }
370 }
371 else
372 {
373 error("put desktop %d:%d\n", offset, length);
374 }
375}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ cache_put_font()

void cache_put_font ( RDPCLIENT This,
uint8  font,
uint16  character,
uint16  offset,
uint16  baseline,
uint16  width,
uint16  height,
HGLYPH  pixmap 
)

Definition at line 279 of file cache.c.

281{
282 FONTGLYPH *glyph;
283
284 if ((font < NUM_ELEMENTS(This->cache.fontcache)) && (character < NUM_ELEMENTS(This->cache.fontcache[0])))
285 {
286 glyph = &This->cache.fontcache[font][character];
287 if (glyph->pixmap != NULL)
289
290 glyph->offset = offset;
291 glyph->baseline = baseline;
292 glyph->width = width;
293 glyph->height = height;
294 glyph->pixmap = pixmap;
295 }
296 else
297 {
298 error("put font %d:%d\n", font, character);
299 }
300}
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

◆ cache_put_text()

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

Definition at line 316 of file cache.c.

317{
318 DATABLOB *text;
319 void * p = malloc(length);
320
321 if(p == NULL)
322 return;
323
324 text = &This->cache.textcache[cache_id];
325 if (text->data != NULL)
326 free(text->data);
327 text->data = p;
328 text->size = length;
329 memcpy(text->data, data, length);
330}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902

◆ cache_rebuild_bmpcache_linked_list()

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

Definition at line 43 of file cache.c.

44{
45 int n = count, c = 0;
46 sint16 n_idx;
47
48 /* find top, skip evicted bitmaps */
49 while (--n >= 0 && This->cache.bmpcache[id][idx[n]].bitmap == NULL);
50 if (n < 0)
51 {
52 This->cache.bmpcache_mru[id] = This->cache.bmpcache_lru[id] = NOT_SET;
53 return;
54 }
55
56 This->cache.bmpcache_mru[id] = idx[n];
57 This->cache.bmpcache[id][idx[n]].next = NOT_SET;
58 n_idx = idx[n];
59 c++;
60
61 /* link list */
62 while (n >= 0)
63 {
64 /* skip evicted bitmaps */
65 while (--n >= 0 && This->cache.bmpcache[id][idx[n]].bitmap == NULL);
66
67 if (n < 0)
68 break;
69
70 This->cache.bmpcache[id][n_idx].previous = idx[n];
71 This->cache.bmpcache[id][idx[n]].next = n_idx;
72 n_idx = idx[n];
73 c++;
74 }
75
76 This->cache.bmpcache[id][n_idx].previous = NOT_SET;
77 This->cache.bmpcache_lru[id] = n_idx;
78
79 if (c != This->cache.bmpcache_count[id])
80 {
81 error("Oops. %d in bitmap cache linked list, %d in ui cache...\n", c,
82 This->cache.bmpcache_count[id]);
83 exit(1);
84 }
85}
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

◆ cache_save_state()

void cache_save_state ( RDPCLIENT This)

Definition at line 239 of file cache.c.

240{
241 uint32 id = 0, t = 0;
242 int idx;
243
244 for (id = 0; id < NUM_ELEMENTS(This->cache.bmpcache); id++)
245 if (IS_PERSISTENT(id))
246 {
247 DEBUG_RDP5(("Saving cache state for bitmap cache %d...", id));
248 idx = This->cache.bmpcache_lru[id];
249 while (idx >= 0)
250 {
252 idx = This->cache.bmpcache[id][idx].next;
253 }
254 DEBUG_RDP5((" %d stamps written.\n", t));
255 }
256}
unsigned int uint32
Definition: types.h:32
GLdouble GLdouble t
Definition: gl.h:2047