/[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

Annotation of /sourceforge.net/trunk/rdesktop/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations)
Thu Jul 18 16:38:31 2002 UTC (21 years, 10 months ago) by astrand
File MIME type: text/plain
File size: 4907 byte(s)
Fixed indentation with indent

1 matty 9 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Cache routines
4 matty 30 Copyright (C) Matthew Chapman 1999-2001
5 matty 9
6     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
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 10 #include "rdesktop.h"
22 matty 9
23 matty 10 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
24    
25    
26     /* BITMAP CACHE */
27     static HBITMAP bmpcache[3][600];
28    
29     /* Retrieve a bitmap from the cache */
30 matty 25 HBITMAP
31     cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
32 matty 9 {
33     HBITMAP bitmap;
34    
35 matty 10 if ((cache_id < NUM_ELEMENTS(bmpcache))
36 matty 24 && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
37 matty 9 {
38 matty 10 bitmap = bmpcache[cache_id][cache_idx];
39 matty 9 if (bitmap != NULL)
40     return bitmap;
41     }
42    
43 matty 30 error("get bitmap %d:%d\n", cache_id, cache_idx);
44 matty 9 return NULL;
45     }
46    
47 matty 10 /* Store a bitmap in the cache */
48 matty 25 void
49     cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
50 matty 9 {
51     HBITMAP old;
52    
53 matty 10 if ((cache_id < NUM_ELEMENTS(bmpcache))
54 matty 24 && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
55 matty 9 {
56 matty 10 old = bmpcache[cache_id][cache_idx];
57 matty 9 if (old != NULL)
58 matty 10 ui_destroy_bitmap(old);
59 matty 9
60 matty 10 bmpcache[cache_id][cache_idx] = bitmap;
61 matty 9 }
62     else
63     {
64 matty 30 error("put bitmap %d:%d\n", cache_id, cache_idx);
65 matty 9 }
66     }
67    
68 matty 10
69     /* FONT CACHE */
70     static FONTGLYPH fontcache[12][256];
71    
72     /* Retrieve a glyph from the font cache */
73 matty 25 FONTGLYPH *
74     cache_get_font(uint8 font, uint16 character)
75 matty 9 {
76 matty 10 FONTGLYPH *glyph;
77 matty 9
78 matty 10 if ((font < NUM_ELEMENTS(fontcache))
79 matty 24 && (character < NUM_ELEMENTS(fontcache[0])))
80 matty 9 {
81 matty 10 glyph = &fontcache[font][character];
82 matty 9 if (glyph->pixmap != NULL)
83     return glyph;
84     }
85    
86 matty 30 error("get font %d:%d\n", font, character);
87 matty 9 return NULL;
88     }
89    
90 matty 10 /* Store a glyph in the font cache */
91 matty 25 void
92     cache_put_font(uint8 font, uint16 character, uint16 offset,
93     uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
94 matty 9 {
95 matty 10 FONTGLYPH *glyph;
96 matty 9
97 matty 10 if ((font < NUM_ELEMENTS(fontcache))
98 matty 24 && (character < NUM_ELEMENTS(fontcache[0])))
99 matty 9 {
100 matty 10 glyph = &fontcache[font][character];
101 matty 9 if (glyph->pixmap != NULL)
102 matty 10 ui_destroy_glyph(glyph->pixmap);
103 matty 9
104 matty 20 glyph->offset = offset;
105 matty 9 glyph->baseline = baseline;
106     glyph->width = width;
107     glyph->height = height;
108     glyph->pixmap = pixmap;
109     }
110     else
111     {
112 matty 30 error("put font %d:%d\n", font, character);
113 matty 9 }
114     }
115    
116 matty 10
117     /* TEXT CACHE */
118     static DATABLOB textcache[256];
119    
120     /* Retrieve a text item from the cache */
121 matty 25 DATABLOB *
122     cache_get_text(uint8 cache_id)
123 matty 9 {
124 matty 10 DATABLOB *text;
125 matty 9
126 matty 10 if (cache_id < NUM_ELEMENTS(textcache))
127 matty 9 {
128 matty 10 text = &textcache[cache_id];
129 matty 9 if (text->data != NULL)
130     return text;
131     }
132    
133 matty 30 error("get text %d\n", cache_id);
134 matty 9 return NULL;
135     }
136    
137 matty 10 /* Store a text item in the cache */
138 matty 25 void
139     cache_put_text(uint8 cache_id, void *data, int length)
140 matty 9 {
141 matty 10 DATABLOB *text;
142 matty 9
143 matty 10 if (cache_id < NUM_ELEMENTS(textcache))
144 matty 9 {
145 matty 10 text = &textcache[cache_id];
146 matty 9 if (text->data != NULL)
147 matty 10 xfree(text->data);
148 matty 9
149 matty 10 text->data = xmalloc(length);
150 matty 9 text->size = length;
151     memcpy(text->data, data, length);
152     }
153     else
154     {
155 matty 30 error("put text %d\n", cache_id);
156 matty 9 }
157     }
158 matty 10
159    
160     /* DESKTOP CACHE */
161 matty 28 static uint8 deskcache[0x38400 * 4];
162 matty 10
163     /* Retrieve desktop data from the cache */
164 matty 25 uint8 *
165 matty 28 cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
166 matty 10 {
167 matty 28 int length = cx * cy * bytes_per_pixel;
168 matty 16
169 matty 10 if ((offset + length) <= sizeof(deskcache))
170     {
171     return &deskcache[offset];
172     }
173    
174 matty 30 error("get desktop %d:%d\n", offset, length);
175 matty 10 return NULL;
176     }
177    
178     /* Store desktop data in the cache */
179 matty 25 void
180 matty 28 cache_put_desktop(uint32 offset, int cx, int cy, int scanline,
181 astrand 64 int bytes_per_pixel, uint8 * data)
182 matty 10 {
183 matty 28 int length = cx * cy * bytes_per_pixel;
184 matty 16
185 matty 10 if ((offset + length) <= sizeof(deskcache))
186     {
187 matty 28 cx *= bytes_per_pixel;
188 matty 16 while (cy--)
189     {
190     memcpy(&deskcache[offset], data, cx);
191     data += scanline;
192     offset += cx;
193     }
194 matty 10 }
195     else
196     {
197 matty 30 error("put desktop %d:%d\n", offset, length);
198 matty 10 }
199     }
200 matty 28
201    
202     /* CURSOR CACHE */
203     static HCURSOR cursorcache[0x20];
204    
205     /* Retrieve cursor from cache */
206 astrand 64 HCURSOR
207     cache_get_cursor(uint16 cache_idx)
208 matty 28 {
209     HCURSOR cursor;
210    
211     if (cache_idx < NUM_ELEMENTS(cursorcache))
212     {
213     cursor = cursorcache[cache_idx];
214     if (cursor != NULL)
215     return cursor;
216     }
217    
218 matty 30 error("get cursor %d\n", cache_idx);
219 matty 28 return NULL;
220     }
221    
222     /* Store cursor in cache */
223     void
224     cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
225     {
226     HCURSOR old;
227    
228     if (cache_idx < NUM_ELEMENTS(cursorcache))
229     {
230     old = cursorcache[cache_idx];
231     if (old != NULL)
232     ui_destroy_cursor(old);
233    
234     cursorcache[cache_idx] = cursor;
235     }
236     else
237     {
238 matty 30 error("put cursor %d\n", cache_idx);
239 matty 28 }
240     }

  ViewVC Help
Powered by ViewVC 1.1.26