diff --git a/crates/render/src/changed.rs b/crates/render/src/changed.rs index e7ab2c01ef..c0efa55a0b 100644 --- a/crates/render/src/changed.rs +++ b/crates/render/src/changed.rs @@ -96,16 +96,25 @@ impl crate::Renderer { /// renderer draws copies of the objects (`proof::prepare`), so they are measured afresh and /// nothing is held. pub fn changed(&mut self, old: &Document, new: &Document, opts: &crate::RenderOptions) -> Changed { - self.measuring = true; // Trim View clips each draw when blending reaches the page and clips one composited // layer otherwise. Changing modes can change unchanged art at an artboard edge. if opts.trim && !old.artboards.is_empty() { + // `children_blend` caches the groups it reads in `blends`, which holds their nodes, + // so this counts as a measurement for `finish_measurement_only`. + self.measuring = true; let before = crate::proof::prepare(old, opts, &mut self.proof_art); let after = crate::proof::prepare(new, opts, &mut self.proof_art); if self.children_blend(&before.layers) != self.children_blend(&after.layers) { return Changed::Everything; } } + // A change outside the layers (symbol definitions among them) redraws everything without + // measuring anything here; the caches still age so that bounds kept for the old + // definitions expire. + if new.pattern_edit.is_some() || !old.same_outside_layers(new) { + self.measuring = true; + return Changed::Everything; + } let renderer = (!crate::proof::overprints(opts)).then_some(self); changed_with(old, new, renderer, opts) } @@ -250,7 +259,11 @@ impl Diff<'_, '_> { Side::New => new, }; match renderer { - Some(r) => r.bounds_of(symbols, n), + Some(r) => { + // Only a measurement ages the renderer's caches in `finish_measurement_only`. + r.measuring = true; + r.bounds_of(symbols, n) + } None => crate::brush_fx::cull_bounds(symbols, n), } } diff --git a/crates/render/src/tests/memory.rs b/crates/render/src/tests/memory.rs index 2e890606bd..023a62bad3 100644 --- a/crates/render/src/tests/memory.rs +++ b/crates/render/src/tests/memory.rs @@ -58,6 +58,30 @@ fn finishing_without_a_measurement_keeps_the_drawn_paths() { assert!(renderer.geom.contains_key(&drawn), "frames that measured nothing keep the drawn path"); } +/// Comparing a document with itself measures nothing, so the frames that follow keep the paths +/// this renderer drew. +#[test] +fn an_unchanged_document_keeps_the_drawn_paths() { + let mut doc = Document::new(100.0, 100.0); + let layer = doc.layers[0].id; + let id = doc.alloc_id(); + let path = Node::path( + id, + vectorcraft_geom::shapes::rectangle(Rect::new(5.0, 10.0, 25.0, 30.0)), + vectorcraft_doc::Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0), + ); + doc.insert(Some(layer), 0, path).unwrap(); + let drawn = Arc::as_ptr(&doc.layers[0].children().unwrap()[0]) as usize; + let mut renderer = Renderer::new(); + let opts = RenderOptions::default(); + renderer.render(&doc, 100, 100, Affine::IDENTITY, &opts); + for _ in 0..4 { + assert!(matches!(renderer.changed(&doc, &doc, &opts), Changed::Nothing)); + renderer.finish_measurement_only(); + } + assert!(renderer.geom.contains_key(&drawn), "frames that measured nothing keep the drawn path"); +} + /// A `w`×`h` PNG whose pixels depend on `seed` (each test its own image: the store is shared by /// the tests running alongside). fn png(w: u32, h: u32, seed: u8) -> Vec {