pub struct GlyphCache { /* private fields */ }Expand description
Glyph cache with LRU eviction.
Tracks a frame generation counter. Each get marks the glyph as used
in the current generation. evict_unused removes glyphs not used
for max_idle_frames generations and deallocates their atlas space.
Implementations§
Source§impl GlyphCache
impl GlyphCache
pub fn new() -> Self
Sourcepub fn advance_generation(&mut self)
pub fn advance_generation(&mut self)
Advance the frame generation counter. Call once per render frame.
pub fn generation(&self) -> u64
Sourcepub fn get(&mut self, key: &GlyphCacheKey) -> Option<&CachedGlyph>
pub fn get(&mut self, key: &GlyphCacheKey) -> Option<&CachedGlyph>
Look up a cached glyph, marking it as used in the current generation.
Sourcepub fn peek(&self, key: &GlyphCacheKey) -> Option<&CachedGlyph>
pub fn peek(&self, key: &GlyphCacheKey) -> Option<&CachedGlyph>
Look up without marking as used (for read-only queries).
pub fn insert(&mut self, key: GlyphCacheKey, glyph: CachedGlyph)
Sourcepub fn evict_unused(&mut self) -> Vec<AllocId>
pub fn evict_unused(&mut self) -> Vec<AllocId>
Evict glyphs unused for MAX_IDLE_FRAMES generations. Returns the AllocIds that should be deallocated from the atlas. Only runs the actual eviction scan every 60 calls (~1 second at 60fps) to avoid iterating the entire cache on every render.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn touch(&mut self, keys: &[GlyphCacheKey])
pub fn touch(&mut self, keys: &[GlyphCacheKey])
Mark multiple glyphs as used in the current generation without returning their data. Used by callers that cache glyph output externally (e.g. per-widget paint caches) and need to keep the glyphs alive in the atlas even though they don’t re-measure them every frame.