[Bf-blender-cvs] [cd1bb631592] master: BLF: Do Not Cache Unused Rendered Glyphs
Harley Acheson
noreply at git.blender.org
Wed Aug 11 22:57:17 CEST 2021
Commit: cd1bb63159215396662ce49c8bc8d6d437114093
Author: Harley Acheson
Date: Wed Aug 11 13:55:58 2021 -0700
Branches: master
https://developer.blender.org/rBcd1bb63159215396662ce49c8bc8d6d437114093
BLF: Do Not Cache Unused Rendered Glyphs
The loading of a font size or style renders bitmaps of the characters
0-255 and stores them in a cache. But glyphs 128-255 in this cache are
not accessible. What used to be ansi high-bit characters are now multi-
byte UTF-8 sequences.
Therefore this patch reduces the glyph_ascii_table size to 128 and
only caches characters 32-127, the visible portion of ASCII, which
greatly reduces the time to load a font.
See D12189 for more details.
Differential Revision: https://developer.blender.org/D12189
Reviewed by Campbell Barton
===================================================================
M source/blender/blenfont/intern/blf_font.c
M source/blender/blenfont/intern/blf_internal_types.h
===================================================================
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 6e2be4a8353..8e306730e3c 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -317,7 +317,8 @@ static GlyphBLF **blf_font_ensure_ascii_table(FontBLF *font, GlyphCacheBLF *gc)
/* build ascii on demand */
if (glyph_ascii_table['0'] == NULL) {
GlyphBLF *g;
- for (uint i = 0; i < 256; i++) {
+ /* Skip control characters and just cache rendered glyphs for visible ASCII range. */
+ for (uint i = 32; i < 128; i++) {
g = blf_glyph_search(gc, i);
if (!g) {
FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 36bb8769306..6816c97321d 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -71,7 +71,7 @@ typedef struct GlyphCacheBLF {
ListBase bucket[257];
/* fast ascii lookup */
- struct GlyphBLF *glyph_ascii_table[256];
+ struct GlyphBLF *glyph_ascii_table[128];
/* texture array, to draw the glyphs. */
GPUTexture *texture;
More information about the Bf-blender-cvs
mailing list