2
* Copyright (c) 1998-1999 Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
4
* Copyright (c) 1998-1999 X-TrueType Server Project, All rights
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
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.
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
28
* Id: fontcache.c,v 1.12 1999/01/31 13:47:45 akiyama Exp $
30
/* $XFree86: xc/programs/Xserver/Xext/fontcache.c,v 1.7 2003/10/28 23:08:43 tsi Exp $ */
32
/* THIS IS NOT AN X CONSORTIUM STANDARD */
36
#ifdef HAVE_DIX_CONFIG_H
37
#include <dix-config.h>
41
#include <X11/Xproto.h>
43
#include "dixstruct.h"
44
#include "extnsionst.h"
45
#include "scrnintstr.h"
48
#define _FONTCACHE_SERVER_
49
#include "fontcacheP.h"
50
#include "fontcachstr.h"
51
#include <X11/Xfuncproto.h>
56
static int miscErrorBase;
58
static void FontCacheResetProc(
59
ExtensionEntry* /* extEntry */
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);
74
static unsigned char FontCacheReqCode = 0;
78
FontCacheExtensionInit(INITARGS)
80
ExtensionEntry* extEntry;
83
(extEntry = AddExtension(FONTCACHENAME,
84
FontCacheNumberEvents,
85
FontCacheNumberErrors,
86
ProcFontCacheDispatch,
87
SProcFontCacheDispatch,
89
StandardMinorOpcode))) {
91
FontCacheReqCode = (unsigned char)extEntry->base;
93
miscErrorBase = extEntry->errorBase;
99
FontCacheResetProc (extEntry)
100
ExtensionEntry* extEntry;
105
ProcFontCacheQueryVersion(client)
106
register ClientPtr client;
108
xFontCacheQueryVersionReply rep;
111
REQUEST_SIZE_MATCH(xFontCacheQueryVersionReq);
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);
123
WriteToClient(client, SIZEOF(xFontCacheQueryVersionReply), (char *)&rep);
124
return (client->noClientException);
128
ProcFontCacheGetCacheSettings(client)
129
register ClientPtr client;
131
xFontCacheGetCacheSettingsReply rep;
132
FontCacheSettings cinfo;
135
REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq);
137
rep.sequenceNumber = client->sequence;
141
FontCacheGetSettings(&cinfo);
142
rep.himark = cinfo.himark;
143
rep.lowmark = cinfo.lowmark;
144
rep.balance = cinfo.balance;
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);
160
WriteToClient(client, SIZEOF(xFontCacheGetCacheSettingsReply),
162
return (client->noClientException);
166
ProcFontCacheGetCacheStatistics(client)
167
register ClientPtr client;
169
xFontCacheGetCacheStatisticsReply rep;
170
FontCacheStatistics cstats;
173
REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq);
175
rep.sequenceNumber = client->sequence;
176
rep.length = (sz_xFontCacheGetCacheStatisticsReply - 32) >> 2;
179
FontCacheGetStatistics(&cstats);
180
rep.purge_runs = cstats.purge_runs;
181
rep.purge_stat = cstats.purge_stat;
182
rep.balance = cstats.balance;
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;
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;
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);
213
WriteToClient(client, SIZEOF(xFontCacheGetCacheStatisticsReply),
215
return (client->noClientException);
219
ProcFontCacheChangeCacheSettings(client)
220
register ClientPtr client;
222
FontCacheSettings cs;
224
REQUEST(xFontCacheChangeCacheSettingsReq);
226
REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq);
229
cs.himark = stuff->himark;
230
cs.lowmark = stuff->lowmark;
231
cs.balance = stuff->balance;
233
if (cs.himark < 0 || cs.lowmark < 0)
235
if (cs.himark <= cs.lowmark)
237
if (!(10 <= cs.balance && cs.balance <= 90))
240
if (FontCacheChangeSettings(&cs) == 0)
241
return miscErrorBase + FontCacheCannotAllocMemory;
244
return (client->noClientException);
248
ProcFontCacheDispatch (client)
249
register ClientPtr client;
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);
263
return miscErrorBase + FontCacheBadProtocol;
268
SProcFontCacheQueryVersion(client)
269
register ClientPtr client;
272
REQUEST(xFontCacheQueryVersionReq);
273
swaps(&stuff->length, n);
274
return ProcFontCacheQueryVersion(client);
278
SProcFontCacheGetCacheSettings(client)
282
REQUEST(xFontCacheGetCacheSettingsReq);
283
swaps(&stuff->length, n);
284
REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq);
285
return ProcFontCacheGetCacheSettings(client);
289
SProcFontCacheGetCacheStatistics(client)
293
REQUEST(xFontCacheGetCacheStatisticsReq);
294
swaps(&stuff->length, n);
295
REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq);
296
return ProcFontCacheGetCacheStatistics(client);
300
SProcFontCacheChangeCacheSettings(client)
304
REQUEST(xFontCacheChangeCacheSettingsReq);
305
swaps(&stuff->length, n);
306
REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq);
308
swapl(&stuff->himark, n);
309
swapl(&stuff->lowmark, n);
310
swapl(&stuff->balance, n);
312
return ProcFontCacheChangeCacheSettings(client);
316
SProcFontCacheDispatch (client)
317
register ClientPtr client;
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);
331
return miscErrorBase + FontCacheBadProtocol;