/[rdesktop]/jpeg/rdesktop/trunk/cache.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/cache.c

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

revision 563 by jsorg71, Wed Dec 24 17:23:03 2003 UTC revision 725 by jsorg71, Sun Jun 27 17:51:54 2004 UTC
# Line 21  Line 21 
21  #include "rdesktop.h"  #include "rdesktop.h"
22    
23  #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))  #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
24    #define TOUCH(id, idx) (g_bmpcache[id][idx].usage = ++g_stamp)
25    #define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0)
26    
27    extern int g_pstcache_fd[];
28    
29    uint32 g_stamp;
30    int g_num_bitmaps_in_memory[3];
31    
32    
33  /* BITMAP CACHE */  /* BITMAP CACHE */
34  static HBITMAP g_bmpcache[3][600];  static BMPCACHEENTRY g_bmpcache[3][0xa00];
35    
36    /* Remove the least-recently used bitmap from the cache */
37    void
38    cache_remove_lru_bitmap(uint8 cache_id)
39    {
40            int i;
41            uint16 cache_idx = 0;
42            uint32 m = -1;
43            BMPCACHEENTRY *pbce;
44    
45            for (i = 0; i < NUM_ELEMENTS(g_bmpcache[cache_id]); i++)
46            {
47                    if (g_bmpcache[cache_id][i].bitmap && g_bmpcache[cache_id][i].usage < m)
48                    {
49                            cache_idx = i;
50                            m = g_bmpcache[cache_id][i].usage;
51                    }
52            }
53    
54            pbce = &g_bmpcache[cache_id][cache_idx];
55            ui_destroy_bitmap(pbce->bitmap);
56            --g_num_bitmaps_in_memory[cache_id];
57            pbce->bitmap = 0;
58            pbce->usage = 0;
59    }
60    
61  /* Retrieve a bitmap from the cache */  /* Retrieve a bitmap from the cache */
62  HBITMAP  HBITMAP
63  cache_get_bitmap(uint8 cache_id, uint16 cache_idx)  cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
64  {  {
65          HBITMAP bitmap;          HBITMAP *pbitmap;
66    
67          if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))          if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
68          {          {
69                  bitmap = g_bmpcache[cache_id][cache_idx];                  pbitmap = &g_bmpcache[cache_id][cache_idx].bitmap;
70                  if (bitmap != NULL)                  if ((*pbitmap != 0) || pstcache_load_bitmap(cache_id, cache_idx))
71                          return bitmap;                  {
72                            if (IS_PERSISTENT(cache_id))
73                                    TOUCH(cache_id, cache_idx);
74    
75                            return *pbitmap;
76                    }
77          }          }
78    
79          error("get bitmap %d:%d\n", cache_id, cache_idx);          error("get bitmap %d:%d\n", cache_id, cache_idx);
# Line 45  cache_get_bitmap(uint8 cache_id, uint16 Line 82  cache_get_bitmap(uint8 cache_id, uint16
82    
83  /* Store a bitmap in the cache */  /* Store a bitmap in the cache */
84  void  void
85  cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)  cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap, uint32 stamp)
86  {  {
87          HBITMAP old;          HBITMAP old;
88    
89          if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))          if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
90          {          {
91                  old = g_bmpcache[cache_id][cache_idx];                  old = g_bmpcache[cache_id][cache_idx].bitmap;
92                  if (old != NULL)                  if (old != NULL)
93                    {
94                          ui_destroy_bitmap(old);                          ui_destroy_bitmap(old);
95                    }
96                    else
97                    {
98                            if (++g_num_bitmaps_in_memory[cache_id] > BMPCACHE2_C2_CELLS)
99                                    cache_remove_lru_bitmap(cache_id);
100                    }
101    
102                  g_bmpcache[cache_id][cache_idx] = bitmap;                  g_bmpcache[cache_id][cache_idx].bitmap = bitmap;
103                    g_bmpcache[cache_id][cache_idx].usage = stamp;
104          }          }
105          else          else
106          {          {
# Line 63  cache_put_bitmap(uint8 cache_id, uint16 Line 108  cache_put_bitmap(uint8 cache_id, uint16
108          }          }
109  }  }
110    
111    /* Updates the persistent bitmap cache MRU information on exit */
112    void
113    cache_save_state(void)
114    {
115            int id, idx;
116    
117            for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++)
118                    if (IS_PERSISTENT(id))
119                            for (idx = 0; idx < NUM_ELEMENTS(g_bmpcache[id]); idx++)
120                                    pstcache_touch_bitmap(id, idx, g_bmpcache[id][idx].usage);
121    }
122    
123    
124  /* FONT CACHE */  /* FONT CACHE */
125  static FONTGLYPH g_fontcache[12][256];  static FONTGLYPH g_fontcache[12][256];

Legend:
Removed from v.563  
changed lines
  Added in v.725

  ViewVC Help
Powered by ViewVC 1.1.26