2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Cache routines |
Cache routines |
4 |
Copyright (C) Matthew Chapman 1999-2002 |
Copyright (C) Matthew Chapman 1999-2002 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
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 |
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 |
the Free Software Foundation; either version 2 of the License, or |
9 |
(at your option) any later version. |
(at your option) any later version. |
10 |
|
|
11 |
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 |
#define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0) |
#define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0) |
26 |
|
|
27 |
extern int g_pstcache_fd[]; |
extern int g_pstcache_fd[]; |
28 |
|
extern BOOL g_use_rdp5; |
29 |
|
|
30 |
uint32 g_stamp; |
uint32 g_stamp; |
|
int g_num_bitmaps_in_memory[3]; |
|
31 |
|
|
32 |
|
static int g_num_bitmaps_in_memory[3]; |
33 |
|
|
34 |
/* BITMAP CACHE */ |
/* BITMAP CACHE */ |
35 |
static BMPCACHEENTRY g_bmpcache[3][0xa00]; |
static BMPCACHEENTRY g_bmpcache[3][0xa00]; |
36 |
|
static HBITMAP g_volatile_bc[3]; |
37 |
|
|
38 |
/* Remove the least-recently used bitmap from the cache */ |
/* Remove the least-recently used bitmap from the cache */ |
39 |
void |
void |
40 |
cache_remove_lru_bitmap(uint8 cache_id) |
cache_remove_lru_bitmap(uint8 cache_id) |
41 |
{ |
{ |
42 |
int i; |
uint32 i; |
43 |
uint16 cache_idx = 0; |
uint16 cache_idx = 0; |
44 |
uint32 m = (uint32)-1; |
uint32 m = 0xffffffff; |
45 |
BMPCACHEENTRY *pbce; |
BMPCACHEENTRY *pbce; |
46 |
|
|
47 |
for (i = 0; i < NUM_ELEMENTS(g_bmpcache[cache_id]); i++) |
for (i = 0; i < NUM_ELEMENTS(g_bmpcache[cache_id]); i++) |
77 |
return *pbitmap; |
return *pbitmap; |
78 |
} |
} |
79 |
} |
} |
80 |
|
else if ((cache_id < NUM_ELEMENTS(g_volatile_bc)) && (cache_idx == 0x7fff)) |
81 |
|
{ |
82 |
|
return g_volatile_bc[cache_id]; |
83 |
|
} |
84 |
|
|
85 |
error("get bitmap %d:%d\n", cache_id, cache_idx); |
error("get bitmap %d:%d\n", cache_id, cache_idx); |
86 |
return NULL; |
return NULL; |
99 |
{ |
{ |
100 |
ui_destroy_bitmap(old); |
ui_destroy_bitmap(old); |
101 |
} |
} |
102 |
else |
else if (g_use_rdp5) |
103 |
{ |
{ |
104 |
if (++g_num_bitmaps_in_memory[cache_id] > BMPCACHE2_C2_CELLS) |
if (++g_num_bitmaps_in_memory[cache_id] > BMPCACHE2_C2_CELLS) |
105 |
cache_remove_lru_bitmap(cache_id); |
cache_remove_lru_bitmap(cache_id); |
108 |
g_bmpcache[cache_id][cache_idx].bitmap = bitmap; |
g_bmpcache[cache_id][cache_idx].bitmap = bitmap; |
109 |
g_bmpcache[cache_id][cache_idx].usage = stamp; |
g_bmpcache[cache_id][cache_idx].usage = stamp; |
110 |
} |
} |
111 |
|
else if ((cache_id < NUM_ELEMENTS(g_volatile_bc)) && (cache_idx == 0x7fff)) |
112 |
|
{ |
113 |
|
old = g_volatile_bc[cache_id]; |
114 |
|
if (old != NULL) |
115 |
|
ui_destroy_bitmap(old); |
116 |
|
g_volatile_bc[cache_id] = bitmap; |
117 |
|
} |
118 |
else |
else |
119 |
{ |
{ |
120 |
error("put bitmap %d:%d\n", cache_id, cache_idx); |
error("put bitmap %d:%d\n", cache_id, cache_idx); |
125 |
void |
void |
126 |
cache_save_state(void) |
cache_save_state(void) |
127 |
{ |
{ |
128 |
int id, idx; |
uint32 id, idx; |
129 |
|
|
130 |
for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++) |
for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++) |
131 |
if (IS_PERSISTENT(id)) |
if (IS_PERSISTENT(id)) |