1 /***************************************************************************/
5 /* FreeType chunk cache (specification). */
7 /* Copyright 2000-2001 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 /*************************************************************************/
21 /* Important: The functions defined in this file are only used to */
22 /* implement an abstract chunk cache class. You need to */
23 /* provide additional logic to implement a complete cache. */
24 /* For example, see `ftcmetrx.h' and `ftcmetrx.c' which */
25 /* implement a glyph metrics cache based on this code. */
27 /*************************************************************************/
30 /*************************************************************************/
31 /*************************************************************************/
32 /*************************************************************************/
33 /*************************************************************************/
34 /*************************************************************************/
36 /********* WARNING, THIS IS BETA CODE. *********/
38 /*************************************************************************/
39 /*************************************************************************/
40 /*************************************************************************/
41 /*************************************************************************/
42 /*************************************************************************/
45 #ifndef __FTCCHUNK_H__
46 #define __FTCCHUNK_H__
51 #include FT_CACHE_MANAGER_H
57 /* maximum number of chunk sets in a given chunk cache */
58 #define FTC_MAX_CHUNK_SETS 16
61 typedef struct FTC_ChunkNodeRec_* FTC_ChunkNode;
62 typedef struct FTC_ChunkSetRec_* FTC_ChunkSet;
63 typedef struct FTC_Chunk_CacheRec_* FTC_Chunk_Cache;
65 typedef struct FTC_ChunkNodeRec_
67 FTC_CacheNodeRec root;
70 FT_UShort num_elements;
76 #define FTC_CHUNKNODE_TO_LRUNODE( x ) ((FT_ListNode)( x ))
77 #define FTC_LRUNODE_TO_CHUNKNODE( x ) ((FTC_ChunkNode)( x ))
80 /*************************************************************************/
82 /* chunk set methods */
85 /* used to set "element_max", "element_count" and "element_size" */
87 (*FTC_ChunkSet_SizesFunc)( FTC_ChunkSet cset,
91 (*FTC_ChunkSet_InitFunc)( FTC_ChunkSet cset,
95 (*FTC_ChunkSet_DoneFunc)( FTC_ChunkSet cset );
98 (*FTC_ChunkSet_CompareFunc)( FTC_ChunkSet cset,
103 (*FTC_ChunkSet_NewNodeFunc)( FTC_ChunkSet cset,
105 FTC_ChunkNode* anode );
108 (*FTC_ChunkSet_DestroyNodeFunc)( FTC_ChunkNode node );
111 (*FTC_ChunkSet_SizeNodeFunc)( FTC_ChunkNode node );
114 typedef struct FTC_ChunkSet_Class_
116 FT_UInt cset_byte_size;
118 FTC_ChunkSet_InitFunc init;
119 FTC_ChunkSet_DoneFunc done;
120 FTC_ChunkSet_CompareFunc compare;
121 FTC_ChunkSet_SizesFunc sizes;
123 FTC_ChunkSet_NewNodeFunc new_node;
124 FTC_ChunkSet_SizeNodeFunc size_node;
125 FTC_ChunkSet_DestroyNodeFunc destroy_node;
127 } FTC_ChunkSet_Class;
130 typedef struct FTC_ChunkSetRec_
132 FTC_Chunk_Cache cache;
135 FTC_ChunkSet_Class* clazz;
136 FT_UInt cset_index; /* index in parent cache */
138 FT_UInt element_max; /* maximum number of elements */
139 FT_UInt element_size; /* element size in bytes */
140 FT_UInt element_count; /* number of elements per chunk */
143 FTC_ChunkNode* chunks;
148 /* the abstract chunk cache class */
149 typedef struct FTC_Chunk_Cache_Class_
151 FTC_Cache_Class root;
152 FTC_ChunkSet_Class* cset_class;
154 } FTC_Chunk_Cache_Class;
157 /* the abstract chunk cache object */
158 typedef struct FTC_Chunk_CacheRec_
161 FT_Lru csets_lru; /* static chunk set lru list */
162 FTC_ChunkSet last_cset; /* small cache :-) */
163 FTC_ChunkSet_CompareFunc compare; /* useful shortcut */
165 } FTC_Chunk_CacheRec;
168 /*************************************************************************/
170 /* These functions are exported so that they can be called from */
171 /* user-provided cache classes; otherwise, they are really part of the */
172 /* cache sub-system internals. */
175 FT_EXPORT( FT_Error )
176 FTC_ChunkNode_Init( FTC_ChunkNode node,
181 #define FTC_ChunkNode_Ref( n ) \
182 FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count++
184 #define FTC_ChunkNode_Unref( n ) \
185 FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count--
188 /* chunk set objects */
191 FTC_ChunkNode_Destroy( FTC_ChunkNode node );
194 FT_EXPORT( FT_Error )
195 FTC_ChunkSet_New( FTC_Chunk_Cache cache,
197 FTC_ChunkSet *aset );
200 FT_EXPORT( FT_Error )
201 FTC_ChunkSet_Lookup_Node( FTC_ChunkSet cset,
203 FTC_ChunkNode* anode,
207 /* chunk cache objects */
209 FT_EXPORT( FT_Error )
210 FTC_Chunk_Cache_Init( FTC_Chunk_Cache cache );
213 FTC_Chunk_Cache_Done( FTC_Chunk_Cache cache );
215 FT_EXPORT( FT_Error )
216 FTC_Chunk_Cache_Lookup( FTC_Chunk_Cache cache,
219 FTC_ChunkNode *anode,
225 #endif /* __FTCCHUNK_H__ */