Fix fill and stroke paints' own blend modes blending with what lies beneath the shape in Vello

This commit is contained in:
Keavon Chambers committed 2026-12-05 04:42:59 -08:00
1 parent 017234b15b
commit 0fbc09eabd
2 files changed
+44 -2

No files matched your search

@@ -5372,7 +5372,8 @@ fn render_vector_item_to_vello(
| Graphic::GraphicList(_)
| Graphic::TextList(_)
| Graphic::StrokeList(_) => {
scene.push_clip_layer(fill_rule, kurbo::Affine::new(element_transform.to_cols_array()), path);
// The paint composites within its own layer, as in its SVG pattern, so its blend modes act on nothing beneath the shape
scene.push_layer(fill_rule, peniko::Mix::Normal, 1., kurbo::Affine::new(element_transform.to_cols_array()), path);
paint.render_to_vello(scene, multiplied_transform, &painting_within(layer_bounds));
scene.pop_layer();
}
@@ -5471,7 +5472,8 @@ fn render_vector_item_to_vello(
| Graphic::StrokeList(_) => {
let stroked = placed.stroke_outline(&stroke, 0.01);
scene.push_clip_layer(peniko::Fill::NonZero, element_affine, &*stroked);
// The paint composites within its own layer, as for the fill
scene.push_layer(peniko::Fill::NonZero, peniko::Mix::Normal, 1., element_affine, &*stroked);
paint.render_to_vello(scene, multiplied_transform, &painting_within(stroke_bounds()));
scene.pop_layer();
}
@@ -1919,6 +1919,46 @@ fn a_half_filled_paint_made_opaque_looks_the_same_whether_drawn_by_its_color_or_
}
}
#[test]
fn a_paints_own_blend_mode_composites_within_the_paint_rather_than_onto_what_lies_beneath_the_shape() {
use core_types::list::{ATTR_APPEARANCE, ATTR_EFFECTS, Item, List};
use core_types::{ATTR_BLEND_MODE, Color as GraphicColor};
use graphic_types::vector_types::vector::style::Stroke;
use graphic_types::{Appearance, Coverage, EffectOperation, Effects, Graphic, Vector};
use rendering::{Render, RenderParams};
use vello_gpu::kurbo::Shape;
let size = UVec2::new(140, 140);
let shape = |rect: Rect, coverage: Coverage, paint: Graphic| {
let mut vector = Vector::item_from_bezpath(&rect.to_path(0.1));
vector.set_attribute(ATTR_APPEARANCE, Appearance::new_single(coverage, paint));
Graphic::VectorList(List::new_from_item(vector))
};
let background = shape(Rect::new(0., 0., 140., 140.), Coverage::new_fill(), Graphic::ColorList(List::new_from_element(GraphicColor::RED)));
// Green multiplied with nothing beneath it in its paint stays green, whatever lies beneath the shape, as in SVG's pattern, though a blur of it draws it as content
let blur = EffectOperation::Blur {
radius_mask: Graphic::default(),
radius: 4.,
box_blur: false,
gamma: false,
};
let green = Item::new_from_element(GraphicColor::GREEN)
.with_attribute(ATTR_BLEND_MODE, BlendMode::Multiply)
.with_attribute(ATTR_EFFECTS, Effects::from_operations([blur]));
for (coverage, inside) in [(Coverage::new_fill(), (70, 70)), (Coverage::new_stroke(&Stroke::new(10.)), (20, 70))] {
let square = shape(Rect::new(20., 20., 120., 120.), coverage, Graphic::Color(green.clone()));
let Some(pixels) = render(size, |scene| {
background.render_to_vello(scene, DAffine2::IDENTITY, &RenderParams::default());
square.render_to_vello(scene, DAffine2::IDENTITY, &RenderParams::default());
}) else {
return;
};
let (x, y) = inside;
assert_eq!(pixel(&pixels, size, x, y), [0, 255, 0, 255], "green at ({x}, {y})");
}
}
#[test]
fn feathers_fade_the_content_to_nothing_at_its_edges() {
use graphic_types::EffectOperation;