acadia/rust/sys/teton/src/framebuffer.rs
Drew Galbraith 5c3d4ac7a9
Some checks failed
Check / Check Rust (pull_request) Failing after 1s
Add rust lint CI job.
2025-12-14 00:58:36 -08:00

47 lines
1.3 KiB
Rust

use mammoth::{mem::MemoryRegion, zion::ZError};
use yellowstone_yunq::FramebufferInfo;
pub struct Framebuffer {
fb_info: FramebufferInfo,
memory_region: MemoryRegion,
}
impl Framebuffer {
pub fn from_info(fb_info: FramebufferInfo) -> Result<Self, ZError> {
let size = fb_info.height * fb_info.pitch;
let memory_region = MemoryRegion::direct_physical(fb_info.address_phys, size)?;
Ok(Self {
fb_info,
memory_region,
})
}
fn draw_pixel(&mut self, row: u32, col: u32, pixel: u32) {
let index = row * (self.fb_info.pitch as u32 / 4) + col;
self.memory_region.mut_slice()[index as usize] = pixel;
}
pub fn draw_glyph(&mut self, glyph: &[u8], row: u32, col: u32) {
let gl_width = 8;
let gl_height = 16;
#[allow(clippy::needless_range_loop)]
for r in 0..gl_height {
for c in 0..gl_width {
if ((glyph[r] >> c) % 2) == 1 {
self.draw_pixel(row + (r as u32), col + (gl_width - c - 1), 0xFFFFFFFF);
} else {
self.draw_pixel(row + (r as u32), col + (gl_width - c - 1), 0);
}
}
}
}
pub fn width(&self) -> u32 {
self.fb_info.width as u32
}
pub fn height(&self) -> u32 {
self.fb_info.height as u32
}
}