5c03abe055277a43337252751bf6fb22b33bebfb
[reactos.git] / lib / 3rdparty / freetype / src / cache / ftcglyph.c
1 /***************************************************************************/
2 /* */
3 /* ftcglyph.c */
4 /* */
5 /* FreeType Glyph Image (FT_Glyph) cache (body). */
6 /* */
7 /* Copyright 2000-2001, 2003, 2004, 2006 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 /***************************************************************************/
17
18
19 #include <ft2build.h>
20 #include FT_CACHE_H
21 #include "ftcglyph.h"
22 #include FT_ERRORS_H
23 #include FT_INTERNAL_OBJECTS_H
24 #include FT_INTERNAL_DEBUG_H
25
26 #include "ftccback.h"
27 #include "ftcerror.h"
28
29
30 /* create a new chunk node, setting its cache index and ref count */
31 FT_LOCAL_DEF( void )
32 FTC_GNode_Init( FTC_GNode gnode,
33 FT_UInt gindex,
34 FTC_Family family )
35 {
36 gnode->family = family;
37 gnode->gindex = gindex;
38 family->num_nodes++;
39 }
40
41
42 FT_LOCAL_DEF( void )
43 FTC_GNode_UnselectFamily( FTC_GNode gnode,
44 FTC_Cache cache )
45 {
46 FTC_Family family = gnode->family;
47
48
49 gnode->family = NULL;
50 if ( family && --family->num_nodes == 0 )
51 FTC_FAMILY_FREE( family, cache );
52 }
53
54
55 FT_LOCAL_DEF( void )
56 FTC_GNode_Done( FTC_GNode gnode,
57 FTC_Cache cache )
58 {
59 /* finalize the node */
60 gnode->gindex = 0;
61
62 FTC_GNode_UnselectFamily( gnode, cache );
63 }
64
65
66 FT_LOCAL_DEF( FT_Bool )
67 ftc_gnode_compare( FTC_Node ftcgnode,
68 FT_Pointer ftcgquery,
69 FTC_Cache cache )
70 {
71 FTC_GNode gnode = (FTC_GNode)ftcgnode;
72 FTC_GQuery gquery = (FTC_GQuery)ftcgquery;
73 FT_UNUSED( cache );
74
75
76 return FT_BOOL( gnode->family == gquery->family &&
77 gnode->gindex == gquery->gindex );
78 }
79
80
81 FT_LOCAL_DEF( FT_Bool )
82 FTC_GNode_Compare( FTC_GNode gnode,
83 FTC_GQuery gquery )
84 {
85 return ftc_gnode_compare( FTC_NODE( gnode ), gquery, NULL );
86 }
87
88
89 /*************************************************************************/
90 /*************************************************************************/
91 /***** *****/
92 /***** CHUNK SETS *****/
93 /***** *****/
94 /*************************************************************************/
95 /*************************************************************************/
96
97 FT_LOCAL_DEF( void )
98 FTC_Family_Init( FTC_Family family,
99 FTC_Cache cache )
100 {
101 FTC_GCacheClass clazz = FTC_CACHE__GCACHE_CLASS( cache );
102
103
104 family->clazz = clazz->family_class;
105 family->num_nodes = 0;
106 family->cache = cache;
107 }
108
109
110 FT_LOCAL_DEF( FT_Error )
111 ftc_gcache_init( FTC_Cache ftccache )
112 {
113 FTC_GCache cache = (FTC_GCache)ftccache;
114 FT_Error error;
115
116
117 error = FTC_Cache_Init( FTC_CACHE( cache ) );
118 if ( !error )
119 {
120 FTC_GCacheClass clazz = (FTC_GCacheClass)FTC_CACHE( cache )->org_class;
121
122 FTC_MruList_Init( &cache->families,
123 clazz->family_class,
124 0, /* no maximum here! */
125 cache,
126 FTC_CACHE( cache )->memory );
127 }
128
129 return error;
130 }
131
132
133 #if 0
134
135 FT_LOCAL_DEF( FT_Error )
136 FTC_GCache_Init( FTC_GCache cache )
137 {
138 return ftc_gcache_init( FTC_CACHE( cache ) );
139 }
140
141 #endif /* 0 */
142
143
144 FT_LOCAL_DEF( void )
145 ftc_gcache_done( FTC_Cache ftccache )
146 {
147 FTC_GCache cache = (FTC_GCache)ftccache;
148
149
150 FTC_Cache_Done( (FTC_Cache)cache );
151 FTC_MruList_Done( &cache->families );
152 }
153
154
155 #if 0
156
157 FT_LOCAL_DEF( void )
158 FTC_GCache_Done( FTC_GCache cache )
159 {
160 ftc_gcache_done( FTC_CACHE( cache ) );
161 }
162
163 #endif /* 0 */
164
165
166 FT_LOCAL_DEF( FT_Error )
167 FTC_GCache_New( FTC_Manager manager,
168 FTC_GCacheClass clazz,
169 FTC_GCache *acache )
170 {
171 return FTC_Manager_RegisterCache( manager, (FTC_CacheClass)clazz,
172 (FTC_Cache*)acache );
173 }
174
175
176 #ifndef FTC_INLINE
177
178 FT_LOCAL_DEF( FT_Error )
179 FTC_GCache_Lookup( FTC_GCache cache,
180 FT_UInt32 hash,
181 FT_UInt gindex,
182 FTC_GQuery query,
183 FTC_Node *anode )
184 {
185 FT_Error error;
186
187
188 query->gindex = gindex;
189
190 FTC_MRULIST_LOOKUP( &cache->families, query, query->family, error );
191 if ( !error )
192 {
193 FTC_Family family = query->family;
194
195
196 /* prevent the family from being destroyed too early when an */
197 /* out-of-memory condition occurs during glyph node initialization. */
198 family->num_nodes++;
199
200 error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query, anode );
201
202 if ( --family->num_nodes == 0 )
203 FTC_FAMILY_FREE( family, cache );
204 }
205 return error;
206 }
207
208 #endif /* !FTC_INLINE */
209
210
211 /* END */