|
PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
|
#include <FontCache.h>
Public Member Functions | |
| TTF_Font * | GetFont (const FontCacheKey &key, const std::string &full_path) |
| void | ReleaseFont (const FontCacheKey &key) |
| void | GetStats (int &unique_fonts, int &total_refs, int &cache_hits, int &cache_misses) |
| void | PrintCache () |
| Print cache contents to stdout (for debugging) | |
Static Public Member Functions | |
| static FontCacheManager & | GetInstance () |
| Get singleton instance. | |
Singleton font cache manager Eliminates duplicate TTF_Font objects for fonts that differ only in color
Example: font_red = MakeFont("DejaVuSans.ttf", normal, 24, red, white) font_blue = MakeFont("DejaVuSans.ttf", normal, 24, blue, white)
Without cache: 2 separate TTF_Font objects (~66KB) With cache: 1 shared TTF_Font object (~33KB) - 50% memory savings
The cache automatically manages TTF_Font lifecycle via reference counting.
Definition at line 46 of file FontCache.h.
| TTF_Font * FontCache::FontCacheManager::GetFont | ( | const FontCacheKey & | key, |
| const std::string & | full_path | ||
| ) |
Get or create TTF_Font for given key
| key | Font cache key (filename, style, size) |
| full_path | Full filesystem path to font file |
If font already in cache, increments ref count and returns existing font. Otherwise, loads font from disk, adds to cache, and returns new font.
Definition at line 42 of file FontCache.cpp.
References FontCache::FontCacheKey::size, and FontCache::FontCacheKey::style.
Referenced by PlatformFont::PlatformFont(), PlatformFont::PlatformFont(), PlatformFont::SetFontSize(), and PlatformFont::SetFontStyle().
|
static |
Get singleton instance.
Definition at line 33 of file FontCache.cpp.
Referenced by PlatformFont::PlatformFont(), PlatformFont::PlatformFont(), PlatformFont::SetFontSize(), PlatformFont::SetFontStyle(), and PlatformFont::~PlatformFont().
| void FontCache::FontCacheManager::GetStats | ( | int & | unique_fonts, |
| int & | total_refs, | ||
| int & | cache_hits, | ||
| int & | cache_misses | ||
| ) |
Get cache statistics for debugging
| unique_fonts | Number of unique TTF_Font objects in cache |
| total_refs | Total reference count across all fonts |
| cache_hits | Number of cache hits since program start |
| cache_misses | Number of cache misses since program start |
Definition at line 119 of file FontCache.cpp.
| void FontCache::FontCacheManager::PrintCache | ( | ) |
Print cache contents to stdout (for debugging)
Definition at line 137 of file FontCache.cpp.
| void FontCache::FontCacheManager::ReleaseFont | ( | const FontCacheKey & | key | ) |
Release font reference
| key | Font cache key |
Decrements ref count. If ref count reaches 0, closes TTF_Font and removes from cache. Should be called from PlatformFont destructor.
Definition at line 79 of file FontCache.cpp.
References FontCache::FontCacheKey::filename, FontCache::FontCacheKey::size, and FontCache::FontCacheKey::style.
Referenced by PlatformFont::SetFontSize(), PlatformFont::SetFontStyle(), and PlatformFont::~PlatformFont().