FontCache.c revision 2faa96e0
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, 86 int *event_base_return, 87 int *error_base_return) 88{ 89 XExtDisplayInfo *info = find_display (dpy); 90 91 if (XextHasExtension(info)) { 92 *event_base_return = info->codes->first_event; 93 *error_base_return = info->codes->first_error; 94 return True; 95 } else { 96 return False; 97 } 98} 99 100Bool 101FontCacheQueryVersion(Display *dpy, 102 int *major_version_return, 103 int *minor_version_return) 104{ 105 XExtDisplayInfo *info = find_display (dpy); 106 xFontCacheQueryVersionReply rep; 107 xFontCacheQueryVersionReq *req; 108 109 FontCacheCheckExtension (dpy, info, False); 110 111 LockDisplay(dpy); 112 GetReq(FontCacheQueryVersion, req); 113 req->reqType = info->codes->major_opcode; 114 req->fontcacheReqType = X_FontCacheQueryVersion; 115 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 116 UnlockDisplay(dpy); 117 SyncHandle(); 118 return False; 119 } 120 *major_version_return = rep.majorVersion; 121 *minor_version_return = rep.minorVersion; 122 UnlockDisplay(dpy); 123 SyncHandle(); 124 return True; 125} 126 127Bool 128FontCacheGetCacheSettings(Display *dpy, FontCacheSettings *cacheinfo) 129{ 130 XExtDisplayInfo *info = find_display (dpy); 131 xFontCacheGetCacheSettingsReply rep; 132 xFontCacheGetCacheSettingsReq *req; 133 134 FontCacheCheckExtension (dpy, info, False); 135 136 LockDisplay(dpy); 137 GetReq(FontCacheGetCacheSettings, req); 138 req->reqType = info->codes->major_opcode; 139 req->fontcacheReqType = X_FontCacheGetCacheSettings; 140 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 141 UnlockDisplay(dpy); 142 SyncHandle(); 143 return False; 144 } 145 /* XXX */ 146 cacheinfo->himark = rep.himark; 147 cacheinfo->lowmark = rep.lowmark; 148 cacheinfo->balance = rep.balance; 149 /* XXX */ 150 UnlockDisplay(dpy); 151 SyncHandle(); 152 return True; 153} 154 155Bool 156FontCacheChangeCacheSettings(Display *dpy, FontCacheSettings *cacheinfo) 157{ 158 XExtDisplayInfo *info = find_display (dpy); 159 xFontCacheChangeCacheSettingsReq *req; 160 161 FontCacheCheckExtension (dpy, info, False); 162 163 LockDisplay(dpy); 164 GetReq(FontCacheChangeCacheSettings, req); 165 req->reqType = info->codes->major_opcode; 166 req->fontcacheReqType = X_FontCacheChangeCacheSettings; 167 /* XXX */ 168 req->himark = cacheinfo->himark; 169 req->lowmark = cacheinfo->lowmark; 170 req->balance = cacheinfo->balance; 171 /* XXX */ 172 UnlockDisplay(dpy); 173 SyncHandle(); 174 return True; 175} 176 177Bool 178FontCacheGetCacheStatistics(Display *dpy, FontCacheStatistics *cachestats) 179{ 180 XExtDisplayInfo *info = find_display (dpy); 181 xFontCacheGetCacheStatisticsReply rep; 182 xFontCacheGetCacheStatisticsReq *req; 183 184 FontCacheCheckExtension (dpy, info, False); 185 186 LockDisplay(dpy); 187 GetReq(FontCacheGetCacheStatistics, req); 188 req->reqType = info->codes->major_opcode; 189 req->fontcacheReqType = X_FontCacheGetCacheStatistics; 190 if (!_XReply(dpy, (xReply *)&rep, 191 (SIZEOF(xFontCacheGetCacheStatisticsReply)-SIZEOF(xReply))>>2, 192 xFalse)) { 193 UnlockDisplay(dpy); 194 SyncHandle(); 195 return False; 196 } 197 /* XXX */ 198 cachestats->purge_runs = rep.purge_runs; 199 cachestats->purge_stat = rep.purge_stat; 200 cachestats->balance = rep.balance; 201 cachestats->f.hits = rep.f_hits; 202 cachestats->f.misshits = rep.f_misshits; 203 cachestats->f.purged = rep.f_purged; 204 cachestats->f.usage = rep.f_usage; 205 cachestats->v.hits = rep.v_hits; 206 cachestats->v.misshits = rep.v_misshits; 207 cachestats->v.purged = rep.v_purged; 208 cachestats->v.usage = rep.v_usage; 209 /* XXX */ 210 UnlockDisplay(dpy); 211 SyncHandle(); 212 return True; 213} 214