/**************************************************************************** * * ftccache.h * * FreeType internal cache interface (specification). * * Copyright (C) 2000-2023 by * 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. * */ #ifndef FTCCACHE_H_ #define FTCCACHE_H_ #include <freetype/internal/compiler-macros.h> #include "ftcmru.h" FT_BEGIN_HEADER #define FTC_FACE_ID_HASH( i ) … /* handle to cache object */ FTC_Cache; /* handle to cache class */ FTC_CacheClass; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CACHE NODE DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /************************************************************************** * * 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. * */ /* structure size should be 20 bytes on 32-bits machines */ FTC_NodeRec; #define FTC_NODE( x ) … #define FTC_NODE_P( x ) … #define FTC_NODE_NEXT( x ) … #define FTC_NODE_PREV( x ) … /* address the hash table entries */ #ifdef FTC_INLINE #define FTC_NODE_TOP_FOR_HASH( cache, hash ) … #else FT_LOCAL( FTC_Node* ) ftc_get_top_node_for_hash( FTC_Cache cache, FT_Offset hash ); #define FTC_NODE_TOP_FOR_HASH … #endif /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** CACHE DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ /* initialize a new cache node */ FTC_Node_NewFunc; FTC_Node_WeightFunc; /* compare a node to a given key pair */ FTC_Node_CompareFunc; FTC_Node_FreeFunc; FTC_Cache_InitFunc; FTC_Cache_DoneFunc; FTC_CacheClassRec; /* each cache really implements a hash table to manage its nodes */ /* the number of the table entries (buckets) can change dynamically */ /* each bucket contains a linked lists of nodes for a given hash */ FTC_CacheRec; #define FTC_CACHE( x ) … #define FTC_CACHE_P( x ) … /* default cache initialize */ FT_LOCAL( FT_Error ) FTC_Cache_Init( FTC_Cache cache ); /* default cache finalizer */ FT_LOCAL( void ) FTC_Cache_Done( FTC_Cache cache ); /* Call this function to look up the cache. If no corresponding * 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. */ #ifndef FTC_INLINE FT_LOCAL( FT_Error ) FTC_Cache_Lookup( FTC_Cache cache, FT_Offset hash, FT_Pointer query, FTC_Node *anode ); #endif FT_LOCAL( FT_Error ) FTC_Cache_NewNode( FTC_Cache cache, FT_Offset hash, 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 * the face_id but is locked (i.e., has `ref_count > 0'), the node * 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. */ FT_LOCAL( void ) FTC_Cache_RemoveFaceID( FTC_Cache cache, FTC_FaceID face_id ); #ifdef FTC_INLINE #define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) … #else /* !FTC_INLINE */ #define FTC_CACHE_LOOKUP_CMP … #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 * that needs to allocate data (e.g. the sbit cache lookup). * * Example: * * { * FTC_CACHE_TRYLOOP( cache ) * error = load_data( ... ); * FTC_CACHE_TRYLOOP_END() * } * */ #define FTC_CACHE_TRYLOOP( cache ) … #define FTC_CACHE_TRYLOOP_END( list_changed ) … /* */ FT_END_HEADER #endif /* FTCCACHE_H_ */ /* END */