1 /****************************************************************************
5 * FreeType Cache Manager (specification).
7 * Copyright (C) 2000-2023 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 /**************************************************************************
21 * A cache manager is in charge of the following:
23 * - Maintain a mapping between generic FTC_FaceIDs and live FT_Face
24 * objects. The mapping itself is performed through a user-provided
25 * callback. However, the manager maintains a small cache of FT_Face
26 * and FT_Size objects in order to speed up things considerably.
28 * - Manage one or more cache objects. Each cache is in charge of
29 * holding a varying number of `cache nodes'. Each cache node
30 * represents a minimal amount of individually accessible cached
31 * data. For example, a cache node can be an FT_Glyph image
32 * containing a vector outline, or some glyph metrics, or anything
35 * Each cache node has a certain size in bytes that is added to the
36 * total amount of `cache memory' within the manager.
38 * All cache nodes are located in a global LRU list, where the oldest
39 * node is at the tail of the list.
41 * Each node belongs to a single cache, and includes a reference
42 * count to avoid destroying it (due to caching).
47 /*************************************************************************/
48 /*************************************************************************/
49 /*************************************************************************/
50 /*************************************************************************/
51 /*************************************************************************/
53 /********* WARNING, THIS IS BETA CODE. *********/
55 /*************************************************************************/
56 /*************************************************************************/
57 /*************************************************************************/
58 /*************************************************************************/
59 /*************************************************************************/
66 #include <freetype/ftcache.h>
74 /**************************************************************************
82 #define FTC_MAX_FACES_DEFAULT 2
83 #define FTC_MAX_SIZES_DEFAULT 4
84 #define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */
86 /* maximum number of caches registered in a single manager */
87 #define FTC_MAX_CACHES 16
90 typedef struct FTC_ManagerRec_
100 FTC_Cache caches[FTC_MAX_CACHES];
103 FTC_MruListRec faces;
104 FTC_MruListRec sizes;
106 FT_Pointer request_data;
107 FTC_Face_Requester request_face;
112 /**************************************************************************
115 * FTC_Manager_Compress
118 * This function is used to check the state of the cache manager if
119 * its `num_bytes' field is greater than its `max_bytes' field. It
120 * will flush as many old cache nodes as possible (ignoring cache
121 * nodes with a non-zero reference count).
125 * A handle to the cache manager.
128 * Client applications should not call this function directly. It is
129 * normally invoked by specific cache implementations.
131 * The reason this function is exported is to allow client-specific
135 FTC_Manager_Compress( FTC_Manager manager );
138 /* try to flush `count' old nodes from the cache; return the number
139 * of really flushed nodes
142 FTC_Manager_FlushN( FTC_Manager manager,
146 /* this must be used internally for the moment */
148 FTC_Manager_RegisterCache( FTC_Manager manager,
149 FTC_CacheClass clazz,
154 #define FTC_SCALER_COMPARE( a, b ) \
155 ( (a)->face_id == (b)->face_id && \
156 (a)->width == (b)->width && \
157 (a)->height == (b)->height && \
158 ((a)->pixel != 0) == ((b)->pixel != 0) && \
160 ( (a)->x_res == (b)->x_res && \
161 (a)->y_res == (b)->y_res ) ) )
163 #define FTC_SCALER_HASH( q ) \
164 ( FTC_FACE_ID_HASH( (q)->face_id ) + \
165 (q)->width + (q)->height*7 + \
166 ( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) )
172 #endif /* FTCMANAG_H_ */