diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs index 8dc21b61..d23a40c4 100644 --- a/tiny_skia/src/engine.rs +++ b/tiny_skia/src/engine.rs @@ -36,15 +36,6 @@ impl Engine { clip_mask: &mut tiny_skia::Mask, clip_bounds: Rectangle, ) { - debug_assert!( - quad.bounds.width.is_normal(), - "Quad with non-normal width!" - ); - debug_assert!( - quad.bounds.height.is_normal(), - "Quad with non-normal height!" - ); - let physical_bounds = quad.bounds * transformation; if !clip_bounds.intersects(&physical_bounds) { @@ -497,7 +488,7 @@ impl Engine { transformation: Transformation, pixels: &mut tiny_skia::PixmapMut<'_>, clip_mask: &mut tiny_skia::Mask, - layer_bounds: Rectangle, + clip_bounds: Rectangle, ) { match primitive { Primitive::Fill { path, paint, rule } => { @@ -512,14 +503,12 @@ impl Engine { } * transformation }; - let Some(clip_bounds) = - layer_bounds.intersection(&physical_bounds) - else { + if !clip_bounds.intersects(&physical_bounds) { return; - }; + } - let clip_mask = - (physical_bounds != clip_bounds).then_some(clip_mask as &_); + let clip_mask = (!physical_bounds.is_within(&clip_bounds)) + .then_some(clip_mask as &_); pixels.fill_path( path, @@ -545,14 +534,12 @@ impl Engine { } * transformation }; - let Some(clip_bounds) = - layer_bounds.intersection(&physical_bounds) - else { + if !clip_bounds.intersects(&physical_bounds) { return; - }; + } - let clip_mask = - (physical_bounds != clip_bounds).then_some(clip_mask as &_); + let clip_mask = (!physical_bounds.is_within(&clip_bounds)) + .then_some(clip_mask as &_); pixels.stroke_path( path, diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index d39278b2..56b70b2c 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -268,8 +268,8 @@ impl Layer { .filter_map(|bounds| bounds.intersection(group_bounds)) .collect() } - Item::Cached(_, bounds, _) => { - vec![*bounds] + Item::Cached(_, bounds, transformation) => { + vec![*bounds * *transformation] } }, |primitive_a, primitive_b| match (primitive_a, primitive_b) { diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index 5e219bd2..05b498ff 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -76,15 +76,15 @@ impl Renderer { self.layers.flush(); - for ®ion in damage { - let region = region * scale_factor; + for &damage_bounds in damage { + let damage_bounds = damage_bounds * scale_factor; let path = tiny_skia::PathBuilder::from_rect( tiny_skia::Rect::from_xywh( - region.x, - region.y, - region.width, - region.height, + damage_bounds.x, + damage_bounds.y, + damage_bounds.width, + damage_bounds.height, ) .expect("Create damage rectangle"), ); @@ -105,13 +105,13 @@ impl Renderer { ); for layer in self.layers.iter() { - let Some(clip_bounds) = - region.intersection(&(layer.bounds * scale_factor)) + let Some(layer_bounds) = + damage_bounds.intersection(&(layer.bounds * scale_factor)) else { continue; }; - engine::adjust_clip_mask(clip_mask, clip_bounds); + engine::adjust_clip_mask(clip_mask, layer_bounds); if !layer.quads.is_empty() { let render_span = debug::render(debug::Primitive::Quad); @@ -122,7 +122,7 @@ impl Renderer { Transformation::scale(scale_factor), pixels, clip_mask, - clip_bounds, + layer_bounds, ); } render_span.finish(); @@ -132,14 +132,15 @@ impl Renderer { let render_span = debug::render(debug::Primitive::Triangle); for group in &layer.primitives { - let Some(new_clip_bounds) = (group.clip_bounds() + let Some(group_bounds) = (group.clip_bounds() + * group.transformation() * scale_factor) - .intersection(&clip_bounds) + .intersection(&layer_bounds) else { continue; }; - engine::adjust_clip_mask(clip_mask, new_clip_bounds); + engine::adjust_clip_mask(clip_mask, group_bounds); for primitive in group.as_slice() { self.engine.draw_primitive( @@ -148,11 +149,11 @@ impl Renderer { * Transformation::scale(scale_factor), pixels, clip_mask, - clip_bounds, + group_bounds, ); } - engine::adjust_clip_mask(clip_mask, clip_bounds); + engine::adjust_clip_mask(clip_mask, layer_bounds); } render_span.finish(); @@ -167,7 +168,7 @@ impl Renderer { Transformation::scale(scale_factor), pixels, clip_mask, - clip_bounds, + layer_bounds, ); } @@ -185,7 +186,7 @@ impl Renderer { * Transformation::scale(scale_factor), pixels, clip_mask, - clip_bounds, + layer_bounds, ); } }