/[rdesktop]/jpeg/rdesktop/trunk/pstcache.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/pstcache.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 829 by jdmeijer, Sat Dec 25 13:37:08 2004 UTC revision 830 by jdmeijer, Tue Mar 8 00:23:02 2005 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Persistent Bitmap Cache routines     Persistent Bitmap Cache routines
4     Copyright (C) Jeroen Meijer 2004     Copyright (C) Jeroen Meijer 2004-2005
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
# Line 25  Line 25 
25  #define IS_PERSISTENT(id) (id < 8 && 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;
 extern uint32 g_stamp;  
28  extern BOOL g_bitmap_cache;  extern BOOL g_bitmap_cache;
29  extern BOOL g_bitmap_cache_persist_enable;  extern BOOL g_bitmap_cache_persist_enable;
30  extern BOOL g_bitmap_cache_precache;  extern BOOL g_bitmap_cache_precache;
# Line 33  extern BOOL g_bitmap_cache_precache; Line 32  extern BOOL g_bitmap_cache_precache;
32  int g_pstcache_fd[8];  int g_pstcache_fd[8];
33  int g_pstcache_Bpp;  int g_pstcache_Bpp;
34  BOOL g_pstcache_enumerated = False;  BOOL g_pstcache_enumerated = False;
35  uint8 zero_id[] = { 0, 0, 0, 0, 0, 0, 0, 0 };  uint8 zero_key[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
36    
37    
38  /* Update usage info for a bitmap */  /* Update mru stamp/index for a bitmap */
39  void  void
40  pstcache_touch_bitmap(uint8 cache_id, uint16 cache_idx, uint32 stamp)  pstcache_touch_bitmap(uint8 cache_id, uint16 cache_idx, uint32 stamp)
41  {  {
# Line 71  pstcache_load_bitmap(uint8 cache_id, uin Line 70  pstcache_load_bitmap(uint8 cache_id, uin
70          celldata = (uint8 *) xmalloc(cellhdr.length);          celldata = (uint8 *) xmalloc(cellhdr.length);
71          rd_read_file(fd, celldata, cellhdr.length);          rd_read_file(fd, celldata, cellhdr.length);
72    
         DEBUG(("Loading bitmap from disk (%d:%d)\n", cache_id, cache_idx));  
   
73          bitmap = ui_create_bitmap(cellhdr.width, cellhdr.height, celldata);          bitmap = ui_create_bitmap(cellhdr.width, cellhdr.height, celldata);
74          cache_put_bitmap(cache_id, cache_idx, bitmap, cellhdr.stamp);          DEBUG(("Load bitmap from disk: id=%d, idx=%d, bmp=0x%x)\n", cache_id, cache_idx, bitmap));
75            cache_put_bitmap(cache_id, cache_idx, bitmap);
76    
77          xfree(celldata);          xfree(celldata);
78          return True;          return True;
# Line 82  pstcache_load_bitmap(uint8 cache_id, uin Line 80  pstcache_load_bitmap(uint8 cache_id, uin
80    
81  /* Store a bitmap in the persistent cache */  /* Store a bitmap in the persistent cache */
82  BOOL  BOOL
83  pstcache_put_bitmap(uint8 cache_id, uint16 cache_idx, uint8 * bitmap_id,  pstcache_save_bitmap(uint8 cache_id, uint16 cache_idx, uint8 * key,
84                      uint16 width, uint16 height, uint16 length, uint8 * data)                       uint16 width, uint16 height, uint16 length, uint8 * data)
85  {  {
86          int fd;          int fd;
87          CELLHEADER cellhdr;          CELLHEADER cellhdr;
# Line 91  pstcache_put_bitmap(uint8 cache_id, uint Line 89  pstcache_put_bitmap(uint8 cache_id, uint
89          if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)          if (!IS_PERSISTENT(cache_id) || cache_idx >= BMPCACHE2_NUM_PSTCELLS)
90                  return False;                  return False;
91    
92          memcpy(cellhdr.bitmap_id, bitmap_id, sizeof(BITMAP_ID));          memcpy(cellhdr.key, key, sizeof(HASH_KEY));
93          cellhdr.width = width;          cellhdr.width = width;
94          cellhdr.height = height;          cellhdr.height = height;
95          cellhdr.length = length;          cellhdr.length = length;
# Line 105  pstcache_put_bitmap(uint8 cache_id, uint Line 103  pstcache_put_bitmap(uint8 cache_id, uint
103          return True;          return True;
104  }  }
105    
106  /* list the bitmaps from the persistent cache file */  /* List the bitmap keys from the persistent cache file */
107  int  int
108  pstcache_enumerate(uint8 cache_id, uint8 * idlist)  pstcache_enumerate(uint8 id, HASH_KEY * keylist)
109  {  {
110          int fd, n, c = 0;          int fd, idx, n;
111            sint16 mru_idx[0xa00];
112            uint32 mru_stamp[0xa00];
113          CELLHEADER cellhdr;          CELLHEADER cellhdr;
114    
115          if (!(g_bitmap_cache && g_bitmap_cache_persist_enable && IS_PERSISTENT(cache_id)))          if (!(g_bitmap_cache && g_bitmap_cache_persist_enable && IS_PERSISTENT(id)))
116                  return 0;                  return 0;
117    
118          /* The server disconnects if the bitmap cache content is sent more than once */          /* The server disconnects if the bitmap cache content is sent more than once */
119          if (g_pstcache_enumerated)          if (g_pstcache_enumerated)
120                  return 0;                  return 0;
121    
122          DEBUG(("pstcache enumeration... "));          DEBUG_RDP5(("Persistent bitmap cache enumeration... "));
123          for (n = 0; n < BMPCACHE2_NUM_PSTCELLS; n++)          for (idx = 0; idx < BMPCACHE2_NUM_PSTCELLS; idx++)
124          {          {
125                  fd = g_pstcache_fd[cache_id];                  fd = g_pstcache_fd[id];
126                  rd_lseek_file(fd, n * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));                  rd_lseek_file(fd, idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
127                  if (rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)) <= 0)                  if (rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)) <= 0)
128                          break;                          break;
129    
130                  if (memcmp(cellhdr.bitmap_id, zero_id, sizeof(BITMAP_ID)) != 0)                  if (memcmp(cellhdr.key, zero_key, sizeof(HASH_KEY)) != 0)
131                  {                  {
132                          memcpy(idlist + n * sizeof(BITMAP_ID), cellhdr.bitmap_id,                          memcpy(keylist[idx], cellhdr.key, sizeof(HASH_KEY));
                                sizeof(BITMAP_ID));  
133    
134                          if (cellhdr.stamp)                          /* Pre-cache (not possible for 8bpp because 8bpp needs a colourmap) */
135                          {                          if (g_bitmap_cache_precache && cellhdr.stamp && g_server_bpp > 8)
136                                  /* Pre-caching is not possible with 8bpp because a colourmap                                  pstcache_load_bitmap(id, idx);
                                  * is needed to load them */  
                                 if (g_bitmap_cache_precache && (g_server_bpp > 8))  
                                 {  
                                         if (pstcache_load_bitmap(cache_id, n))  
                                                 c++;  
                                 }  
137    
138                                  g_stamp = MAX(g_stamp, cellhdr.stamp);                          /* 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                  else
149                  {                  {
# Line 151  pstcache_enumerate(uint8 cache_id, uint8 Line 151  pstcache_enumerate(uint8 cache_id, uint8
151                  }                  }
152          }          }
153    
154          DEBUG(("%d bitmaps in persistent cache, %d bitmaps loaded in memory\n", n, c));          DEBUG_RDP5(("%d cached bitmaps.\n", idx));
155    
156            cache_rebuild_bmpcache_linked_list(id, mru_idx, idx);
157          g_pstcache_enumerated = True;          g_pstcache_enumerated = True;
158          return n;          return idx;
159  }  }
160    
161  /* initialise the persistent bitmap cache */  /* initialise the persistent bitmap cache */

Legend:
Removed from v.829  
changed lines
  Added in v.830

  ViewVC Help
Powered by ViewVC 1.1.26