Page MenuHome

BLF: FreeType Optional Caching
ClosedPublic

Authored by Harley Acheson (harley) on Aug 13 2022, 8:10 PM.

Details

Summary

Implementation of the FreeType 2 cache subsystem, which limits the
number of concurrently-opened FT_Face and FT_Size objects, as well as
caching information like character maps to speed up glyph id lookups.
This time with the option of opening FontBLFs that are not cached.


Like D13137: BLF: Implement FreeType Caching, this patch implements the FreeType caching system. However, this time it allows the option of opening FontBLF objects that are not managed by the cache.

blf_font_new_ex is extended to allow the passing of a custom FT_Library object. If NULL it uses the global static object, is managed by the cache, and gets a new BLF_CACHED font flag. If you pass an FT_Library object it behaves as it does now, using non-cache code. It adds slight complication to support both caching and not, but it isn't too bad.

This time the maximum number of faces that the cache can keep open is set to four - since we normally have three in use in normal operation.

BLF_thumb_preview was an issue before because it creates as many simultaneous thumbnails as the number processor cores. Now it just uses a custom FT_Library and works threaded well with very few changes.

BLF_display_name_from_file could have been changed similarly, but I instead rewrote it so it does not use a FontBLF at all, just FreeType calls. Could be a separate patch though.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Aug 13 2022, 8:10 PM
Harley Acheson (harley) created this revision.
Harley Acheson (harley) edited the summary of this revision. (Show Details)Aug 13 2022, 8:15 PM

If you explicitly pass the global static FT_Library object, the font should still be cache-managed.

When caching, library locking has to be in blf_cache_face_requester, not around FTC_Manager_LookupFace, since the former can be called without a call to the latter.

Looks fine to me, just would put some of the reasoning from the description into code comments.

source/blender/blenfont/intern/blf.c
889–902

Add a comment like this to clarify the reason for the extra code:

/* Use own freetype library instance so that font thumbnails don't interfere with the font cache. */
source/blender/blenfont/intern/blf_thumbs.c
54–59

Expand comment to explain why it should not be managed by the cache.

This revision is now accepted and ready to land.Aug 15 2022, 2:05 PM
Harley Acheson (harley) marked 2 inline comments as done.Aug 16 2022, 11:54 PM

Updated to current state of master.
Improved and increased comments.

This revision was automatically updated to reflect the committed changes.