20 |
|
|
21 |
#include "rdesktop.h" |
#include "rdesktop.h" |
22 |
|
|
23 |
#define MAX_CELL_SIZE 0x1000 /* pixels */ |
#define MAX_CELL_SIZE 0x1000 /* pixels */ |
24 |
|
|
25 |
#define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0) |
#define IS_PERSISTENT(id) (id < 8 && g_pstcache_fd[id] > 0) |
26 |
|
|
27 |
extern int g_server_bpp; |
extern int g_server_bpp; |
28 |
extern uint32 g_stamp; |
extern uint32 g_stamp; |
33 |
int g_pstcache_fd[8]; |
int g_pstcache_fd[8]; |
34 |
int g_pstcache_Bpp; |
int g_pstcache_Bpp; |
35 |
BOOL g_pstcache_enumerated = False; |
BOOL g_pstcache_enumerated = False; |
36 |
uint8 zero_id[] = {0, 0, 0, 0, 0, 0, 0, 0}; |
uint8 zero_id[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
37 |
|
|
38 |
|
|
39 |
/* Update usage info for a bitmap */ |
/* Update usage info for a bitmap */ |
42 |
{ |
{ |
43 |
int fd; |
int fd; |
44 |
|
|
45 |
if (!IS_PERSISTENT(cache_id)) |
if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS) |
46 |
return; |
return; |
47 |
|
|
48 |
fd = g_pstcache_fd[cache_id]; |
fd = g_pstcache_fd[cache_id]; |
59 |
CELLHEADER cellhdr; |
CELLHEADER cellhdr; |
60 |
HBITMAP bitmap; |
HBITMAP bitmap; |
61 |
|
|
62 |
if (!(g_bitmap_cache_persist_enable && IS_PERSISTENT(cache_id))) |
if (!g_bitmap_cache_persist_enable) |
63 |
|
return False; |
64 |
|
|
65 |
|
if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS) |
66 |
return False; |
return False; |
67 |
|
|
68 |
fd = g_pstcache_fd[cache_id]; |
fd = g_pstcache_fd[cache_id]; |
69 |
rd_lseek_file(fd, cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER))); |
rd_lseek_file(fd, cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER))); |
70 |
rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)); |
rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)); |
71 |
celldata = (uint8 *)xmalloc(cellhdr.length); |
celldata = (uint8 *) xmalloc(cellhdr.length); |
72 |
rd_read_file(fd, celldata, cellhdr.length); |
rd_read_file(fd, celldata, cellhdr.length); |
73 |
|
|
74 |
DEBUG(("Loading bitmap from disk (%d:%d)\n", cache_id, cache_idx)); |
DEBUG(("Loading bitmap from disk (%d:%d)\n", cache_id, cache_idx)); |
82 |
|
|
83 |
/* Store a bitmap in the persistent cache */ |
/* Store a bitmap in the persistent cache */ |
84 |
BOOL |
BOOL |
85 |
pstcache_put_bitmap(uint8 cache_id, uint16 cache_idx, uint8 *bitmap_id, |
pstcache_put_bitmap(uint8 cache_id, uint16 cache_idx, uint8 * bitmap_id, |
86 |
uint16 width, uint16 height, uint16 length, uint8 *data) |
uint16 width, uint16 height, uint16 length, uint8 * data) |
87 |
{ |
{ |
88 |
int fd; |
int fd; |
89 |
CELLHEADER cellhdr; |
CELLHEADER cellhdr; |
90 |
|
|
91 |
if (!IS_PERSISTENT(cache_id)) |
if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS) |
92 |
return False; |
return False; |
93 |
|
|
94 |
memcpy(cellhdr.bitmap_id, bitmap_id, sizeof(BITMAP_ID)); |
memcpy(cellhdr.bitmap_id, bitmap_id, sizeof(BITMAP_ID)); |
107 |
|
|
108 |
/* list the bitmaps from the persistent cache file */ |
/* list the bitmaps from the persistent cache file */ |
109 |
int |
int |
110 |
pstcache_enumerate(uint8 cache_id, uint8 *idlist) |
pstcache_enumerate(uint8 cache_id, uint8 * idlist) |
111 |
{ |
{ |
112 |
int fd, n, c = 0; |
int fd, n, c = 0; |
113 |
CELLHEADER cellhdr; |
CELLHEADER cellhdr; |
130 |
if (memcmp(cellhdr.bitmap_id, zero_id, sizeof(BITMAP_ID)) != 0) |
if (memcmp(cellhdr.bitmap_id, zero_id, sizeof(BITMAP_ID)) != 0) |
131 |
{ |
{ |
132 |
memcpy(idlist + n * sizeof(BITMAP_ID), cellhdr.bitmap_id, |
memcpy(idlist + n * sizeof(BITMAP_ID), cellhdr.bitmap_id, |
133 |
sizeof(BITMAP_ID)); |
sizeof(BITMAP_ID)); |
134 |
|
|
135 |
if (cellhdr.stamp) |
if (cellhdr.stamp) |
136 |
{ |
{ |