diff --git a/Cargo.lock b/Cargo.lock index ef8dd4145..36b2502ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3744,6 +3744,7 @@ version = "0.0.1" dependencies = [ "bytemuck", "crossbeam-channel", + "log", "ordered-channel", "rayon", "smallvec", diff --git a/sparse_strips/vello_cpu/Cargo.toml b/sparse_strips/vello_cpu/Cargo.toml index f447ac7d8..d8682df80 100644 --- a/sparse_strips/vello_cpu/Cargo.toml +++ b/sparse_strips/vello_cpu/Cargo.toml @@ -24,6 +24,7 @@ ordered-channel = { workspace = true, optional = true, features = ["crossbeam-ch rayon = { workspace = true, optional = true } smallvec = { workspace = true, optional = true } thread_local = { workspace = true, optional = true } +log = { workspace = true } [features] diff --git a/sparse_strips/vello_cpu/src/render.rs b/sparse_strips/vello_cpu/src/render.rs index 115b74462..19553beb4 100644 --- a/sparse_strips/vello_cpu/src/render.rs +++ b/sparse_strips/vello_cpu/src/render.rs @@ -15,6 +15,7 @@ use alloc::boxed::Box; use alloc::sync::Arc; use alloc::vec; use alloc::vec::Vec; +use log::warn; use vello_common::blurred_rounded_rect::BlurredRoundedRectangle; use vello_common::encode::{EncodeExt, EncodedPaint}; use vello_common::fearless_simd::Level; @@ -448,9 +449,19 @@ impl RenderContext { } /// Render the current context into a pixmap. + /// + /// Note that the pixmap needs to have the same dimensions as the render context. pub fn render_to_pixmap(&self, pixmap: &mut Pixmap) { let width = pixmap.width(); let height = pixmap.height(); + + if width != self.width || height != self.height { + warn!("cannot render a pixmap with the dimensions {width}x{height} into \ + a render context with the dimensions {}x{}", self.width, self.height); + + return; + } + self.render_to_buffer( pixmap.data_as_u8_slice_mut(), width, @@ -945,6 +956,7 @@ impl RenderContext { mod tests { use crate::RenderContext; use vello_common::kurbo::{Rect, Shape}; + use vello_common::pixmap::Pixmap; use vello_common::tile::Tile; #[test] @@ -981,4 +993,17 @@ mod tests { ctx.flush(); ctx.render_to_pixmap(&mut pixmap); } + + #[test] + fn mismatched_dimensions() { + let mut ctx = RenderContext::new(20, 15); + let mut pixmap = Pixmap::new(20, 20); + let rect = Rect::new(0.0, 0.0, 20.0, 20.0); + + ctx.push_layer(Some(&rect.to_path(0.1)), None, None, None); + ctx.pop_layer(); + + ctx.flush(); + ctx.render_to_pixmap(&mut pixmap); + } }