Phase 4: prefetch upcoming images during playback

`assets_needed_at(document, time)` (core) enumerates the image asset ids referenced by
the visible vector layers' active keyframes at a time (top-level + group children).
During playback the stage decodes the images needed ~0.5s ahead into the bounded
ImageCache, so a keyframe that swaps image fills doesn't hitch when the playhead
reaches it. Gated on is_playing; nested clip-instance recursion + background decode
are refinements.

Completes Phase 4 (image asset paging: Tier 2 decoded-cache LRU, Tier 1 lazy bytes,
playback prefetch).
This commit is contained in:
Skyler Lehmkuhl
2026-06-21 01:12:37 -04:00
parent 3d0a334014
commit 0883c77e2b
2 changed files with 41 additions and 0 deletions
@@ -158,6 +158,28 @@ impl Default for ImageCache {
}
}
/// Image asset ids referenced by the visible vector layers' active keyframes at `time`
/// (top-level + group children). Used to prefetch/decode images ahead during playback.
/// (Recursing into nested clip instances is a refinement.)
pub fn assets_needed_at(document: &Document, time: f64) -> Vec<Uuid> {
let mut ids = Vec::new();
for layer in document.all_layers() {
if let crate::layer::AnyLayer::Vector(vl) = layer {
if !vl.layer.visible {
continue;
}
if let Some(kf) = vl.keyframe_at(time) {
for fill in &kf.graph.fills {
if let Some(id) = fill.image_fill {
ids.push(id);
}
}
}
}
}
ids
}
/// Decode image bytes to a premultiplied tiny-skia Pixmap (CPU render path).
fn decode_image_to_pixmap(data: &[u8]) -> Option<tiny_skia::Pixmap> {
let img = image::load_from_memory(data).ok()?;