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

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

revision 9 by matty, Tue Jul 25 12:34:29 2000 UTC revision 379 by jsorg71, Fri May 30 21:31:59 2003 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Cache routines     Cache routines
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2002
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 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
21  #include "includes.h"  #include "rdesktop.h"
22    
23  HBITMAP cache_get_bitmap(HCONN conn, uint8 cache_id, uint16 cache_idx)  #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
24    
25    
26    /* BITMAP CACHE */
27    static HBITMAP g_bmpcache[3][600];
28    
29    /* Retrieve a bitmap from the cache */
30    HBITMAP
31    cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
32  {  {
33          HBITMAP bitmap;          HBITMAP bitmap;
34    
35          if ((cache_id < NUM_ELEMENTS(conn->bmpcache))          if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
                         && (cache_idx < NUM_ELEMENTS(conn->bmpcache[0])))  
36          {          {
37                  bitmap = conn->bmpcache[cache_id][cache_idx];                  bitmap = g_bmpcache[cache_id][cache_idx];
38                  if (bitmap != NULL)                  if (bitmap != NULL)
39                          return bitmap;                          return bitmap;
40          }          }
41    
42          ERROR("Bitmap %d:%d not found\n", cache_id, cache_idx);          error("get bitmap %d:%d\n", cache_id, cache_idx);
43          return NULL;          return NULL;
44  }  }
45    
46  void cache_put_bitmap(HCONN conn, uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)  /* Store a bitmap in the cache */
47    void
48    cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
49  {  {
50          HBITMAP old;          HBITMAP old;
51    
52          if ((cache_id < NUM_ELEMENTS(conn->bmpcache))          if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
                         && (cache_idx < NUM_ELEMENTS(conn->bmpcache[0])))  
53          {          {
54                  old = conn->bmpcache[cache_id][cache_idx];                  old = g_bmpcache[cache_id][cache_idx];
55                  if (old != NULL)                  if (old != NULL)
56                          ui_destroy_bitmap(conn->wnd, old);                          ui_destroy_bitmap(old);
57    
58                  conn->bmpcache[cache_id][cache_idx] = bitmap;                  g_bmpcache[cache_id][cache_idx] = bitmap;
59          }          }
60          else          else
61          {          {
62                  ERROR("Bitmap %d:%d past end of cache\n", cache_id, cache_idx);                  error("put bitmap %d:%d\n", cache_id, cache_idx);
63          }          }
64  }  }
65    
66  FONT_GLYPH *cache_get_font(HCONN conn, uint8 font, uint16 character)  
67    /* FONT CACHE */
68    static FONTGLYPH g_fontcache[12][256];
69    
70    /* Retrieve a glyph from the font cache */
71    FONTGLYPH *
72    cache_get_font(uint8 font, uint16 character)
73  {  {
74          FONT_GLYPH *glyph;          FONTGLYPH *glyph;
75    
76          if ((font < NUM_ELEMENTS(conn->fontcache))          if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
                         && (character < NUM_ELEMENTS(conn->fontcache[0])))  
77          {          {
78                  glyph = &conn->fontcache[font][character];                  glyph = &g_fontcache[font][character];
79                  if (glyph->pixmap != NULL)                  if (glyph->pixmap != NULL)
80                          return glyph;                          return glyph;
81          }          }
82    
83          ERROR("Font %d character %d not found\n", font, character);          error("get font %d:%d\n", font, character);
84          return NULL;          return NULL;
85  }  }
86    
87  void cache_put_font(HCONN conn, uint8 font, uint32 character, uint16 baseline,  /* Store a glyph in the font cache */
88                      uint16 width, uint16 height, HGLYPH pixmap)  void
89    cache_put_font(uint8 font, uint16 character, uint16 offset,
90                   uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
91  {  {
92          FONT_GLYPH *glyph;          FONTGLYPH *glyph;
93    
94          if ((font < NUM_ELEMENTS(conn->fontcache))          if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
                         && (character < NUM_ELEMENTS(conn->fontcache[0])))  
95          {          {
96                  glyph = &conn->fontcache[font][character];                  glyph = &g_fontcache[font][character];
97                  if (glyph->pixmap != NULL)                  if (glyph->pixmap != NULL)
98                          ui_destroy_glyph(conn->wnd, glyph->pixmap);                          ui_destroy_glyph(glyph->pixmap);
99    
100                    glyph->offset = offset;
101                  glyph->baseline = baseline;                  glyph->baseline = baseline;
102                  glyph->width = width;                  glyph->width = width;
103                  glyph->height = height;                  glyph->height = height;
# Line 90  void cache_put_font(HCONN conn, uint8 fo Line 105  void cache_put_font(HCONN conn, uint8 fo
105          }          }
106          else          else
107          {          {
108                  ERROR("Font %d character %d past end of cache\n",                  error("put font %d:%d\n", font, character);
                       font, character);  
109          }          }
110  }  }
111    
112  BLOB *cache_get_text(HCONN conn, uint8 cache_id)  
113    /* TEXT CACHE */
114    static DATABLOB g_textcache[256];
115    
116    /* Retrieve a text item from the cache */
117    DATABLOB *
118    cache_get_text(uint8 cache_id)
119  {  {
120          BLOB *text;          DATABLOB *text;
121    
122          if (cache_id < NUM_ELEMENTS(conn->textcache))          if (cache_id < NUM_ELEMENTS(g_textcache))
123          {          {
124                  text = &conn->textcache[cache_id];                  text = &g_textcache[cache_id];
125                  if (text->data != NULL)                  if (text->data != NULL)
126                          return text;                          return text;
127          }          }
128    
129          ERROR("Text cache id %d not found\n", cache_id);          error("get text %d\n", cache_id);
130          return NULL;          return NULL;
131  }  }
132    
133  void cache_put_text(HCONN conn, uint8 cache_id, void *data, int length)  /* Store a text item in the cache */
134    void
135    cache_put_text(uint8 cache_id, void *data, int length)
136  {  {
137          BLOB *text;          DATABLOB *text;
138    
139          if (cache_id < NUM_ELEMENTS(conn->textcache))          if (cache_id < NUM_ELEMENTS(g_textcache))
140          {          {
141                  text = &conn->textcache[cache_id];                  text = &g_textcache[cache_id];
142                  if (text->data != NULL)                  if (text->data != NULL)
143                          free(text->data);                          xfree(text->data);
144    
145                  text->data = malloc(length);                  text->data = xmalloc(length);
146                  text->size = length;                  text->size = length;
147                  memcpy(text->data, data, length);                  memcpy(text->data, data, length);
148          }          }
149          else          else
150          {          {
151                  ERROR("Text cache id %d past end of cache\n", cache_id);                  error("put text %d\n", cache_id);
152            }
153    }
154    
155    
156    /* DESKTOP CACHE */
157    static uint8 g_deskcache[0x38400 * 4];
158    
159    /* Retrieve desktop data from the cache */
160    uint8 *
161    cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
162    {
163            int length = cx * cy * bytes_per_pixel;
164    
165            if ((offset + length) <= sizeof(g_deskcache))
166            {
167                    return &g_deskcache[offset];
168            }
169    
170            error("get desktop %d:%d\n", offset, length);
171            return NULL;
172    }
173    
174    /* Store desktop data in the cache */
175    void
176    cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
177    {
178            int length = cx * cy * bytes_per_pixel;
179    
180            if ((offset + length) <= sizeof(g_deskcache))
181            {
182                    cx *= bytes_per_pixel;
183                    while (cy--)
184                    {
185                            memcpy(&g_deskcache[offset], data, cx);
186                            data += scanline;
187                            offset += cx;
188                    }
189            }
190            else
191            {
192                    error("put desktop %d:%d\n", offset, length);
193            }
194    }
195    
196    
197    /* CURSOR CACHE */
198    static HCURSOR g_cursorcache[0x20];
199    
200    /* Retrieve cursor from cache */
201    HCURSOR
202    cache_get_cursor(uint16 cache_idx)
203    {
204            HCURSOR cursor;
205    
206            if (cache_idx < NUM_ELEMENTS(g_cursorcache))
207            {
208                    cursor = g_cursorcache[cache_idx];
209                    if (cursor != NULL)
210                            return cursor;
211            }
212    
213            error("get cursor %d\n", cache_idx);
214            return NULL;
215    }
216    
217    /* Store cursor in cache */
218    void
219    cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
220    {
221            HCURSOR old;
222    
223            if (cache_idx < NUM_ELEMENTS(g_cursorcache))
224            {
225                    old = g_cursorcache[cache_idx];
226                    if (old != NULL)
227                            ui_destroy_cursor(old);
228    
229                    g_cursorcache[cache_idx] = cursor;
230            }
231            else
232            {
233                    error("put cursor %d\n", cache_idx);
234          }          }
235  }  }

Legend:
Removed from v.9  
changed lines
  Added in v.379

  ViewVC Help
Powered by ViewVC 1.1.26