~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to Xext/fontcache.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * Copyright (c) 1998-1999 Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
 
3
 * All rights reserved.
 
4
 * Copyright (c) 1998-1999 X-TrueType Server Project, All rights
 
5
 * reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 * 1. Redistributions of source code must retain the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer.
 
12
 * 2. Redistributions in binary form must reproduce the above copyright
 
13
 *    notice, this list of conditions and the following disclaimer in the
 
14
 *    documentation and/or other materials provided with the distribution.
 
15
 *
 
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
26
 * SUCH DAMAGE.
 
27
 *
 
28
 *      Id: fontcache.c,v 1.12 1999/01/31 13:47:45 akiyama Exp $
 
29
 */
 
30
/* $XFree86: xc/programs/Xserver/Xext/fontcache.c,v 1.7 2003/10/28 23:08:43 tsi Exp $ */
 
31
 
 
32
/* THIS IS NOT AN X CONSORTIUM STANDARD */
 
33
 
 
34
#define NEED_REPLIES
 
35
#define NEED_EVENTS
 
36
#ifdef HAVE_DIX_CONFIG_H
 
37
#include <dix-config.h>
 
38
#endif
 
39
 
 
40
#include <X11/X.h>
 
41
#include <X11/Xproto.h>
 
42
#include "misc.h"
 
43
#include "dixstruct.h"
 
44
#include "extnsionst.h"
 
45
#include "scrnintstr.h"
 
46
#include "inputstr.h"
 
47
#include "servermd.h"
 
48
#define _FONTCACHE_SERVER_
 
49
#include "fontcacheP.h"
 
50
#include "fontcachstr.h"
 
51
#include <X11/Xfuncproto.h>
 
52
 
 
53
#include "swaprep.h"
 
54
#include "modinit.h"
 
55
 
 
56
static int miscErrorBase;
 
57
 
 
58
static void FontCacheResetProc(
 
59
    ExtensionEntry* /* extEntry */
 
60
);
 
61
 
 
62
static DISPATCH_PROC(ProcFontCacheDispatch);
 
63
static DISPATCH_PROC(ProcFontCacheGetCacheSettings);
 
64
static DISPATCH_PROC(ProcFontCacheGetCacheStatistics);
 
65
static DISPATCH_PROC(ProcFontCacheQueryVersion);
 
66
static DISPATCH_PROC(ProcFontCacheChangeCacheSettings);
 
67
static DISPATCH_PROC(SProcFontCacheDispatch);
 
68
static DISPATCH_PROC(SProcFontCacheGetCacheSettings);
 
69
static DISPATCH_PROC(SProcFontCacheGetCacheStatistics);
 
70
static DISPATCH_PROC(SProcFontCacheQueryVersion);
 
71
static DISPATCH_PROC(SProcFontCacheChangeCacheSettings);
 
72
 
 
73
#if 0
 
74
static unsigned char FontCacheReqCode = 0;
 
75
#endif
 
76
 
 
77
void
 
78
FontCacheExtensionInit(INITARGS)
 
79
{
 
80
    ExtensionEntry* extEntry;
 
81
 
 
82
    if (
 
83
        (extEntry = AddExtension(FONTCACHENAME,
 
84
                                FontCacheNumberEvents,
 
85
                                FontCacheNumberErrors,
 
86
                                ProcFontCacheDispatch,
 
87
                                SProcFontCacheDispatch,
 
88
                                FontCacheResetProc,
 
89
                                StandardMinorOpcode))) {
 
90
#if 0
 
91
        FontCacheReqCode = (unsigned char)extEntry->base;
 
92
#endif
 
93
        miscErrorBase = extEntry->errorBase;
 
94
    }
 
95
}
 
96
 
 
97
/*ARGSUSED*/
 
98
static void
 
99
FontCacheResetProc (extEntry)
 
100
    ExtensionEntry* extEntry;
 
101
{
 
102
}
 
103
 
 
104
static int
 
105
ProcFontCacheQueryVersion(client)
 
106
    register ClientPtr client;
 
107
{
 
108
    xFontCacheQueryVersionReply rep;
 
109
    register int n;
 
110
 
 
111
    REQUEST_SIZE_MATCH(xFontCacheQueryVersionReq);
 
112
    rep.type = X_Reply;
 
113
    rep.length = 0;
 
114
    rep.sequenceNumber = client->sequence;
 
115
    rep.majorVersion = FONTCACHE_MAJOR_VERSION;
 
116
    rep.minorVersion = FONTCACHE_MINOR_VERSION;
 
117
    if (client->swapped) {
 
118
        swaps(&rep.sequenceNumber, n);
 
119
        swapl(&rep.length, n);
 
120
        swaps(&rep.majorVersion, n);
 
121
        swaps(&rep.minorVersion, n);
 
122
    }
 
123
    WriteToClient(client, SIZEOF(xFontCacheQueryVersionReply), (char *)&rep);
 
124
    return (client->noClientException);
 
125
}
 
