1
/***************************************************************************/
5
/* FreeType Cache Manager (specification). */
7
/* Copyright 2000-2001 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. */
16
/***************************************************************************/
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). */
44
/*************************************************************************/
47
/*************************************************************************/
48
/*************************************************************************/
49
/*************************************************************************/
50
/*************************************************************************/
51
/*************************************************************************/
53
/********* WARNING, THIS IS BETA CODE. *********/
55
/*************************************************************************/
56
/*************************************************************************/
57
/*************************************************************************/
58
/*************************************************************************/
59
/*************************************************************************/
62
#ifndef __FTCMANAG_H__
63
#define __FTCMANAG_H__
68
#include FT_CACHE_INTERNAL_LRU_H
69
#include FT_CACHE_INTERNAL_CACHE_H
75
/*************************************************************************/
80
/*************************************************************************/
83
#define FTC_MAX_FACES_DEFAULT 2
84
#define FTC_MAX_SIZES_DEFAULT 4
85
#define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */
87
/* maximum number of caches registered in a single manager */
88
#define FTC_MAX_CACHES 16
91
typedef struct FTC_FamilyEntryRec_
98
} FTC_FamilyEntryRec, *FTC_FamilyEntry;
101
#define FTC_FAMILY_ENTRY_NONE ( (FT_UInt)-1 )
104
typedef struct FTC_FamilyTableRec_
108
FTC_FamilyEntry entries;
111
} FTC_FamilyTableRec, *FTC_FamilyTable;
114
FT_EXPORT( FT_Error )
115
ftc_family_table_alloc( FTC_FamilyTable table,
117
FTC_FamilyEntry *aentry );
120
ftc_family_table_free( FTC_FamilyTable table,
124
/*************************************************************************/
130
/* The cache manager structure. */
133
/* library :: A handle to a FreeType library instance. */
135
/* faces_list :: The lru list of @FT_Face objects in the cache. */
137
/* sizes_list :: The lru list of @FT_Size objects in the cache. */
139
/* max_weight :: The maximum cache pool weight. */
141
/* cur_weight :: The current cache pool weight. */
143
/* num_nodes :: The current number of nodes in the manager. */
145
/* nodes_list :: The global lru list of all cache nodes. */
147
/* caches :: A table of installed/registered cache objects. */
149
/* request_data :: User-provided data passed to the requester. */
151
/* request_face :: User-provided function used to implement a mapping */
152
/* between abstract @FTC_FaceID values and real */
153
/* @FT_Face objects. */
155
/* families :: Global table of families. */
157
typedef struct FTC_ManagerRec_
160
FT_LruList faces_list;
161
FT_LruList sizes_list;
169
FTC_Cache caches[FTC_MAX_CACHES];
171
FT_Pointer request_data;
172
FTC_Face_Requester request_face;
174
FTC_FamilyTableRec families;
179
/*************************************************************************/
182
/* FTC_Manager_Compress */
185
/* This function is used to check the state of the cache manager if */
186
/* its `num_bytes' field is greater than its `max_bytes' field. It */
187
/* will flush as many old cache nodes as possible (ignoring cache */
188
/* nodes with a non-zero reference count). */
191
/* manager :: A handle to the cache manager. */
194
/* Client applications should not call this function directly. It is */
195
/* normally invoked by specific cache implementations. */
197
/* The reason this function is exported is to allow client-specific */
201
FTC_Manager_Compress( FTC_Manager manager );
204
/* this must be used internally for the moment */
205
FT_EXPORT( FT_Error )
206
FTC_Manager_Register_Cache( FTC_Manager manager,
207
FTC_Cache_Class clazz,
211
/* can be called to increment a node's reference count */
213
FTC_Node_Ref( FTC_Node node,
214
FTC_Manager manager );
217
/*************************************************************************/
223
/* Decrement a cache node's internal reference count. When the count */
224
/* reaches 0, it is not destroyed but becomes eligible for subsequent */
228
/* node :: The cache node handle. */
230
/* manager :: The cache manager handle. */
233
FTC_Node_Unref( FTC_Node node,
234
FTC_Manager manager );
241
#endif /* __FTCMANAG_H__ */