diff options
author | greg <greg@blackbox> | 2009-06-18 14:09:35 +0200 |
---|---|---|
committer | greg <greg@blackbox> | 2009-06-19 05:17:22 +0200 |
commit | 2f59cd0e21b3f4a953b67525fa56b133d4d6b352 (patch) | |
tree | 14d1c2ebf7cb0aa2f147f13472d4536c3c34c908 /libass/ass_cache.c | |
parent | 3dcfa5a61e58068b38fb97477e8935550ca8c683 (diff) | |
download | libass-2f59cd0e21b3f4a953b67525fa56b133d4d6b352.tar.bz2 libass-2f59cd0e21b3f4a953b67525fa56b133d4d6b352.tar.xz |
Remove cache globals; move cache data into a separate cache_store struct
that is part of ass_renderer.
Diffstat (limited to 'libass/ass_cache.c')
-rw-r--r-- | libass/ass_cache.c | 86 |
1 files changed, 33 insertions, 53 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c index 2e941c0..69efa55 100644 --- a/libass/ass_cache.c +++ b/libass/ass_cache.c @@ -37,26 +37,6 @@ #include "ass_cache.h" -typedef struct hashmap_item_s { - void* key; - void* value; - struct hashmap_item_s* next; -} hashmap_item_t; -typedef hashmap_item_t* hashmap_item_p; - -struct hashmap_s { - int nbuckets; - size_t key_size, value_size; - hashmap_item_p* root; - hashmap_item_dtor_t item_dtor; // a destructor for hashmap key/value pairs - hashmap_key_compare_t key_compare; - hashmap_hash_t hash; - // stats - int hit_count; - int miss_count; - int count; -}; - #define FNV1_32A_INIT (unsigned)0x811c9dc5 static inline unsigned fnv_32a_buf(void* buf, size_t len, unsigned hval) @@ -171,8 +151,6 @@ void* hashmap_find(hashmap_t* map, void* key) //--------------------------------- // font cache -hashmap_t* font_cache; - static unsigned font_desc_hash(void* buf, size_t len) { ass_font_desc_t* desc = buf; @@ -203,7 +181,7 @@ static void font_hash_dtor(void* key, size_t key_size, void* value, size_t value free(key); } -ass_font_t* ass_font_cache_find(ass_font_desc_t* desc) +ass_font_t* ass_font_cache_find(hashmap_t* font_cache, ass_font_desc_t* desc) { return hashmap_find(font_cache, desc); } @@ -212,20 +190,22 @@ ass_font_t* ass_font_cache_find(ass_font_desc_t* desc) * \brief Add a face struct to cache. * \param font font struct */ -void* ass_font_cache_add(ass_font_t* font) +void* ass_font_cache_add(hashmap_t* font_cache, ass_font_t* font) { return hashmap_insert(font_cache, &(font->desc), font); } -void ass_font_cache_init(void) +hashmap_t* ass_font_cache_init(void) { + hashmap_t* font_cache; font_cache = hashmap_init(sizeof(ass_font_desc_t), sizeof(ass_font_t), 1000, font_hash_dtor, font_compare, font_desc_hash); + return font_cache; } -void ass_font_cache_done(void) +void ass_font_cache_done(hashmap_t* font_cache) { hashmap_done(font_cache); } @@ -240,8 +220,6 @@ void ass_font_cache_done(void) //--------------------------------- // bitmap cache -hashmap_t* bitmap_cache; - static void bitmap_hash_dtor(void* key, size_t key_size, void* value, size_t value_size) { bitmap_hash_val_t* v = value; @@ -252,7 +230,7 @@ static void bitmap_hash_dtor(void* key, size_t key_size, void* value, size_t val free(value); } -void* cache_add_bitmap(bitmap_hash_key_t* key, bitmap_hash_val_t* val) +void* cache_add_bitmap(hashmap_t* bitmap_cache, bitmap_hash_key_t* key, bitmap_hash_val_t* val) { return hashmap_insert(bitmap_cache, key, val); } @@ -262,36 +240,36 @@ void* cache_add_bitmap(bitmap_hash_key_t* key, bitmap_hash_val_t* val) * \param key hash key * \return requested hash val or 0 if not found */ -bitmap_hash_val_t* cache_find_bitmap(bitmap_hash_key_t* key) +bitmap_hash_val_t* cache_find_bitmap(hashmap_t* bitmap_cache, bitmap_hash_key_t* key) { return hashmap_find(bitmap_cache, key); } -void ass_bitmap_cache_init(void) +hashmap_t* ass_bitmap_cache_init(void) { + hashmap_t* bitmap_cache; bitmap_cache = hashmap_init(sizeof(bitmap_hash_key_t), sizeof(bitmap_hash_val_t), 0xFFFF + 13, bitmap_hash_dtor, bitmap_compare, bitmap_hash); + return bitmap_cache; } -void ass_bitmap_cache_done(void) +void ass_bitmap_cache_done(hashmap_t* bitmap_cache) { hashmap_done(bitmap_cache); } -void ass_bitmap_cache_reset(void) +hashmap_t* ass_bitmap_cache_reset(hashmap_t* bitmap_cache) { - ass_bitmap_cache_done(); - ass_bitmap_cache_init(); + ass_bitmap_cache_done(bitmap_cache); + return ass_bitmap_cache_init(); } //--------------------------------- // glyph cache -hashmap_t* glyph_cache; - static void glyph_hash_dtor(void* key, size_t key_size, void* value, size_t value_size) { glyph_hash_val_t* v = value; @@ -301,7 +279,7 @@ static void glyph_hash_dtor(void* key, size_t key_size, void* value, size_t valu free(value); } -void* cache_add_glyph(glyph_hash_key_t* key, glyph_hash_val_t* val) +void* cache_add_glyph(hashmap_t* glyph_cache, glyph_hash_key_t* key, glyph_hash_val_t* val) { return hashmap_insert(glyph_cache, key, val); } @@ -311,36 +289,36 @@ void* cache_add_glyph(glyph_hash_key_t* key, glyph_hash_val_t* val) * \param key hash key * \return requested hash val or 0 if not found */ -glyph_hash_val_t* cache_find_glyph(glyph_hash_key_t* key) +glyph_hash_val_t* cache_find_glyph(hashmap_t* glyph_cache, glyph_hash_key_t* key) { return hashmap_find(glyph_cache, key); } -void ass_glyph_cache_init(void) +hashmap_t* ass_glyph_cache_init(void) { + hashmap_t* glyph_cache; glyph_cache = hashmap_init(sizeof(glyph_hash_key_t), sizeof(glyph_hash_val_t), 0xFFFF + 13, glyph_hash_dtor, glyph_compare, glyph_hash); + return glyph_cache; } -void ass_glyph_cache_done(void) +void ass_glyph_cache_done(hashmap_t* glyph_cache) { hashmap_done(glyph_cache); } -void ass_glyph_cache_reset(void) +hashmap_t* ass_glyph_cache_reset(hashmap_t* glyph_cache) { - ass_glyph_cache_done(); - ass_glyph_cache_init(); + ass_glyph_cache_done(glyph_cache); + return ass_glyph_cache_init(); } //--------------------------------- // composite cache -hashmap_t* composite_cache; - static void composite_hash_dtor(void* key, size_t key_size, void* value, size_t value_size) { composite_hash_val_t* v = value; @@ -350,7 +328,7 @@ static void composite_hash_dtor(void* key, size_t key_size, void* value, size_t free(value); } -void* cache_add_composite(composite_hash_key_t* key, composite_hash_val_t* val) +void* cache_add_composite(hashmap_t* composite_cache, composite_hash_key_t* key, composite_hash_val_t* val) { return hashmap_insert(composite_cache, key, val); } @@ -360,27 +338,29 @@ void* cache_add_composite(composite_hash_key_t* key, composite_hash_val_t* val) * \param key hash key * \return requested hash val or 0 if not found */ -composite_hash_val_t* cache_find_composite(composite_hash_key_t* key) +composite_hash_val_t* cache_find_composite(hashmap_t* composite_cache, composite_hash_key_t* key) { return hashmap_find(composite_cache, key); } -void ass_composite_cache_init(void) +hashmap_t* ass_composite_cache_init(void) { + hashmap_t* composite_cache; composite_cache = hashmap_init(sizeof(composite_hash_key_t), sizeof(composite_hash_val_t), 0xFFFF + 13, composite_hash_dtor, NULL, NULL); + return composite_cache; } -void ass_composite_cache_done(void) +void ass_composite_cache_done(hashmap_t* composite_cache) { hashmap_done(composite_cache); } -void ass_composite_cache_reset(void) +hashmap_t* ass_composite_cache_reset(hashmap_t* composite_cache) { - ass_composite_cache_done(); - ass_composite_cache_init(); + ass_composite_cache_done(composite_cache); + return ass_composite_cache_init(); } |