~ubuntu-branches/ubuntu/feisty/rdesktop/feisty-proposed

« back to all changes in this revision

Viewing changes to cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Johnston
  • Date: 2004-02-04 17:52:26 UTC
  • Revision ID: james.westby@ubuntu.com-20040204175226-87kz4bzs1nimji68
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   rdesktop: A Remote Desktop Protocol client.
 
3
   Cache routines
 
4
   Copyright (C) Matthew Chapman 1999-2002
 
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
#include "rdesktop.h"
 
22
 
 
23
#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;
 
34
 
 
35
        if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
 
36
        {
 
37
                bitmap = g_bmpcache[cache_id][cache_idx];
 
38
                if (bitmap != NULL)
 
39
                        return bitmap;
 
40
        }
 
41
 
 
42
        error("get bitmap %d:%d\n", cache_id, cache_idx);
 
43
        return NULL;
 
44
}
 
45
 
 
46
/* Store a bitmap in the cache */
 
47
void
 
48
cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
 
49
{
 
50
        HBITMAP old;
 
51
 
 
52
        if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
 
53
        {
 
54
                old = g_bmpcache[cache_id][cache_idx];
 
55
                if (old != NULL)
 
56
                        ui_destroy_bitmap(old);
 
57
 
 
58
                g_bmpcache[cache_id][cache_idx] = bitmap;
 
59
        }
 
60
        else
 
61
        {
 
62
                error("put bitmap %d:%d\n", cache_id, cache_idx);
 
63
        }
 
64
}
 
65
 
 
66
 
 
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
        FONTGLYPH *glyph;
 
75
 
 
76
        if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
 
77
        {
 
78
                glyph = &g_fontcache[font][character];
 
79
                if (glyph->pixmap != NULL)
 
80
                        return glyph;
 
81
        }
 
82
 
 
83
        error("get font %d:%d\n", font, character);
 
84
        return NULL;
 
85
}
 
86
 
 
87
/* Store a glyph in the font cache */
 
88
void
 
89
cache_put_font(uint8 font, uint16 character, uint16 offset,
 
90
               uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
 
91
{
 
92
        FONTGLYPH *glyph;
 
93
 
 
94
        if ((font < NUM_ELEMENTS(g_fontcache)) && (character < NUM_ELEMENTS(g_fontcache[0])))
 
95
        {
 
96
                glyph = &g_fontcache[font][character];
 
97
                if (glyph->pixmap != NULL)
 
98
                        ui_destroy_glyph(glyph->pixmap);
 
99
 
 
100
                glyph->offset = offset;
 
101
                glyph->baseline = baseline;
 
102
                glyph->width = width;
 
103
                glyph->height = height;
 
104
                glyph->pixmap = pixmap;
 
105
        }
 
106
        else
 
107
        {
 
108
                error("put font %d:%d\n", font, character);
 
109
        }
 
110
}
 
111
 
 
112
 
 
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
        DATABLOB *text;
 
121
 
 
122
        if (cache_id < NUM_ELEMENTS(g_textcache))
 
123
        {
 
124
                text = &g_textcache[cache_id];
 
125
                if (text->data != NULL)
 
126
                        return text;
 
127
        }
 
128
 
 
129
        error("get text %d\n", cache_id);
 
130
        return NULL;
 
131
}
 
132
 
 
133
/* Store a text item in the cache */
 
134
void
 
135
cache_put_text(uint8 cache_id, void *data, int length)
 
136
{
 
137
        DATABLOB *text;
 
138
 
 
139
        if (cache_id < NUM_ELEMENTS(g_textcache))
 
140
        {
 
141
                text = &g_textcache[cache_id];
 
142
                if (text->data != NULL)
 
143
                        xfree(text->data);
 
144
 
 
145
                text->data = xmalloc(length);
 
146
                text->size = length;
 
147
                memcpy(text->data, data, length);
 
148
        }
 
149
        else
 
150
        {
 
151
                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 > sizeof(g_deskcache))
 
166
                offset = 0;
 
167
 
 
168
        if ((offset + length) <= sizeof(g_deskcache))
 
169
        {
 
170
                return &g_deskcache[offset];
 
171
        }
 
172
 
 
173
        error("get desktop %d:%d\n", offset, length);
 
174
        return NULL;
 
175
}
 
176
 
 
177
/* Store desktop data in the cache */
 
178
void
 
179
cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
 
180
{
 
181
        int length = cx * cy * bytes_per_pixel;
 
182
 
 
183
        if (offset > sizeof(g_deskcache))
 
184
                offset = 0;
 
185
 
 
186
        if ((offset + length) <= sizeof(g_deskcache))
 
187
        {
 
188
                cx *= bytes_per_pixel;
 
189
                while (cy--)
 
190
                {
 
191
                        memcpy(&g_deskcache[offset], data, cx);
 
192
                        data += scanline;
 
193
                        offset += cx;
 
194
                }
 
195
        }
 
196
        else
 
197
        {
 
198
                error("put desktop %d:%d\n", offset, length);
 
199
        }
 
200
}
 
201
 
 
202
 
 
203
/* CURSOR CACHE */
 
204
static HCURSOR g_cursorcache[0x20];
 
205
 
 
206
/* Retrieve cursor from cache */
 
207
HCURSOR
 
208
cache_get_cursor(uint16 cache_idx)
 
209
{
 
210
        HCURSOR cursor;
 
211
 
 
212
        if (cache_idx < NUM_ELEMENTS(g_cursorcache))
 
213
        {
 
214
                cursor = g_cursorcache[cache_idx];
 
215
                if (cursor != NULL)
 
216
                        return cursor;
 
217
        }
 
218
 
 
219
        error("get cursor %d\n", cache_idx);
 
220
        return NULL;
 
221
}
 
222
 
 
223
/* Store cursor in cache */
 
224
void
 
225
cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
 
226
{
 
227
        HCURSOR old;
 
228
 
 
229
        if (cache_idx < NUM_ELEMENTS(g_cursorcache))
 
230
        {
 
231
                old = g_cursorcache[cache_idx];
 
232
                if (old != NULL)
 
233
                        ui_destroy_cursor(old);
 
234
 
 
235
                g_cursorcache[cache_idx] = cursor;
 
236
        }
 
237
        else
 
238
        {
 
239
                error("put cursor %d\n", cache_idx);
 
240
        }
 
241
}