Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sparse_strips/vello_cpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 25 additions & 0 deletions sparse_strips/vello_cpu/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere, when invariants like this aren't obeyed, we typically panic:

https://github.com/linebender/vello/blob/main/sparse_strips%2Fvello_common%2Fsrc%2Fpixmap.rs#L43-L47

I'm wondering whether we should either return an Error or similarly panic (to at least be consistent).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I’m not sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best option is allowing the consumer to decide what to do when they break an invariant (i.e. return an Error). Vello hybrid can return an Error type IIRC when spatiotemporal allocation suffers slot exhaustion.

Otherwise, I think it's fine to defer that to a larger review of this question and simply panic here (to be consistent with the rest of the system).

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,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}
}
Loading