1 /***************************************************************************/
5 /* FreeType internal cache interface (specification). */
7 /* Copyright 2000-2001, 2002 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
19 #ifndef __FTCCACHE_H__
20 #define __FTCCACHE_H__
23 /* define to allow cache lookup inlining */
24 #define FTC_CACHE_USE_INLINE
29 /* handle to cache object */
30 typedef struct FTC_CacheRec_* FTC_Cache;
32 /* handle to cache class */
33 typedef const struct FTC_Cache_ClassRec_* FTC_Cache_Class;
35 /* handle to cache node family */
36 typedef struct FTC_FamilyRec_* FTC_Family;
38 /* handle to cache root query */
39 typedef struct FTC_QueryRec_* FTC_Query;
42 /*************************************************************************/
43 /*************************************************************************/
45 /***** CACHE NODE DEFINITIONS *****/
47 /*************************************************************************/
48 /*************************************************************************/
50 /*************************************************************************/
52 /* Each cache controls one or more cache nodes. Each node is part of */
53 /* the global_lru list of the manager. Its `data' field however is used */
54 /* as a reference count for now. */
56 /* A node can be anything, depending on the type of information held by */
57 /* the cache. It can be an individual glyph image, a set of bitmaps */
58 /* glyphs for a given size, some metrics, etc. */
60 /*************************************************************************/
62 /* structure size should be 20 bytes on 32-bits machines */
63 typedef struct FTC_NodeRec_
65 FTC_Node mru_next; /* circular mru list pointer */
66 FTC_Node mru_prev; /* circular mru list pointer */
67 FTC_Node link; /* used for hashing */
68 FT_UInt32 hash; /* used for hashing too */
69 FT_UShort fam_index; /* index of family the node belongs to */
70 FT_Short ref_count; /* reference count for this node */
75 #define FTC_NODE( x ) ( (FTC_Node)(x) )
76 #define FTC_NODE_P( x ) ( (FTC_Node*)(x) )
79 /*************************************************************************/
81 /* These functions are exported so that they can be called from */
82 /* user-provided cache classes; otherwise, they are really part of the */
83 /* cache sub-system internals. */
86 /* can be used as a FTC_Node_DoneFunc */
88 ftc_node_done( FTC_Node node,
91 /* reserved for manager's use */
93 ftc_node_destroy( FTC_Node node,
94 FTC_Manager manager );
97 /*************************************************************************/
98 /*************************************************************************/
100 /***** CACHE QUERY DEFINITIONS *****/
102 /*************************************************************************/
103 /*************************************************************************/
105 /* A structure modelling a cache node query. The following fields must */
106 /* all be set by the @FTC_Family_CompareFunc method of a cache's family */
109 typedef struct FTC_QueryRec_
117 #define FTC_QUERY( x ) ( (FTC_Query)(x) )
118 #define FTC_QUERY_P( x ) ( (FTC_Query*)(x) )
121 /*************************************************************************/
122 /*************************************************************************/
124 /***** CACHE FAMILY DEFINITIONS *****/
126 /*************************************************************************/
127 /*************************************************************************/
129 typedef struct FTC_FamilyRec_
139 #define FTC_FAMILY( x ) ( (FTC_Family)(x) )
140 #define FTC_FAMILY_P( x ) ( (FTC_Family*)(x) )
143 /*************************************************************************/
145 /* These functions are exported so that they can be called from */
146 /* user-provided cache classes; otherwise, they are really part of the */
147 /* cache sub-system internals. */
150 /* must be called by any FTC_Node_InitFunc routine */
151 FT_EXPORT( FT_Error )
152 ftc_family_init( FTC_Family family,
157 /* can be used as a FTC_Family_DoneFunc; otherwise, must be called */
158 /* by any family finalizer function */
160 ftc_family_done( FTC_Family family );
163 /*************************************************************************/
164 /*************************************************************************/
166 /***** CACHE DEFINITIONS *****/
168 /*************************************************************************/
169 /*************************************************************************/
171 /* each cache really implements a dynamic hash table to manage its nodes */
172 typedef struct FTC_CacheRec_
176 FTC_Cache_Class clazz;
178 FT_UInt cache_index; /* in manager's table */
179 FT_Pointer cache_data; /* used by cache node methods */
186 FT_LruList_ClassRec family_class;
192 #define FTC_CACHE( x ) ( (FTC_Cache)(x) )
193 #define FTC_CACHE_P( x ) ( (FTC_Cache*)(x) )
196 /* initialize a given cache */
198 (*FTC_Cache_InitFunc)( FTC_Cache cache );
202 (*FTC_Cache_ClearFunc)( FTC_Cache cache );
204 /* finalize a given cache */
206 (*FTC_Cache_DoneFunc)( FTC_Cache cache );
210 (*FTC_Family_InitFunc)( FTC_Family family,
215 (*FTC_Family_CompareFunc)( FTC_Family family,
219 (*FTC_Family_DoneFunc)( FTC_Family family,
222 /* initialize a new cache node */
224 (*FTC_Node_InitFunc)( FTC_Node node,
228 /* compute the weight of a given cache node */
230 (*FTC_Node_WeightFunc)( FTC_Node node,
233 /* compare a node to a given key pair */
235 (*FTC_Node_CompareFunc)( FTC_Node node,
239 /* finalize a given cache node */
241 (*FTC_Node_DoneFunc)( FTC_Node node,
245 typedef struct FTC_Cache_ClassRec_
248 FTC_Cache_InitFunc cache_init;
249 FTC_Cache_ClearFunc cache_clear;
250 FTC_Cache_DoneFunc cache_done;
253 FTC_Family_InitFunc family_init;
254 FTC_Family_CompareFunc family_compare;
255 FTC_Family_DoneFunc family_done;
258 FTC_Node_InitFunc node_init;
259 FTC_Node_WeightFunc node_weight;
260 FTC_Node_CompareFunc node_compare;
261 FTC_Node_DoneFunc node_done;
263 } FTC_Cache_ClassRec;
269 /*************************************************************************/
271 /* These functions are exported so that they can be called from */
272 /* user-provided cache classes; otherwise, they are really part of the */
273 /* cache sub-system internals. */
276 /* can be used directly as FTC_Cache_DoneFunc(), or called by custom */
277 /* cache finalizers */
279 ftc_cache_done( FTC_Cache cache );
281 /* can be used directly as FTC_Cache_ClearFunc(), or called by custom */
282 /* cache clear routines */
284 ftc_cache_clear( FTC_Cache cache );
286 /* initalize the hash table within the cache */
287 FT_EXPORT( FT_Error )
288 ftc_cache_init( FTC_Cache cache );
290 /* can be called when the key's hash value has been computed */
291 FT_EXPORT( FT_Error )
292 ftc_cache_lookup( FTC_Cache cache,
301 #endif /* __FTCCACHE_H__ */