summaryrefslogtreecommitdiff
path: root/src/FontCache.c
blob: 7561f6605a473b2a0306a0dad3a666cd34407a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*-
 * Copyright (c) 1998-1999 Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
 * All rights reserved.
 * Copyright (c) 1998-1999 X-TrueType Server Project, All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	Id: FontCache.c,v 1.8 1999/01/31 12:52:49 akiyama Exp $
 */
/* $XFree86: FontCache.c,v 1.3 2002/10/16 00:37:28 dawes Exp $ */

/* THIS IS NOT AN X CONSORTIUM STANDARD */

#define NEED_EVENTS
#define NEED_REPLIES
#include <X11/Xlibint.h>
#include <X11/extensions/fontcachstr.h>
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>

static XExtensionInfo _fontcache_info_data;
static XExtensionInfo *fontcache_info = &_fontcache_info_data;
static char *fontcache_extension_name = FONTCACHENAME;

#define FontCacheCheckExtension(dpy,i,val) \
  XextCheckExtension (dpy, i, fontcache_extension_name, val)

/*****************************************************************************
 *                                                                           *
 *			   private utility routines                          *
 *                                                                           *
 *****************************************************************************/

static int close_display(Display *, XExtCodes *);

static /* const */ XExtensionHooks fontcache_extension_hooks = {
    NULL,				/* create_gc */
    NULL,				/* copy_gc */
    NULL,				/* flush_gc */
    NULL,				/* free_gc */
    NULL,				/* create_font */
    NULL,				/* free_font */
    close_display,			/* close_display */
    NULL,				/* wire_to_event */
    NULL,				/* event_to_wire */
    NULL,				/* error */
    NULL,				/* error_string */
};

static XEXT_GENERATE_FIND_DISPLAY (find_display, fontcache_info, 
				   fontcache_extension_name, 
				   &fontcache_extension_hooks, 
				   0, NULL)

static XEXT_GENERATE_CLOSE_DISPLAY (close_display, fontcache_info)


/*****************************************************************************
 *                                                                           *
 *		    public Font-Misc Extension routines                      *
 *                                                                           *
 *****************************************************************************/

Bool
FontCacheQueryExtension(Display *dpy, int *event_basep, int *error_basep)
{
    XExtDisplayInfo *info = find_display (dpy);

    if (XextHasExtension(info)) {
	*event_basep = info->codes->first_event;
	*error_basep = info->codes->first_error;
	return True;
    } else {
	return False;
    }
}

Bool
FontCacheQueryVersion(Display *dpy, int *majorVersion, int *minorVersion)
{
    XExtDisplayInfo *info = find_display (dpy);
    xFontCacheQueryVersionReply rep;
    xFontCacheQueryVersionReq *req;

    FontCacheCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(FontCacheQueryVersion, req);
    req->reqType = info->codes->major_opcode;
    req->fontcacheReqType = X_FontCacheQueryVersion;
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }
    *majorVersion = rep.majorVersion;
    *minorVersion = rep.minorVersion;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool
FontCacheGetCacheSettings(Display *dpy, FontCacheSettings *cacheinfo)
{
    XExtDisplayInfo *info = find_display (dpy);
    xFontCacheGetCacheSettingsReply rep;
    xFontCacheGetCacheSettingsReq *req;

    FontCacheCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(FontCacheGetCacheSettings, req);
    req->reqType = info->codes->major_opcode;
    req->fontcacheReqType = X_FontCacheGetCacheSettings;
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }
    /* XXX */
    cacheinfo->himark = rep.himark;
    cacheinfo->lowmark = rep.lowmark;
    cacheinfo->balance = rep.balance;
    /* XXX */
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool
FontCacheChangeCacheSettings(Display *dpy, FontCacheSettings *cacheinfo)
{
    XExtDisplayInfo *info = find_display (dpy);
    xFontCacheChangeCacheSettingsReq *req;

    FontCacheCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(FontCacheChangeCacheSettings, req);
    req->reqType = info->codes->major_opcode;
    req->fontcacheReqType = X_FontCacheChangeCacheSettings;
    /* XXX */
    req->himark = cacheinfo->himark;
    req->lowmark = cacheinfo->lowmark;
    req->balance = cacheinfo->balance;
    /* XXX */
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool
FontCacheGetCacheStatistics(Display *dpy, FontCacheStatistics *cachestats)
{
    XExtDisplayInfo *info = find_display (dpy);
    xFontCacheGetCacheStatisticsReply rep;
    xFontCacheGetCacheStatisticsReq *req;

    FontCacheCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(FontCacheGetCacheStatistics, req);
    req->reqType = info->codes->major_opcode;
    req->fontcacheReqType = X_FontCacheGetCacheStatistics;
    if (!_XReply(dpy, (xReply *)&rep,
		(SIZEOF(xFontCacheGetCacheStatisticsReply)-SIZEOF(xReply))>>2,
		 xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }
    /* XXX */
    cachestats->purge_runs = rep.purge_runs;
    cachestats->purge_stat = rep.purge_stat;
    cachestats->balance = rep.balance;
    cachestats->f.hits = rep.f_hits;
    cachestats->f.misshits = rep.f_misshits;
    cachestats->f.purged = rep.f_purged;
    cachestats->f.usage = rep.f_usage;
    cachestats->v.hits = rep.v_hits;
    cachestats->v.misshits = rep.v_misshits;
    cachestats->v.purged = rep.v_purged;
    cachestats->v.usage = rep.v_usage;
    /* XXX */
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}