From 9239fe7f9e08a90bc156b468a5428332d83e337e Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 8 May 2023 21:56:10 -0500 Subject: [PATCH] add back buffer support to agl --- .../src/raw_pixel/arch/x86/mod.rs | 13 ++++++++++++- .../src/raw_pixel/raw_pixel.aidl | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 libraries/able_graphics_library/src/raw_pixel/raw_pixel.aidl diff --git a/libraries/able_graphics_library/src/raw_pixel/arch/x86/mod.rs b/libraries/able_graphics_library/src/raw_pixel/arch/x86/mod.rs index 8e15c0f..5c9b3f5 100644 --- a/libraries/able_graphics_library/src/raw_pixel/arch/x86/mod.rs +++ b/libraries/able_graphics_library/src/raw_pixel/arch/x86/mod.rs @@ -7,6 +7,8 @@ use embedded_graphics::{ pub struct Display { pub fb: *mut u32, + // Back buffer + pub bb: *mut u32, pub size: Size, pub color: Rgb888, } @@ -15,6 +17,15 @@ impl Display { pub fn set_color(&mut self, color: Rgb888) { self.color = color; } + pub fn swap_buffers(&mut self) { + let size: usize = (self.size.height * self.size.width).try_into().unwrap(); + + unsafe { + let dst_ptr = self.fb; + let src_ptr = self.bb; + core::ptr::copy_nonoverlapping(src_ptr, dst_ptr, size); + } + } pub fn line( &mut self, @@ -53,7 +64,7 @@ impl DrawTarget for Display { return Err(BlitOutOfBoundsError); } - self.fb + self.bb .add( (pos_y * self.size.width + pos_x) .try_into() diff --git a/libraries/able_graphics_library/src/raw_pixel/raw_pixel.aidl b/libraries/able_graphics_library/src/raw_pixel/raw_pixel.aidl new file mode 100644 index 0000000..0930ca1 --- /dev/null +++ b/libraries/able_graphics_library/src/raw_pixel/raw_pixel.aidl @@ -0,0 +1,5 @@ +Type Coordinate = i32; +Type Coordinates = (Coordinate, Coordinate); + + +Function line Takes(Coordinates, Coordinates) Returns(Nothing); \ No newline at end of file