2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftccache.h
|
|
|
|
*
|
|
|
|
* FreeType internal cache interface (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.
|
|
|
|
*
|
|
|
|
*/
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#ifndef FTCCACHE_H_
|
|
|
|
#define FTCCACHE_H_
|
2006-03-20 12:48:13 +01:00
|
|
|
|
2020-07-06 10:56:36 +02:00
|
|
|
#include <freetype/internal/compiler-macros.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"
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
FT_BEGIN_HEADER
|
|
|
|
|
2016-01-12 22:28:14 +01:00
|
|
|
#define FTC_FACE_ID_HASH( i ) \
|
|
|
|
( ( (FT_Offset)(i) >> 3 ) ^ ( (FT_Offset)(i) << 7 ) )
|
2010-10-24 19:07:52 +02:00
|
|
|
|
2006-03-20 12:48:13 +01:00
|
|
|
/* handle to cache object */
|
|
|
|
typedef struct FTC_CacheRec_* FTC_Cache;
|
|
|
|
|
|
|
|
/* handle to cache class */
|
|
|
|
typedef const struct FTC_CacheClassRec_* FTC_CacheClass;
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** CACHE NODE DEFINITIONS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Each cache controls one or more cache nodes. Each node is part of
|
|
|
|
* the global_lru list of the manager. Its `data' field however is used
|
|
|
|
* as a reference count for now.
|
|
|
|
*
|
|
|
|
* A node can be anything, depending on the type of information held by
|
|
|
|
* the cache. It can be an individual glyph image, a set of bitmaps
|
|
|
|
* glyphs for a given size, some metrics, etc.
|
|
|
|
*
|
|
|
|
*/
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
/* structure size should be 20 bytes on 32-bits machines */
|
|
|
|
typedef struct FTC_NodeRec_
|
|
|
|
{
|
|
|
|
FTC_MruNodeRec mru; /* circular mru list pointer */
|
|
|
|
FTC_Node link; /* used for hashing */
|
2015-02-23 08:20:27 +01:00
|
|
|
FT_Offset hash; /* used for hashing too */
|
2006-03-20 12:48:13 +01:00
|
|
|
FT_UShort cache_index; /* index of cache the node belongs to */
|
|
|
|
FT_Short ref_count; /* reference count for this node */
|
|
|
|
|
|
|
|
} FTC_NodeRec;
|
|
|
|
|
|
|
|
|
|
|
|
#define FTC_NODE( x ) ( (FTC_Node)(x) )
|
|
|
|
#define FTC_NODE_P( x ) ( (FTC_Node*)(x) )
|
|
|
|
|
2016-01-12 21:40:53 +01:00
|
|
|
#define FTC_NODE_NEXT( x ) FTC_NODE( (x)->mru.next )
|
|
|
|
#define FTC_NODE_PREV( x ) FTC_NODE( (x)->mru.prev )
|
2006-03-20 12:48:13 +01:00
|
|
|
|
2011-01-09 13:09:58 +01:00
|
|
|
#ifdef FTC_INLINE
|
2016-01-12 21:40:53 +01:00
|
|
|
#define FTC_NODE_TOP_FOR_HASH( cache, hash ) \
|
2011-01-13 10:33:04 +01:00
|
|
|
( ( cache )->buckets + \
|
|
|
|
( ( ( ( hash ) & ( cache )->mask ) < ( cache )->p ) \
|
|
|
|
? ( ( hash ) & ( ( cache )->mask * 2 + 1 ) ) \
|
|
|
|
: ( ( hash ) & ( cache )->mask ) ) )
|
2011-01-09 13:09:58 +01:00
|
|
|
#else
|
|
|
|
FT_LOCAL( FTC_Node* )
|
2015-02-23 08:20:27 +01:00
|
|
|
ftc_get_top_node_for_hash( FTC_Cache cache,
|
|
|
|
FT_Offset hash );
|
2016-01-12 21:40:53 +01:00
|
|
|
#define FTC_NODE_TOP_FOR_HASH( cache, hash ) \
|
2011-01-09 13:09:58 +01:00
|
|
|
ftc_get_top_node_for_hash( ( cache ), ( hash ) )
|
|
|
|
#endif
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** CACHE DEFINITIONS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/* initialize a new cache node */
|
|
|
|
typedef FT_Error
|
|
|
|
(*FTC_Node_NewFunc)( FTC_Node *pnode,
|
|
|
|
FT_Pointer query,
|
|
|
|
FTC_Cache cache );
|
|
|
|
|
2009-07-31 17:32:10 +02:00
|
|
|
typedef FT_Offset
|
2006-03-20 12:48:13 +01:00
|
|
|
(*FTC_Node_WeightFunc)( FTC_Node node,
|
|
|
|
FTC_Cache cache );
|
|
|
|
|
|
|
|
/* compare a node to a given key pair */
|
|
|
|
typedef FT_Bool
|
|
|
|
(*FTC_Node_CompareFunc)( FTC_Node node,
|
|
|
|
FT_Pointer key,
|
[cache] Notice if a cache query induced the node list change.
Some node comparators (comparing the cache node content and
the properties specified by the query) can flush the cache
node to prevent the cache inflation. The change may
invalidate the pointers to the node obtained before the node
comparison, so the change should be noticed to the caller.
The problem caused by the cache node changing is reported by
Harsha, see Savannah bug #31923.
* src/cache/ftccache.h (FTC_Node_CompareFunc): Add new
argument `FT_Bool* list_changed' to indicate the change of
the cached nodes to the caller.
(FTC_CACHE_LOOKUP_CMP): Watch the change of the cached nodes
by `_list_changed'.
(FTC_CACHE_TRYLOOP_END): Take new macro argument `_list_changed'
and update it when FTC_Manager_FlushN() flushes any nodes.
* src/cache/ftccback.h (ftc_snode_compare): Updated to fit
with new FTC_Node_CompareFunc type. (ftc_gnode_compare): Ditto.
* src/cache/ftcbasic.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_basic_gnode_compare_faceid):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
* src/cache/ftccmap.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_cmap_node_compare):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
(ftc_cmap_node_remove_faceid): Ditto.
* src/cache/ftccache.c (FTC_Cache_NewNode): Pass a NULL
pointer to FTC_CACHE_TRYLOOP_END(), because the result is
not needed. (FTC_Cache_Lookup): Watch the change of the cache
nodes by `list_changed'. (FTC_Cache_RemoveFaceID): Ditto.
* src/cache/ftcglyph.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_gnode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway, it is always FALSE. (FTC_GNode_Compare):
New argument `FT_Bool* list_changed' to be passed to
ftc_gnode_compare().
* src/cache/ftcglyph.h (FTC_GNode_Compare): Ditto.
* src/cache/ftcsbits.c (ftc_snode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway. It is updated by FTC_CACHE_TRYLOOP().
(FTC_SNode_Compare): New argument `FT_Bool* list_changed'
to be passed to ftc_snode_compare().
* src/cache/ftcsbits.h (FTC_SNode_Compare): Ditto.
2011-01-09 14:49:07 +01:00
|
|
|
FTC_Cache cache,
|
|
|
|
FT_Bool* list_changed );
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
typedef void
|
|
|
|
(*FTC_Node_FreeFunc)( FTC_Node node,
|
|
|
|
FTC_Cache cache );
|
|
|
|
|
|
|
|
typedef FT_Error
|
|
|
|
(*FTC_Cache_InitFunc)( FTC_Cache cache );
|
|
|
|
|
|
|
|
typedef void
|
|
|
|
(*FTC_Cache_DoneFunc)( FTC_Cache cache );
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct FTC_CacheClassRec_
|
|
|
|
{
|
|
|
|
FTC_Node_NewFunc node_new;
|
|
|
|
FTC_Node_WeightFunc node_weight;
|
|
|
|
FTC_Node_CompareFunc node_compare;
|
|
|
|
FTC_Node_CompareFunc node_remove_faceid;
|
|
|
|
FTC_Node_FreeFunc node_free;
|
|
|
|
|
2009-07-31 17:32:10 +02:00
|
|
|
FT_Offset cache_size;
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Cache_InitFunc cache_init;
|
|
|
|
FTC_Cache_DoneFunc cache_done;
|
|
|
|
|
|
|
|
} FTC_CacheClassRec;
|
|
|
|
|
|
|
|
|
|
|
|
/* each cache really implements a dynamic hash table to manage its nodes */
|
|
|
|
typedef struct FTC_CacheRec_
|
|
|
|
{
|
|
|
|
FT_UFast p;
|
|
|
|
FT_UFast mask;
|
|
|
|
FT_Long slack;
|
|
|
|
FTC_Node* buckets;
|
|
|
|
|
|
|
|
FTC_CacheClassRec clazz; /* local copy, for speed */
|
|
|
|
|
|
|
|
FTC_Manager manager;
|
|
|
|
FT_Memory memory;
|
|
|
|
FT_UInt index; /* in manager's table */
|
|
|
|
|
|
|
|
FTC_CacheClass org_class; /* original class pointer */
|
|
|
|
|
|
|
|
} FTC_CacheRec;
|
|
|
|
|
|
|
|
|
|
|
|
#define FTC_CACHE( x ) ( (FTC_Cache)(x) )
|
|
|
|
#define FTC_CACHE_P( x ) ( (FTC_Cache*)(x) )
|
|
|
|
|
|
|
|
|
|
|
|
/* default cache initialize */
|
* 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
|
|
|
FT_LOCAL( FT_Error )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Cache_Init( FTC_Cache cache );
|
|
|
|
|
|
|
|
/* default cache finalizer */
|
* 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
|
|
|
FT_LOCAL( void )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Cache_Done( FTC_Cache cache );
|
|
|
|
|
2011-01-13 10:33:04 +01:00
|
|
|
/* Call this function to look up the cache. If no corresponding
|
2006-03-20 12:48:13 +01:00
|
|
|
* node is found, a new one is automatically created. This function
|
|
|
|
* is capable of flushing the cache adequately to make room for the
|
|
|
|
* new cache object.
|
|
|
|
*/
|
* 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
|
|
|
|
|
|
|
#ifndef FTC_INLINE
|
* 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
|
|
|
FT_LOCAL( FT_Error )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Cache_Lookup( FTC_Cache cache,
|
2015-02-23 08:20:27 +01:00
|
|
|
FT_Offset hash,
|
2006-03-20 12:48:13 +01:00
|
|
|
FT_Pointer query,
|
|
|
|
FTC_Node *anode );
|
* 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
|
|
|
#endif
|
2006-03-20 12:48:13 +01:00
|
|
|
|
* 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
|
|
|
FT_LOCAL( FT_Error )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Cache_NewNode( FTC_Cache cache,
|
2015-02-23 08:20:27 +01:00
|
|
|
FT_Offset hash,
|
2006-03-20 12:48:13 +01:00
|
|
|
FT_Pointer query,
|
|
|
|
FTC_Node *anode );
|
|
|
|
|
|
|
|
/* Remove all nodes that relate to a given face_id. This is useful
|
|
|
|
* when un-installing fonts. Note that if a cache node relates to
|
2011-01-13 10:33:04 +01:00
|
|
|
* the face_id but is locked (i.e., has `ref_count > 0'), the node
|
2006-03-20 12:48:13 +01:00
|
|
|
* will _not_ be destroyed, but its internal face_id reference will
|
|
|
|
* be modified.
|
|
|
|
*
|
|
|
|
* The final result will be that the node will never come back
|
|
|
|
* in further lookup requests, and will be flushed on demand from
|
|
|
|
* the cache normally when its reference count reaches 0.
|
|
|
|
*/
|
* 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
|
|
|
FT_LOCAL( void )
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Cache_RemoveFaceID( FTC_Cache cache,
|
|
|
|
FTC_FaceID face_id );
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef FTC_INLINE
|
|
|
|
|
|
|
|
#define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) \
|
|
|
|
FT_BEGIN_STMNT \
|
|
|
|
FTC_Node *_bucket, *_pnode, _node; \
|
|
|
|
FTC_Cache _cache = FTC_CACHE(cache); \
|
2015-02-23 08:20:27 +01:00
|
|
|
FT_Offset _hash = (FT_Offset)(hash); \
|
2006-03-20 12:48:13 +01:00
|
|
|
FTC_Node_CompareFunc _nodcomp = (FTC_Node_CompareFunc)(nodecmp); \
|
[cache] Notice if a cache query induced the node list change.
Some node comparators (comparing the cache node content and
the properties specified by the query) can flush the cache
node to prevent the cache inflation. The change may
invalidate the pointers to the node obtained before the node
comparison, so the change should be noticed to the caller.
The problem caused by the cache node changing is reported by
Harsha, see Savannah bug #31923.
* src/cache/ftccache.h (FTC_Node_CompareFunc): Add new
argument `FT_Bool* list_changed' to indicate the change of
the cached nodes to the caller.
(FTC_CACHE_LOOKUP_CMP): Watch the change of the cached nodes
by `_list_changed'.
(FTC_CACHE_TRYLOOP_END): Take new macro argument `_list_changed'
and update it when FTC_Manager_FlushN() flushes any nodes.
* src/cache/ftccback.h (ftc_snode_compare): Updated to fit
with new FTC_Node_CompareFunc type. (ftc_gnode_compare): Ditto.
* src/cache/ftcbasic.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_basic_gnode_compare_faceid):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
* src/cache/ftccmap.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_cmap_node_compare):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
(ftc_cmap_node_remove_faceid): Ditto.
* src/cache/ftccache.c (FTC_Cache_NewNode): Pass a NULL
pointer to FTC_CACHE_TRYLOOP_END(), because the result is
not needed. (FTC_Cache_Lookup): Watch the change of the cache
nodes by `list_changed'. (FTC_Cache_RemoveFaceID): Ditto.
* src/cache/ftcglyph.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_gnode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway, it is always FALSE. (FTC_GNode_Compare):
New argument `FT_Bool* list_changed' to be passed to
ftc_gnode_compare().
* src/cache/ftcglyph.h (FTC_GNode_Compare): Ditto.
* src/cache/ftcsbits.c (ftc_snode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway. It is updated by FTC_CACHE_TRYLOOP().
(FTC_SNode_Compare): New argument `FT_Bool* list_changed'
to be passed to ftc_snode_compare().
* src/cache/ftcsbits.h (FTC_SNode_Compare): Ditto.
2011-01-09 14:49:07 +01:00
|
|
|
FT_Bool _list_changed = FALSE; \
|
2006-03-20 12:48:13 +01:00
|
|
|
\
|
|
|
|
\
|
2013-03-14 11:21:17 +01:00
|
|
|
error = FT_Err_Ok; \
|
2006-03-20 12:48:13 +01:00
|
|
|
node = NULL; \
|
2011-01-09 15:09:36 +01:00
|
|
|
\
|
|
|
|
/* Go to the `top' node of the list sharing same masked hash */ \
|
2016-01-12 21:40:53 +01:00
|
|
|
_bucket = _pnode = FTC_NODE_TOP_FOR_HASH( _cache, _hash ); \
|
2006-03-20 12:48:13 +01:00
|
|
|
\
|
2011-01-13 10:33:04 +01:00
|
|
|
/* Look up a node with identical hash and queried properties. */ \
|
2011-01-09 15:09:36 +01:00
|
|
|
/* NOTE: _nodcomp() may change the linked list to reduce memory. */ \
|
2006-03-20 12:48:13 +01:00
|
|
|
for (;;) \
|
|
|
|
{ \
|
|
|
|
_node = *_pnode; \
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !_node ) \
|
2016-01-12 22:28:14 +01:00
|
|
|
goto NewNode_; \
|
2006-03-20 12:48:13 +01:00
|
|
|
\
|
[cache] Notice if a cache query induced the node list change.
Some node comparators (comparing the cache node content and
the properties specified by the query) can flush the cache
node to prevent the cache inflation. The change may
invalidate the pointers to the node obtained before the node
comparison, so the change should be noticed to the caller.
The problem caused by the cache node changing is reported by
Harsha, see Savannah bug #31923.
* src/cache/ftccache.h (FTC_Node_CompareFunc): Add new
argument `FT_Bool* list_changed' to indicate the change of
the cached nodes to the caller.
(FTC_CACHE_LOOKUP_CMP): Watch the change of the cached nodes
by `_list_changed'.
(FTC_CACHE_TRYLOOP_END): Take new macro argument `_list_changed'
and update it when FTC_Manager_FlushN() flushes any nodes.
* src/cache/ftccback.h (ftc_snode_compare): Updated to fit
with new FTC_Node_CompareFunc type. (ftc_gnode_compare): Ditto.
* src/cache/ftcbasic.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_basic_gnode_compare_faceid):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
* src/cache/ftccmap.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_cmap_node_compare):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
(ftc_cmap_node_remove_faceid): Ditto.
* src/cache/ftccache.c (FTC_Cache_NewNode): Pass a NULL
pointer to FTC_CACHE_TRYLOOP_END(), because the result is
not needed. (FTC_Cache_Lookup): Watch the change of the cache
nodes by `list_changed'. (FTC_Cache_RemoveFaceID): Ditto.
* src/cache/ftcglyph.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_gnode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway, it is always FALSE. (FTC_GNode_Compare):
New argument `FT_Bool* list_changed' to be passed to
ftc_gnode_compare().
* src/cache/ftcglyph.h (FTC_GNode_Compare): Ditto.
* src/cache/ftcsbits.c (ftc_snode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway. It is updated by FTC_CACHE_TRYLOOP().
(FTC_SNode_Compare): New argument `FT_Bool* list_changed'
to be passed to ftc_snode_compare().
* src/cache/ftcsbits.h (FTC_SNode_Compare): Ditto.
2011-01-09 14:49:07 +01:00
|
|
|
if ( _node->hash == _hash && \
|
|
|
|
_nodcomp( _node, query, _cache, &_list_changed ) ) \
|
2006-03-20 12:48:13 +01:00
|
|
|
break; \
|
|
|
|
\
|
|
|
|
_pnode = &_node->link; \
|
|
|
|
} \
|
|
|
|
\
|
2011-01-09 15:09:36 +01:00
|
|
|
if ( _list_changed ) \
|
|
|
|
{ \
|
|
|
|
/* Update _bucket by possibly modified linked list */ \
|
2016-01-12 21:40:53 +01:00
|
|
|
_bucket = _pnode = FTC_NODE_TOP_FOR_HASH( _cache, _hash ); \
|
2011-01-09 15:09:36 +01:00
|
|
|
\
|
|
|
|
/* Update _pnode by possibly modified linked list */ \
|
|
|
|
while ( *_pnode != _node ) \
|
|
|
|
{ \
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !*_pnode ) \
|
2011-01-09 15:09:36 +01:00
|
|
|
{ \
|
2011-01-13 10:33:04 +01:00
|
|
|
FT_ERROR(( "FTC_CACHE_LOOKUP_CMP: oops!!! node missing\n" )); \
|
2016-01-12 22:28:14 +01:00
|
|
|
goto NewNode_; \
|
2011-01-09 15:09:36 +01:00
|
|
|
} \
|
|
|
|
else \
|
2021-09-18 13:05:55 +02:00
|
|
|
_pnode = &(*_pnode)->link; \
|
2011-01-09 15:09:36 +01:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
/* Reorder the list to move the found node to the `top' */ \
|
2006-03-20 12:48:13 +01:00
|
|
|
if ( _node != *_bucket ) \
|
|
|
|
{ \
|
|
|
|
*_pnode = _node->link; \
|
|
|
|
_node->link = *_bucket; \
|
|
|
|
*_bucket = _node; \
|
|
|
|
} \
|
|
|
|
\
|
2011-01-09 15:09:36 +01:00
|
|
|
/* Update MRU list */ \
|
2006-03-20 12:48:13 +01:00
|
|
|
{ \
|
|
|
|
FTC_Manager _manager = _cache->manager; \
|
2007-05-16 17:19:42 +02:00
|
|
|
void* _nl = &_manager->nodes_list; \
|
2006-03-20 12:48:13 +01:00
|
|
|
\
|
|
|
|
\
|
|
|
|
if ( _node != _manager->nodes_list ) \
|
2007-05-16 17:19:42 +02:00
|
|
|
FTC_MruNode_Up( (FTC_MruNode*)_nl, \
|
2006-03-20 12:48:13 +01:00
|
|
|
(FTC_MruNode)_node ); \
|
|
|
|
} \
|
2016-01-12 22:28:14 +01:00
|
|
|
goto Ok_; \
|
2006-03-20 12:48:13 +01:00
|
|
|
\
|
2016-01-12 22:28:14 +01:00
|
|
|
NewNode_: \
|
2006-03-20 12:48:13 +01:00
|
|
|
error = FTC_Cache_NewNode( _cache, _hash, query, &_node ); \
|
|
|
|
\
|
2016-01-12 22:28:14 +01:00
|
|
|
Ok_: \
|
2009-07-29 11:53:13 +02:00
|
|
|
node = _node; \
|
2006-03-20 12:48:13 +01:00
|
|
|
FT_END_STMNT
|
|
|
|
|
|
|
|
#else /* !FTC_INLINE */
|
|
|
|
|
|
|
|
#define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) \
|
|
|
|
FT_BEGIN_STMNT \
|
|
|
|
error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query, \
|
|
|
|
(FTC_Node*)&(node) ); \
|
|
|
|
FT_END_STMNT
|
|
|
|
|
|
|
|
#endif /* !FTC_INLINE */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This macro, together with FTC_CACHE_TRYLOOP_END, defines a retry
|
|
|
|
* loop to flush the cache repeatedly in case of memory overflows.
|
|
|
|
*
|
|
|
|
* It is used when creating a new cache node, or within a lookup
|
2011-01-13 10:33:04 +01:00
|
|
|
* that needs to allocate data (e.g. the sbit cache lookup).
|
* 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
|
|
|
*
|
2006-03-20 12:48:13 +01:00
|
|
|
* Example:
|
|
|
|
*
|
2018-06-03 09:01:17 +02:00
|
|
|
* {
|
|
|
|
* FTC_CACHE_TRYLOOP( cache )
|
|
|
|
* error = load_data( ... );
|
|
|
|
* FTC_CACHE_TRYLOOP_END()
|
|
|
|
* }
|
2006-03-20 12:48:13 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define FTC_CACHE_TRYLOOP( cache ) \
|
|
|
|
{ \
|
|
|
|
FTC_Manager _try_manager = FTC_CACHE( cache )->manager; \
|
|
|
|
FT_UInt _try_count = 4; \
|
|
|
|
\
|
|
|
|
\
|
|
|
|
for (;;) \
|
|
|
|
{ \
|
|
|
|
FT_UInt _try_done;
|
|
|
|
|
|
|
|
|
[cache] Notice if a cache query induced the node list change.
Some node comparators (comparing the cache node content and
the properties specified by the query) can flush the cache
node to prevent the cache inflation. The change may
invalidate the pointers to the node obtained before the node
comparison, so the change should be noticed to the caller.
The problem caused by the cache node changing is reported by
Harsha, see Savannah bug #31923.
* src/cache/ftccache.h (FTC_Node_CompareFunc): Add new
argument `FT_Bool* list_changed' to indicate the change of
the cached nodes to the caller.
(FTC_CACHE_LOOKUP_CMP): Watch the change of the cached nodes
by `_list_changed'.
(FTC_CACHE_TRYLOOP_END): Take new macro argument `_list_changed'
and update it when FTC_Manager_FlushN() flushes any nodes.
* src/cache/ftccback.h (ftc_snode_compare): Updated to fit
with new FTC_Node_CompareFunc type. (ftc_gnode_compare): Ditto.
* src/cache/ftcbasic.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_basic_gnode_compare_faceid):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
* src/cache/ftccmap.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_cmap_node_compare):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
(ftc_cmap_node_remove_faceid): Ditto.
* src/cache/ftccache.c (FTC_Cache_NewNode): Pass a NULL
pointer to FTC_CACHE_TRYLOOP_END(), because the result is
not needed. (FTC_Cache_Lookup): Watch the change of the cache
nodes by `list_changed'. (FTC_Cache_RemoveFaceID): Ditto.
* src/cache/ftcglyph.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_gnode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway, it is always FALSE. (FTC_GNode_Compare):
New argument `FT_Bool* list_changed' to be passed to
ftc_gnode_compare().
* src/cache/ftcglyph.h (FTC_GNode_Compare): Ditto.
* src/cache/ftcsbits.c (ftc_snode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway. It is updated by FTC_CACHE_TRYLOOP().
(FTC_SNode_Compare): New argument `FT_Bool* list_changed'
to be passed to ftc_snode_compare().
* src/cache/ftcsbits.h (FTC_SNode_Compare): Ditto.
2011-01-09 14:49:07 +01:00
|
|
|
#define FTC_CACHE_TRYLOOP_END( list_changed ) \
|
2013-03-14 17:50:49 +01:00
|
|
|
if ( !error || FT_ERR_NEQ( error, Out_Of_Memory ) ) \
|
2006-03-20 12:48:13 +01:00
|
|
|
break; \
|
|
|
|
\
|
|
|
|
_try_done = FTC_Manager_FlushN( _try_manager, _try_count ); \
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( _try_done > 0 && list_changed != NULL ) \
|
[cache] Notice if a cache query induced the node list change.
Some node comparators (comparing the cache node content and
the properties specified by the query) can flush the cache
node to prevent the cache inflation. The change may
invalidate the pointers to the node obtained before the node
comparison, so the change should be noticed to the caller.
The problem caused by the cache node changing is reported by
Harsha, see Savannah bug #31923.
* src/cache/ftccache.h (FTC_Node_CompareFunc): Add new
argument `FT_Bool* list_changed' to indicate the change of
the cached nodes to the caller.
(FTC_CACHE_LOOKUP_CMP): Watch the change of the cached nodes
by `_list_changed'.
(FTC_CACHE_TRYLOOP_END): Take new macro argument `_list_changed'
and update it when FTC_Manager_FlushN() flushes any nodes.
* src/cache/ftccback.h (ftc_snode_compare): Updated to fit
with new FTC_Node_CompareFunc type. (ftc_gnode_compare): Ditto.
* src/cache/ftcbasic.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_basic_gnode_compare_faceid):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
* src/cache/ftccmap.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_cmap_node_compare):
New argument `FT_Bool* list_changed' to indicate the change
of the cache nodes, anyway, it is always FALSE.
(ftc_cmap_node_remove_faceid): Ditto.
* src/cache/ftccache.c (FTC_Cache_NewNode): Pass a NULL
pointer to FTC_CACHE_TRYLOOP_END(), because the result is
not needed. (FTC_Cache_Lookup): Watch the change of the cache
nodes by `list_changed'. (FTC_Cache_RemoveFaceID): Ditto.
* src/cache/ftcglyph.c: Include FT_INTERNAL_OBJECTS_H to
use TRUE/FALSE macros. (ftc_gnode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway, it is always FALSE. (FTC_GNode_Compare):
New argument `FT_Bool* list_changed' to be passed to
ftc_gnode_compare().
* src/cache/ftcglyph.h (FTC_GNode_Compare): Ditto.
* src/cache/ftcsbits.c (ftc_snode_compare): New argument
`FT_Bool* list_changed' to indicate the change of the cache
nodes, anyway. It is updated by FTC_CACHE_TRYLOOP().
(FTC_SNode_Compare): New argument `FT_Bool* list_changed'
to be passed to ftc_snode_compare().
* src/cache/ftcsbits.h (FTC_SNode_Compare): Ditto.
2011-01-09 14:49:07 +01:00
|
|
|
*(FT_Bool*)( list_changed ) = TRUE; \
|
|
|
|
\
|
2006-03-20 12:48:13 +01:00
|
|
|
if ( _try_done == 0 ) \
|
|
|
|
break; \
|
|
|
|
\
|
|
|
|
if ( _try_done == _try_count ) \
|
|
|
|
{ \
|
|
|
|
_try_count *= 2; \
|
|
|
|
if ( _try_count < _try_done || \
|
|
|
|
_try_count > _try_manager->num_nodes ) \
|
|
|
|
_try_count = _try_manager->num_nodes; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
|
|
|
FT_END_HEADER
|
|
|
|
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#endif /* FTCCACHE_H_ */
|
2006-03-20 12:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|