misc/libfreetype/src/cache/ftccache.h
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftccache.h                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType internal cache interface (specification).                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010,   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*            2011 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#ifndef __FTCCACHE_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#define __FTCCACHE_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "ftcmru.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
FT_BEGIN_HEADER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#define _FTC_FACE_ID_HASH( i )                                                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
          ((FT_PtrDist)(( (FT_PtrDist)(i) >> 3 ) ^ ( (FT_PtrDist)(i) << 7 )))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* handle to cache object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  typedef struct FTC_CacheRec_*  FTC_Cache;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* handle to cache class */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  typedef const struct FTC_CacheClassRec_*  FTC_CacheClass;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*****                   CACHE NODE DEFINITIONS                      *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* Each cache controls one or more cache nodes.  Each node is part of    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /* the global_lru list of the manager.  Its `data' field however is used */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /* as a reference count for now.                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  /* A node can be anything, depending on the type of information held by  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /* the cache.  It can be an individual glyph image, a set of bitmaps     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  /* glyphs for a given size, some metrics, etc.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /* structure size should be 20 bytes on 32-bits machines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  typedef struct  FTC_NodeRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    FTC_MruNodeRec  mru;          /* circular mru list pointer           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    FTC_Node        link;         /* used for hashing                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    FT_PtrDist      hash;         /* used for hashing too                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    FT_UShort       cache_index;  /* index of cache the node belongs to  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    FT_Short        ref_count;    /* reference count for this node       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  } FTC_NodeRec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
#define FTC_NODE( x )    ( (FTC_Node)(x) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
#define FTC_NODE_P( x )  ( (FTC_Node*)(x) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
#define FTC_NODE__NEXT( x )  FTC_NODE( (x)->mru.next )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
#define FTC_NODE__PREV( x )  FTC_NODE( (x)->mru.prev )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
#ifdef FTC_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
#define FTC_NODE__TOP_FOR_HASH( cache, hash )                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
        ( ( cache )->buckets +                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
            ( ( ( ( hash ) &   ( cache )->mask ) < ( cache )->p ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
              ? ( ( hash ) & ( ( cache )->mask * 2 + 1 ) )        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
              : ( ( hash ) &   ( cache )->mask ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  FT_LOCAL( FTC_Node* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  ftc_get_top_node_for_hash( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
                             FT_PtrDist  hash );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
#define FTC_NODE__TOP_FOR_HASH( cache, hash )            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
        ftc_get_top_node_for_hash( ( cache ), ( hash ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  FT_BASE( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  ftc_node_destroy( FTC_Node     node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
                    FTC_Manager  manager );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  /*****                       CACHE DEFINITIONS                       *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  /* initialize a new cache node */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  typedef FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  (*FTC_Node_NewFunc)( FTC_Node    *pnode,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
                       FT_Pointer   query,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
                       FTC_Cache    cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  typedef FT_Offset
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  (*FTC_Node_WeightFunc)( FTC_Node   node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
                          FTC_Cache  cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  /* compare a node to a given key pair */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  typedef FT_Bool
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  (*FTC_Node_CompareFunc)( FTC_Node    node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
                           FT_Pointer  key,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
                           FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
                           FT_Bool*    list_changed );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  typedef void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  (*FTC_Node_FreeFunc)( FTC_Node   node,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
                        FTC_Cache  cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  typedef FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
  (*FTC_Cache_InitFunc)( FTC_Cache  cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  typedef void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
  (*FTC_Cache_DoneFunc)( FTC_Cache  cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  typedef struct  FTC_CacheClassRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    FTC_Node_NewFunc      node_new;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    FTC_Node_WeightFunc   node_weight;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    FTC_Node_CompareFunc  node_compare;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    FTC_Node_CompareFunc  node_remove_faceid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    FTC_Node_FreeFunc     node_free;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    FT_Offset             cache_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    FTC_Cache_InitFunc    cache_init;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    FTC_Cache_DoneFunc    cache_done;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  } FTC_CacheClassRec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  /* each cache really implements a dynamic hash table to manage its nodes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
  typedef struct  FTC_CacheRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    FT_UFast           p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    FT_UFast           mask;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    FT_Long            slack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    FTC_Node*          buckets;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    FTC_CacheClassRec  clazz;       /* local copy, for speed  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    FTC_Manager        manager;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    FT_Memory          memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    FT_UInt            index;       /* in manager's table     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    FTC_CacheClass     org_class;   /* original class pointer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  } FTC_CacheRec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
#define FTC_CACHE( x )    ( (FTC_Cache)(x) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
#define FTC_CACHE_P( x )  ( (FTC_Cache*)(x) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  /* default cache initialize */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  FTC_Cache_Init( FTC_Cache  cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
  /* default cache finalizer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
  FT_LOCAL( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
  FTC_Cache_Done( FTC_Cache  cache );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
  /* Call this function to look up the cache.  If no corresponding
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
   * node is found, a new one is automatically created.  This function
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
   * is capable of flushing the cache adequately to make room for the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
   * new cache object.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
#ifndef FTC_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  FTC_Cache_Lookup( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
                    FT_PtrDist  hash,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
                    FT_Pointer  query,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
                    FTC_Node   *anode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
  FT_LOCAL( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
  FTC_Cache_NewNode( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
                     FT_PtrDist  hash,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
                     FT_Pointer  query,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
                     FTC_Node   *anode );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
  /* Remove all nodes that relate to a given face_id.  This is useful
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
   * when un-installing fonts.  Note that if a cache node relates to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
   * the face_id but is locked (i.e., has `ref_count > 0'), the node
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
   * will _not_ be destroyed, but its internal face_id reference will
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
   * be modified.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
   * The final result will be that the node will never come back
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
   * in further lookup requests, and will be flushed on demand from
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
   * the cache normally when its reference count reaches 0.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  FT_LOCAL( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  FTC_Cache_RemoveFaceID( FTC_Cache   cache,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
                          FTC_FaceID  face_id );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
#ifdef FTC_INLINE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
#define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
  FT_BEGIN_STMNT                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    FTC_Node             *_bucket, *_pnode, _node;                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    FTC_Cache             _cache   = FTC_CACHE(cache);                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    FT_PtrDist            _hash    = (FT_PtrDist)(hash);                 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    FTC_Node_CompareFunc  _nodcomp = (FTC_Node_CompareFunc)(nodecmp);    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    FT_Bool               _list_changed = FALSE;                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
    error = FTC_Err_Ok;                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
    node  = NULL;                                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    /* Go to the `top' node of the list sharing same masked hash */      \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    _bucket = _pnode = FTC_NODE__TOP_FOR_HASH( _cache, _hash );          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    /* Look up a node with identical hash and queried properties.    */  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    /* NOTE: _nodcomp() may change the linked list to reduce memory. */  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    for (;;)                                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    {                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      _node = *_pnode;                                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      if ( _node == NULL )                                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        goto _NewNode;                                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      if ( _node->hash == _hash                             &&           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
           _nodcomp( _node, query, _cache, &_list_changed ) )            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
        break;                                                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
      _pnode = &_node->link;                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    }                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    if ( _list_changed )                                                 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    {                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
      /* Update _bucket by possibly modified linked list */              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
      _bucket = _pnode = FTC_NODE__TOP_FOR_HASH( _cache, _hash );        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
      /* Update _pnode by possibly modified linked list */               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      while ( *_pnode != _node )                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      {                                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
        if ( *_pnode == NULL )                                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
        {                                                                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
          FT_ERROR(( "FTC_CACHE_LOOKUP_CMP: oops!!! node missing\n" ));  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
          goto _NewNode;                                                 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
        }                                                                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
        else                                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
          _pnode = &((*_pnode)->link);                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      }                                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    }                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    /* Reorder the list to move the found node to the `top' */           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    if ( _node != *_bucket )                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    {                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
      *_pnode     = _node->link;                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
      _node->link = *_bucket;                                            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      *_bucket    = _node;                                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
    }                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    /* Update MRU list */                                                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    {                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      FTC_Manager  _manager = _cache->manager;                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
      void*        _nl      = &_manager->nodes_list;                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      if ( _node != _manager->nodes_list )                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
        FTC_MruNode_Up( (FTC_MruNode*)_nl,                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
                        (FTC_MruNode)_node );                            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    }                                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    goto _Ok;                                                            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
  _NewNode:                                                              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    error = FTC_Cache_NewNode( _cache, _hash, query, &_node );           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
                                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
  _Ok:                                                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    node = _node;                                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  FT_END_STMNT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
#else /* !FTC_INLINE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
#define FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
  FT_BEGIN_STMNT                                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    error = FTC_Cache_Lookup( FTC_CACHE( cache ), hash, query,           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
                              (FTC_Node*)&(node) );                      \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
  FT_END_STMNT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
#endif /* !FTC_INLINE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
   * This macro, together with FTC_CACHE_TRYLOOP_END, defines a retry
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
   * loop to flush the cache repeatedly in case of memory overflows.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
   * It is used when creating a new cache node, or within a lookup
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
   * that needs to allocate data (e.g. the sbit cache lookup).
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
   * Example:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
   *   {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
   *     FTC_CACHE_TRYLOOP( cache )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
   *       error = load_data( ... );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
   *     FTC_CACHE_TRYLOOP_END()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
   *   }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
#define FTC_CACHE_TRYLOOP( cache )                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  {                                                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    FTC_Manager  _try_manager = FTC_CACHE( cache )->manager; \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    FT_UInt      _try_count   = 4;                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
                                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
                                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    for (;;)                                                 \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    {                                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      FT_UInt  _try_done;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
#define FTC_CACHE_TRYLOOP_END( list_changed )                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      if ( !error || error != FTC_Err_Out_Of_Memory )             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
        break;                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
                                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      _try_done = FTC_Manager_FlushN( _try_manager, _try_count ); \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
      if ( _try_done > 0 && ( list_changed ) )                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
        *(FT_Bool*)( list_changed ) = TRUE;                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
                                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      if ( _try_done == 0 )                                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
        break;                                                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
                                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      if ( _try_done == _try_count )                              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
      {                                                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
        _try_count *= 2;                                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
        if ( _try_count < _try_done              ||               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
            _try_count > _try_manager->num_nodes )                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
          _try_count = _try_manager->num_nodes;                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      }                                                           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
    }                                                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
 /* */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
FT_END_HEADER
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
#endif /* __FTCCACHE_H__ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
/* END */