Skip to content

Commit

Permalink
[agx] LayerSlice blits row-by-row instead of by-pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Nov 27, 2022
1 parent cf460c5 commit 8139a62
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions rust_programs/agx_definitions/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,27 @@ impl LikeLayerSlice for LayerSlice {
}

fn blit2(&self, source_layer: &Box<dyn LikeLayerSlice>) {
assert!(self.frame().size == source_layer.frame().size);
//let pixel_data = source_layer.pixel_data();
assert_eq!(
self.frame().size,
source_layer.frame().size,
"{} != {}",
self.frame().size,
source_layer.frame().size
);
let bpp = 4;
let parent_size = self.parent_framebuffer_size;
let parent_bytes_per_row = parent_size.width * bpp;
let bpp_multiple = Point::new(bpp, parent_bytes_per_row);
let mut fb = self.parent_framebuffer.borrow_mut();
let slice_origin_offset = self.frame.origin * bpp_multiple;

for y in 0..self.frame().height() {
for x in 0..self.frame().width() {
let p = Point::new(x, y);
self.putpixel(p, source_layer.getpixel(p));
}
// Blit an entire row at once
let point_offset = slice_origin_offset + (Point::new(0, y) * bpp_multiple);
let off = (point_offset.y + point_offset.x) as usize;
let mut dst_row_slice = &mut fb[off..off + ((self.frame.width() * bpp) as usize)];
let row_slice = source_layer.get_pixel_row(y as _);
dst_row_slice.copy_from_slice(&row_slice);
}
}

Expand Down

0 comments on commit 8139a62

Please sign in to comment.