/[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 24 - (hide annotations)
Sat Jan 6 03:12:10 2001 UTC (23 years, 5 months ago) by matty
File MIME type: text/plain
File size: 4154 byte(s)
ran indent (-bli0 -i8 -cli8 -npcs -npsl)

1 matty 9 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Cache routines
4     Copyright (C) Matthew Chapman 1999-2000
5    
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     HBITMAP cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
31 matty 9 {
32     HBITMAP bitmap;
33    
34 matty 10 if ((cache_id < NUM_ELEMENTS(bmpcache))
35 matty 24 && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
36 matty 9 {
37 matty 10 bitmap = bmpcache[cache_id][cache_idx];
38 matty 9 if (bitmap != NULL)
39     return bitmap;
40     }
41    
42 matty 10 ERROR("get bitmap %d:%d\n", cache_id, cache_idx);
43 matty 9 return NULL;
44     }
45    
46 matty 10 /* Store a bitmap in the cache */
47     void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
48 matty 9 {
49     HBITMAP old;
50    
51 matty 10 if ((cache_id < NUM_ELEMENTS(bmpcache))
52 matty 24 && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
53 matty 9 {
54 matty 10 old = bmpcache[cache_id][cache_idx];
55 matty 9 if (old != NULL)
56 matty 10 ui_destroy_bitmap(old);
57 matty 9
58 matty 10 bmpcache[cache_id][cache_idx] = bitmap;
59 matty 9 }
60     else
61     {
62 matty 10 ERROR("put bitmap %d:%d\n", cache_id, cache_idx);
63 matty 9 }
64     }
65    
66 matty 10
67     /* FONT CACHE */
68     static FONTGLYPH fontcache[12][256];
69    
70     /* Retrieve a glyph from the font cache */
71     FONTGLYPH *cache_get_font(uint8 font, uint16 character)
72 matty 9 {
73 matty 10 FONTGLYPH *glyph;
74 matty 9
75 matty 10 if ((font < NUM_ELEMENTS(fontcache))
76 matty 24 && (character < NUM_ELEMENTS(fontcache[0])))
77 matty 9 {
78 matty 10 glyph = &fontcache[font][character];
79 matty 9 if (glyph->pixmap != NULL)
80     return glyph;
81     }
82    
83 matty 10 ERROR("get font %d:%d\n", font, character);
84 matty 9 return NULL;
85     }
86    
87 matty 10 /* Store a glyph in the font cache */
88 matty 20 void cache_put_font(uint8 font, uint16 character, uint16 offset,
89 matty 24 uint16 baseline, uint16 width, uint16 height,
90     HGLYPH pixmap)
91 matty 9 {
92 matty 10 FONTGLYPH *glyph;
93 matty 9
94 matty 10 if ((font < NUM_ELEMENTS(fontcache))
95 matty 24 && (character < NUM_ELEMENTS(fontcache[0])))
96 matty 9 {
97 matty 10 glyph = &fontcache[font][character];
98 matty 9 if (glyph->pixmap != NULL)
99 matty 10 ui_destroy_glyph(glyph->pixmap);
100 matty 9
101 matty 20 glyph->offset = offset;
102 matty 9 glyph->baseline = baseline;
103     glyph->width = width;
104     glyph->height = height;
105     glyph->pixmap = pixmap;
106     }
107     else
108     {
109 matty 10 ERROR("put font %d:%d\n", font, character);
110 matty 9 }
111     }
112    
113 matty 10
114     /* TEXT CACHE */
115     static DATABLOB textcache[256];
116    
117     /* Retrieve a text item from the cache */
118     DATABLOB *cache_get_text(uint8 cache_id)
119 matty 9 {
120 matty 10 DATABLOB *text;
121 matty 9
122 matty 10 if (cache_id < NUM_ELEMENTS(textcache))
123 matty 9 {
124 matty 10 text = &textcache[cache_id];
125 matty 9 if (text->data != NULL)
126     return text;
127     }
128    
129 matty 10 ERROR("get text %d\n", cache_id);
130 matty 9 return NULL;
131     }
132    
133 matty 10 /* Store a text item in the cache */
134     void cache_put_text(uint8 cache_id, void *data, int length)
135 matty 9 {
136 matty 10 DATABLOB *text;
137 matty 9
138 matty 10 if (cache_id < NUM_ELEMENTS(textcache))
139 matty 9 {
140 matty 10 text = &textcache[cache_id];
141 matty 9 if (text->data != NULL)
142 matty 10 xfree(text->data);
143 matty 9
144 matty 10 text->data = xmalloc(length);
145 matty 9 text->size = length;
146     memcpy(text->data, data, length);
147     }
148     else
149     {
150 matty 10 ERROR("put text %d\n", cache_id);
151 matty 9 }
152     }
153 matty 10
154    
155     /* DESKTOP CACHE */
156     static uint8 deskcache[0x38400];
157    
158     /* Retrieve desktop data from the cache */
159 matty 16 uint8 *cache_get_desktop(uint32 offset, int cx, int cy)
160 matty 10 {
161 matty 16 int length = cx * cy;
162    
163 matty 10 if ((offset + length) <= sizeof(deskcache))
164     {
165     return &deskcache[offset];
166     }
167    
168     ERROR("get desktop %d:%d\n", offset, length);
169     return NULL;
170     }
171    
172     /* Store desktop data in the cache */
173 matty 24 void cache_put_desktop(uint32 offset, int cx, int cy, int scanline,
174     uint8 *data)
175 matty 10 {
176 matty 16 int length = cx * cy;
177    
178 matty 10 if ((offset + length) <= sizeof(deskcache))
179     {
180 matty 16 while (cy--)
181     {
182     memcpy(&deskcache[offset], data, cx);
183     data += scanline;
184     offset += cx;
185     }
186 matty 10 }
187     else
188     {
189     ERROR("put desktop %d:%d\n", offset, length);
190     }
191     }

  ViewVC Help
Powered by ViewVC 1.1.26