mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 12:35:48 -05:00
Render: only a measurement ages the canvas renderer's caches
Renderer::changed set the measuring flag before it compared anything, so comparing a document with itself still made the next finish_measurement_only sweep the paths of the last frame. The flag is now set where the diff measures an object through the renderer, in the Trim View check (children_blend caches the groups it reads), and when a change outside the layers redraws everything, so bounds kept for old symbol definitions still expire.
This commit is contained in:
1 parent
629ad05f3c
commit
e00a12ac60
2 files changed
+39
-2
No files matched your search
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<u8> {
|
||||
|
||||
Reference in new issue
Block a user