1 /****************************************************************************
5 * FreeType Glyph Image (FT_Glyph) cache (body).
7 * Copyright (C) 2000-2020 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.
19 #include <freetype/internal/ftobjs.h>
20 #include <freetype/ftcache.h>
22 #include <freetype/fterrors.h>
28 /* create a new chunk node, setting its cache index and ref count */
30 FTC_GNode_Init( FTC_GNode gnode,
34 gnode->family = family;
35 gnode->gindex = gindex;
41 FTC_GNode_UnselectFamily( FTC_GNode gnode,
44 FTC_Family family = gnode->family;
48 if ( family && --family->num_nodes == 0 )
49 FTC_FAMILY_FREE( family, cache );
54 FTC_GNode_Done( FTC_GNode gnode,
57 /* finalize the node */
60 FTC_GNode_UnselectFamily( gnode, cache );
64 FT_LOCAL_DEF( FT_Bool )
65 ftc_gnode_compare( FTC_Node ftcgnode,
68 FT_Bool* list_changed )
70 FTC_GNode gnode = (FTC_GNode)ftcgnode;
71 FTC_GQuery gquery = (FTC_GQuery)ftcgquery;
76 *list_changed = FALSE;
77 return FT_BOOL( gnode->family == gquery->family &&
78 gnode->gindex == gquery->gindex );
84 FT_LOCAL_DEF( FT_Bool )
85 FTC_GNode_Compare( FTC_GNode gnode,
88 FT_Bool* list_changed )
90 return ftc_gnode_compare( FTC_NODE( gnode ), gquery,
91 cache, list_changed );
96 /*************************************************************************/
97 /*************************************************************************/
99 /***** CHUNK SETS *****/
101 /*************************************************************************/
102 /*************************************************************************/
105 FTC_Family_Init( FTC_Family family,
108 FTC_GCacheClass clazz = FTC_CACHE_GCACHE_CLASS( cache );
111 family->clazz = clazz->family_class;
112 family->num_nodes = 0;
113 family->cache = cache;
117 FT_LOCAL_DEF( FT_Error )
118 ftc_gcache_init( FTC_Cache ftccache )
120 FTC_GCache cache = (FTC_GCache)ftccache;
124 error = FTC_Cache_Init( FTC_CACHE( cache ) );
127 FTC_GCacheClass clazz = (FTC_GCacheClass)FTC_CACHE( cache )->org_class;
129 FTC_MruList_Init( &cache->families,
131 0, /* no maximum here! */
133 FTC_CACHE( cache )->memory );
142 FT_LOCAL_DEF( FT_Error )
143 FTC_GCache_Init( FTC_GCache cache )
145 return ftc_gcache_init( FTC_CACHE( cache ) );
152 ftc_gcache_done( FTC_Cache ftccache )
154 FTC_GCache cache = (FTC_GCache)ftccache;
157 FTC_Cache_Done( (FTC_Cache)cache );
158 FTC_MruList_Done( &cache->families );
165 FTC_GCache_Done( FTC_GCache cache )
167 ftc_gcache_done( FTC_CACHE( cache ) );
173 FT_LOCAL_DEF( FT_Error )
174 FTC_GCache_New( FTC_Manager manager,
175 FTC_GCacheClass clazz,
178 return FTC_Manager_RegisterCache( manager, (FTC_CacheClass)clazz,
179 (FTC_Cache*)acache );
185 FT_LOCAL_DEF( FT_Error )
186 FTC_GCache_Lookup( FTC_GCache cache,
195 query->gindex = gindex;
197 FTC_MRULIST_LOOKUP( &cache->families, query, query->family, error );
200 FTC_Family family = query->family;
203 /* prevent the family from being destroyed too early when an */
204 /* out-of-memory condition occurs during glyph node initialization. */
207 error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query, anode );
209 if ( --family->num_nodes == 0 )
210 FTC_FAMILY_FREE( family, cache );
215 #endif /* !FTC_INLINE */