Commit: 4dc0c923fb7f5c9c6f36ce0a63c1d19f241befa2
Author: Clément Foucault
Date:   Sat Mar 31 16:12:00 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB4dc0c923fb7f5c9c6f36ce0a63c1d19f241befa2

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.

===================================================================

M       source/blender/blenfont/intern/blf_font.c

===================================================================

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;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to