Footage cache (#3271): a region of interest asks for rows only where the source reads rows

With a viewer region of interest the renderer asked a PNG still for some rows, which the media pool reads whole anyway, and the layer was left out of the layer cache: its masks and effects ran again on every render. FootageSource::reads_rows tells whether a source reads only the rows asked for (the media pool: an OpenEXR frame whose channels no effect reads); otherwise the renderer asks for the whole frame and the layer stays cached. A test renders a still twice under a region; it fails on the old code (two row reads instead of one whole read).
This commit is contained in:
vangel76 committed 2026-11-08 10:31:38 +01:00
1 parent 35788373cf
commit 74099e32bc
5 files changed
+76 -2

No files matched your search

+47
View File
@@ -140,3 +140,50 @@ fn exr_sequence_layers_are_cached_per_frame() {
assert_eq!(src.sizes.unwrap().into_inner().unwrap().len(), fetches, "{ext}");
}
}
/// #3271 review: with a viewer region of interest, a still from a source that reads whole frames
/// anyway (not by rows) is asked for whole and stays in the layer cache: a second render reads
/// nothing. A source that reads rows is asked for only the rows the region shows.
#[test]
fn a_source_that_reads_whole_frames_keeps_the_layer_cached_under_a_region() {
struct Counting {
reads: Mutex<Vec<Option<(i64, i64)>>>,
by_rows: bool,
}
impl FootageSource for Counting {
fn frame(&self, item: ItemId, f: &Footage, t: Tick) -> Option<Arc<Image>> {
self.reads.lock().unwrap().push(None);
Clip { sizes: None }.frame(item, f, t)
}
fn frame_rows(&self, item: ItemId, f: &Footage, t: Tick, _: Option<(u32, u32)>, _: crate::FloatCurve, rows: (i64, i64)) -> Option<Arc<Image>> {
self.reads.lock().unwrap().push(Some(rows));
Clip { sizes: None }.frame(item, f, t)
}
fn reads_rows(&self, _: &Footage, _: Tick) -> bool {
self.by_rows
}
}
let (mut p, cid) = project(BitDepth::Bpc8, false);
let Some(LayerSource::Footage { item }) = p.comp(cid).map(|c| c.layers[0].source.clone()) else { panic!("footage layer") };
if let Some(ItemKind::Footage(f)) = p.item_mut(item).map(|it| &mut it.kind) {
f.kind = FootageKind::Still;
f.path = "/still.png".into();
}
let opts = RenderOpts { roi: Some([0.0, 0.0, 96.0, 10.0]), ..Default::default() };
for by_rows in [false, true] {
let src = Counting { reads: Mutex::default(), by_rows };
let cache = crate::LayerCache::default();
for _ in 0..2 {
let mut r = Renderer::new(&p, &src, opts);
r.cache = Some(&cache);
r.comp_frame(cid, Tick::ZERO);
}
let reads = src.reads.into_inner().unwrap();
if by_rows {
assert_eq!(reads.len(), 2, "by rows, each render: {reads:?}");
assert!(reads.iter().all(|r| r.is_some_and(|(y0, y1)| y0 == 0 && y1 < 54)), "{reads:?}");
} else {
assert_eq!(reads, [None], "whole, once: the layer cache keeps it");
}
}
}