summaryrefslogtreecommitdiffstats
path: root/libass/ass_shaper.c
diff options
context:
space:
mode:
authorDr.Smile <vabnick@gmail.com>2015-09-15 20:18:17 +0300
committerDr.Smile <vabnick@gmail.com>2016-06-30 23:13:53 +0300
commit25d65abce1a0fabe3c3bf81f1ee7ee7f24b91a4e (patch)
treea5d82da3707fcf2801a960fbea70ccfca4052469 /libass/ass_shaper.c
parent7d05b1d3b8d08672bd7297516514396d1d1a846f (diff)
downloadlibass-25d65abce1a0fabe3c3bf81f1ee7ee7f24b91a4e.tar.bz2
libass-25d65abce1a0fabe3c3bf81f1ee7ee7f24b91a4e.tar.xz
cache: switch to gradual cache clearing
Advantages over the old algorithm consist of the following. * There are no glitches due to full cache clearing. Items are arranged into linked list ordered by time of last use. Only the oldest items get deleted at the clearing event. * Each item now keeps track of number of references. Referenced cache values are immune to clearing. * Reduced amount of total cache memory for the same performance. * Reduced number of memory allocations per cache item.
Diffstat (limited to 'libass/ass_shaper.c')
-rw-r--r--libass/ass_shaper.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
index fa50982..95ffda3 100644
--- a/libass/ass_shaper.c
+++ b/libass/ass_shaper.c
@@ -207,26 +207,25 @@ get_cached_metrics(struct ass_shaper_metrics_data *metrics, FT_Face face,
hb_codepoint_t unicode, hb_codepoint_t glyph)
{
GlyphMetricsHashValue *val;
-
metrics->hash_key.glyph_index = glyph;
- val = ass_cache_get(metrics->metrics_cache, &metrics->hash_key);
-
- if (!val) {
+ if (!ass_cache_get(metrics->metrics_cache, &metrics->hash_key, &val)) {
int load_flags = FT_LOAD_DEFAULT | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
| FT_LOAD_IGNORE_TRANSFORM;
- GlyphMetricsHashValue new_val;
- if (FT_Load_Glyph(face, glyph, load_flags))
+ if (FT_Load_Glyph(face, glyph, load_flags)) {
+ ass_cache_cancel(val);
return NULL;
+ }
- memcpy(&new_val.metrics, &face->glyph->metrics, sizeof(FT_Glyph_Metrics));
+ memcpy(&val->metrics, &face->glyph->metrics, sizeof(FT_Glyph_Metrics));
// if @font rendering is enabled and the glyph should be rotated,
// make cached_h_advance pick up the right advance later
if (metrics->vertical && unicode >= VERTICAL_LOWER_BOUND)
- new_val.metrics.horiAdvance = new_val.metrics.vertAdvance;
+ val->metrics.horiAdvance = val->metrics.vertAdvance;
- val = ass_cache_put(metrics->metrics_cache, &metrics->hash_key, &new_val);
+ ass_cache_inc_ref(metrics->hash_key.font);
+ ass_cache_commit(val);
}
return val;