126
 
 
127
static int
 
128
ProcFontCacheGetCacheSettings(client)
 
129
    register ClientPtr client;
 
130
{
 
131
    xFontCacheGetCacheSettingsReply rep;
 
132
    FontCacheSettings cinfo;
 
133
    register int n;
 
134
 
 
135
    REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq);
 
136
    rep.type = X_Reply;
 
137
    rep.sequenceNumber = client->sequence;
 
138
    rep.length = 0;
 
139
 
 
140
    /* XXX */
 
141
    FontCacheGetSettings(&cinfo);
 
142
    rep.himark = cinfo.himark;
 
143
    rep.lowmark = cinfo.lowmark;
 
144
    rep.balance = cinfo.balance;
 
145
    rep.reserve0 = 0;
 
146
    rep.reserve1 = 0;
 
147
    rep.reserve2 = 0;
 
148
 
 
149
    if (client->swapped) {
 
150
        swaps(&rep.sequenceNumber, n);
 
151
        swapl(&rep.himark, n);
 
152
        swapl(&rep.lowmark, n);
 
153
        swapl(&rep.balance, n);
 
154
        swapl(&rep.reserve0, n);
 
155
        swapl(&rep.reserve1, n);
 
156
        swapl(&rep.reserve2, n);
 
157
    }
 
158
    /* XXX */
 
159
 
 
160
    WriteToClient(client, SIZEOF(xFontCacheGetCacheSettingsReply),
 
161
                  (char *)&rep);
 
162
    return (client->noClientException);
 
163
}
 
164
 
 
165
static int
 
166
ProcFontCacheGetCacheStatistics(client)
 
167
    register ClientPtr client;
 
168
{
 
169
    xFontCacheGetCacheStatisticsReply rep;
 
170
    FontCacheStatistics cstats;
 
171
    register int n;
 
172
 
 
173
    REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq);
 
174
    rep.type = X_Reply;
 
175
    rep.sequenceNumber = client->sequence;
 
176
    rep.length = (sz_xFontCacheGetCacheStatisticsReply - 32) >> 2;
 
177
 
 
178
    /* XXX */
 
179
    FontCacheGetStatistics(&cstats);
 
180
    rep.purge_runs = cstats.purge_runs;
 
181
    rep.purge_stat = cstats.purge_stat;
 
182
    rep.balance = cstats.balance;
 
183
    rep.reserve0 = 0;
 
184
    rep.f_hits = cstats.f.hits;
 
185
    rep.f_misshits = cstats.f.misshits;
 
186
    rep.f_purged = cstats.f.purged;
 
187
    rep.f_usage = cstats.f.usage;
 
188
    rep.f_reserve0 = 0;
 
189
    rep.v_hits = cstats.v.hits;
 
190
    rep.v_misshits = cstats.v.misshits;
 
191
    rep.v_purged = cstats.v.purged;
 
192
    rep.v_usage = cstats.v.usage;
 
193
    rep.v_reserve0 = 0;
 
194
    if (client->swapped) {
 
195
        swaps(&rep.sequenceNumber, n);
 
196
        swapl(&rep.length, n);
 
197
        swapl(&rep.purge_runs, n);
 
198
        swapl(&rep.purge_stat, n);
 
199
        swapl(&rep.balance, n);
 
200
        swapl(&rep.reserve0, n);
 
201
        swapl(&rep.f_hits, n);
 
202
        swapl(&rep.f_misshits, n);
 
203
        swapl(&rep.f_purged, n);
 
204
        swapl(&rep.f_usage, n);
 
205
        swapl(&rep.f_reserve0, n);
 
206
        swapl(&rep.v_hits, n);
 
207
        swapl(&rep.v_misshits, n);
 
208
        swapl(&rep.v_purged, n);
 
209
        swapl(&rep.v_usage, n);
 
210
        swapl(&rep.v_reserve0, n);
 
211
    }
 
212
    /* XXX */
 
213
    WriteToClient(client, SIZEOF(xFontCacheGetCacheStatisticsReply),
 
214
                  (char *)&rep);
 
215
    return (client->noClientException);
 
216
}
 
217
 
 
218
static int
 
