graphics: initial version

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-08-14 17:25:20 +08:00
parent 3ed964507d
commit 92a21a9fce
4 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,15 @@
[package]
name = "graphics"
version = "0.1.0"
authors = ["Sean Cross <sean@xobs.io>"]
edition = "2018"
description = "Manage the video output"
[dependencies]
xous = { path = "../../xous-rs" }
[target.'cfg(not(target_os = "none"))'.dependencies]
minifb = "0.17"
#pixels = "0.1"
rand = "*"

View file

@ -0,0 +1,44 @@
use minifb::{Key, Window, WindowOptions};
const WIDTH: usize = 336;
const HEIGHT: usize = 536;
const MAX_FPS: u64 = 10;
const LIGHT_COLOUR: u32 = 0xB5B5AD;
const DARK_COLOUR: u32 = 0x1B1B19;
use rand::prelude::*;
pub fn run() {
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
let mut window = Window::new(
"Betrusted",
WIDTH,
HEIGHT,
WindowOptions {
scale_mode: minifb::ScaleMode::AspectRatioStretch,
resize: true,
..WindowOptions::default()
},
)
.unwrap_or_else(|e| {
panic!("{}", e);
});
// Limit the maximum refresh rate
window.limit_update_rate(Some(std::time::Duration::from_micros(
1000 * 1000 / MAX_FPS,
)));
let mut rng = rand::thread_rng();
while window.is_open() && !window.is_key_down(Key::Escape) {
for i in buffer.iter_mut() {
*i = if rng.gen() { LIGHT_COLOUR } else { DARK_COLOUR };
}
// We unwrap here as we want this code to exit if it fails.
// Real applications may want to handle this in a different way
window.update_with_buffer(&buffer, WIDTH, HEIGHT).unwrap();
}
std::process::exit(0);
}

View file

@ -0,0 +1,4 @@
#[cfg(not(target_os = "none"))]
mod minifb;
#[cfg(not(target_os = "none"))]
pub use crate::backend::minifb::*;

View file

@ -0,0 +1,10 @@
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
mod backend;
#[xous::xous_main]
fn xmain() -> ! {
backend::run();
loop {};
}