ReactOS  0.4.14-dev-52-g6116262
pstcache.c File Reference
#include "rdesktop.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 && This->pstcache_fd[id] > 0)
 

Functions

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

Variables

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

Macro Definition Documentation

◆ IS_PERSISTENT

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

Definition at line 25 of file pstcache.c.

◆ MAX_CELL_SIZE

#define MAX_CELL_SIZE   0x1000 /* pixels */

Definition at line 23 of file pstcache.c.

Function Documentation

◆ pstcache_enumerate()

int pstcache_enumerate ( RDPCLIENT This,
uint8  id,
HASH_KEY keylist 
)

Definition at line 104 of file pstcache.c.

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

◆ pstcache_init()

BOOL pstcache_init ( RDPCLIENT This,
uint8  cache_id 
)

Definition at line 160 of file pstcache.c.

161 {
162  int fd;
163  char filename[256];
164 
165  if (This->pstcache_enumerated)
166  return True;
167 
168  This->pstcache_fd[cache_id] = 0;
169 
170  if (!(This->bitmap_cache && This->bitmap_cache_persist_enable))
171  return False;
172 
173  if (!rd_pstcache_mkdir())
174  {
175  DEBUG(("failed to get/make cache directory!\n"));
176  return False;
177  }
178 
179  This->pstcache_Bpp = (This->server_depth + 7) / 8;
180  sprintf(filename, "cache/pstcache_%d_%d", cache_id, This->pstcache_Bpp);
181  DEBUG(("persistent bitmap cache file: %s\n", filename));
182 
184  if (fd == -1)
185  return False;
186 
187  if (!rd_lock_file(fd, 0, 0))
188  {
189  warning("Persistent bitmap caching is disabled. (The file is already in use)\n");
190  rd_close_file(fd);
191  return False;
192  }
193 
194  This->pstcache_fd[cache_id] = fd;
195  return True;
196 }
void rd_close_file(int fd)
Definition: uimain.c:847
static int fd
Definition: io.c:51
const char * filename
Definition: ioapi.h:135
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define True
Definition: types.h:24
#define False
Definition: types.h:25
int rd_open_file(char *filename)
Definition: uimain.c:840
RD_BOOL rd_pstcache_mkdir(void)
Definition: uimain.c:833
RD_BOOL rd_lock_file(int fd, int start, int len)
Definition: uimain.c:875
#define DEBUG(args)
Definition: rdesktop.h:129
#define warning(s)
Definition: debug.h:71

◆ pstcache_load_bitmap()

BOOL pstcache_load_bitmap ( RDPCLIENT This,
uint8  cache_id,
uint16  cache_idx 
)

Definition at line 46 of file pstcache.c.

47 {
48  uint8 *celldata;
49  int fd;
50  CELLHEADER cellhdr;
52 
53  if (!This->bitmap_cache_persist_enable)
54  return False;
55 
56  if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
57  return False;
58 
59  fd = This->pstcache_fd[cache_id];
60  rd_lseek_file(fd, cache_idx * (This->pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
61  rd_read_file(fd, &cellhdr, sizeof(CELLHEADER));
62  celldata = (uint8 *) malloc(cellhdr.length);
63 
64  if(celldata == NULL)
65  return False;
66 
67  rd_read_file(fd, celldata, cellhdr.length);
68 
69  bitmap = ui_create_bitmap(This, cellhdr.width, cellhdr.height, celldata);
70  DEBUG(("Load bitmap from disk: id=%d, idx=%d, bmp=0x%x)\n", cache_id, cache_idx, bitmap));
71  cache_put_bitmap(This, cache_id, cache_idx, bitmap);
72 
73  free(celldata);
74  return True;
75 }
#define free
Definition: debug_ros.c:5
static int fd
Definition: io.c:51
RD_HBITMAP ui_create_bitmap(int width, int height, uint8 *data)
Definition: uimain.c:277
#define IS_PERSISTENT(id)
Definition: pstcache.c:25
void cache_put_bitmap(uint8 id, uint16 idx, RD_HBITMAP bitmap)
Definition: cache.c:218
smooth NULL
Definition: ftsmooth.c:416
Definition: uimain.c:88
#define True
Definition: types.h:24
#define False
Definition: types.h:25
unsigned char uint8
Definition: types.h:28
int rd_read_file(int fd, void *ptr, int len)
Definition: uimain.c:854
#define MAX_CELL_SIZE
Definition: pstcache.c:23
#define BMPCACHE2_NUM_PSTCELLS
Definition: constants.h:285
#define malloc
Definition: debug_ros.c:4
static HBITMAP bitmap
Definition: clipboard.c:1344
#define DEBUG(args)
Definition: rdesktop.h:129
static HBITMAP
Definition: button.c:44
int rd_lseek_file(int fd, int offset)
Definition: uimain.c:868

◆ pstcache_save_bitmap()

BOOL pstcache_save_bitmap ( RDPCLIENT This,
uint8  cache_id,
uint16  cache_idx,
uint8 key,
uint8  width,
uint8  height,
uint16  length,
uint8 data 
)

Definition at line 79 of file pstcache.c.

81 {
82  int fd;
83  CELLHEADER cellhdr;
84 
85  if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
86  return False;
87 
88  memcpy(cellhdr.key, key, sizeof(HASH_KEY));
89  cellhdr.width = width;
90  cellhdr.height = height;
91  cellhdr.length = length;
92  cellhdr.stamp = 0;
93 
94  fd = This->pstcache_fd[cache_id];
95  rd_lseek_file(fd, cache_idx * (This->pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
96  rd_write_file(fd, &cellhdr, sizeof(CELLHEADER));
98 
99  return True;
100 }
GLint GLint GLsizei width
Definition: gl.h:1546
static int fd
Definition: io.c:51
#define IS_PERSISTENT(id)
Definition: pstcache.c:25
uint8 HASH_KEY[8]
Definition: types.h:161
#define True
Definition: types.h:24
#define False
Definition: types.h:25
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
int rd_write_file(int fd, void *ptr, int len)
Definition: uimain.c:861
#define MAX_CELL_SIZE
Definition: pstcache.c:23
#define BMPCACHE2_NUM_PSTCELLS
Definition: constants.h:285
HASH_KEY key
Definition: types.h:166
Definition: path.c:42
int rd_lseek_file(int fd, int offset)
Definition: uimain.c:868

◆ pstcache_touch_bitmap()

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

Definition at line 32 of file pstcache.c.

33 {
34  int fd;
35 
36  if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
37  return;
38 
39  fd = This->pstcache_fd[cache_id];
40  rd_lseek_file(fd, 12 + cache_idx * (This->pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
41  rd_write_file(fd, &stamp, sizeof(stamp));
42 }
static int fd
Definition: io.c:51
#define IS_PERSISTENT(id)
Definition: pstcache.c:25
int rd_write_file(int fd, void *ptr, int len)
Definition: uimain.c:861
#define MAX_CELL_SIZE
Definition: pstcache.c:23
#define BMPCACHE2_NUM_PSTCELLS
Definition: constants.h:285
int rd_lseek_file(int fd, int offset)
Definition: uimain.c:868

Variable Documentation

◆ zero_key

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

Definition at line 27 of file pstcache.c.