2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftcmanag.h
|
|
|
|
*
|
|
|
|
* FreeType Cache Manager (specification).
|
|
|
|
*
|
2021-01-17 07:18:48 +01:00
|
|
|
* Copyright (C) 2000-2021 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* A cache manager is in charge of the following:
|
|
|
|
*
|
|
|
|
* - Maintain a mapping between generic FTC_FaceIDs and live FT_Face
|
|
|
|
* objects. The mapping itself is performed through a user-provided
|
|
|
|
* callback. However, the manager maintains a small cache of FT_Face
|
|
|
|
* and FT_Size objects in order to speed up things considerably.
|
|
|
|
*
|
|
|
|
* - Manage one or more cache objects. Each cache is in charge of
|
|
|
|
* holding a varying number of `cache nodes'. Each cache node
|
|
|
|
* represents a minimal amount of individually accessible cached
|
|
|
|
* data. For example, a cache node can be an FT_Glyph image
|
|
|
|
* containing a vector outline, or some glyph metrics, or anything
|
|
|
|
* else.
|
|
|
|
*
|
|
|
|
* Each cache node has a certain size in bytes that is added to the
|
|
|
|
* total amount of `cache memory' within the manager.
|
|
|
|
*
|
|
|
|
* All cache nodes are located in a global LRU list, where the oldest
|
|
|
|
* node is at the tail of the list.
|
|
|
|
*
|
|
|
|
* Each node belongs to a single cache, and includes a reference
|
|
|
|
* count to avoid destroying it (due to caching).
|
|
|
|
*
|
|
|
|
*/
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/********* *********/
|
|
|
|
/********* WARNING, THIS IS BETA CODE. *********/
|
|
|
|
/********* *********/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#ifndef FTCMANAG_H_
|
|
|
|
#define FTCMANAG_H_
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/ftcache.h>
|
* include/freetype/cache/ftccache.h,
include/freetype/cache/ftccmap.h,
include/freetype/cache/ftcglyph.h
include/freetype/cache/ftcimage.h
include/freetype/cache/ftcmanag.h
include/freetype/cache/ftcmru.h
include/freetype/cache/ftcsbits.h:
removing these header files from the public include directory.
* include/freetype/config/ftheader.h:
changing the definition of FT_CACHE_INTERNAL_XXX_H macros to
redirect to FT_CACHE_H instead
* src/cache/ftcbasic.c, src/cache/ftccache.c, src/cache/ftccache.h,
src/cache/ftccback.h, src/cache/ftccmap.c, src/cache/ftcglyph.c,
src/cache/ftcglyph.h, src/cache/ftcimage.c, src/cache/ftcimage.h,
src/cache/ftcmanag.c, src/cache/ftcmanag.h, src/cache/ftcmru.c,
src/cache/ftcmru.h, src/cache/ftcsbits.c, src/cache/ftcsbits.h:
modifications to prevent using the FT_CACHE_INTERNAL_XXX_H macros,
and grab the headers in 'src/cache' instead (see below).
2006-03-20 13:10:24 +01:00
|
|
|
#include "ftcmru.h"
|
|
|
|
#include "ftccache.h"
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
FT_BEGIN_HEADER
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Section:
|
|
|
|
* cache_subsystem
|
|
|
|
*
|
|
|
|
*/
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define FTC_MAX_FACES_DEFAULT 2
|
|
|
|
#define FTC_MAX_SIZES_DEFAULT 4
|
|
|
|
#define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */
|
|
|
|
|
|
|
|
/* maximum number of caches registered in a single manager */
|
|
|
|
#define FTC_MAX_CACHES 16
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct FTC_ManagerRec_
|
|
|
|
{
|
|
|
|
FT_Library library;
|
|
|
|
FT_Memory memory;
|
|
|
|
|
|
|
|
FTC_Node nodes_list;
|
2013-06-06 09:16:38 +02:00
|
|
|
FT_Offset max_weight;
|
|
|
|
FT_Offset cur_weight;
|
2006-03-20 12:48:13 +01:00
|
|
|
FT_UInt num_nodes;
|
|
|
|
|
|
|
|
FTC_Cache caches[FTC_MAX_CACHES];
|
|
|
|
FT_UInt num_caches;
|
|
|
|
|
|
|
|
FTC_MruListRec faces;
|
|
|
|
FTC_MruListRec sizes;
|
|
|
|
|
|
|
|
FT_Pointer request_data;
|
|
|
|
FTC_Face_Requester request_face;
|
|
|
|
|
|
|
|
} FTC_ManagerRec;
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* FTC_Manager_Compress
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* This function is used to check the state of the cache manager if
|
|
|
|
* its `num_bytes' field is greater than its `max_bytes' field. It
|
|
|
|
* will flush as many old cache nodes as possible (ignoring cache
|
|
|
|
* nodes with a non-zero reference count).
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* manager ::
|
|
|
|
* A handle to the cache manager.
|
|
|
|
*
|
|
|
|
* @Note:
|
|
|
|
* Client applications should not call this function directly. It is
|
|
|
|
* normally invoked by specific cache implementations.
|
|
|
|
*
|
|
|
|
* The reason this function is exported is to allow client-specific
|
|
|
|
* cache classes.
|
|
|
|
*/
|
* src/cache/ftccache.c, (ftc_node_mru_up, FTC_Cache_Lookup)
[!FTC_INLINE]: Compile conditionally.
* src/cache/ftccache.h: Updated.
* src/cache/ftcglyph.c (FTC_GNode_Init, FTC_GNode_UnselectFamily,
FTC_GNode_Done, FTC_GNode_Compare, FTC_Family_Init, FTC_GCache_New):
s/FT_EXPORT/FT_LOCAL/.
(FTC_GCache_Init, FTC_GCache_Done): Commented out.
(FTC_GCache_Lookup) [!FTC_INLINE]: Compile conditionally.
s/FT_EXPORT/FT_LOCAL/.
* src/cache/ftcglyph.h: Updated.
* src/cache/ftcimage.c (FTC_INode_Free, FTC_INode_New):
s/FT_EXPORT/FT_LOCAL/.
(FTC_INode_Weight): Commented out.
* src/cache/ftcimage.h: Updated.
* src/cache/ftmanag.c (FTC_Manager_Compress,
FTC_Manager_RegisterCache, FTC_Manager_FlushN):
s/FT_EXPORT/FT_LOCAL/.
* src/cache/ftmanag.h: Updated.
* src/cache/ftcsbits.c (FTC_SNode_Free, FTC_SNode_New,
FTC_SNode_Compare): s/FT_EXPORT/FT_LOCAL/.
(FTC_SNode_Weight): Commented out.
* src/cache/ftcsbits.h: Updated.
2006-03-22 16:30:41 +01:00
|
|
|
FT_LOCAL( void )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Manager_Compress( FTC_Manager manager );
|
|
|
|
|
|
|
|
|
|
|
|
/* try to flush `count' old nodes from the cache; return the number
|
|
|
|
* of really flushed nodes
|
|
|
|
*/
|
* src/cache/ftccache.c, (ftc_node_mru_up, FTC_Cache_Lookup)
[!FTC_INLINE]: Compile conditionally.
* src/cache/ftccache.h: Updated.
* src/cache/ftcglyph.c (FTC_GNode_Init, FTC_GNode_UnselectFamily,
FTC_GNode_Done, FTC_GNode_Compare, FTC_Family_Init, FTC_GCache_New):
s/FT_EXPORT/FT_LOCAL/.
(FTC_GCache_Init, FTC_GCache_Done): Commented out.
(FTC_GCache_Lookup) [!FTC_INLINE]: Compile conditionally.
s/FT_EXPORT/FT_LOCAL/.
* src/cache/ftcglyph.h: Updated.
* src/cache/ftcimage.c (FTC_INode_Free, FTC_INode_New):
s/FT_EXPORT/FT_LOCAL/.
(FTC_INode_Weight): Commented out.
* src/cache/ftcimage.h: Updated.
* src/cache/ftmanag.c (FTC_Manager_Compress,
FTC_Manager_RegisterCache, FTC_Manager_FlushN):
s/FT_EXPORT/FT_LOCAL/.
* src/cache/ftmanag.h: Updated.
* src/cache/ftcsbits.c (FTC_SNode_Free, FTC_SNode_New,
FTC_SNode_Compare): s/FT_EXPORT/FT_LOCAL/.
(FTC_SNode_Weight): Commented out.
* src/cache/ftcsbits.h: Updated.
2006-03-22 16:30:41 +01:00
|
|
|
FT_LOCAL( FT_UInt )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Manager_FlushN( FTC_Manager manager,
|
|
|
|
FT_UInt count );
|
|
|
|
|
|
|
|
|
|
|
|
/* this must be used internally for the moment */
|
* src/cache/ftccache.c, (ftc_node_mru_up, FTC_Cache_Lookup)
[!FTC_INLINE]: Compile conditionally.
* src/cache/ftccache.h: Updated.
* src/cache/ftcglyph.c (FTC_GNode_Init, FTC_GNode_UnselectFamily,
FTC_GNode_Done, FTC_GNode_Compare, FTC_Family_Init, FTC_GCache_New):
s/FT_EXPORT/FT_LOCAL/.
(FTC_GCache_Init, FTC_GCache_Done): Commented out.
(FTC_GCache_Lookup) [!FTC_INLINE]: Compile conditionally.
s/FT_EXPORT/FT_LOCAL/.
* src/cache/ftcglyph.h: Updated.
* src/cache/ftcimage.c (FTC_INode_Free, FTC_INode_New):
s/FT_EXPORT/FT_LOCAL/.
(FTC_INode_Weight): Commented out.
* src/cache/ftcimage.h: Updated.
* src/cache/ftmanag.c (FTC_Manager_Compress,
FTC_Manager_RegisterCache, FTC_Manager_FlushN):
s/FT_EXPORT/FT_LOCAL/.
* src/cache/ftmanag.h: Updated.
* src/cache/ftcsbits.c (FTC_SNode_Free, FTC_SNode_New,
FTC_SNode_Compare): s/FT_EXPORT/FT_LOCAL/.
(FTC_SNode_Weight): Commented out.
* src/cache/ftcsbits.h: Updated.
2006-03-22 16:30:41 +01:00
|
|
|
FT_LOCAL( FT_Error )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Manager_RegisterCache( FTC_Manager manager,
|
|
|
|
FTC_CacheClass clazz,
|
|
|
|
FTC_Cache *acache );
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
|
|
|
#define FTC_SCALER_COMPARE( a, b ) \
|
|
|
|
( (a)->face_id == (b)->face_id && \
|
|
|
|
(a)->width == (b)->width && \
|
|
|
|
(a)->height == (b)->height && \
|
|
|
|
((a)->pixel != 0) == ((b)->pixel != 0) && \
|
|
|
|
( (a)->pixel || \
|
|
|
|
( (a)->x_res == (b)->x_res && \
|
|
|
|
(a)->y_res == (b)->y_res ) ) )
|
|
|
|
|
|
|
|
#define FTC_SCALER_HASH( q ) \
|
2016-01-12 22:28:14 +01:00
|
|
|
( FTC_FACE_ID_HASH( (q)->face_id ) + \
|
2006-03-20 12:48:13 +01:00
|
|
|
(q)->width + (q)->height*7 + \
|
|
|
|
( (q)->pixel ? 0 : ( (q)->x_res*33 ^ (q)->y_res*61 ) ) )
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
|
|
|
FT_END_HEADER
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#endif /* FTCMANAG_H_ */
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|