ReactOS 0.4.16-dev-334-g4d9f67c
pstcache.c File Reference
#include "precomp.h"
Include dependency graph for pstcache.c:

Go to the source code of this file.

Macros

#define MAX_CELL_SIZE   0x1000 /* pixels */
 
#define IS_PERSISTENT(id)   (id < 8 && g_pstcache_fd[id] > 0)
 

Functions

void pstcache_touch_bitmap (uint8 cache_id, uint16 cache_idx, uint32 stamp)
 
RD_BOOL pstcache_load_bitmap (uint8 cache_id, uint16 cache_idx)
 
RD_BOOL pstcache_save_bitmap (uint8 cache_id, uint16 cache_idx, uint8 *key, uint8 width, uint8 height, uint16 length, uint8 *data)
 
int pstcache_enumerate (uint8 id, HASH_KEY *keylist)
 
RD_BOOL pstcache_init (uint8 cache_id)
 

Variables

int g_server_depth
 
RD_BOOL g_bitmap_cache
 
RD_BOOL g_bitmap_cache_persist_enable
 
RD_BOOL g_bitmap_cache_precache
 
int g_pstcache_fd [8]
 
int g_pstcache_Bpp
 
RD_BOOL g_pstcache_enumerated = False
 
uint8 zero_key [] = { 0, 0, 0, 0, 0, 0, 0, 0 }
 

Macro Definition Documentation

◆ IS_PERSISTENT

#define IS_PERSISTENT (   id)    (id < 8 && g_pstcache_fd[id] > 0)

Definition at line 24 of file pstcache.c.

◆ MAX_CELL_SIZE

#define MAX_CELL_SIZE   0x1000 /* pixels */

Definition at line 22 of file pstcache.c.

Function Documentation

◆ pstcache_enumerate()

int pstcache_enumerate ( uint8  id,
HASH_KEY keylist 
)

Definition at line 107 of file pstcache.c.

108{
109 int fd, n;
110 uint16 idx;
111 sint16 mru_idx[0xa00];
112 uint32 mru_stamp[0xa00];
113 CELLHEADER cellhdr;
114
116 return 0;
117
118 /* The server disconnects if the bitmap cache content is sent more than once */
120 return 0;
121
122 DEBUG_RDP5(("Persistent bitmap cache enumeration... "));
123 for (idx = 0; idx < BMPCACHE2_NUM_PSTCELLS; idx++)
124 {
127 if (rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)) <= 0)
128 break;
129
130 if (memcmp(cellhdr.key, zero_key, sizeof(HASH_KEY)) != 0)
131 {
132 memcpy(keylist[idx], cellhdr.key, sizeof(HASH_KEY));
133
134 /* Pre-cache (not possible for 8 bit colour depth cause it needs a colourmap) */
135 if (g_bitmap_cache_precache && cellhdr.stamp && g_server_depth > 8)
137
138 /* Sort by stamp */
139 for (n = idx; n > 0 && cellhdr.stamp < mru_stamp[n - 1]; n--)
140 {
141 mru_idx[n] = mru_idx[n - 1];
142 mru_stamp[n] = mru_stamp[n - 1];
143 }
144
145 mru_idx[n] = idx;
146 mru_stamp[n] = cellhdr.stamp;
147 }
148 else
149 {
150 break;
151 }
152 }
153
154 DEBUG_RDP5(("%d cached bitmaps.\n", idx));
155
158 return idx;
159}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
void cache_rebuild_bmpcache_linked_list(uint8 id, sint16 *idx, int count)
Definition: cache.c:58
#define BMPCACHE2_NUM_PSTCELLS
Definition: constants.h:285
int rd_read_file(int fd, void *ptr, int len)
Definition: uimain.c:854
int rd_lseek_file(int fd, int offset)
Definition: uimain.c:868
int g_server_depth
Definition: uimain.c:41
RD_BOOL g_bitmap_cache_precache
Definition: uimain.c:38
int g_pstcache_Bpp
Definition: pstcache.c:32
RD_BOOL pstcache_load_bitmap(uint8 cache_id, uint16 cache_idx)
Definition: pstcache.c:53
uint8 zero_key[]
Definition: pstcache.c:34
RD_BOOL g_pstcache_enumerated
Definition: pstcache.c:33
int g_pstcache_fd[8]
Definition: pstcache.c:31
RD_BOOL g_bitmap_cache_persist_enable
Definition: uimain.c:37
#define IS_PERSISTENT(id)
Definition: pstcache.c:24
RD_BOOL g_bitmap_cache
Definition: uimain.c:39
#define MAX_CELL_SIZE
Definition: pstcache.c:22
#define DEBUG_RDP5(args)
Definition: rdesktop.h:141
unsigned short uint16
Definition: types.h:30
unsigned int uint32
Definition: types.h:32
uint8 HASH_KEY[8]
Definition: types.h:161
signed short sint16
Definition: types.h:31
#define True
Definition: types.h:24
unsigned int idx
Definition: utils.c:41
GLdouble n
Definition: glext.h:7729
GLuint id
Definition: glext.h:5910
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static int fd
Definition: io.c:51
HASH_KEY key
Definition: types.h:166
Definition: path.c:35

Referenced by rdp_enum_bmpcache2().

◆ pstcache_init()

RD_BOOL pstcache_init ( uint8  cache_id)

Definition at line 163 of file pstcache.c.

