Skip to main content

GlyphCache

Struct GlyphCache 

Source
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

Source

pub fn new() -> Self

Source

pub fn advance_generation(&mut self)

Advance the frame generation counter. Call once per render frame.

Source

pub fn generation(&self) -> u64

Source

pub fn get(&mut self, key: &GlyphCacheKey) -> Option<&CachedGlyph>

Look up a cached glyph, marking it as used in the current generation.

Source

pub fn peek(&self, key: &GlyphCacheKey) -> Option<&CachedGlyph>

Look up without marking as used (for read-only queries).

Source

pub fn insert(&mut self, key: GlyphCacheKey, glyph: CachedGlyph)

Source

pub fn evict_unused(&mut self) -> Vec<EvictedGlyph>

Evict glyphs unused for MAX_IDLE_FRAMES generations. Returns the evicted entries — each carries the AllocId to deallocate from the atlas plus the atlas rectangle it occupied (the bucketed allocator cannot resolve a rectangle from an AllocId after the fact, so the rect is captured here, before the entry is dropped; debug builds use it to poison-fill the freed pixels). Only runs the actual eviction scan every 60 calls (~1 second at 60fps) to avoid iterating the entire cache on every render.

Source

pub fn evict_for_pressure(&mut self) -> Vec<EvictedGlyph>

Emergency eviction when the atlas is full: drop every glyph not used in the current generation, regardless of the idle window.

Unlike evict_unused this runs unconditionally (no every-60-generations gate) — it is only called when an allocation has already failed at the atlas size cap, where the alternative is silently dropping the new glyph. Glyphs touched this generation are still referenced by quads in the frame being built and must survive.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Trait Implementations§

Source§

impl Default for GlyphCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.