mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
graphics-server: remove embedded-graphics from backends
Use native drawing for these platforms. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
a2fd6b0438
commit
7607b0f9ee
2 changed files with 60 additions and 72 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
use embedded_graphics::{drawable::Pixel, geometry::Size, pixelcolor::BinaryColor, DrawTarget};
|
|
||||||
use xous::MemoryRange;
|
use xous::MemoryRange;
|
||||||
use utralib::generated::*;
|
use utralib::generated::*;
|
||||||
|
|
||||||
|
|
@ -26,6 +25,9 @@ impl XousDisplay {
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
)
|
)
|
||||||
.expect("couldn't map frame buffer");
|
.expect("couldn't map frame buffer");
|
||||||
|
for mem_offset in 0..(FB_SIZE / 4) {
|
||||||
|
unsafe { fb.as_mut_ptr().add(mem_offset).write_volatile(0) };
|
||||||
|
}
|
||||||
|
|
||||||
let control = xous::syscall::map_memory(
|
let control = xous::syscall::map_memory(
|
||||||
xous::MemoryAddress::new(HW_MEMLCD_BASE),
|
xous::MemoryAddress::new(HW_MEMLCD_BASE),
|
||||||
|
|
@ -49,7 +51,11 @@ impl XousDisplay {
|
||||||
|
|
||||||
pub fn update(&mut self) {}
|
pub fn update(&mut self) {}
|
||||||
|
|
||||||
pub fn force_bitmap(&mut self, bmp: [u32; FB_SIZE]) {
|
pub fn native_buffer(&mut self) -> &mut [u32; FB_SIZE] {
|
||||||
|
unsafe { &mut *(self.fb.as_mut_ptr() as *mut [u32; FB_SIZE]) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn blit_screen(&mut self, bmp: [u32; FB_SIZE]) {
|
||||||
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
|
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
|
||||||
|
|
||||||
for words in 0..FB_SIZE {
|
for words in 0..FB_SIZE {
|
||||||
|
|
@ -113,47 +119,3 @@ impl XousDisplay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawTarget<BinaryColor> for XousDisplay {
|
|
||||||
type Error = core::convert::Infallible;
|
|
||||||
|
|
||||||
/// Draw a `Pixel` that has a color defined as `BinaryColor`.
|
|
||||||
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
|
|
||||||
let Pixel(coord, color) = pixel;
|
|
||||||
if coord.x < 0 || coord.y < 0 {
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
if coord.x < FB_WIDTH_PIXELS as _ && coord.y < FB_LINES as _ {
|
|
||||||
let framebuffer = self.fb.as_mut_ptr() as *mut u32;
|
|
||||||
let offset = (coord.x / 32 + coord.y * FB_WIDTH_WORDS as i32) as usize;
|
|
||||||
match color {
|
|
||||||
BinaryColor::Off => {
|
|
||||||
unsafe {
|
|
||||||
framebuffer.add(offset).write_volatile(
|
|
||||||
framebuffer.add(offset).read_volatile() | (1 << (coord.x % 32)),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
BinaryColor::On => {
|
|
||||||
unsafe {
|
|
||||||
framebuffer.add(offset).write_volatile(
|
|
||||||
framebuffer.add(offset).read_volatile() & !(1 << (coord.x % 32)),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the dirty bit on the line
|
|
||||||
unsafe {
|
|
||||||
framebuffer
|
|
||||||
.add(offset)
|
|
||||||
.write_volatile(framebuffer.add(offset).read_volatile() | 0x1_0000)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size(&self) -> Size {
|
|
||||||
Size::new(FB_WIDTH_PIXELS as _, FB_LINES as _)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
use embedded_graphics::{drawable::Pixel, geometry::Size, pixelcolor::BinaryColor, DrawTarget};
|
|
||||||
use minifb::{Key, Window, WindowOptions};
|
use minifb::{Key, Window, WindowOptions};
|
||||||
|
|
||||||
const WIDTH: usize = 336;
|
const WIDTH: usize = 336;
|
||||||
const HEIGHT: usize = 536;
|
const HEIGHT: usize = 536;
|
||||||
|
|
||||||
|
/// Width of the screen in 32-bit words
|
||||||
|
const WIDTH_WORDS: usize = 11;
|
||||||
|
const FB_SIZE: usize = WIDTH_WORDS * HEIGHT; // 44 bytes by 536 lines
|
||||||
|
|
||||||
const MAX_FPS: u64 = 15;
|
const MAX_FPS: u64 = 15;
|
||||||
const DARK_COLOUR: u32 = 0xB5B5AD;
|
const DARK_COLOUR: u32 = 0xB5B5AD;
|
||||||
const LIGHT_COLOUR: u32 = 0x1B1B19;
|
const LIGHT_COLOUR: u32 = 0x1B1B19;
|
||||||
|
|
||||||
pub struct XousDisplay {
|
pub struct XousDisplay {
|
||||||
buffer: Vec<u32>, //[u32; WIDTH * HEIGHT],
|
native_buffer: Vec<u32>, //[u32; WIDTH * HEIGHT],
|
||||||
|
emulated_buffer: [u32; FB_SIZE],
|
||||||
window: Window,
|
window: Window,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,45 +38,66 @@ impl XousDisplay {
|
||||||
1000 * 1000 / MAX_FPS,
|
1000 * 1000 / MAX_FPS,
|
||||||
)));
|
)));
|
||||||
|
|
||||||
let buffer = vec![DARK_COLOUR; WIDTH * HEIGHT];
|
let native_buffer = vec![DARK_COLOUR; WIDTH * HEIGHT];
|
||||||
window.update_with_buffer(&buffer, WIDTH, HEIGHT).unwrap();
|
window
|
||||||
|
.update_with_buffer(&native_buffer, WIDTH, HEIGHT)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
XousDisplay { buffer, window }
|
XousDisplay {
|
||||||
|
native_buffer,
|
||||||
|
window,
|
||||||
|
emulated_buffer: [0u32; FB_SIZE],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn blit_screen(&mut self, bmp: [u32; FB_SIZE]) {
|
||||||
|
for (dest, src) in self.emulated_buffer.iter_mut().zip(bmp.iter()) {
|
||||||
|
*dest = *src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn native_buffer(&mut self) -> &mut [u32; FB_SIZE] {
|
||||||
|
&mut self.emulated_buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn redraw(&mut self) {
|
pub fn redraw(&mut self) {
|
||||||
|
self.emulated_to_native();
|
||||||
self.window
|
self.window
|
||||||
.update_with_buffer(&self.buffer, WIDTH, HEIGHT)
|
.update_with_buffer(&self.native_buffer, WIDTH, HEIGHT)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
|
self.emulated_to_native();
|
||||||
self.window.update();
|
self.window.update();
|
||||||
if !self.window.is_open() || self.window.is_key_down(Key::Escape) {
|
if !self.window.is_open() || self.window.is_key_down(Key::Escape) {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl DrawTarget<BinaryColor> for XousDisplay {
|
fn emulated_to_native(&mut self) {
|
||||||
type Error = core::convert::Infallible;
|
for y in 0..HEIGHT {
|
||||||
|
for x in 0..WIDTH {
|
||||||
/// Draw a `Pixel` that has a color defined as `Gray8`.
|
// print!("({}, {}): {} @ {}: ", x, y, (x + y * 44 * 8) / 8, self.emulated_buffer.len());
|
||||||
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
|
// println!("{:08x}", self.emulated_buffer[(x + y * 44 * 8) / 8]);
|
||||||
let Pixel(point, color) = pixel;
|
if ((x + y * 11 * 32) / 32) >= self.emulated_buffer.len() {
|
||||||
let w = WIDTH as _;
|
panic!(
|
||||||
let h = HEIGHT as _;
|
"Value exceeds src buffer ({}, {}) @ {}",
|
||||||
if point.x < w && point.y < h && point.x >= 0 && point.y >= 0 {
|
x,
|
||||||
self.buffer[(point.y * w + point.x) as usize] = if color == BinaryColor::On {
|
y,
|
||||||
LIGHT_COLOUR
|
self.emulated_buffer.len()
|
||||||
} else {
|
);
|
||||||
DARK_COLOUR
|
}
|
||||||
};
|
if (x + y * WIDTH) > self.native_buffer.len() {
|
||||||
|
panic!("Value exceeds dest buffer");
|
||||||
|
}
|
||||||
|
self.native_buffer[x + y * WIDTH] =
|
||||||
|
if ((self.emulated_buffer[(x + y * 11 * 32) / 32] >> (x % 32)) & 1) > 0 {
|
||||||
|
DARK_COLOUR
|
||||||
|
} else {
|
||||||
|
LIGHT_COLOUR
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size(&self) -> Size {
|
|
||||||
Size::new(WIDTH as _, HEIGHT as _)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue