FontCache.c revision 52f9793f
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.8 1999/01/31 12:52:49 akiyama Exp $ 29 */ 30/* $XFree86: FontCache.c,v 1.3 2002/10/16 00:37:28 dawes Exp $ */ 31 32/* THIS IS NOT AN X CONSORTIUM STANDARD */ 33 34#define NEED_EVENTS 35#define NEED_REPLIES 36#include <X11/Xlibint.h> 37#include <X11/extensions/fontcachstr.h> 38#include <X11/extensions/Xext.h> 39#include <X11/extensions/extutil.h> 40 41static XExtensionInfo _fontcache_info_data; 42static XExtensionInfo *fontcache_info = &_fontcache_info_data; 43static char *fontcache_extension_name = FONTCACHENAME; 44 45#define FontCacheCheckExtension(dpy,i,val) \ 46 XextCheckExtension (dpy, i, fontcache_extension_name, val) 47 48/***************************************************************************** 49 * * 50 * private utility routines * 51 * * 52 *****************************************************************************/ 53 54static int close_display(Display *, XExtCodes *); 55 56static /* const */ XExtensionHooks fontcache_extension_hooks = { 57 NULL, /* create_gc */ 58 NULL, /* copy_gc */ 59 NULL, /* flush_gc */ 60 NULL, /* free_gc */ 61 NULL, /* create_font */ 62 NULL, /* free_font */ 63 close_display, /* close_display */ 64 NULL, /* wire_to_event */ 65 NULL, /* event_to_wire */ 66 NULL, /* error */ 67 NULL, /* error_string */ 68}; 69 70static XEXT_GENERATE_FIND_DISPLAY (find_display, fontcache_info, 71 fontcache_extension_name, 72 &fontcache_extension_hooks, 73 0, NULL) 74 75static XEXT_GENERATE_CLOSE_DISPLAY (close_display, fontcache_info) 76 77 78/***************************************************************************** 79 * * 80 * public Font-Misc Extension routines * 81 * * 82 *****************************************************************************/ 83 84Bool 85FontCacheQueryExtension(Display *dpy, int *event_basep, int *error_basep) 86{ 87 XExtDisplayInfo *info = find_display (dpy); 88 89 if (XextHasExtension(info)) { 90 *event_basep = info->codes->first_event; 91 *error_basep = info->codes->first_error; 92 return True; 93 } else { 94 return False; 95 } 96} 97 98Bool 99FontCacheQueryVersion(Display *dpy, int *majorVersion, int *minorVersion) 100{ 101 XExtDisplayInfo *info = find_display (dpy); 102 xFontCacheQueryVersionReply rep; 103 xFontCacheQueryVersionReq *req; 104 105 FontCacheCheckExtension (dpy, info, False); 106 107 LockDisplay(dpy); 108 GetReq(FontCacheQueryVersion, req); 109 req->reqType = info->codes->major_opcode; 110 req->fontcacheReqType = X_FontCacheQueryVersion; 111 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 112 UnlockDisplay(dpy); 113 SyncHandle(); 114 return False; 115 } 116 *majorVersion = rep.majorVersion; 117 *minorVersion = rep.minorVersion; 118 UnlockDisplay(dpy); 119 SyncHandle(); 120 return True; 121} 122 123Bool 124FontCacheGetCacheSettings(Display *dpy, FontCacheSettings *cacheinfo) 125{ 126 XExtDisplayInfo *info = find_display (dpy); 127 xFontCacheGetCacheSettingsReply rep; 128 xFontCacheGetCacheSettingsReq *req; 129 130 FontCacheCheckExtension (dpy, info, False); 131 132 LockDisplay(dpy); 133 GetReq(FontCacheGetCacheSettings, req); 134 req->reqType = info->codes->major_opcode; 135 req->fontcacheReqType = X_FontCacheGetCacheSettings; 136 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 137 UnlockDisplay(dpy); 138 SyncHandle(); 139 return False; 140 } 141 /* XXX */ 142 cacheinfo->himark = rep.himark; 143 cacheinfo->lowmark = rep.lowmark; 144 cacheinfo->balance = rep.balance; 145 /* XXX */ 146 UnlockDisplay(dpy); 147 SyncHandle(); 148 return True; 149} 150 151Bool 152FontCacheChangeCacheSettings(Display *dpy, FontCacheSettings *cacheinfo) 153{ 154 XExtDisplayInfo *info = find_display (dpy); 155 xFontCacheChangeCacheSettingsReq *req; 156 157 FontCacheCheckExtension (dpy, info, False); 158 159 LockDisplay(dpy); 160 GetReq(FontCacheChangeCacheSettings, req); 161 req->reqType = info->codes->major_opcode; 162 req->fontcacheReqType = X_FontCacheChangeCacheSettings; 163 /* XXX */ 164 req->himark = cacheinfo->himark; 165 req->lowmark = cacheinfo->lowmark; 166 req->balance = cacheinfo->balance; 167 /* XXX */ 168 UnlockDisplay(dpy); 169 SyncHandle(); 170 return True; 171} 172 173Bool 174FontCacheGetCacheStatistics(Display *dpy, FontCacheStatistics *cachestats) 175{ 176 XExtDisplayInfo *info = find_display (dpy); 177 xFontCacheGetCacheStatisticsReply rep; 178 xFontCacheGetCacheStatisticsReq *req; 179 180 FontCacheCheckExtension (dpy, info, False); 181 182 LockDisplay(dpy); 183 GetReq(FontCacheGetCacheStatistics, req); 184 req->reqType = info->codes->major_opcode; 185 req->fontcacheReqType = X_FontCacheGetCacheStatistics; 186 if (!_XReply(dpy, (xReply *)&rep, 187 (SIZEOF(xFontCacheGetCacheStatisticsReply)-SIZEOF(xReply))>>2, 188 xFalse)) { 189 UnlockDisplay(dpy); 190 SyncHandle(); 191 return False; 192 } 193 /* XXX */ 194 cachestats->purge_runs = rep.purge_runs; 195 cachestats->purge_stat = rep.purge_stat; 196 cachestats->balance = rep.balance; 197 cachestats->f.hits = rep.f_hits; 198 cachestats->f.misshits = rep.f_misshits; 199 cachestats->f.purged = rep.f_purged; 200 cachestats->f.usage = rep.f_usage; 201 cachestats->v.hits = rep.v_hits; 202 cachestats->v.misshits = rep.v_misshits; 203 cachestats->v.purged = rep.v_purged; 204 cachestats->v.usage = rep.v_usage; 205 /* XXX */ 206 UnlockDisplay(dpy); 207 SyncHandle(); 208 return True; 209} 210