2025-10-11 14:35:29 -07:00
|
|
|
use anyhow::{Context, Result};
|
2025-10-11 14:11:31 -07:00
|
|
|
use uefi::proto::console::gop::{BltOp, BltPixel, BltRegion, GraphicsOutput};
|
|
|
|
|
|
2025-10-19 23:03:28 -07:00
|
|
|
/// Represents the EFI framebuffer.
|
2025-10-11 14:11:31 -07:00
|
|
|
pub struct Framebuffer {
|
2025-10-19 23:03:28 -07:00
|
|
|
/// The width of the framebuffer in pixels.
|
2025-10-11 14:11:31 -07:00
|
|
|
width: usize,
|
2025-10-19 23:03:28 -07:00
|
|
|
/// The height of the framebuffer in pixels.
|
2025-10-11 14:11:31 -07:00
|
|
|
height: usize,
|
2025-10-19 23:03:28 -07:00
|
|
|
/// The pixels of the framebuffer.
|
2025-10-11 14:11:31 -07:00
|
|
|
pixels: Vec<BltPixel>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Framebuffer {
|
2025-10-19 23:03:28 -07:00
|
|
|
/// Creates a new framebuffer of the specified `width` and `height`.
|
2025-10-11 14:11:31 -07:00
|
|
|
pub fn new(width: usize, height: usize) -> Self {
|
|
|
|
|
Framebuffer {
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
pixels: vec![BltPixel::new(0, 0, 0); width * height],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-19 23:03:28 -07:00
|
|
|
/// Mutably acquires a pixel of the framebuffer at the specified `x` and `y` coordinate.
|
2025-10-11 14:11:31 -07:00
|
|
|
pub fn pixel(&mut self, x: usize, y: usize) -> Option<&mut BltPixel> {
|
|
|
|
|
self.pixels.get_mut(y * self.width + x)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-19 23:03:28 -07:00
|
|
|
/// Blit the framebuffer to the specified `gop` [GraphicsOutput].
|
2025-10-11 14:35:29 -07:00
|
|
|
pub fn blit(&self, gop: &mut GraphicsOutput) -> Result<()> {
|
2025-10-11 14:11:31 -07:00
|
|
|
gop.blt(BltOp::BufferToVideo {
|
|
|
|
|
buffer: &self.pixels,
|
|
|
|
|
src: BltRegion::Full,
|
|
|
|
|
dest: (0, 0),
|
|
|
|
|
dims: (self.width, self.height),
|
|
|
|
|
})
|
2025-10-14 12:47:33 -07:00
|
|
|
.context("unable to blit framebuffer")?;
|
2025-10-11 14:35:29 -07:00
|
|
|
Ok(())
|
2025-10-11 14:11:31 -07:00
|
|
|
}
|
|
|
|
|
}
|