Effects: kept effect rasters of brushed strokes follow plug-ins used in brush art

The brush library now notes whether any brush art holds a plug-in
effect. Content with brushed strokes then reads the plug-ins installed,
so installing or removing a plug-in that brush art uses filters the
stroke's effect raster again instead of drawing the old pixels after a
pan.
This commit is contained in:
dotCooCoo committed 2026-12-05 06:39:15 -08:00
1 parent 9e49dbdd28
commit 545f6f97cf
4 files changed
+57 -3

No files matched your search

+9
View File
@@ -61,6 +61,8 @@ pub(crate) struct BrushCache {
/// (frame stamp, document address) the library was last validated for.
checked: (u64, usize),
lib: HashMap<String, Arc<Brush>>,
/// Whether brush art or an opacity mask there has a visible plug-in effect.
plugins: bool,
/// The names and art of the document's patterns and symbols ([`definitions`]) when the library
/// was last validated, the art held weakly as the pattern tiles hold theirs.
definitions: Vec<(String, Weak<Node>)>,
@@ -78,6 +80,7 @@ impl Default for BrushCache {
key: 0,
checked: (0, 0),
lib: HashMap::new(),
plugins: false,
definitions: Vec::new(),
entries: FrameCache::new(lru::BRUSH_BUDGET, 512),
#[cfg(test)]
@@ -113,6 +116,7 @@ impl BrushCache {
for b in vectorcraft_brush::library(doc) {
self.lib.entry(b.name.clone()).or_insert_with(|| Arc::new(b));
}
self.plugins = self.lib.values().any(|b| b.art().into_iter().any(crate::holds_plugin_effect));
}
/// [`Self::key`] for the brush library `doc` holds (checked once a frame, `stamp`).
@@ -121,6 +125,11 @@ impl BrushCache {
self.key
}
/// Whether brush art has a visible plug-in effect, valid after [`Self::library_key`] for the frame.
pub(crate) fn has_plugins(&self) -> bool {
self.plugins
}
/// [`Self::library_key`] checked now, between frames: `doc` may be the document of the last
/// frame, edited in place.
pub(crate) fn library_key_now(&mut self, doc: &Document, stamp: u64) -> u64 {
+2 -1
View File
@@ -238,7 +238,8 @@ pub(crate) struct Reads {
/// substitution highlights.
pub(super) text: bool,
/// Plug-in effects on its objects: the plug-ins installed. Those in the symbol and pattern art
/// it shows are found with the document's inputs ([`DocInputs`]).
/// it shows are found with the document's inputs ([`DocInputs`]). Those in brush art are found
/// with the brush library ([`crate::brush_fx::BrushCache`]).
pub(super) plugins: bool,
}
+3 -2
View File
@@ -611,7 +611,8 @@ impl Renderer {
/// hyphenation exceptions, whether overprinting shows ([`crate::proof::overprints`]) and
/// Document Setup's substitution highlights; and the plug-ins installed, with the names of the
/// document's swatches and patterns and its pattern definitions (a plug-in's painted pieces
/// can name them), when an object in it has a plug-in effect, and when it shows symbol or
/// can name them), when an object in the content has a plug-in effect, when it uses brushed
/// strokes and an object in the document's brush art has one, and when it shows symbol or
/// pattern art and an object in the document's symbol or pattern art has one.
pub(crate) fn raster_inputs(&mut self, f: &Frame, n: &Node, reads: Reads) -> Inputs {
let doc = self.doc_inputs(f.doc);
@@ -667,7 +668,7 @@ impl Renderer {
// Color bitmap glyphs are sampled as images are (`draw_glyph_image`).
(vectorcraft_text::layout_inputs(), crate::proof::overprints(f.opts), highlights, o.smooth_images).hash(&mut h);
}
if reads.plugins || (doc.plugins && (reads.symbols || reads.patterns)) {
if reads.plugins || (reads.brushes && self.brushes.has_plugins()) || (doc.plugins && (reads.symbols || reads.patterns)) {
(effects::plugin_revision(), doc.names, doc.patterns).hash(&mut h);
}
Inputs { reads, key: h.finish(), _doc: doc }
+43
View File
@@ -2181,6 +2181,49 @@ fn editing_a_symbol_in_brush_art_filters_a_brushed_strokes_raster_again_after_a_
assert!(pixels != unchanged, "the edited symbol changes the brush art through the effect");
}
/// Removing a plug-in used only in brush art filters a stroke again after a whole-pixel pan.
#[test]
fn removing_a_plugin_in_brush_art_filters_a_brushed_strokes_raster_again_after_a_pan() {
use vectorcraft_brush::{Brush, BrushKind, Colorization, Scatter};
use vectorcraft_geom::{PathData, SubPath};
use vectorcraft_plugins::wat as tpl;
let _fonts = fonts_steady();
const ID: &str = "test.render.fx.brush-art";
let triangle = PathData::single(SubPath::polyline(&[Point::new(-4.0, -4.0), Point::new(4.0, -4.0), Point::new(0.0, 4.0)], true));
let output = json!({"objects": [{"path": triangle}]}).to_string();
let module = wat::parse_str(tpl::returning(&tpl::manifest(ID, "effect", "{}"), &output)).unwrap();
vectorcraft_plugins::registry::install_bytes(&module).unwrap();
let mut d = Document::new(160.0, 100.0);
let mut r = Renderer::new();
let mut art =
Node::path(d.alloc_id(), shapes::rectangle(Rect::new(-4.0, -4.0, 4.0, 4.0)), Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0));
art.appearance.effects = vec![Effect { id: format!("plugin.{ID}"), params: json!({}), visible: true }];
vectorcraft_brush::store(
&mut d,
&[Brush { name: "Stamps".into(), kind: BrushKind::Scatter(Scatter { art, colorization: Colorization::None, ..Default::default() }) }],
);
let mut appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 2.0);
appearance.stroke_mut().unwrap().brush = Some("Stamps".into());
let mut n = Node::path(d.alloc_id(), shapes::line((20.0, 50.0).into(), (100.0, 50.0).into()), appearance);
n.appearance.effects = vec![Effect { id: "blur.gaussian".into(), params: json!({"radius": 1}), visible: true }];
let l = d.layers[0].id;
d.insert(Some(l), 0, n).unwrap();
let opts = RenderOptions { precise: true, background: Some([255, 255, 255, 255]), ..Default::default() };
let _ = r.render(&d, 160, 100, Affine::IDENTITY, &opts);
let kept = r.pixel_fx.values().next().unwrap();
assert!(kept.view.is_none(), "a raster of the whole object");
let image = kept.image.clone();
let view = Affine::translate((4.0, 0.0));
let unchanged = Renderer::new().render(&d, 160, 100, view, &opts).pixels;
assert!(vectorcraft_plugins::registry::remove(ID), "the plug-in was installed");
let pixels = r.render(&d, 160, 100, view, &opts).pixels;
assert!(!r.pixel_fx.values().any(|e| Arc::ptr_eq(&e.image, &image)), "removing the brush art's plug-in filters the content again");
assert!(pixels != unchanged, "the plug-in changes the brush art through the effect");
assert!(pixels == Renderer::new().render(&d, 160, 100, view, &opts).pixels, "removing the plug-in draws as a new renderer does");
}
/// Symbol editing leaves out the original instance inside a group's whole-object raster.
#[test]
fn symbol_editing_filters_the_whole_object_raster_again_after_a_pan() {