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
29 /* THIS IS NOT AN X CONSORTIUM STANDARD */
33 #ifdef HAVE_DIX_CONFIG_H
34 #include <dix-config.h>
38 #include <X11/Xproto.h>
40 #include "dixstruct.h"
41 #include "extnsionst.h"
42 #include "scrnintstr.h"
45 #define _FONTCACHE_SERVER_
46 #include <X11/extensions/fontcacheP.h>
47 #include <X11/extensions/fontcachstr.h>
48 #include <X11/Xfuncproto.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
);
71 static unsigned char FontCacheReqCode
= 0;
75 FontCacheExtensionInit(INITARGS
)
77 ExtensionEntry
* extEntry
;
80 (extEntry
= AddExtension(FONTCACHENAME
,
81 FontCacheNumberEvents
,
82 FontCacheNumberErrors
,
83 ProcFontCacheDispatch
,
84 SProcFontCacheDispatch
,
86 StandardMinorOpcode
))) {
88 FontCacheReqCode
= (unsigned char)extEntry
->base
;
90 miscErrorBase
= extEntry
->errorBase
;
96 FontCacheResetProc (extEntry
)
97 ExtensionEntry
* extEntry
;
102 ProcFontCacheQueryVersion(client
)
103 register ClientPtr client
;
105 xFontCacheQueryVersionReply rep
;
108 REQUEST_SIZE_MATCH(xFontCacheQueryVersionReq
);
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
);
125 ProcFontCacheGetCacheSettings(client
)
126 register ClientPtr client
;
128 xFontCacheGetCacheSettingsReply rep
;
129 FontCacheSettings cinfo
;
132 REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq
);
134 rep
.sequenceNumber
= client
->sequence
;
138 FontCacheGetSettings(&cinfo
);
139 rep
.himark
= cinfo
.himark
;
140 rep
.lowmark
= cinfo
.lowmark
;
141 rep
.balance
= cinfo
.balance
;
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
);
157 WriteToClient(client
, SIZEOF(xFontCacheGetCacheSettingsReply
),
159 return (client
->noClientException
);
163 ProcFontCacheGetCacheStatistics(client
)
164 register ClientPtr client
;
166 xFontCacheGetCacheStatisticsReply rep
;
167 FontCacheStatistics cstats
;
170 REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq
);
172 rep
.sequenceNumber
= client
->sequence
;
173 rep
.length
= (sz_xFontCacheGetCacheStatisticsReply
- 32) >> 2;
176 FontCacheGetStatistics(&cstats
);
177 rep
.purge_runs
= cstats
.purge_runs
;
178 rep
.purge_stat
= cstats
.purge_stat
;
179 rep
.balance
= cstats
.balance
;
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
;
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
;
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
);
210 WriteToClient(client
, SIZEOF(xFontCacheGetCacheStatisticsReply
),
212 return (client
->noClientException
);
216 ProcFontCacheChangeCacheSettings(client
)
217 register ClientPtr client
;
219 FontCacheSettings cs
;
221 REQUEST(xFontCacheChangeCacheSettingsReq
);
223 REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq
);
226 cs
.himark
= stuff
->himark
;
227 cs
.lowmark
= stuff
->lowmark
;
228 cs
.balance
= stuff
->balance
;
230 if (cs
.himark
< 0 || cs
.lowmark
< 0)
232 if (cs
.himark
<= cs
.lowmark
)
234 if (!(10 <= cs
.balance
&& cs
.balance
<= 90))
237 if (FontCacheChangeSettings(&cs
) == 0)
238 return miscErrorBase
+ FontCacheCannotAllocMemory
;
241 return (client
->noClientException
);
245 ProcFontCacheDispatch (client
)
246 register ClientPtr client
;
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
);
260 return miscErrorBase
+ FontCacheBadProtocol
;
265 SProcFontCacheQueryVersion(client
)
266 register ClientPtr client
;
269 REQUEST(xFontCacheQueryVersionReq
);
270 swaps(&stuff
->length
, n
);
271 return ProcFontCacheQueryVersion(client
);
275 SProcFontCacheGetCacheSettings(client
)
279 REQUEST(xFontCacheGetCacheSettingsReq
);
280 swaps(&stuff
->length
, n
);
281 REQUEST_SIZE_MATCH(xFontCacheGetCacheSettingsReq
);
282 return ProcFontCacheGetCacheSettings(client
);
286 SProcFontCacheGetCacheStatistics(client
)
290 REQUEST(xFontCacheGetCacheStatisticsReq
);
291 swaps(&stuff
->length
, n
);
292 REQUEST_SIZE_MATCH(xFontCacheGetCacheStatisticsReq
);
293 return ProcFontCacheGetCacheStatistics(client
);
297 SProcFontCacheChangeCacheSettings(client
)
301 REQUEST(xFontCacheChangeCacheSettingsReq
);
302 swaps(&stuff
->length
, n
);
303 REQUEST_SIZE_MATCH(xFontCacheChangeCacheSettingsReq
);
305 swapl(&stuff
->himark
, n
);
306 swapl(&stuff
->lowmark
, n
);
307 swapl(&stuff
->balance
, n
);
309 return ProcFontCacheChangeCacheSettings(client
);
313 SProcFontCacheDispatch (client
)
314 register ClientPtr client
;
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
);
328 return miscErrorBase
+ FontCacheBadProtocol
;