]> granicus.if.org Git - libass/blob - libass/ass_cache.h
Fix and simplify opaque box border
[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_bitmap.h"
26
27 typedef struct cache Cache;
28
29 // cache values
30
31 typedef struct {
32     Bitmap *bm;               // the actual bitmaps
33     Bitmap *bm_o;
34     Bitmap *bm_s;
35 } BitmapHashValue;
36
37 typedef struct {
38     unsigned char *a;
39     unsigned char *b;
40 } CompositeHashValue;
41
42 typedef struct {
43     FT_Library lib;
44     FT_Outline *outline;
45     FT_Outline *border;
46     FT_BBox bbox_scaled;        // bbox after scaling, but before rotation
47     FT_Vector advance;          // 26.6, advance distance to the next outline in line
48     int asc, desc;              // ascender/descender
49 } OutlineHashValue;
50
51 typedef struct {
52     FT_Glyph_Metrics metrics;
53 } GlyphMetricsHashValue;
54
55 // Create definitions for bitmap, outline and composite hash keys
56 #define CREATE_STRUCT_DEFINITIONS
57 #include "ass_cache_template.h"
58
59 // Type-specific function pointers
60 typedef unsigned(*HashFunction)(void *key, size_t key_size);
61 typedef size_t(*ItemSize)(void *value, size_t value_size);
62 typedef unsigned(*HashCompare)(void *a, void *b, size_t key_size);
63 typedef void(*CacheItemDestructor)(void *key, void *value);
64
65 // cache hash keys
66
67 typedef struct outline_hash_key {
68     enum {
69         OUTLINE_GLYPH,
70         OUTLINE_DRAWING,
71     } type;
72     union {
73         GlyphHashKey glyph;
74         DrawingHashKey drawing;
75     } u;
76 } OutlineHashKey;
77
78 typedef struct bitmap_hash_key {
79     enum {
80         BITMAP_OUTLINE,
81         BITMAP_CLIP,
82     } type;
83     union {
84         OutlineBitmapHashKey outline;
85         ClipMaskHashKey clip;
86     } u;
87 } BitmapHashKey;
88
89 Cache *ass_cache_create(HashFunction hash_func, HashCompare compare_func,
90                         CacheItemDestructor destruct_func, ItemSize size_func,
91                         size_t key_size, size_t value_size);
92 void *ass_cache_put(Cache *cache, void *key, void *value);
93 void *ass_cache_get(Cache *cache, void *key);
94 int ass_cache_empty(Cache *cache, size_t max_size);
95 void ass_cache_stats(Cache *cache, size_t *size, unsigned *hits,
96                      unsigned *misses, unsigned *count);
97 void ass_cache_done(Cache *cache);
98 Cache *ass_font_cache_create(void);
99 Cache *ass_outline_cache_create(void);
100 Cache *ass_glyph_metrics_cache_create(void);
101 Cache *ass_bitmap_cache_create(void);
102 Cache *ass_composite_cache_create(void);
103
104 #endif                          /* LIBASS_CACHE_H */