1 /***************************************************************************/
2 /* */
3 /* ftcchunk.h */
4 /* */
5 /* FreeType chunk cache (specification). */
6 /* */
7 /* Copyright 2000-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
19 /*************************************************************************/
20 /* */
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. */
26 /* */
27 /*************************************************************************/
30 /*************************************************************************/
31 /*************************************************************************/
32 /*************************************************************************/
33 /*************************************************************************/
34 /*************************************************************************/
35 /********* *********/
36 /********* WARNING, THIS IS BETA CODE. *********/
37 /********* *********/
38 /*************************************************************************/
39 /*************************************************************************/
40 /*************************************************************************/
41 /*************************************************************************/
42 /*************************************************************************/
45 #ifndef __FTCCHUNK_H__
46 #define __FTCCHUNK_H__
49 #include <ft2build.h>
50 #include FT_CACHE_H
51 #include FT_CACHE_MANAGER_H
54 FT_BEGIN_HEADER
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_
66 {
67 FTC_CacheNodeRec root;
68 FTC_ChunkSet cset;
69 FT_UShort cset_index;
70 FT_UShort num_elements;
71 FT_Byte* elements;
73 } FTC_ChunkNodeRec;
76 #define FTC_CHUNKNODE_TO_LRUNODE( x ) ((FT_ListNode)( x ))
77 #define FTC_LRUNODE_TO_CHUNKNODE( x ) ((FTC_ChunkNode)( x ))
80 /*************************************************************************/
81 /* */
82 /* chunk set methods */
83 /* */
85 /* used to set "element_max", "element_count" and "element_size" */
86 typedef FT_Error
87 (*FTC_ChunkSet_SizesFunc)( FTC_ChunkSet cset,
88 FT_Pointer type );
90 typedef FT_Error
91 (*FTC_ChunkSet_InitFunc)( FTC_ChunkSet cset,
92 FT_Pointer type );
94 typedef void
95 (*FTC_ChunkSet_DoneFunc)( FTC_ChunkSet cset );
97 typedef FT_Bool
98 (*FTC_ChunkSet_CompareFunc)( FTC_ChunkSet cset,
99 FT_Pointer type );
102 typedef FT_Error
103 (*FTC_ChunkSet_NewNodeFunc)( FTC_ChunkSet cset,
104 FT_UInt index,
105 FTC_ChunkNode* anode );
107 typedef void
108 (*FTC_ChunkSet_DestroyNodeFunc)( FTC_ChunkNode node );
110 typedef FT_ULong
111 (*FTC_ChunkSet_SizeNodeFunc)( FTC_ChunkNode node );
114 typedef struct FTC_ChunkSet_Class_
115 {
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_
131 {
132 FTC_Chunk_Cache cache;
133 FTC_Manager manager;
134 FT_Memory memory;
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 */
142 FT_UInt num_chunks;
143 FTC_ChunkNode* chunks;
145 } FTC_ChunkSetRec;
148 /* the abstract chunk cache class */
149 typedef struct FTC_Chunk_Cache_Class_
150 {
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_
159 {
160 FTC_CacheRec root;
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 /*************************************************************************/
169 /* */
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. */
173 /* */
175 FT_EXPORT( FT_Error )
176 FTC_ChunkNode_Init( FTC_ChunkNode node,
177 FTC_ChunkSet cset,
178 FT_UInt index,
179 FT_Bool alloc );
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 */
190 FT_EXPORT( void )
191 FTC_ChunkNode_Destroy( FTC_ChunkNode node );
194 FT_EXPORT( FT_Error )
195 FTC_ChunkSet_New( FTC_Chunk_Cache cache,
196 FT_Pointer type,
197 FTC_ChunkSet *aset );
200 FT_EXPORT( FT_Error )
201 FTC_ChunkSet_Lookup_Node( FTC_ChunkSet cset,
202 FT_UInt glyph_index,
203 FTC_ChunkNode* anode,
204 FT_UInt *anindex );
207 /* chunk cache objects */
209 FT_EXPORT( FT_Error )
210 FTC_Chunk_Cache_Init( FTC_Chunk_Cache cache );
212 FT_EXPORT( void )
213 FTC_Chunk_Cache_Done( FTC_Chunk_Cache cache );
215 FT_EXPORT( FT_Error )
216 FTC_Chunk_Cache_Lookup( FTC_Chunk_Cache cache,
217 FT_Pointer type,
218 FT_UInt gindex,
219 FTC_ChunkNode *anode,
220 FT_UInt *aindex );
223 FT_END_HEADER
225 #endif /* __FTCCHUNK_H__ */
228 /* END */