Skip to content

Commit

Permalink
[agx] fill_rect and blit2 protect against degenerate rects
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Dec 24, 2022
1 parent 4b520d6 commit a70a203
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rust_programs/agx_definitions/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ impl LikeLayerSlice for LayerSlice {

fn fill_rect(&self, raw_rect: Rect, color: Color, thickness: StrokeThickness) {
let rect = self.frame.constrain(raw_rect);
if rect.is_degenerate() {
return;
}

// Note that this rect has been damaged
//self.record_damaged_rect(rect);
Expand Down Expand Up @@ -128,10 +131,11 @@ impl LikeLayerSlice for LayerSlice {
};
let mut fb = (*self.parent_framebuffer).borrow_mut();
for y in 0..rect.height() {
let row_start =
rect_origin_offset.y + (y * parent_bytes_per_row) + (rect_origin_offset.x);
let row_slice = &mut fb
[(row_start as usize)..(row_start + (rect.width() * bpp as isize)) as usize];
let row_start = (rect_origin_offset.y
+ (y * parent_bytes_per_row)
+ (rect_origin_offset.x)) as usize;
let row_end = (row_start as isize + (rect.width() * bpp as isize)) as usize;
let row_slice = &mut fb[(row_start as usize)..row_end];
let (prefix, row_as_u32_slice, suffix) = unsafe { row_slice.align_to_mut::<u32>() };
// Ensure the slice was exactly u32-aligned
assert_eq!(prefix.len(), 0);
Expand Down Expand Up @@ -258,6 +262,9 @@ impl LikeLayerSlice for LayerSlice {
}

fn blit2(&self, source_layer: &Box<dyn LikeLayerSlice>) {
if self.frame().is_degenerate() {
return;
}
assert_eq!(
self.frame().size,
source_layer.frame().size,
Expand Down

0 comments on commit a70a203

Please sign in to comment.