diff --git a/vello_gpu/src/scene.rs b/vello_gpu/src/scene.rs index 5f7a4fb02..10108b121 100644 --- a/vello_gpu/src/scene.rs +++ b/vello_gpu/src/scene.rs @@ -219,8 +219,6 @@ pub struct Scene { pub(crate) aliasing_threshold: Option, /// Storage for encoded non-solid paint data. pub(crate) encoded_paints: Vec, - /// Whether the current paint is visible (e.g., alpha > 0). - paint_visible: bool, /// Storage for generated strips and alpha values. pub(crate) strip_storage: RefCell, /// Current filter effect applied to individual draw operations. @@ -249,7 +247,6 @@ impl Scene { root_transforms: RootTransforms::default(), aliasing_threshold: None, encoded_paints: vec![], - paint_visible: true, strip_storage: RefCell::new(StripStorage::new(GenerationMode::Append)), filter: None, recorder: CommandRecorder::new(width, height), @@ -317,9 +314,7 @@ impl Scene { /// Whether drawing with the current paint can produce any pixels. fn paint_has_area(&self) -> bool { - self.paint_visible - && (matches!(self.render_state.paint, PaintType::Solid(_)) - || self.paint_transform_has_area()) + matches!(self.render_state.paint, PaintType::Solid(_)) || self.paint_transform_has_area() } /// Fill a path with the current paint and fill rule. @@ -559,7 +554,7 @@ impl Scene { std_dev: f32, invert: bool, ) { - if !self.paint_visible || !self.paint_transform_has_area() { + if !self.paint_transform_has_area() { return; } @@ -777,14 +772,6 @@ impl Scene { // render time into a texture usable by the renderer backend. pub fn set_paint(&mut self, paint: impl Into) { self.render_state.paint = paint.into(); - self.set_paint_visible(); - } - - fn set_paint_visible(&mut self) { - self.paint_visible = match &self.render_state.paint { - PaintType::Solid(color) => color.components[3] != 0.0, - _ => true, - }; } /// Set the tint for subsequent image paint operations. @@ -878,8 +865,6 @@ impl Scene { self.root_transforms.reset(); self.render_state.reset(); self.aliasing_threshold = None; - self.set_paint_visible(); - self.recorder.reset(self.width, self.height); self.filter = None; } @@ -896,10 +881,7 @@ impl Scene { /// Take current rendering state and reset the existing state to its default. pub fn take_current_state(&mut self) -> RenderState { - let state = core::mem::take(&mut self.render_state); - self.set_paint_visible(); - - state + core::mem::take(&mut self.render_state) } /// Save a copy of the current rendering state. @@ -910,7 +892,6 @@ impl Scene { /// Restore rendering state. pub fn restore_state(&mut self, state: RenderState) { self.render_state = state; - self.set_paint_visible(); } } @@ -928,7 +909,7 @@ mod tests { use vello_common::kurbo::{BezPath, Rect}; use vello_common::paint::{Image, ImageSource, Paint, PremulColor}; use vello_common::peniko::ImageSampler; - use vello_common::peniko::color::palette::css::{BLUE, TRANSPARENT}; + use vello_common::peniko::color::palette::css::BLUE; #[cfg(feature = "text")] use vello_common::peniko::{Blob, FontData}; use vello_common::record::Drawable; @@ -958,17 +939,6 @@ mod tests { assert!(scene.strip_storage.borrow().strips.is_empty()); } - #[test] - fn reset_restores_default_paint_visibility() { - let mut scene = Scene::new(100, 100); - scene.set_paint(TRANSPARENT); - - scene.reset(); - scene.fill_rect(&Rect::new(0.0, 0.0, 10.0, 10.0)); - - assert_eq!(scene.recorder.draws.len(), 1); - } - #[test] fn reset_restores_default_aliasing_threshold() { let mut scene = Scene::new(4, 4); diff --git a/vello_tests/snapshots/filter_flood_transparent_paint.png b/vello_tests/snapshots/filter_flood_transparent_paint.png new file mode 100644 index 000000000..c66d9f923 --- /dev/null +++ b/vello_tests/snapshots/filter_flood_transparent_paint.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c09ccf697bceeb468aa0fcec29cac4c73da7c482d4787afecae0530a9230498b +size 105 diff --git a/vello_tests/tests/filter.rs b/vello_tests/tests/filter.rs index c93ab183f..3335cd373 100644 --- a/vello_tests/tests/filter.rs +++ b/vello_tests/tests/filter.rs @@ -8,7 +8,7 @@ use crate::util::{circular_star, stops_blue_green_red_yellow}; use crate::{renderer::Renderer, util::layout_glyphs_roboto}; use vello_common::color::AlphaColor; use vello_common::color::palette::css::{ - BLACK, LIME, PURPLE, REBECCA_PURPLE, ROYAL_BLUE, SEA_GREEN, TOMATO, VIOLET, + BLACK, LIME, PURPLE, REBECCA_PURPLE, ROYAL_BLUE, SEA_GREEN, TOMATO, TRANSPARENT, VIOLET, }; use vello_common::filter_effects::{EdgeMode, Filter, FilterPrimitive}; use vello_common::kurbo::{Affine, BezPath, Circle, Point, Rect, Shape, Stroke}; @@ -52,6 +52,26 @@ fn filter_flood_star(ctx: &mut impl Renderer) { ctx.pop_layer(); } +#[vello_test(skip_multithreaded)] +fn filter_flood_transparent_paint(ctx: &mut impl Renderer) { + let filter_flood = Filter::from_primitive(FilterPrimitive::Flood { color: TOMATO }); + let left = Rect::new(8.0, 8.0, 48.0, 92.0); + let right = Rect::new(52.0, 8.0, 92.0, 92.0); + ctx.set_paint(TRANSPARENT); + + ctx.push_clip_layer(&left.to_path(0.1)); + ctx.push_filter_layer(filter_flood.clone()); + ctx.fill_rect(&left); + ctx.pop_layer(); + ctx.pop_layer(); + + ctx.push_clip_layer(&right.to_path(0.1)); + ctx.set_filter_effect(filter_flood); + ctx.fill_rect(&right); + ctx.reset_filter_effect(); + ctx.pop_layer(); +} + #[vello_test(skip_multithreaded)] fn filter_offset_simple(ctx: &mut impl Renderer) { let filter = Filter::from_primitive(FilterPrimitive::Offset { dx: 15.0, dy: 15.0 });