summaryrefslogtreecommitdiffstats
path: root/libass/ass_cache.c
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@blackbox>2009-07-11 02:18:51 +0200
committerGrigori Goronzy <greg@blackbox>2009-07-11 02:22:18 +0200
commit2c412cdab94a7bb27c5a1e04ab902295215de888 (patch)
treec1372ebf5e6473b287e152a40c88587f3470d237 /libass/ass_cache.c
parent613a22ab9b96453c10de6d75b43067652ad6d7db (diff)
downloadlibass-2c412cdab94a7bb27c5a1e04ab902295215de888.tar.bz2
libass-2c412cdab94a7bb27c5a1e04ab902295215de888.tar.xz
Message callback funtionality
Introduce functionality for providing a message callback that is used for passing messages to the controlling application instead of simply printing them to standard output. The function pointer to the callback is stored in the ass_library_t instance. ass_msg needs access to it, so in many places the library instance needs to be passed around now. The default behavior is the old one: messages of MSGL_INFO or lower are printed to the standard output, prefixed with "[ass]".
Diffstat (limited to 'libass/ass_cache.c')
-rw-r--r--libass/ass_cache.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c
index adee0cc..ed44a2f 100644
--- a/libass/ass_cache.c
+++ b/libass/ass_cache.c
@@ -51,12 +51,14 @@ static void hashmap_item_dtor(void *key, size_t key_size, void *value,
free(value);
}
-hashmap_t *hashmap_init(size_t key_size, size_t value_size, int nbuckets,
+hashmap_t *hashmap_init(ass_library_t *library, size_t key_size,
+ size_t value_size, int nbuckets,
hashmap_item_dtor_t item_dtor,
hashmap_key_compare_t key_compare,
hashmap_hash_t hash)
{
hashmap_t *map = calloc(1, sizeof(hashmap_t));
+ map->library = library;
map->nbuckets = nbuckets;
map->key_size = key_size;
map->value_size = value_size;
@@ -72,7 +74,7 @@ void hashmap_done(hashmap_t *map)
int i;
// print stats
if (map->count > 0 || map->hit_count + map->miss_count > 0)
- ass_msg(MSGL_V,
+ ass_msg(map->library, MSGL_V,
"cache statistics: \n total accesses: %d\n hits: %d\n "
"misses: %d\n object count: %d",
map->hit_count + map->miss_count, map->hit_count,
@@ -179,10 +181,10 @@ void *ass_font_cache_add(hashmap_t *font_cache, ass_font_t *font)
return hashmap_insert(font_cache, &(font->desc), font);
}
-hashmap_t *ass_font_cache_init(void)
+hashmap_t *ass_font_cache_init(ass_library_t *library)
{
hashmap_t *font_cache;
- font_cache = hashmap_init(sizeof(ass_font_desc_t),
+ font_cache = hashmap_init(library, sizeof(ass_font_desc_t),
sizeof(ass_font_t),
1000,
font_hash_dtor, font_compare, font_desc_hash);
@@ -235,10 +237,11 @@ bitmap_hash_val_t *cache_find_bitmap(hashmap_t *bitmap_cache,
return hashmap_find(bitmap_cache, key);
}
-hashmap_t *ass_bitmap_cache_init(void)
+hashmap_t *ass_bitmap_cache_init(ass_library_t *library)
{
hashmap_t *bitmap_cache;
- bitmap_cache = hashmap_init(sizeof(bitmap_hash_key_t),
+ bitmap_cache = hashmap_init(library,
+ sizeof(bitmap_hash_key_t),
sizeof(bitmap_hash_val_t),
0xFFFF + 13,
bitmap_hash_dtor, bitmap_compare,
@@ -253,8 +256,10 @@ void ass_bitmap_cache_done(hashmap_t *bitmap_cache)
hashmap_t *ass_bitmap_cache_reset(hashmap_t *bitmap_cache)
{
+ ass_library_t *lib = bitmap_cache->library;
+
ass_bitmap_cache_done(bitmap_cache);
- return ass_bitmap_cache_init();
+ return ass_bitmap_cache_init(lib);
}
//---------------------------------
@@ -289,10 +294,10 @@ glyph_hash_val_t *cache_find_glyph(hashmap_t *glyph_cache,
return hashmap_find(glyph_cache, key);
}
-hashmap_t *ass_glyph_cache_init(void)
+hashmap_t *ass_glyph_cache_init(ass_library_t *library)
{
hashmap_t *glyph_cache;
- glyph_cache = hashmap_init(sizeof(glyph_hash_key_t),
+ glyph_cache = hashmap_init(library, sizeof(glyph_hash_key_t),
sizeof(glyph_hash_val_t),
0xFFFF + 13,
glyph_hash_dtor, glyph_compare, glyph_hash);
@@ -306,8 +311,10 @@ void ass_glyph_cache_done(hashmap_t *glyph_cache)
hashmap_t *ass_glyph_cache_reset(hashmap_t *glyph_cache)
{
+ ass_library_t *lib = glyph_cache->library;
+
ass_glyph_cache_done(glyph_cache);
- return ass_glyph_cache_init();
+ return ass_glyph_cache_init(lib);
}
@@ -342,10 +349,10 @@ composite_hash_val_t *cache_find_composite(hashmap_t *composite_cache,
return hashmap_find(composite_cache, key);
}
-hashmap_t *ass_composite_cache_init(void)
+hashmap_t *ass_composite_cache_init(ass_library_t *library)
{
hashmap_t *composite_cache;
- composite_cache = hashmap_init(sizeof(composite_hash_key_t),
+ composite_cache = hashmap_init(library, sizeof(composite_hash_key_t),
sizeof(composite_hash_val_t),
0xFFFF + 13,
composite_hash_dtor, composite_compare,
@@ -360,6 +367,8 @@ void ass_composite_cache_done(hashmap_t *composite_cache)
hashmap_t *ass_composite_cache_reset(hashmap_t *composite_cache)
{
+ ass_library_t *lib = composite_cache->library;
+
ass_composite_cache_done(composite_cache);
- return ass_composite_cache_init();
+ return ass_composite_cache_init(lib);
}