From 209f30bee3121bbae32799b0bbb10f5e6db4158c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 11 Jan 2012 23:26:49 +0100 Subject: Hide glyph cache in context. --- draw/draw_device.c | 16 +++++++--------- draw/draw_glyph.c | 33 ++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 22 deletions(-) (limited to 'draw') diff --git a/draw/draw_device.c b/draw/draw_device.c index 07a2bb82..9a238b73 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -36,7 +36,6 @@ struct fz_draw_state_s { struct fz_draw_device_s { - fz_glyph_cache *cache; fz_gel *gel; fz_context *ctx; int flags; @@ -494,7 +493,7 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm, trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_glyph(dev->ctx, dev->cache, text->font, gid, trm, model); + glyph = fz_render_glyph(dev->ctx, text->font, gid, trm, model); if (glyph) { if (glyph->n == 1) @@ -553,7 +552,7 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_ trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_stroked_glyph(dev->ctx, dev->cache, text->font, gid, trm, ctm, stroke); + glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, trm, ctm, stroke); if (glyph) { draw_glyph(colorbv, state->dest, glyph, x, y, state->scissor); @@ -645,7 +644,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate) trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_glyph(dev->ctx, dev->cache, text->font, gid, trm, model); + glyph = fz_render_glyph(dev->ctx, text->font, gid, trm, model); if (glyph) { draw_glyph(NULL, mask, glyph, x, y, bbox); @@ -711,7 +710,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX); trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX); - glyph = fz_render_stroked_glyph(dev->ctx, dev->cache, text->font, gid, trm, ctm, stroke); + glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, trm, ctm, stroke); if (glyph) { draw_glyph(NULL, mask, glyph, x, y, bbox); @@ -1543,7 +1542,7 @@ fz_draw_free_user(fz_device *devp) } fz_device * -fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) +fz_new_draw_device(fz_context *ctx, fz_pixmap *dest) { fz_device *dev = NULL; fz_draw_device *ddev = fz_malloc_struct(ctx, fz_draw_device); @@ -1553,7 +1552,6 @@ fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) fz_var(dev); fz_try(ctx) { - ddev->cache = cache; ddev->gel = fz_new_gel(ctx); ddev->flags = 0; ddev->ctx = ctx; @@ -1609,9 +1607,9 @@ fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) } fz_device * -fz_new_draw_device_type3(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) +fz_new_draw_device_type3(fz_context *ctx, fz_pixmap *dest) { - fz_device *dev = fz_new_draw_device(ctx, cache, dest); + fz_device *dev = fz_new_draw_device(ctx, dest); fz_draw_device *ddev = dev->user; ddev->flags |= FZ_DRAWDEV_FLAGS_TYPE3; return dev; diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c index 6b83af74..ebda003e 100644 --- a/draw/draw_glyph.c +++ b/draw/draw_glyph.c @@ -21,8 +21,8 @@ struct fz_glyph_key_s unsigned char e, f; }; -fz_glyph_cache * -fz_new_glyph_cache(fz_context *ctx) +void +fz_new_glyph_cache_context(fz_context *ctx) { fz_glyph_cache *cache; @@ -38,12 +38,13 @@ fz_new_glyph_cache(fz_context *ctx) } cache->total = 0; - return cache; + ctx->glyph_cache = cache; } static void -fz_evict_glyph_cache(fz_context *ctx, fz_glyph_cache *cache) +fz_evict_glyph_cache(fz_context *ctx) { + fz_glyph_cache *cache = ctx->glyph_cache; fz_glyph_key *key; fz_pixmap *pixmap; int i; @@ -64,31 +65,37 @@ fz_evict_glyph_cache(fz_context *ctx, fz_glyph_cache *cache) } void -fz_free_glyph_cache(fz_context *ctx, fz_glyph_cache *cache) +fz_free_glyph_cache_context(fz_context *ctx) { - if (!cache) + if (!ctx->glyph_cache) return; - fz_evict_glyph_cache(ctx, cache); - fz_free_hash(cache->hash); - fz_free(ctx, cache); + fz_evict_glyph_cache(ctx); + fz_free_hash(ctx->glyph_cache->hash); + fz_free(ctx, ctx->glyph_cache); + ctx->glyph_cache = NULL; } fz_pixmap * -fz_render_stroked_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke) +fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke) { if (font->ft_face) return fz_render_ft_stroked_glyph(ctx, font, gid, trm, ctm, stroke); - return fz_render_glyph(ctx, cache, font, gid, trm, NULL); + return fz_render_glyph(ctx, font, gid, trm, NULL); } fz_pixmap * -fz_render_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model) +fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model) { + fz_glyph_cache *cache; fz_glyph_key key; fz_pixmap *val; float size = fz_matrix_expansion(ctm); + if (!ctx->glyph_cache) + fz_new_glyph_cache_context(ctx); + cache = ctx->glyph_cache; + if (size > MAX_FONT_SIZE) { /* TODO: this case should be handled by rendering glyph as a path fill */ @@ -132,7 +139,7 @@ fz_render_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, if (val->w < MAX_GLYPH_SIZE && val->h < MAX_GLYPH_SIZE) { if (cache->total + val->w * val->h > MAX_CACHE_SIZE) - fz_evict_glyph_cache(ctx, cache); + fz_evict_glyph_cache(ctx); fz_try(ctx) { fz_hash_insert(cache->hash, &key, val); -- cgit v1.2.3