ftcmanag.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /***************************************************************************/
  2. /* */
  3. /* ftcmanag.h */
  4. /* */
  5. /* FreeType Cache Manager (specification). */
  6. /* */
  7. /* Copyright 2000-2001 by */
  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. /* A cache manager is in charge of the following: */
  20. /* */
  21. /* - Maintain a mapping between generic FTC_FaceIDs and live FT_Face */
  22. /* objects. The mapping itself is performed through a user-provided */
  23. /* callback. However, the manager maintains a small cache of FT_Face */
  24. /* and FT_Size objects in order to speed up things considerably. */
  25. /* */
  26. /* - Manage one or more cache objects. Each cache is in charge of */
  27. /* holding a varying number of `cache nodes'. Each cache node */
  28. /* represents a minimal amount of individually accessible cached */
  29. /* data. For example, a cache node can be an FT_Glyph image */
  30. /* containing a vector outline, or some glyph metrics, or anything */
  31. /* else. */
  32. /* */
  33. /* Each cache node has a certain size in bytes that is added to the */
  34. /* total amount of `cache memory' within the manager. */
  35. /* */
  36. /* All cache nodes are located in a global LRU list, where the oldest */
  37. /* node is at the tail of the list. */
  38. /* */
  39. /* Each node belongs to a single cache, and includes a reference */
  40. /* count to avoid destroying it (due to caching). */
  41. /* */
  42. /*************************************************************************/
  43. /*************************************************************************/
  44. /*************************************************************************/
  45. /*************************************************************************/
  46. /*************************************************************************/
  47. /*************************************************************************/
  48. /********* *********/
  49. /********* WARNING, THIS IS BETA CODE. *********/
  50. /********* *********/
  51. /*************************************************************************/
  52. /*************************************************************************/
  53. /*************************************************************************/
  54. /*************************************************************************/
  55. /*************************************************************************/
  56. #ifndef __FTCMANAG_H__
  57. #define __FTCMANAG_H__
  58. #include <ft2build.h>
  59. #include FT_CACHE_H
  60. #include FT_CACHE_INTERNAL_LRU_H
  61. #include FT_CACHE_INTERNAL_CACHE_H
  62. FT_BEGIN_HEADER
  63. /*************************************************************************/
  64. /* */
  65. /* <Section> */
  66. /* cache_subsystem */
  67. /* */
  68. /*************************************************************************/
  69. #define FTC_MAX_FACES_DEFAULT 2
  70. #define FTC_MAX_SIZES_DEFAULT 4
  71. #define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */
  72. /* maximum number of caches registered in a single manager */
  73. #define FTC_MAX_CACHES 16
  74. typedef struct FTC_FamilyEntryRec_
  75. {
  76. FTC_Family family;
  77. FTC_Cache cache;
  78. FT_UInt index;
  79. FT_UInt link;
  80. } FTC_FamilyEntryRec, *FTC_FamilyEntry;
  81. #define FTC_FAMILY_ENTRY_NONE ( (FT_UInt)-1 )
  82. typedef struct FTC_FamilyTableRec_
  83. {
  84. FT_UInt count;
  85. FT_UInt size;
  86. FTC_FamilyEntry entries;
  87. FT_UInt free;
  88. } FTC_FamilyTableRec, *FTC_FamilyTable;
  89. FT_EXPORT( FT_Error )
  90. ftc_family_table_alloc( FTC_FamilyTable table,
  91. FT_Memory memory,
  92. FTC_FamilyEntry *aentry );
  93. FT_EXPORT( void )
  94. ftc_family_table_free( FTC_FamilyTable table,
  95. FT_UInt idx );
  96. /*************************************************************************/
  97. /* */
  98. /* <Struct> */
  99. /* FTC_ManagerRec */
  100. /* */
  101. /* <Description> */
  102. /* The cache manager structure. */
  103. /* */
  104. /* <Fields> */
  105. /* library :: A handle to a FreeType library instance. */
  106. /* */
  107. /* faces_list :: The lru list of @FT_Face objects in the cache. */
  108. /* */
  109. /* sizes_list :: The lru list of @FT_Size objects in the cache. */
  110. /* */
  111. /* max_weight :: The maximum cache pool weight. */
  112. /* */
  113. /* cur_weight :: The current cache pool weight. */
  114. /* */
  115. /* num_nodes :: The current number of nodes in the manager. */
  116. /* */
  117. /* nodes_list :: The global lru list of all cache nodes. */
  118. /* */
  119. /* caches :: A table of installed/registered cache objects. */
  120. /* */
  121. /* request_data :: User-provided data passed to the requester. */
  122. /* */
  123. /* request_face :: User-provided function used to implement a mapping */
  124. /* between abstract @FTC_FaceID values and real */
  125. /* @FT_Face objects. */
  126. /* */
  127. /* families :: Global table of families. */
  128. /* */
  129. typedef struct FTC_ManagerRec_
  130. {
  131. FT_Library library;
  132. FT_LruList faces_list;
  133. FT_LruList sizes_list;
  134. FT_ULong max_weight;
  135. FT_ULong cur_weight;
  136. FT_UInt num_nodes;
  137. FTC_Node nodes_list;
  138. FTC_Cache caches[FTC_MAX_CACHES];
  139. FT_Pointer request_data;
  140. FTC_Face_Requester request_face;
  141. FTC_FamilyTableRec families;
  142. } FTC_ManagerRec;
  143. /*************************************************************************/
  144. /* */
  145. /* <Function> */
  146. /* FTC_Manager_Compress */
  147. /* */
  148. /* <Description> */
  149. /* This function is used to check the state of the cache manager if */
  150. /* its `num_bytes' field is greater than its `max_bytes' field. It */
  151. /* will flush as many old cache nodes as possible (ignoring cache */
  152. /* nodes with a non-zero reference count). */
  153. /* */
  154. /* <InOut> */
  155. /* manager :: A handle to the cache manager. */
  156. /* */
  157. /* <Note> */
  158. /* Client applications should not call this function directly. It is */
  159. /* normally invoked by specific cache implementations. */
  160. /* */
  161. /* The reason this function is exported is to allow client-specific */
  162. /* cache classes. */
  163. /* */
  164. FT_EXPORT( void )
  165. FTC_Manager_Compress( FTC_Manager manager );
  166. /* this must be used internally for the moment */
  167. FT_EXPORT( FT_Error )
  168. FTC_Manager_Register_Cache( FTC_Manager manager,
  169. FTC_Cache_Class clazz,
  170. FTC_Cache *acache );
  171. /* can be called to increment a node's reference count */
  172. FT_EXPORT( void )
  173. FTC_Node_Ref( FTC_Node node,
  174. FTC_Manager manager );
  175. /*************************************************************************/
  176. /* */
  177. /* <Function> */
  178. /* FTC_Node_Unref */
  179. /* */
  180. /* <Description> */
  181. /* Decrement a cache node's internal reference count. When the count */
  182. /* reaches 0, it is not destroyed but becomes eligible for subsequent */
  183. /* cache flushes. */
  184. /* */
  185. /* <Input> */
  186. /* node :: The cache node handle. */
  187. /* */
  188. /* manager :: The cache manager handle. */
  189. /* */
  190. FT_EXPORT( void )
  191. FTC_Node_Unref( FTC_Node node,
  192. FTC_Manager manager );
  193. /* */
  194. FT_END_HEADER
  195. #endif /* __FTCMANAG_H__ */
  196. /* END */