Skip to content

Commit

Permalink
Fix graphics tests on QEMu
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMajeri committed Jun 4, 2018
1 parent f75cf20 commit ab2317f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/proto/console/gop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl GraphicsOutput {
}

/// Returns information about available graphics modes and output devices.
pub fn modes(&self) -> impl Iterator<Item = Mode> {
pub fn modes<'a>(&'a self) -> impl Iterator<Item = Mode> + 'a {
ModeIter {
gop: self,
current: 0,
Expand All @@ -71,7 +71,7 @@ impl GraphicsOutput {
}

/// Sets the current graphics mode.
pub fn set_mode(&mut self, mode: &Mode) -> Result<()> {
pub fn set_mode(&mut self, mode: Mode) -> Result<()> {
(self.set_mode)(self, mode.index).into()
}

Expand Down Expand Up @@ -214,13 +214,13 @@ pub struct PixelBitmask {
}

/// Represents a graphics mode compatible with a given graphics device.
pub struct Mode<'a> {
pub struct Mode {
index: u32,
info_sz: usize,
info: &'a ModeInfo,
info: &'static ModeInfo,
}

impl<'a> Mode<'a> {
impl Mode {
/// The size of the info structure in bytes.
///
/// Newer versions of the spec might add extra information, in a backwards compatible way.
Expand Down Expand Up @@ -285,7 +285,7 @@ struct ModeIter<'a> {
}

impl<'a> Iterator for ModeIter<'a> {
type Item = Mode<'a>;
type Item = Mode;

fn next(&mut self) -> Option<Self::Item> {
let index = self.current;
Expand Down
47 changes: 30 additions & 17 deletions uefi-test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -
{
stdout.enable_cursor(true).expect("Failed to enable cursor");
stdout.set_cursor_position(24, 0).expect("Failed to move cursor");
stdout.enable_cursor(false).expect("Failed to enable cursor");

// This will make this `info!` line be (somewhat) centered.
info!("# uefi-rs test runner");
Expand Down Expand Up @@ -115,25 +116,25 @@ pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -
info!("");

{
let mut pointer = uefi_utils::proto::find_protocol::<uefi::proto::console::pointer::Pointer>()
.expect("No pointer device was found");
if let Some(mut pointer) = uefi_utils::proto::find_protocol::<uefi::proto::console::pointer::Pointer>() {
let pointer = unsafe { pointer.as_mut() };

let pointer = unsafe { pointer.as_mut() };
pointer.reset(false).expect("Failed to reset pointer device");

pointer.reset(false).expect("Failed to reset pointer device");

if let Ok(state) = pointer.state() {
info!("Pointer State: {:#?}", state);
if let Ok(state) = pointer.state() {
info!("Pointer State: {:#?}", state);
} else {
error!("Failed to retrieve pointer state");
}
} else {
error!("Failed to retrieve pointer state");
warn!("No pointer device found");
}
}

stdout.enable_cursor(false).unwrap();

info!("");

timeout!("Testing UEFI graphics in {} second(s)...", 5);
timeout!("Testing UEFI graphics in {} second(s)...", 3);
stdout.reset(false).unwrap();

// Draw some graphics.

Expand All @@ -143,29 +144,41 @@ pub extern "C" fn uefi_start(_handle: Handle, st: &'static table::SystemTable) -
if let Some(mut gop_proto) = uefi_utils::proto::find_protocol::<GraphicsOutput>() {
let gop = unsafe { gop_proto.as_mut() };

// First, fill the screen with color.
// Set a larger graphics mode.
{
// We know for sure QEMU has a 1024x768, mode.
let mode = gop.modes()
.find(|ref mode| {
let info = mode.info();

info.resolution() == (1024, 768)
})
.unwrap();

gop.set_mode(mode).expect("Failed to set graphics mode");
}

// Fill the screen with color.
{
let op = BltOp::VideoFill {
// Cornflower blue.
color: BltPixel::new(100, 149, 237),
dest: (0, 0),
dims: (32, 32),
dims: (1024, 768),
};

gop.blt(op).expect("Failed to fill screen with color");
}

bt.stall(1_000_000);
bt.stall(3_000_000);
} else {
warn!("UEFI Graphics Output Protocol is not supported");
}

// TODO: also test manipulating the pixel buffer directly.
}

info!("");

timeout!("Testing complete, shutting down in {} second(s)...", 5);
timeout!("Testing complete, shutting down in {} second(s)...", 3);

let rt = st.runtime;
rt.reset(table::runtime::ResetType::Shutdown, Status::Success, None);
Expand Down

0 comments on commit ab2317f

Please sign in to comment.