From 8139a62ad06f5f80b6c63736e657492c213c2cc2 Mon Sep 17 00:00:00 2001 From: Phillip Tennen Date: Sun, 27 Nov 2022 12:14:47 +0000 Subject: [PATCH] [agx] LayerSlice blits row-by-row instead of by-pixel --- rust_programs/agx_definitions/src/layer.rs | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/rust_programs/agx_definitions/src/layer.rs b/rust_programs/agx_definitions/src/layer.rs index d95d1b0c6..1c4f5656f 100644 --- a/rust_programs/agx_definitions/src/layer.rs +++ b/rust_programs/agx_definitions/src/layer.rs @@ -299,13 +299,27 @@ impl LikeLayerSlice for LayerSlice { } fn blit2(&self, source_layer: &Box) { - 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); } }