From 27d323f7ce88b238b5dc94f350832b081e7ca6ff Mon Sep 17 00:00:00 2001 From: TerminalCursor Date: Wed, 29 Jun 2022 21:14:02 -0700 Subject: Initial commit --- src/gfx.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/gfx.rs (limited to 'src/gfx.rs') diff --git a/src/gfx.rs b/src/gfx.rs new file mode 100644 index 0000000..fda870c --- /dev/null +++ b/src/gfx.rs @@ -0,0 +1,54 @@ +use uefi::prelude::*; +use uefi::proto::console::gop::*; + +pub struct GOP<'boot>(&'boot mut GraphicsOutput<'boot>); + +impl<'boot> GOP<'boot> { + pub fn new(st: &SystemTable) -> Result, uefi::Error> { + let res = st.boot_services().locate_protocol::(); + match res { + Ok(protocol) => { + return Ok(unsafe { GOP(&mut *protocol.get()) }) + }, + Err(e) => {return Err(e)} + } + } + + pub fn get_modes(&'boot self) -> impl ExactSizeIterator + 'boot { + self.0.modes() + } + + pub fn set_mode(&mut self, mode: &Mode) -> Result<(), uefi::Error> { + self.0.set_mode(mode) + } + + pub fn set_highest_resolution(&mut self) -> Result<(), uefi::Error> { + let mut last_mode; + let res = self.0.query_mode(0); + match res { + Ok(mode) => {last_mode = mode;}, + Err(e) => {return Err(e)} + } + for mode in self.0.modes() { + last_mode = mode; + } + self.0.set_mode(&last_mode) + } + + pub fn get_resolution(&self) -> (usize, usize) { + self.0.current_mode_info().resolution() + } + + pub fn fill_box(&mut self, + x: usize, y: usize, + dx: usize, dy: usize, + r: u8, g: u8, b: u8) + -> Result<(), uefi::Error> { + let blt_op = BltOp::VideoFill { + color: BltPixel::new(r, g, b), + dest: (x, y), + dims: (dx, dy) + }; + self.0.blt(blt_op) + } +} -- cgit v1.2.1