LRC-PRINT-GUIDES: the Print preview stops re-rendering thumbnails every frame

A thumbnail is kept at one size. The page preview asked for each cell's photo at the cell's size
on every frame, and the library grid behind the dialog asked for its own size, so the two replaced
each other's request: while the Print dialog was open a thumbnail render was always in flight and
about two render jobs were rebuilt per frame, keeping a core busy. The preview now uses the
photo's thumbnail when there is one and asks for one only when there is none.

Regression test: with the dialog open in Contact Sheet, Picture Package (the same photo in cells of
different sizes) and Single Image, the dialog settles, no render is in flight and no thumbnail job
is rebuilt over 60 idle frames. Before the fix the job count rose by about 100 every 50 frames.
The Print dialog's UI tests now finish in seconds (they were waiting out each settle timeout).
This commit is contained in:
Atmik Shetty
2026-10-12 15:39:08 +05:30
parent 65775b4716
commit 5cbaf64579
2 changed files with 30 additions and 2 deletions
+7 -2
View File
@@ -729,8 +729,13 @@ fn paint_cell(
}
let clip = painter.with_clip_rect(avail.intersect(painter.clip_rect()));
let tex = photo.and_then(|id| {
let px = (shown.width().max(shown.height()) * 2.0).clamp(64.0, 1024.0) as usize;
crate::panels::grid::request_thumb(app, id, px, 10);
// Use the library's thumbnail when there is one. A thumbnail is kept at one size, so asking
// for another size here every frame made the preview and the grid behind the dialog
// re-render each other's thumbnail for as long as the dialog stayed open.
if app.renderer.thumb(id).is_none() {
let px = (shown.width().max(shown.height()) * 2.0).clamp(64.0, 1024.0) as usize;
crate::panels::grid::request_thumb(app, id, px, 10);
}
app.renderer.thumb(id).map(|tex| tex.tex.id())
});
match tex {
+23
View File
@@ -298,3 +298,26 @@ fn the_print_dialog_fits_the_window_with_its_buttons_on_screen() {
}
}
}
#[test]
fn the_print_preview_does_not_rebuild_thumbnails_every_frame() {
let mut h = demo(Services { png: None, ..Default::default() });
let before = h.app.renderer.thumb_jobs_built;
cmd(&mut h, "dialog.print", json!({}));
for style in ["contactSheet", "picturePackage", "singleImage"] {
cmd(&mut h, "print.set", json!({"layout": {"style": style}}));
if style == "picturePackage" {
// the same photo in cells of different sizes
cmd(&mut h, "print.cell.add", json!({"width": 2.0, "height": 2.5}));
cmd(&mut h, "print.cell.add", json!({"width": 5.0, "height": 7.0}));
}
assert!(h.settle(Duration::from_secs(5)), "{style}: the dialog settles");
let built = h.app.renderer.thumb_jobs_built;
for _ in 0..60 {
h.step();
}
assert_eq!(h.app.renderer.thumb_jobs_built, built, "{style}: no thumbnail is rebuilt while nothing changes");
assert_eq!(h.app.renderer.in_flight(), 0, "{style}");
}
assert!(h.app.renderer.thumb_jobs_built - before < 50, "{} jobs", h.app.renderer.thumb_jobs_built - before);
}