Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ftcglyph.c */ |
| 4 | /* */ |
| 5 | /* FreeType Glyph Image (FT_Glyph) cache (body). */ |
| 6 | /* */ |
Werner Lemberg | 09370c8 | 2004-02-17 18:41:58 +0000 | [diff] [blame^] | 7 | /* Copyright 2000-2001, 2003, 2004 by */ |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 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 FT_CACHE_INTERNAL_GLYPH_H |
| 22 | #include FT_ERRORS_H |
| 23 | #include FT_INTERNAL_OBJECTS_H |
| 24 | #include FT_INTERNAL_DEBUG_H |
| 25 | |
Werner Lemberg | 09370c8 | 2004-02-17 18:41:58 +0000 | [diff] [blame^] | 26 | #include "ftccback.h" |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 27 | #include "ftcerror.h" |
| 28 | |
| 29 | |
| 30 | /* create a new chunk node, setting its cache index and ref count */ |
| 31 | FT_EXPORT_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_EXPORT_DEF( void ) |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 43 | FTC_GNode_UnselectFamily( FTC_GNode gnode, |
| 44 | FTC_Cache cache ) |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 45 | { |
| 46 | FTC_Family family = gnode->family; |
| 47 | |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 48 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 49 | gnode->family = NULL; |
| 50 | if ( family && --family->num_nodes <= 0 ) |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 51 | FTC_MruList_Remove( &FTC_GCACHE( cache )->families, |
| 52 | (FTC_MruNode)family ); |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | FT_EXPORT_DEF( void ) |
| 57 | FTC_GNode_Done( FTC_GNode gnode, |
| 58 | FTC_Cache cache ) |
| 59 | { |
| 60 | /* finalize the node */ |
| 61 | gnode->gindex = 0; |
| 62 | |
| 63 | FTC_GNode_UnselectFamily( gnode, cache ); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | FT_EXPORT_DEF( FT_Bool ) |
| 68 | FTC_GNode_Compare( FTC_GNode gnode, |
| 69 | FTC_GQuery gquery ) |
| 70 | { |
| 71 | return FT_BOOL( gnode->family == gquery->family && |
| 72 | gnode->gindex == gquery->gindex ); |
| 73 | } |
| 74 | |
| 75 | |
Werner Lemberg | 09370c8 | 2004-02-17 18:41:58 +0000 | [diff] [blame^] | 76 | FT_LOCAL_DEF( FT_Bool ) |
| 77 | ftc_gnode_compare( FTC_GNode gnode, |
| 78 | FTC_GQuery gquery ) |
| 79 | { |
| 80 | return FTC_GNode_Compare( gnode, gquery ); |
| 81 | } |
| 82 | |
| 83 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 84 | /*************************************************************************/ |
| 85 | /*************************************************************************/ |
| 86 | /***** *****/ |
| 87 | /***** CHUNK SETS *****/ |
| 88 | /***** *****/ |
| 89 | /*************************************************************************/ |
| 90 | /*************************************************************************/ |
| 91 | |
| 92 | FT_EXPORT_DEF( void ) |
| 93 | FTC_Family_Init( FTC_Family family, |
| 94 | FTC_Cache cache ) |
| 95 | { |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 96 | FTC_GCacheClass clazz = FTC_CACHE__GCACHE_CLASS( cache ); |
| 97 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 98 | |
| 99 | family->clazz = clazz->family_class; |
| 100 | family->num_nodes = 0; |
| 101 | family->cache = cache; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | FT_EXPORT_DEF( FT_Error ) |
| 106 | FTC_GCache_Init( FTC_GCache cache ) |
| 107 | { |
| 108 | FT_Error error; |
| 109 | |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 110 | error = FTC_Cache_Init( FTC_CACHE( cache ) ); |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 111 | if ( !error ) |
| 112 | { |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 113 | FTC_GCacheClass clazz = (FTC_GCacheClass)FTC_CACHE( cache )->org_class; |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 114 | |
| 115 | FTC_MruList_Init( &cache->families, |
| 116 | clazz->family_class, |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 117 | 0, /* no maximum here! */ |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 118 | cache, |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 119 | FTC_CACHE( cache )->memory ); |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 120 | } |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 121 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 122 | return error; |
| 123 | } |
| 124 | |
| 125 | |
Werner Lemberg | 09370c8 | 2004-02-17 18:41:58 +0000 | [diff] [blame^] | 126 | FT_LOCAL_DEF( FT_Error ) |
| 127 | ftc_gcache_init( FTC_GCache cache ) |
| 128 | { |
| 129 | return FTC_GCache_Init( cache ); |
| 130 | } |
| 131 | |
| 132 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 133 | FT_EXPORT_DEF( void ) |
| 134 | FTC_GCache_Done( FTC_GCache cache ) |
| 135 | { |
| 136 | FTC_Cache_Done( (FTC_Cache)cache ); |
| 137 | FTC_MruList_Done( &cache->families ); |
| 138 | } |
| 139 | |
| 140 | |
Werner Lemberg | 09370c8 | 2004-02-17 18:41:58 +0000 | [diff] [blame^] | 141 | FT_LOCAL_DEF( void ) |
| 142 | ftc_gcache_done( FTC_GCache cache ) |
| 143 | { |
| 144 | FTC_GCache_Done( cache ); |
| 145 | } |
| 146 | |
| 147 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 148 | FT_EXPORT_DEF( FT_Error ) |
| 149 | FTC_GCache_New( FTC_Manager manager, |
| 150 | FTC_GCacheClass clazz, |
| 151 | FTC_GCache *acache ) |
| 152 | { |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 153 | return FTC_Manager_RegisterCache( manager, (FTC_CacheClass)clazz, |
| 154 | (FTC_Cache*)acache ); |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | FT_EXPORT_DEF( FT_Error ) |
| 159 | FTC_GCache_Lookup( FTC_GCache cache, |
| 160 | FT_UInt32 hash, |
| 161 | FT_UInt gindex, |
| 162 | FTC_GQuery query, |
| 163 | FTC_Node *anode ) |
| 164 | { |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 165 | FT_Error error; |
| 166 | |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 167 | |
| 168 | query->gindex = gindex; |
| 169 | |
| 170 | FTC_MRULIST_LOOKUP( &cache->families, query, query->family, error ); |
| 171 | if ( !error ) |
Werner Lemberg | 80cfbd7 | 2003-12-26 07:26:08 +0000 | [diff] [blame] | 172 | error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query, anode ); |
Werner Lemberg | 328abf3 | 2003-12-24 13:37:58 +0000 | [diff] [blame] | 173 | |
| 174 | return error; |
| 175 | } |
| 176 | |
| 177 | |
| 178 | /* END */ |