219
ProcFontCacheChangeCacheSettings(client)
 
220
    register ClientPtr client;
 
221
{
 
222
    FontCacheSettings cs;
 
223
 
 
224
    REQUEST(xFontCacheChangeCacheSettingsReq);
 
225
 
 
226
    REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq);
 
227
 
 
228
    /* XXX */
 
229
    cs.himark = stuff->himark;
 
230
    cs.lowmark = stuff->lowmark;
 
231
    cs.balance = stuff->balance;
 
232
 
 
233
    if (cs.himark < 0 || cs.lowmark < 0)
 
234
        return BadValue;
 
235
    if (cs.himark <= cs.lowmark)
 
236
        return BadValue;
 
237
    if (!(10 <= cs.balance && cs.balance <= 90))
 
238
        return BadValue;
 
239
 
 
240
    if (FontCacheChangeSettings(&cs) == 0)
 
241
        return miscErrorBase + FontCacheCannotAllocMemory;
 
242
    /* XXX */
 
243
 
 
244
    return (client->noClientException);
 
245
}
 
246
 
 
247
static int
 
248
ProcFontCacheDispatch (client)
 
249
    register ClientPtr  client;
 
250
{
 
251
    REQUEST(xReq);
 
252
    switch (stuff->data)
 
253
    {
 
254
    case X_FontCacheQueryVersion:
 
255
        return ProcFontCacheQueryVersion(client);
 
256
    case X_FontCacheGetCacheSettings:
 
257
        return ProcFontCacheGetCacheSettings(client);
 
258
    case X_FontCacheGetCacheStatistics:
 
259
        return ProcFontCacheGetCacheStatistics(client);
 
260
    case X_FontCacheChangeCacheSettings:
 
261
        return ProcFontCacheChangeCacheSettings(client);
 
262
    default:
 
263
        return miscErrorBase + FontCacheBadProtocol;
 
264
    }
 
265
}
 
266
 
 
267
static int
 
268
SProcFontCacheQueryVersion(client)
 
269
    register ClientPtr  client;
 
270
{
 
271
    register int n;
 
272
    REQUEST(xFontCacheQueryVersionReq);
 
273
    swaps(&stuff->length, n);
 
274
    return ProcFontCacheQueryVersion(client);
 
275
}
 
276
 
 
277
static int
 
278
SProcFontCacheGetCacheSettings(client)
 
279
    ClientPtr client;
 
280
{
 
281
    register int n;
 
282
    REQUEST(xFontCacheGetCacheSettingsReq);
 
283
    swaps(&stuff->length, n);
 
284
    REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq);
 
285
    return ProcFontCacheGetCacheSettings(client);
 
286
}
 
287
 
 
288
static int
 
289
SProcFontCacheGetCacheStatistics(client)
 
290
    ClientPtr client;
 
291
{
 
292
    register int n;
 
293
    REQUEST(xFontCacheGetCacheStatisticsReq);
 
294
    swaps(&stuff->length, n);
 
295
    REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq);
 
296
    return ProcFontCacheGetCacheStatistics(client);
 
297
}
 
298
 
 
299
static int
 
300
SProcFontCacheChangeCacheSettings(client)
 
301
    ClientPtr client;
 
302
{
 
303
    register int n;
 
304
    REQUEST(xFontCacheChangeCacheSettingsReq);
 
305
    swaps(&stuff->length, n);
 
306
    REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq);
 
307
    /* XXX */
 
308
    swapl(&stuff->himark, n);
 
309
    swapl(&stuff->lowmark, n);
 
310
    swapl(&stuff->balance, n);
 
311
    /* XXX */
 
312
    return ProcFontCacheChangeCacheSettings(client);
 
313
}
 
314
 
 
315
static int
 
316
SProcFontCacheDispatch (client)
 
317
    register ClientPtr  client;
 
318
{
 
319
    REQUEST(xReq);
 
320
    switch (stuff->data)
 
321
    {
 
322
    case X_FontCacheQueryVersion:
 
323
        return SProcFontCacheQueryVersion(client);
 
324
    case X_FontCacheGetCacheSettings:
 
325
        return SProcFontCacheGetCacheSettings(client);
 
326
    case X_FontCacheGetCacheStatistics:
 
327
        return SProcFontCacheGetCacheStatistics(client);
 
328
    case X_FontCacheChangeCacheSettings:
 
329
        return SProcFontCacheChangeCacheSettings(client);
 
330
    default:
 
331
        return miscErrorBase + FontCacheBadProtocol;
 
332
    }
 
333
}