Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 4 additions & 34 deletions vello_gpu/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ pub struct Scene {
pub(crate) aliasing_threshold: Option<u8>,
/// Storage for encoded non-solid paint data.
pub(crate) encoded_paints: Vec<EncodedPaint>,
/// 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<StripStorage>,
/// Current filter effect applied to individual draw operations.
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<PaintType>) {
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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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.
Expand All @@ -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();
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions vello_tests/snapshots/filter_flood_transparent_paint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion vello_tests/tests/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 });
Expand Down
Loading