First import
[xorg_rtime.git] / xorg-server-1.4 / Xext / fontcache.c
blobc54340b61637748f167d6c0fe6077776cc7fca23
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.
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.
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.
29 /* THIS IS NOT AN X CONSORTIUM STANDARD */
31 #define NEED_REPLIES
32 #define NEED_EVENTS
33 #ifdef HAVE_DIX_CONFIG_H
34 #include <dix-config.h>
35 #endif
37 #include <X11/X.h>
38 #include <X11/Xproto.h>
39 #include "misc.h"
40 #include "dixstruct.h"
41 #include "extnsionst.h"
42 #include "scrnintstr.h"
43 #include "inputstr.h"
44 #include "servermd.h"
45 #define _FONTCACHE_SERVER_
46 #include <X11/extensions/fontcacheP.h>
47 #include <X11/extensions/fontcachstr.h>
48 #include <X11/Xfuncproto.h>
50 #include "swaprep.h"
51 #include "modinit.h"
53 static int miscErrorBase;
55 static void FontCacheResetProc(
56 ExtensionEntry* /* extEntry */
59 static DISPATCH_PROC(ProcFontCacheDispatch);
60 static DISPATCH_PROC(ProcFontCacheGetCacheSettings);
61 static DISPATCH_PROC(ProcFontCacheGetCacheStatistics);
62 static DISPATCH_PROC(ProcFontCacheQueryVersion);
63 static DISPATCH_PROC(ProcFontCacheChangeCacheSettings);
64 static DISPATCH_PROC(SProcFontCacheDispatch);
65 static DISPATCH_PROC(SProcFontCacheGetCacheSettings);
66 static DISPATCH_PROC(SProcFontCacheGetCacheStatistics);
67 static DISPATCH_PROC(SProcFontCacheQueryVersion);
68 static DISPATCH_PROC(SProcFontCacheChangeCacheSettings);
70 #if 0
71 static unsigned char FontCacheReqCode = 0;
72 #endif
74 void
75 FontCacheExtensionInit(INITARGS)
77 ExtensionEntry* extEntry;
79 if (
80 (extEntry = AddExtension(FONTCACHENAME,
81 FontCacheNumberEvents,
82 FontCacheNumberErrors,
83 ProcFontCacheDispatch,
84 SProcFontCacheDispatch,
85 FontCacheResetProc,
86 StandardMinorOpcode))) {
87 #if 0
88 FontCacheReqCode = (unsigned char)extEntry->base;
89 #endif
90 miscErrorBase = extEntry->errorBase;
94 /*ARGSUSED*/
95 static void
96 FontCacheResetProc (extEntry)
97 ExtensionEntry* extEntry;
101 static int
102 ProcFontCacheQueryVersion(client)
103 register ClientPtr client;
105 xFontCacheQueryVersionReply rep;
106 register int n;
108 REQUEST_SIZE_MATCH(xFontCacheQueryVersionReq);
109 rep.type = X_Reply;
110 rep.length = 0;
111 rep.sequenceNumber = client->sequence;
112 rep.majorVersion = FONTCACHE_MAJOR_VERSION;
113 rep.minorVersion = FONTCACHE_MINOR_VERSION;
114 if (client->swapped) {
115 swaps(&rep.sequenceNumber, n);
116 swapl(&rep.length, n);
117 swaps(&rep.majorVersion, n);
118 swaps(&rep.minorVersion, n);
120 WriteToClient(client, SIZEOF(xFontCacheQueryVersionReply), (char *)&rep);
121 return (client->noClientException);
124 static int
125 ProcFontCacheGetCacheSettings(client)
126 register ClientPtr client;
128 xFontCacheGetCacheSettingsReply rep;
129 FontCacheSettings cinfo;
130 register int n;
132 REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq);
133 rep.type = X_Reply;
134 rep.sequenceNumber = client->sequence;
135 rep.length = 0;
137 /* XXX */
138 FontCacheGetSettings(&cinfo);
139 rep.himark = cinfo.himark;
140 rep.lowmark = cinfo.lowmark;
141 rep.balance = cinfo.balance;
142 rep.reserve0 = 0;
143 rep.reserve1 = 0;
144 rep.reserve2 = 0;
146 if (client->swapped) {
147 swaps(&rep.sequenceNumber, n);
148 swapl(&rep.himark, n);
149 swapl(&rep.lowmark, n);
150 swapl(&rep.balance, n);
151 swapl(&rep.reserve0, n);
152 swapl(&rep.reserve1, n);
153 swapl(&rep.reserve2, n);
155 /* XXX */
157 WriteToClient(client, SIZEOF(xFontCacheGetCacheSettingsReply),
158 (char *)&rep);
159 return (client->noClientException);
162 static int
163 ProcFontCacheGetCacheStatistics(client)
164 register ClientPtr client;
166 xFontCacheGetCacheStatisticsReply rep;
167 FontCacheStatistics cstats;
168 register int n;
170 REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq);
171 rep.type = X_Reply;
172 rep.sequenceNumber = client->sequence;
173 rep.length = (sz_xFontCacheGetCacheStatisticsReply - 32) >> 2;
175 /* XXX */
176 FontCacheGetStatistics(&cstats);
177 rep.purge_runs = cstats.purge_runs;
178 rep.purge_stat = cstats.purge_stat;
179 rep.balance = cstats.balance;
180 rep.reserve0 = 0;
181 rep.f_hits = cstats.f.hits;
182 rep.f_misshits = cstats.f.misshits;
183 rep.f_purged = cstats.f.purged;
184 rep.f_usage = cstats.f.usage;
185 rep.f_reserve0 = 0;
186 rep.v_hits = cstats.v.hits;
187 rep.v_misshits = cstats.v.misshits;
188 rep.v_purged = cstats.v.purged;
189 rep.v_usage = cstats.v.usage;
190 rep.v_reserve0 = 0;
191 if (client->swapped) {
192 swaps(&rep.sequenceNumber, n);
193 swapl(&rep.length, n);
194 swapl(&rep.purge_runs, n);
195 swapl(&rep.purge_stat, n);
196 swapl(&rep.balance, n);
197 swapl(&rep.reserve0, n);
198 swapl(&rep.f_hits, n);
199 swapl(&rep.f_misshits, n);
200 swapl(&rep.f_purged, n);
201 swapl(&rep.f_usage, n);
202 swapl(&rep.f_reserve0, n);
203 swapl(&rep.v_hits, n);
204 swapl(&rep.v_misshits, n);
205 swapl(&rep.v_purged, n);
206 swapl(&rep.v_usage, n);
207 swapl(&rep.v_reserve0, n);
209 /* XXX */
210 WriteToClient(client, SIZEOF(xFontCacheGetCacheStatisticsReply),
211 (char *)&rep);
212 return (client->noClientException);
215 static int
216 ProcFontCacheChangeCacheSettings(client)
217 register ClientPtr client;
219 FontCacheSettings cs;
221 REQUEST(xFontCacheChangeCacheSettingsReq);
223 REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq);
225 /* XXX */
226 cs.himark = stuff->himark;
227 cs.lowmark = stuff->lowmark;
228 cs.balance = stuff->balance;
230 if (cs.himark < 0 || cs.lowmark < 0)
231 return BadValue;
232 if (cs.himark <= cs.lowmark)
233 return BadValue;
234 if (!(10 <= cs.balance && cs.balance <= 90))
235 return BadValue;
237 if (FontCacheChangeSettings(&cs) == 0)
238 return miscErrorBase + FontCacheCannotAllocMemory;
239 /* XXX */
241 return (client->noClientException);
244 static int
245 ProcFontCacheDispatch (client)
246 register ClientPtr client;
248 REQUEST(xReq);
249 switch (stuff->data)
251 case X_FontCacheQueryVersion:
252 return ProcFontCacheQueryVersion(client);
253 case X_FontCacheGetCacheSettings:
254 return ProcFontCacheGetCacheSettings(client);
255 case X_FontCacheGetCacheStatistics:
256 return ProcFontCacheGetCacheStatistics(client);
257 case X_FontCacheChangeCacheSettings:
258 return ProcFontCacheChangeCacheSettings(client);
259 default:
260 return miscErrorBase + FontCacheBadProtocol;
264 static int
265 SProcFontCacheQueryVersion(client)
266 register ClientPtr client;
268 register int n;
269 REQUEST(xFontCacheQueryVersionReq);
270 swaps(&stuff->length, n);
271 return ProcFontCacheQueryVersion(client);
274 static int
275 SProcFontCacheGetCacheSettings(client)
276 ClientPtr client;
278 register int n;
279 REQUEST(xFontCacheGetCacheSettingsReq);
280 swaps(&stuff->length, n);
281 REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq);
282 return ProcFontCacheGetCacheSettings(client);
285 static int
286 SProcFontCacheGetCacheStatistics(client)
287 ClientPtr client;
289 register int n;
290 REQUEST(xFontCacheGetCacheStatisticsReq);
291 swaps(&stuff->length, n);
292 REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq);
293 return ProcFontCacheGetCacheStatistics(client);
296 static int
297 SProcFontCacheChangeCacheSettings(client)
298 ClientPtr client;
300 register int n;
301 REQUEST(xFontCacheChangeCacheSettingsReq);
302 swaps(&stuff->length, n);
303 REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq);
304 /* XXX */
305 swapl(&stuff->himark, n);
306 swapl(&stuff->lowmark, n);
307 swapl(&stuff->balance, n);
308 /* XXX */
309 return ProcFontCacheChangeCacheSettings(client);
312 static int
313 SProcFontCacheDispatch (client)
314 register ClientPtr client;
316 REQUEST(xReq);
317 switch (stuff->data)
319 case X_FontCacheQueryVersion:
320 return SProcFontCacheQueryVersion(client);
321 case X_FontCacheGetCacheSettings:
322 return SProcFontCacheGetCacheSettings(client);
323 case X_FontCacheGetCacheStatistics:
324 return SProcFontCacheGetCacheStatistics(client);
325 case X_FontCacheChangeCacheSettings:
326 return SProcFontCacheChangeCacheSettings(client);
327 default:
328 return miscErrorBase + FontCacheBadProtocol;