pub struct ImageCache { /* private fields */ }Expand description
Caches decoded images to avoid re-decoding on every frame — keyed by
file path (or a content hash for byte sources). Wired for real in
Phase 27 (Image::paint previously did fs::read + PNG decode on
EVERY paint — the former Known-Issues “orphaned ImageCache” entry);
paint-time access goes through ImageCache::global.
Unbounded by design for now: it holds each distinct image an app ever shows, which is the same bound the old decode-per-paint had on peak memory. A byte budget + eviction is real follow-up work, tracked with the compositor’s image-texture eviction.
Implementations§
Source§impl ImageCache
impl ImageCache
Sourcepub fn global() -> &'static Mutex<ImageCache>
pub fn global() -> &'static Mutex<ImageCache>
The process-wide cache used by Image::paint — same global-service
pattern as the scroll-offset channel.
Sourcepub fn invalidate(&mut self, path: impl Into<PathBuf>)
pub fn invalidate(&mut self, path: impl Into<PathBuf>)
Drop the decode for a single path (the rest of the cache survives).
The dev asset watcher uses ImageCache::clear for a blanket flush;
this is the targeted variant for when only one asset changed.
Sourcepub fn get_or_load(&mut self, path: impl Into<PathBuf>) -> Option<DecodedImage>
pub fn get_or_load(&mut self, path: impl Into<PathBuf>) -> Option<DecodedImage>
Return the cached image for path, loading and decoding it on first
access. Returns None if the file cannot be read or decoded as PNG.
Sourcepub fn get_or_decode_bytes(&mut self, bytes: &[u8]) -> Option<DecodedImage>
pub fn get_or_decode_bytes(&mut self, bytes: &[u8]) -> Option<DecodedImage>
Decode-once for byte sources, keyed by a content hash (dims + len + sampled windows — same scheme as the compositor’s texture key).