cache: unified outline cache for glyphs/drawings
[libass.git] / libass / ass_cache.h
blob0ad7cae2c0f847b7c030d04e2e75b1413d50dcbf
1 /*
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3 * Copyright (C) 2011 Grigori Goronzy <greg@chown.ath.cx>
5 * This file is part of libass.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #ifndef LIBASS_CACHE_H
21 #define LIBASS_CACHE_H
23 #include "ass.h"
24 #include "ass_font.h"
25 #include "ass_bitmap.h"
27 typedef struct cache Cache;
29 // Create definitions for bitmap, outline and composite hash keys
30 #define CREATE_STRUCT_DEFINITIONS
31 #include "ass_cache_template.h"
33 // Type-specific function pointers
34 typedef unsigned(*HashFunction)(void *key, size_t key_size);
35 typedef size_t(*ItemSize)(void *value, size_t value_size);
36 typedef unsigned(*HashCompare)(void *a, void *b, size_t key_size);
37 typedef void(*CacheItemDestructor)(void *key, void *value);
39 // cache hash keys
41 typedef struct outline_hash_key {
42 enum {
43 OUTLINE_GLYPH,
44 OUTLINE_DRAWING,
45 } type;
46 union {
47 GlyphHashKey glyph;
48 DrawingHashKey drawing;
49 } u;
50 } OutlineHashKey;
52 // cache values
54 typedef struct {
55 Bitmap *bm; // the actual bitmaps
56 Bitmap *bm_o;
57 Bitmap *bm_s;
58 } BitmapHashValue;
60 typedef struct {
61 unsigned char *a;
62 unsigned char *b;
63 } CompositeHashValue;
65 typedef struct {
66 FT_Library lib;
67 FT_Outline *outline;
68 FT_Outline *border;
69 FT_BBox bbox_scaled; // bbox after scaling, but before rotation
70 FT_Vector advance; // 26.6, advance distance to the next outline in line
71 int asc, desc; // ascender/descender
72 } OutlineHashValue;
74 Cache *ass_cache_create(HashFunction hash_func, HashCompare compare_func,
75 CacheItemDestructor destruct_func, ItemSize size_func,
76 size_t key_size, size_t value_size);
77 void *ass_cache_put(Cache *cache, void *key, void *value);
78 void *ass_cache_get(Cache *cache, void *key);
79 size_t ass_cache_empty(Cache *cache, size_t max_size);
80 void ass_cache_stats(Cache *cache, size_t *size, unsigned *hits,
81 unsigned *misses, unsigned *count);
82 void ass_cache_done(Cache *cache);
83 Cache *ass_font_cache_create(void);
84 Cache *ass_outline_cache_create(void);
85 Cache *ass_bitmap_cache_create(void);
86 Cache *ass_composite_cache_create(void);
88 #endif /* LIBASS_CACHE_H */