164{
165 int fd;
166 char filename[256];
167
169 return True;
170
171 g_pstcache_fd[cache_id] = 0;
172
174 return False;
175
176 if (!rd_pstcache_mkdir())
177 {
178 DEBUG(("failed to get/make cache directory!\n"));
179 return False;
180 }
181
182 g_pstcache_Bpp = (g_server_depth + 7) / 8;
183 sprintf(filename, "cache/pstcache_%d_%d", cache_id, g_pstcache_Bpp);
184 DEBUG(("persistent bitmap cache file: %s\n", filename));
185
187 if (fd == -1)
188 return False;
189
190 if (!rd_lock_file(fd, 0, 0))
191 {
192 warning("Persistent bitmap caching is disabled. (The file is already in use)\n");
194 return False;
195 }
196
197 g_pstcache_fd[cache_id] = fd;
198 return True;
199}
void rd_close_file(int fd)
Definition: uimain.c:847
RD_BOOL rd_lock_file(int fd, int start, int len)
Definition: uimain.c:875
RD_BOOL rd_pstcache_mkdir(void)
Definition: uimain.c:833
int rd_open_file(char *filename)
Definition: uimain.c:840
#define DEBUG(args)
Definition: rdesktop.h:129
#define False
Definition: types.h:25
const char * filename
Definition: ioapi.h:137
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define warning(s)
Definition: debug.h:83

Referenced by rdp_out_bmpcache2_caps().

◆ pstcache_load_bitmap()

RD_BOOL pstcache_load_bitmap ( uint8  cache_id,
uint16  cache_idx 
)

Definition at line 53 of file pstcache.c.

54{
55 uint8 *celldata;
56 int fd;
57 CELLHEADER cellhdr;
59
61 return False;
62
63 if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
64 return False;
65
66 fd = g_pstcache_fd[cache_id];
67 rd_lseek_file(fd, cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
68 rd_read_file(fd, &cellhdr, sizeof(CELLHEADER));
69 celldata = (uint8 *) xmalloc(cellhdr.length);
70 rd_read_file(fd, celldata, cellhdr.length);
71
72 bitmap = ui_create_bitmap(cellhdr.width, cellhdr.height, celldata);
73 DEBUG(("Load bitmap from disk: id=%d, idx=%d, bmp=%p)\n", cache_id, cache_idx, bitmap));
74 cache_put_bitmap(cache_id, cache_idx, bitmap);
75
76 xfree(celldata);
77 return True;
78}
void cache_put_bitmap(uint8 id, uint16 idx, RD_HBITMAP bitmap)
Definition: cache.c:218
void xfree(void *mem)
Definition: uimain.c:758
RD_HBITMAP ui_create_bitmap(int width, int height, uint8 *data)
Definition: uimain.c:277
void * xmalloc(int size)
Definition: uimain.c:747
unsigned char uint8
Definition: types.h:28
Definition: uimain.c:89

Referenced by cache_get_bitmap(), and pstcache_enumerate().

◆ pstcache_save_bitmap()

RD_BOOL pstcache_save_bitmap ( uint8  cache_id,
uint16  cache_idx,
uint8 key,
uint8  width,
uint8  height,
uint16  length,
uint8 data 
)

Definition at line 82 of file pstcache.c.

84{
85 int fd;
86 CELLHEADER cellhdr;
87
88 if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
89 return False;
90
91 memcpy(cellhdr.key, key, sizeof(HASH_KEY));
92 cellhdr.width = width;
93 cellhdr.height = height;
94 cellhdr.length = length;
95 cellhdr.stamp = 0;
96
97 fd = g_pstcache_fd[cache_id];
98 rd_lseek_file(fd, cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
99 rd_write_file(fd, &cellhdr, sizeof(CELLHEADER));
101
102 return True;
103}
int rd_write_file(int fd, void *ptr, int len)
Definition: uimain.c:861
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
Definition: copy.c:22

Referenced by process_bmpcache2().

◆ pstcache_touch_bitmap()

void pstcache_touch_bitmap ( uint8  cache_id,
uint16  cache_idx,
uint32  stamp 
)

Definition at line 39 of file pstcache.c.

40{
41 int fd;
42
43 if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
44 return;
45
46 fd = g_pstcache_fd[cache_id];
47 rd_lseek_file(fd, 12 + cache_idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
48 rd_write_file(fd, &stamp, sizeof(stamp));
49}

Referenced by cache_evict_bitmap(), and cache_save_state().

Variable Documentation

◆ g_bitmap_cache

RD_BOOL g_bitmap_cache
extern

Definition at line 39 of file uimain.c.

Referenced by pstcache_enumerate(), and pstcache_init().

◆ g_bitmap_cache_persist_enable

RD_BOOL g_bitmap_cache_persist_enable
extern

Definition at line 37 of file uimain.c.

Referenced by pstcache_enumerate(), pstcache_init(), and pstcache_load_bitmap().

◆ g_bitmap_cache_precache

RD_BOOL g_bitmap_cache_precache
extern

Definition at line 38 of file uimain.c.

Referenced by pstcache_enumerate().

◆ g_pstcache_Bpp

◆ g_pstcache_enumerated

RD_BOOL g_pstcache_enumerated = False

Definition at line 33 of file pstcache.c.

Referenced by pstcache_enumerate(), and pstcache_init().

◆ g_pstcache_fd

◆ g_server_depth

int g_server_depth
extern

Definition at line 41 of file uimain.c.

Referenced by pstcache_enumerate(), and pstcache_init().

◆ zero_key

uint8 zero_key[] = { 0, 0, 0, 0, 0, 0, 0, 0 }

Definition at line 34 of file pstcache.c.

Referenced by pstcache_enumerate().