]> granicus.if.org Git - libass/blob - libass/ass_cache.h
453cefac8d747c83834f464cbac1d0dabb553496
[libass] / libass / ass_cache.h
1 /*
2  * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3  * Copyright (C) 2011 Grigori Goronzy <greg@chown.ath.cx>
4  *
5  * This file is part of libass.
6  *
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.
10  *
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.
18  */
19
20 #ifndef LIBASS_CACHE_H
21 #define LIBASS_CACHE_H
22
23 #include "ass.h"
24 #include "ass_font.h"
25 #include "ass_outline.h"
26 #include "ass_bitmap.h"
27
28 typedef struct cache Cache;
29
30 // cache values
31
32 typedef struct {
33     bool valid;
34     Bitmap *bm;               // the actual bitmaps
35     Bitmap *bm_o;
36 } BitmapHashValue;
37
38 typedef struct {
39     Bitmap *bm;
40     Bitmap *bm_o;
41     Bitmap *bm_s;
42 } CompositeHashValue;
43
44 typedef struct {
45     bool valid;
46     ASS_Outline outline;
47     ASS_Outline border[2];
48     ASS_Rect bbox_scaled;       // bbox after scaling, but before rotation
49     int advance;                // 26.6, advance distance to the next outline in line
50     int asc, desc;              // ascender/descender
51 } OutlineHashValue;
52
53 typedef struct {
54     FT_Glyph_Metrics metrics;
55 } GlyphMetricsHashValue;
56
57 // Create definitions for bitmap, outline and composite hash keys
58 #define CREATE_STRUCT_DEFINITIONS
59 #include "ass_cache_template.h"
60
61 // Type-specific function pointers
62 typedef uint32_t (*HashFunction)(void *key, uint32_t hval);
63 typedef bool (*HashCompare)(void *a, void *b);
64 typedef bool (*CacheKeyMove)(void *dst, void *src);
65 typedef size_t (*CacheValueConstructor)(void *key, void *value, void *priv);
66 typedef void (*CacheItemDestructor)(void *key, void *value);
67
68 // cache hash keys
69
70 typedef struct outline_hash_key {
71     enum {
72         OUTLINE_GLYPH,
73         OUTLINE_DRAWING,
74     } type;
75     union {
76         GlyphHashKey glyph;
77         DrawingHashKey drawing;
78         OutlineCommonKey common;
79     } u;
80 } OutlineHashKey;
81
82 typedef struct bitmap_hash_key {
83     enum {
84         BITMAP_OUTLINE,
85         BITMAP_CLIP,
86     } type;
87     union {
88         OutlineBitmapHashKey outline;
89         ClipMaskHashKey clip;
90     } u;
91 } BitmapHashKey;
92
93 typedef struct {
94     BitmapHashValue *image;
95     int x, y;
96 } BitmapRef;
97
98 enum {
99     FILTER_BORDER_STYLE_3 = 1,
100     FILTER_NONZERO_BORDER = 2,
101     FILTER_NONZERO_SHADOW = 4,
102     FILTER_DRAW_SHADOW    = 8,  // VSFilter compatibility
103 };
104
105 typedef struct {
106     FilterDesc filter;
107     size_t bitmap_count;
108     BitmapRef *bitmaps;
109 } CompositeHashKey;
110
111 typedef struct
112 {
113     HashFunction hash_func;
114     HashCompare compare_func;
115     CacheKeyMove key_move_func;
116     CacheValueConstructor construct_func;
117     CacheItemDestructor destruct_func;
118     size_t key_size;
119     size_t value_size;
120 } CacheDesc;
121
122 Cache *ass_cache_create(const CacheDesc *desc);
123 void *ass_cache_get(Cache *cache, void *key, void *priv);
124 void *ass_cache_key(void *value);
125 void ass_cache_inc_ref(void *value);
126 void ass_cache_dec_ref(void *value);
127 void ass_cache_cut(Cache *cache, size_t max_size);
128 void ass_cache_stats(Cache *cache, size_t *size, unsigned *hits,
129                      unsigned *misses, unsigned *count);
130 void ass_cache_empty(Cache *cache);
131 void ass_cache_done(Cache *cache);
132 Cache *ass_font_cache_create(void);
133 Cache *ass_outline_cache_create(void);
134 Cache *ass_glyph_metrics_cache_create(void);
135 Cache *ass_bitmap_cache_create(void);
136 Cache *ass_composite_cache_create(void);
137
138 #endif                          /* LIBASS_CACHE_H */