Canvas redraw: the let-go test receives the worker's job; the fit cache's key documented

Review follow-ups:
- The test that art measured for an edit not drawn on this thread is let
  go first checks that measuring the edit through the canvas's renderer
  holds art, so a measure that held nothing can't pass it. Its worker is
  a test channel whose job the test receives, in place of a real thread's
  pending job, which a finished frame could clear. Taking out either
  let_go_of_measured fails it.
- fit_has_art's comment says why its one kept answer can't be stale: a
  document's uid is never reused in the process and its revision only
  moves forward.
This commit is contained in:
Drew Dibble
2026-11-09 13:19:55 -07:00
parent af754bcb23
commit d0b26c0772
2 changed files with 16 additions and 4 deletions
+12 -3
View File
@@ -10693,14 +10693,23 @@ fn art_measured_for_an_edit_not_drawn_here_is_let_go() {
app.run("effect.apply", json!({"effect": "threeD.extrude", "ids": [id], "params": {"depth": 60.0}})).unwrap();
let ctx = egui::Context::default();
shapes(&mut app, &ctx);
// A worker whose jobs the test receives: none finishes unless the test says so.
let mut jobs = None;
if worker {
app.canvas.worker = crate::render_worker::Worker::spawn(ctx.clone());
let (w, rx, done) = crate::render_worker::Worker::test_channel();
app.canvas.worker = Some(w);
jobs = Some((rx, done));
app.canvas.last_ms = 100.0;
}
app.run("effect.setParams", json!({"ids": [id], "index": 0, "item": null, "params": {"depth": 5.0}})).unwrap();
// Measured through the canvas's renderer, the edit holds the art made for it.
let (shown, opts) = app.canvas.shown.clone().unwrap();
let now = app.session.active().unwrap().doc.clone();
app.canvas.renderer.changed(&shown, &now, &opts);
assert!(app.canvas.renderer.measured_bytes() > 0, "worker {worker}: art held");
shapes(&mut app, &ctx);
if worker {
assert!(app.canvas.worker.as_ref().is_some_and(|w| w.pending.is_some()), "the worker draws it");
if let Some((rx, _)) = &jobs {
assert!(rx.try_recv().is_ok(), "the worker draws it");
}
assert_eq!(app.canvas.renderer.measured_bytes(), 0, "worker {worker}");
app.canvas.worker = None;
+4 -1
View File
@@ -314,7 +314,10 @@ pub struct MenuFacts {
/// Whether an unlocked artboard of `indices` has art that Fit to Artwork Bounds fits it to. The
/// answer is kept for the document's revision: the canvas menu asks on every frame it is open
/// without its [`MenuFacts`], and measuring builds the solids of 3D effects.
/// without its [`MenuFacts`], and measuring builds the solids of 3D effects. One answer is kept,
/// the last asked: a document's uid is never given to another in the process, and its revision
/// only moves forward (a document read again, or a batch rolled back, moves past it), so a kept
/// answer is never another document's or another state's.
pub(crate) fn fit_has_art(app: &VectorcraftApp, indices: &[usize]) -> bool {
/// The document's uid and revision, the artboards asked about, and the answer.
type Kept = Option<(u64, u64, Vec<usize>, bool)>;