Commit 25dee217abefb4d3ad7eb49219aa9b7c165db9b1

David Turner 2000-11-06T19:29:06

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
diff --git a/include/freetype/cache/ftcchunk.h b/include/freetype/cache/ftcchunk.h
index 3866659..9803995 100644
--- a/include/freetype/cache/ftcchunk.h
+++ b/include/freetype/cache/ftcchunk.h
@@ -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_ChunkNode_Destroy( FTC_ChunkNode    node );
 
-  FT_EXPORT( void )      FTC_Chunk_Cache_Done(  FTC_Chunk_Cache  cache );
 
+  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
diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h
index 2614c04..3dfed9d 100644
--- a/include/freetype/cache/ftcglyph.h
+++ b/include/freetype/cache/ftcglyph.h
@@ -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
   }
diff --git a/src/cache/ftcchunk.c b/src/cache/ftcchunk.c
index bbea828..a6a013e 100644
--- a/src/cache/ftcchunk.c
+++ b/src/cache/ftcchunk.c
@@ -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 */
diff --git a/src/cache/ftcglyph.c b/src/cache/ftcglyph.c
index a4a6ce7..503fc8e 100644
--- a/src/cache/ftcglyph.c
+++ b/src/cache/ftcglyph.c
@@ -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 */
diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c
index 1a52333..fd1880f 100644
--- a/src/cache/ftcimage.c
+++ b/src/cache/ftcimage.c
@@ -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_GlyphSet_Lookup_Node( gset, gindex, &node );
-    if ( error )
-      goto Exit;
+    error = FTC_Glyph_Cache_Lookup( (FTC_Glyph_Cache)cache,
+                                    desc, gindex, &node );
+                                    
+    if (!error)
+      *aglyph = ((FTC_GlyphImage)node)->ft_glyph;
 
-    /* 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;
   }
 
diff --git a/src/cache/ftcsbits.c b/src/cache/ftcsbits.c
index 0899089..83fbf34 100644
--- a/src/cache/ftcsbits.c
+++ b/src/cache/ftcsbits.c
@@ -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 */