diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-03-31 17:12:00 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-03-31 20:32:53 +0300 |
commit | 4dc0c923fb7f5c9c6f36ce0a63c1d19f241befa2 (patch) | |
tree | f6fd7ddba3d09d6769a476f07642587f3337852f /source/blender | |
parent | f9691bae840a136ff0f55e8a99b42dd10f0fa8d8 (diff) |
BLF: Perf: Do not call FT_Set_Char_Size every time.
Using FT_Set_Char_Size is slow. Calling it only when needed is more clever.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 2c900e897ce..b029fbe5eeb 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -235,6 +235,14 @@ void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi) GlyphCacheBLF *gc; FT_Error err; + gc = blf_glyph_cache_find(font, size, dpi); + if (gc) { + font->glyph_cache = gc; + /* Optimization: do not call FT_Set_Char_Size if size did not change. */ + if (font->size == size && font->dpi == dpi) + return; + } + err = FT_Set_Char_Size(font->face, 0, (FT_F26Dot6)(size * 64), dpi, dpi); if (err) { /* FIXME: here we can go through the fixed size and choice a close one */ @@ -245,10 +253,7 @@ void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi) font->size = size; font->dpi = dpi; - gc = blf_glyph_cache_find(font, size, dpi); - if (gc) - font->glyph_cache = gc; - else { + if (!gc) { gc = blf_glyph_cache_new(font); if (gc) font->glyph_cache = gc; |