some updates to the cache sub-system. some methods were moved from
the concrete "FTC_Image_Cache" and "FTC_SBit_Cache" to the abstract "FTC_Glyph_Cache" and "FTC_Chunk_Cache", respectively.. note: this is not the end of changes to the cache sub-system
This commit is contained in:
parent
3a40847c60
commit
25dee217ab
50
include/freetype/cache/ftcchunk.h
vendored
50
include/freetype/cache/ftcchunk.h
vendored
@ -150,9 +150,10 @@
|
||||
/* the abstract chunk cache object */
|
||||
typedef struct FTC_Chunk_CacheRec_
|
||||
{
|
||||
FTC_CacheRec root;
|
||||
FT_Lru csets_lru; /* static chunk set lru list */
|
||||
FTC_ChunkSet last_cset; /* small cache :-) */
|
||||
FTC_CacheRec root;
|
||||
FT_Lru csets_lru; /* static chunk set lru list */
|
||||
FTC_ChunkSet last_cset; /* small cache :-) */
|
||||
FTC_ChunkSet_CompareFunc compare; /* useful shortcut */
|
||||
|
||||
} FTC_Chunk_CacheRec;
|
||||
|
||||
@ -176,22 +177,41 @@
|
||||
FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count--
|
||||
|
||||
|
||||
FT_EXPORT( void ) FTC_ChunkNode_Destroy( FTC_ChunkNode node );
|
||||
/* chunk set objects */
|
||||
|
||||
FT_EXPORT( FT_Error ) FTC_Chunk_Cache_Init( FTC_Chunk_Cache cache );
|
||||
|
||||
FT_EXPORT( void ) FTC_Chunk_Cache_Done( FTC_Chunk_Cache cache );
|
||||
FT_EXPORT( void )
|
||||
FTC_ChunkNode_Destroy( FTC_ChunkNode node );
|
||||
|
||||
|
||||
FT_EXPORT( FT_Error ) FTC_ChunkSet_New( FTC_Chunk_Cache cache,
|
||||
FT_Pointer type,
|
||||
FTC_ChunkSet *aset );
|
||||
FT_EXPORT( FT_Error )
|
||||
FTC_ChunkSet_New( FTC_Chunk_Cache cache,
|
||||
FT_Pointer type,
|
||||
FTC_ChunkSet *aset );
|
||||
|
||||
FT_EXPORT( FT_Error ) FTC_ChunkSet_Lookup_Node(
|
||||
FTC_ChunkSet cset,
|
||||
FT_UInt glyph_index,
|
||||
FTC_ChunkNode* anode,
|
||||
FT_UInt *anindex );
|
||||
|
||||
FT_EXPORT( FT_Error )
|
||||
FTC_ChunkSet_Lookup_Node( FTC_ChunkSet cset,
|
||||
FT_UInt glyph_index,
|
||||
FTC_ChunkNode* anode,
|
||||
FT_UInt *anindex );
|
||||
|
||||
|
||||
/* chunk cache objects */
|
||||
|
||||
FT_EXPORT( FT_Error )
|
||||
FTC_Chunk_Cache_Init( FTC_Chunk_Cache cache );
|
||||
|
||||
|
||||
FT_EXPORT( void )
|
||||
FTC_Chunk_Cache_Done( FTC_Chunk_Cache cache );
|
||||
|
||||
|
||||
FT_EXPORT( FT_Error )
|
||||
FTC_Chunk_Cache_Lookup( FTC_Chunk_Cache cache,
|
||||
FT_Pointer type,
|
||||
FT_UInt gindex,
|
||||
FTC_ChunkNode *anode,
|
||||
FT_UInt *aindex );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
12
include/freetype/cache/ftcglyph.h
vendored
12
include/freetype/cache/ftcglyph.h
vendored
@ -154,9 +154,10 @@
|
||||
/* the abstract glyph cache object */
|
||||
typedef struct FTC_Glyph_CacheRec_
|
||||
{
|
||||
FTC_CacheRec root;
|
||||
FT_Lru gsets_lru; /* static sets lru list */
|
||||
FTC_GlyphSet last_gset; /* small cache :-) */
|
||||
FTC_CacheRec root;
|
||||
FT_Lru gsets_lru; /* static sets lru list */
|
||||
FTC_GlyphSet last_gset; /* small cache :-) */
|
||||
FTC_GlyphSet_CompareFunc compare; /* useful shortcut */
|
||||
|
||||
} FTC_Glyph_CacheRec;
|
||||
|
||||
@ -196,6 +197,11 @@
|
||||
FT_UInt glyph_index,
|
||||
FTC_GlyphNode *anode );
|
||||
|
||||
FT_EXPORT( FT_Error ) FTC_Glyph_Cache_Lookup( FTC_Glyph_Cache cache,
|
||||
FT_Pointer type,
|
||||
FT_UInt gindex,
|
||||
FTC_GlyphNode *anode );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
63
src/cache/ftcchunk.c
vendored
63
src/cache/ftcchunk.c
vendored
@ -347,16 +347,22 @@
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error ) FTC_Chunk_Cache_Init( FTC_Chunk_Cache cache )
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FTC_Chunk_Cache_Init( FTC_Chunk_Cache cache )
|
||||
{
|
||||
FT_Memory memory = cache->root.memory;
|
||||
FT_Error error;
|
||||
|
||||
FTC_Chunk_Cache_Class* ccache_clazz;
|
||||
|
||||
/* set up root node_class to be used by manager */
|
||||
cache->root.node_clazz =
|
||||
(FTC_CacheNode_Class*)&ftc_chunk_cache_node_class;
|
||||
|
||||
/* setup "compare" shortcut */
|
||||
ccache_clazz = (FTC_Chunk_Cache_Class*)cache->root.clazz;
|
||||
cache->compare = ccache_clazz->cset_class->compare;
|
||||
|
||||
error = FT_Lru_New( &ftc_chunk_set_lru_class,
|
||||
FTC_MAX_CHUNK_SETS,
|
||||
cache,
|
||||
@ -367,11 +373,64 @@
|
||||
}
|
||||
|
||||
|
||||
FT_EXPORT_DEF( void ) FTC_Chunk_Cache_Done( FTC_Chunk_Cache cache )
|
||||
FT_EXPORT_DEF( void )
|
||||
FTC_Chunk_Cache_Done( FTC_Chunk_Cache cache )
|
||||
{
|
||||
/* discard glyph sets */
|
||||
FT_Lru_Done( cache->csets_lru );
|
||||
}
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FTC_Chunk_Cache_Lookup( FTC_Chunk_Cache cache,
|
||||
FT_Pointer type,
|
||||
FT_UInt gindex,
|
||||
FTC_ChunkNode *anode,
|
||||
FT_UInt *aindex )
|
||||
{
|
||||
FT_Error error;
|
||||
FTC_ChunkSet cset;
|
||||
FTC_ChunkNode node;
|
||||
FT_UInt cindex;
|
||||
FTC_Manager manager;
|
||||
|
||||
|
||||
/* check for valid `desc' delayed to FT_Lru_Lookup() */
|
||||
|
||||
if ( !cache || !anode || !aindex )
|
||||
return FT_Err_Invalid_Argument;
|
||||
|
||||
*anode = 0;
|
||||
*aindex = 0;
|
||||
cset = cache->last_cset;
|
||||
|
||||
if ( !cset || !cache->compare( cset, type ) )
|
||||
{
|
||||
error = FT_Lru_Lookup( cache->csets_lru,
|
||||
(FT_LruKey)type,
|
||||
(FT_Pointer*)&cset );
|
||||
cache->last_cset = cset;
|
||||
if ( error )
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
error = FTC_ChunkSet_Lookup_Node( cset, gindex, &node, &cindex );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
/* now compress the manager's cache pool if needed */
|
||||
manager = cache->root.manager;
|
||||
if ( manager->num_bytes > manager->max_bytes )
|
||||
{
|
||||
FTC_ChunkNode_Ref ( node );
|
||||
FTC_Manager_Compress( manager );
|
||||
FTC_ChunkNode_Unref ( node );
|
||||
}
|
||||
|
||||
*anode = node;
|
||||
*aindex = cindex;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
/* END */
|
||||
|
58
src/cache/ftcglyph.c
vendored
58
src/cache/ftcglyph.c
vendored
@ -377,16 +377,22 @@
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error ) FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache )
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache )
|
||||
{
|
||||
FT_Memory memory = cache->root.memory;
|
||||
FT_Error error;
|
||||
|
||||
FTC_Glyph_Cache_Class* gcache_clazz;
|
||||
|
||||
/* set up root node_class to be used by manager */
|
||||
cache->root.node_clazz =
|
||||
(FTC_CacheNode_Class*)&ftc_glyph_cache_node_class;
|
||||
|
||||
/* setup the "compare" shortcut */
|
||||
gcache_clazz = (FTC_Glyph_Cache_Class*)cache->root.clazz;
|
||||
cache->compare = gcache_clazz->gset_class->compare;
|
||||
|
||||
/* The following is extremely important for ftc_destroy_glyph_image() */
|
||||
/* to work properly, as the second parameter that is sent to it */
|
||||
/* through the cache manager is `cache_data' and must be set to */
|
||||
@ -404,11 +410,59 @@
|
||||
}
|
||||
|
||||
|
||||
FT_EXPORT_DEF( void ) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache )
|
||||
FT_EXPORT_DEF( void )
|
||||
FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache )
|
||||
{
|
||||
/* discard glyph sets */
|
||||
FT_Lru_Done( cache->gsets_lru );
|
||||
}
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FTC_Glyph_Cache_Lookup( FTC_Glyph_Cache cache,
|
||||
FT_Pointer type,
|
||||
FT_UInt gindex,
|
||||
FTC_GlyphNode *anode )
|
||||
{
|
||||
FT_Error error;
|
||||
FTC_GlyphSet gset;
|
||||
FTC_GlyphNode node;
|
||||
FTC_Manager manager;
|
||||
|
||||
/* check for valid `desc' delayed to FT_Lru_Lookup() */
|
||||
|
||||
if ( !cache || !anode )
|
||||
return FT_Err_Invalid_Argument;
|
||||
|
||||
*anode = 0;
|
||||
gset = cache->last_gset;
|
||||
if ( !gset || !cache->compare( gset, type ) )
|
||||
{
|
||||
error = FT_Lru_Lookup( cache->gsets_lru,
|
||||
(FT_LruKey)type,
|
||||
(FT_Pointer*)&gset );
|
||||
cache->last_gset = gset;
|
||||
if ( error )
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
error = FTC_GlyphSet_Lookup_Node( gset, gindex, &node );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
/* now compress the manager's cache pool if needed */
|
||||
manager = cache->root.manager;
|
||||
if ( manager->num_bytes > manager->max_bytes )
|
||||
{
|
||||
FTC_GlyphNode_Ref ( node );
|
||||
FTC_Manager_Compress( manager );
|
||||
FTC_GlyphNode_Unref ( node );
|
||||
}
|
||||
|
||||
*anode = node;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
/* END */
|
||||
|
44
src/cache/ftcimage.c
vendored
44
src/cache/ftcimage.c
vendored
@ -274,50 +274,22 @@
|
||||
FT_EXPORT( FT_Error ) FTC_Image_Cache_Lookup( FTC_Image_Cache cache,
|
||||
FTC_Image_Desc* desc,
|
||||
FT_UInt gindex,
|
||||
FT_Glyph* aglyph )
|
||||
FT_Glyph *aglyph )
|
||||
{
|
||||
FT_Error error;
|
||||
FTC_GlyphSet gset;
|
||||
FTC_GlyphNode node;
|
||||
FTC_Manager manager;
|
||||
|
||||
FTC_ImageSet img_set;
|
||||
/* some argument checks are delayed to FTC_Glyph_Cache_Lookup */
|
||||
|
||||
|
||||
/* check for valid `desc' delayed to FT_Lru_Lookup() */
|
||||
|
||||
if ( !cache || !aglyph )
|
||||
if (!aglyph)
|
||||
return FT_Err_Invalid_Argument;
|
||||
|
||||
*aglyph = 0;
|
||||
gset = cache->root.last_gset;
|
||||
img_set = (FTC_ImageSet)gset;
|
||||
if ( !gset || memcmp( &img_set->description, desc, sizeof ( *desc ) ) )
|
||||
{
|
||||
error = FT_Lru_Lookup( cache->root.gsets_lru,
|
||||
(FT_LruKey)desc,
|
||||
(FT_Pointer*)&gset );
|
||||
cache->root.last_gset = gset;
|
||||
if ( error )
|
||||
goto Exit;
|
||||
}
|
||||
error = FTC_Glyph_Cache_Lookup( (FTC_Glyph_Cache)cache,
|
||||
desc, gindex, &node );
|
||||
|
||||
if (!error)
|
||||
*aglyph = ((FTC_GlyphImage)node)->ft_glyph;
|
||||
|
||||
error = FTC_GlyphSet_Lookup_Node( gset, gindex, &node );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
/* now compress the manager's cache pool if needed */
|
||||
manager = cache->root.root.manager;
|
||||
if ( manager->num_bytes > manager->max_bytes )
|
||||
{
|
||||
FTC_GlyphNode_Ref ( node );
|
||||
FTC_Manager_Compress( manager );
|
||||
FTC_GlyphNode_Unref ( node );
|
||||
}
|
||||
|
||||
*aglyph = ((FTC_GlyphImage)node)->ft_glyph;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
51
src/cache/ftcsbits.c
vendored
51
src/cache/ftcsbits.c
vendored
@ -248,6 +248,7 @@
|
||||
|
||||
/* the node itself */
|
||||
size = sizeof ( *node );
|
||||
|
||||
/* the sbit records */
|
||||
size += cset->element_count * sizeof ( FTC_SBitRec );
|
||||
|
||||
@ -369,53 +370,21 @@
|
||||
FTC_SBit* asbit )
|
||||
{
|
||||
FT_Error error;
|
||||
FTC_ChunkSet cset;
|
||||
FTC_ChunkNode node;
|
||||
FT_UInt cindex;
|
||||
FTC_Manager manager;
|
||||
|
||||
FTC_SBitSet sset;
|
||||
FTC_SBit sbit;
|
||||
|
||||
|
||||
/* check for valid `desc' delayed to FT_Lru_Lookup() */
|
||||
|
||||
if ( !cache || !asbit )
|
||||
/* argument checks delayed to FTC_Chunk_Cache_Lookup */
|
||||
if (!asbit)
|
||||
return FT_Err_Invalid_Argument;
|
||||
|
||||
|
||||
*asbit = 0;
|
||||
cset = cache->root.last_cset;
|
||||
sset = (FTC_SBitSet)cset;
|
||||
|
||||
if ( !cset || memcmp( &sset->desc, desc, sizeof ( *desc ) ) )
|
||||
{
|
||||
error = FT_Lru_Lookup( cache->root.csets_lru,
|
||||
(FT_LruKey)desc,
|
||||
(FT_Pointer*)&cset );
|
||||
cache->root.last_cset = cset;
|
||||
if ( error )
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
error = FTC_ChunkSet_Lookup_Node( cset, gindex, &node, &cindex );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
/* now compress the manager's cache pool if needed */
|
||||
manager = cache->root.root.manager;
|
||||
if ( manager->num_bytes > manager->max_bytes )
|
||||
{
|
||||
FTC_ChunkNode_Ref ( node );
|
||||
FTC_Manager_Compress( manager );
|
||||
FTC_ChunkNode_Unref ( node );
|
||||
}
|
||||
|
||||
sbit = ((FTC_SBit)((FTC_ChunkNode)node)->elements) + cindex;
|
||||
*asbit = sbit;
|
||||
|
||||
Exit:
|
||||
error = FTC_Chunk_Cache_Lookup( &cache->root, desc, gindex,
|
||||
&node, &cindex );
|
||||
if (!error)
|
||||
*asbit = (FTC_SBit)node->elements + cindex;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* END */
|
||||
|
Loading…
Reference in New Issue
Block a user