00001 /***************************************************************************/ 00002 /* */ 00003 /* ftcmanag.h */ 00004 /* */ 00005 /* FreeType Cache Manager (specification). */ 00006 /* */ 00007 /* Copyright 2000-2001, 2003, 2004, 2006 by */ 00008 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 00009 /* */ 00010 /* This file is part of the FreeType project, and may only be used, */ 00011 /* modified, and distributed under the terms of the FreeType project */ 00012 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 00013 /* this file you indicate that you have read the license and */ 00014 /* understand and accept it fully. */ 00015 /* */ 00016 /***************************************************************************/ 00017 00018 00019 /*************************************************************************/ 00020 /* */ 00021 /* A cache manager is in charge of the following: */ 00022 /* */ 00023 /* - Maintain a mapping between generic FTC_FaceIDs and live FT_Face */ 00024 /* objects. The mapping itself is performed through a user-provided */ 00025 /* callback. However, the manager maintains a small cache of FT_Face */ 00026 /* and FT_Size objects in order to speed up things considerably. */ 00027 /* */ 00028 /* - Manage one or more cache objects. Each cache is in charge of */ 00029 /* holding a varying number of `cache nodes'. Each cache node */ 00030 /* represents a minimal amount of individually accessible cached */ 00031 /* data. For example, a cache node can be an FT_Glyph image */ 00032 /* containing a vector outline, or some glyph metrics, or anything */ 00033 /* else. */ 00034 /* */ 00035 /* Each cache node has a certain size in bytes that is added to the */ 00036 /* total amount of `cache memory' within the manager. */ 00037 /* */ 00038 /* All cache nodes are located in a global LRU list, where the oldest */ 00039 /* node is at the tail of the list. */ 00040 /* */ 00041 /* Each node belongs to a single cache, and includes a reference */ 00042 /* count to avoid destroying it (due to caching). */ 00043 /* */ 00044 /*************************************************************************/ 00045 00046 00047 /*************************************************************************/ 00048 /*************************************************************************/ 00049 /*************************************************************************/ 00050 /*************************************************************************/ 00051 /*************************************************************************/ 00052 /********* *********/ 00053 /********* WARNING, THIS IS BETA CODE. *********/ 00054 /********* *********/ 00055 /*************************************************************************/ 00056 /*************************************************************************/ 00057 /*************************************************************************/ 00058 /*************************************************************************/ 00059 /*************************************************************************/ 00060 00061 00062 #ifndef __FTCMANAG_H__ 00063 #define __FTCMANAG_H__ 00064 00065 00066 #include <ft2build.h> 00067 #include FT_CACHE_H 00068 #include "ftcmru.h" 00069 #include "ftccache.h" 00070 00071 00072 FT_BEGIN_HEADER 00073 00074 00075 /*************************************************************************/ 00076 /* */ 00077 /* <Section> */ 00078 /* cache_subsystem */ 00079 /* */ 00080 /*************************************************************************/ 00081 00082 00083 #define FTC_MAX_FACES_DEFAULT 2 00084 #define FTC_MAX_SIZES_DEFAULT 4 00085 #define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */ 00086 00087 /* maximum number of caches registered in a single manager */ 00088 #define FTC_MAX_CACHES 16 00089 00090 00091 typedef struct FTC_ManagerRec_ 00092 { 00093 FT_Library library; 00094 FT_Memory memory; 00095 00096 FTC_Node nodes_list; 00097 FT_ULong max_weight; 00098 FT_ULong cur_weight; 00099 FT_UInt num_nodes; 00100 00101 FTC_Cache caches[FTC_MAX_CACHES]; 00102 FT_UInt num_caches; 00103 00104 FTC_MruListRec faces; 00105 FTC_MruListRec sizes; 00106 00107 FT_Pointer request_data; 00108 FTC_Face_Requester request_face; 00109 00110 } FTC_ManagerRec; 00111 00112 00113 /*************************************************************************/ 00114 /* */ 00115 /* <Function> */ 00116 /* FTC_Manager_Compress */ 00117 /* */ 00118 /* <Description> */ 00119 /* This function is used to check the state of the cache manager if */ 00120 /* its `num_bytes' field is greater than its `max_bytes' field. It */ 00121 /* will flush as many old cache nodes as possible (ignoring cache */ 00122 /* nodes with a non-zero reference count). */ 00123 /* */ 00124 /* <InOut> */ 00125 /* manager :: A handle to the cache manager. */ 00126 /* */ 00127 /* <Note> */ 00128 /* Client applications should not call this function directly. It is */ 00129 /* normally invoked by specific cache implementations. */ 00130 /* */ 00131 /* The reason this function is exported is to allow client-specific */ 00132 /* cache classes. */ 00133 /* */ 00134 FT_LOCAL( void ) 00135 FTC_Manager_Compress( FTC_Manager manager ); 00136 00137 00138 /* try to flush `count' old nodes from the cache; return the number 00139 * of really flushed nodes 00140 */ 00141 FT_LOCAL( FT_UInt ) 00142 FTC_Manager_FlushN( FTC_Manager manager, 00143 FT_UInt count ); 00144 00145 00146 /* this must be used internally for the moment */ 00147 FT_LOCAL( FT_Error ) 00148 FTC_Manager_RegisterCache( FTC_Manager manager, 00149 FTC_CacheClass clazz, 00150 FTC_Cache *acache ); 00151 00152 /* */ 00153 00154 #define FTC_SCALER_COMPARE( a, b ) \ 00155 ( (a)->face_id == (b)->face_id && \ 00156 (a)->width == (b)->width && \ 00157 (a)->height == (b)->height && \ 00158 ((a)->pixel != 0) == ((b)->pixel != 0) && \ 00159 ( (a)->pixel || \ 00160 ( (a)->x_res == (b)->x_res && \ 00161 (a)->y_res == (b)->y_res ) ) ) 00162 00163 #define FTC_SCALER_HASH( q ) \ 00164 ( FTC_FACE_ID_HASH( (q)->face_id ) + \ 00165 (q)->width + (q)->height*7 + \ 00166 ( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) ) 00167 00168 /* */ 00169 00170 FT_END_HEADER 00171 00172 #endif /* __FTCMANAG_H__ */ 00173 00174 00175 /* END */