/src/freetype/src/cache/ftcmanag.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 175 lines · 49 code · 36 blank · 90 comment · 14 complexity · d2b821d9df8cce9181f3da50239874a4 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftcmanag.h */
  4. /* */
  5. /* FreeType Cache Manager (specification). */
  6. /* */
  7. /* Copyright 2000-2001, 2003, 2004, 2006, 2010 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 "ftcmru.h"
  61. #include "ftccache.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_ManagerRec_
  75. {
  76. FT_Library library;
  77. FT_Memory memory;
  78. FTC_Node nodes_list;
  79. FT_ULong max_weight;
  80. FT_ULong cur_weight;
  81. FT_UInt num_nodes;
  82. FTC_Cache caches[FTC_MAX_CACHES];
  83. FT_UInt num_caches;
  84. FTC_MruListRec faces;
  85. FTC_MruListRec sizes;
  86. FT_Pointer request_data;
  87. FTC_Face_Requester request_face;
  88. } FTC_ManagerRec;
  89. /*************************************************************************/
  90. /* */
  91. /* <Function> */
  92. /* FTC_Manager_Compress */
  93. /* */
  94. /* <Description> */
  95. /* This function is used to check the state of the cache manager if */
  96. /* its `num_bytes' field is greater than its `max_bytes' field. It */
  97. /* will flush as many old cache nodes as possible (ignoring cache */
  98. /* nodes with a non-zero reference count). */
  99. /* */
  100. /* <InOut> */
  101. /* manager :: A handle to the cache manager. */
  102. /* */
  103. /* <Note> */
  104. /* Client applications should not call this function directly. It is */
  105. /* normally invoked by specific cache implementations. */
  106. /* */
  107. /* The reason this function is exported is to allow client-specific */
  108. /* cache classes. */
  109. /* */
  110. FT_LOCAL( void )
  111. FTC_Manager_Compress( FTC_Manager manager );
  112. /* try to flush `count' old nodes from the cache; return the number
  113. * of really flushed nodes
  114. */
  115. FT_LOCAL( FT_UInt )
  116. FTC_Manager_FlushN( FTC_Manager manager,
  117. FT_UInt count );
  118. /* this must be used internally for the moment */
  119. FT_LOCAL( FT_Error )
  120. FTC_Manager_RegisterCache( FTC_Manager manager,
  121. FTC_CacheClass clazz,
  122. FTC_Cache *acache );
  123. /* */
  124. #define FTC_SCALER_COMPARE( a, b ) \
  125. ( (a)->face_id == (b)->face_id && \
  126. (a)->width == (b)->width && \
  127. (a)->height == (b)->height && \
  128. ((a)->pixel != 0) == ((b)->pixel != 0) && \
  129. ( (a)->pixel || \
  130. ( (a)->x_res == (b)->x_res && \
  131. (a)->y_res == (b)->y_res ) ) )
  132. #define FTC_SCALER_HASH( q ) \
  133. ( _FTC_FACE_ID_HASH( (q)->face_id ) + \
  134. (q)->width + (q)->height*7 + \
  135. ( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) )
  136. /* */
  137. FT_END_HEADER
  138. #endif /* __FTCMANAG_H__ */
  139. /* END */