From f9691bae840a136ff0f55e8a99b42dd10f0fa8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 31 Mar 2018 15:24:10 +0200 Subject: BLF: Perf: Add a kerning cache table for ascii chars. This adds less than a megabyte of mem usage. FT_Get_Kerning was the 2nd hotspot when profilling. This commit completly remove this cost. One concern though: I don't know if the kerning data is constant for every sizes but it seems to be the case. I tested different fonts at different dpi scalling and saw no differences. --- source/blender/blenfont/intern/blf_internal_types.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source/blender/blenfont/intern/blf_internal_types.h') diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index a954cf22370..a34541f62bf 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -49,6 +49,17 @@ typedef struct BatchBLF{ extern BatchBLF g_batch; +typedef struct KerningCacheBLF { + struct KerningCacheBLF *next, *prev; + + /* kerning mode. */ + FT_UInt mode; + + /* only cache a ascii glyph pairs. Only store the x + * offset we are interested in, instead of the full FT_Vector. */ + int table[0x80][0x80]; +} KerningCacheBLF; + typedef struct GlyphCacheBLF { struct GlyphCacheBLF *next; struct GlyphCacheBLF *prev; @@ -243,6 +254,12 @@ typedef struct FontBLF { /* current glyph cache, size and dpi. */ GlyphCacheBLF *glyph_cache; + /* list of kerning cache for this font. */ + ListBase kerning_caches; + + /* current kerning cache for this font and kerning mode. */ + KerningCacheBLF *kerning_cache; + /* freetype2 lib handle. */ FT_Library ft_lib; @@ -252,6 +269,9 @@ typedef struct FontBLF { /* freetype2 face. */ FT_Face face; + /* freetype kerning */ + FT_UInt kerning_mode; + /* data for buffer usage (drawing into a texture buffer) */ FontBufInfoBLF buf_info; } FontBLF; -- cgit v1.2.3