Only compute bounding box for layers being rendered by Vello when actually used (#2771)

Only compute bounding box for vello when it is actually used

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert 2025-06-28 04:06:52 +02:00 committed by GitHub
parent cf8496b5a0
commit 357e77077d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -289,19 +289,21 @@ impl GraphicElementRendered for GraphicGroupTable {
let mut layer = false; let mut layer = false;
let bounds = self let blend_mode = match render_params.view_mode {
.instance_ref_iter() ViewMode::Outline => peniko::Mix::Normal,
.filter_map(|element| element.instance.bounding_box(transform, true)) _ => alpha_blending.blend_mode.to_peniko(),
.reduce(Quad::combine_bounds); };
if let Some(bounds) = bounds { let mut bounds = None;
let blend_mode = match render_params.view_mode {
ViewMode::Outline => peniko::Mix::Normal,
_ => alpha_blending.blend_mode.to_peniko(),
};
let factor = if render_params.for_mask { 1. } else { alpha_blending.fill }; let factor = if render_params.for_mask { 1. } else { alpha_blending.fill };
let opacity = alpha_blending.opacity * factor; let opacity = alpha_blending.opacity * factor;
if opacity < 1. || (render_params.view_mode != ViewMode::Outline && alpha_blending.blend_mode != BlendMode::default()) { if opacity < 1. || (render_params.view_mode != ViewMode::Outline && alpha_blending.blend_mode != BlendMode::default()) {
bounds = self
.instance_ref_iter()
.filter_map(|element| element.instance.bounding_box(transform, true))
.reduce(Quad::combine_bounds);
if let Some(bounds) = bounds {
scene.push_layer( scene.push_layer(
peniko::BlendMode::new(blend_mode, peniko::Compose::SrcOver), peniko::BlendMode::new(blend_mode, peniko::Compose::SrcOver),
opacity, opacity,
@ -321,6 +323,12 @@ impl GraphicElementRendered for GraphicGroupTable {
if !next_clips { if !next_clips {
mask_instance_state = None; mask_instance_state = None;
} }
if !layer {
bounds = self
.instance_ref_iter()
.filter_map(|element| element.instance.bounding_box(transform, true))
.reduce(Quad::combine_bounds);
}
if let Some(bounds) = bounds { if let Some(bounds) = bounds {
let rect = kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y); let rect = kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y);