clean up test code to use new module

This commit is contained in:
2023-03-18 20:35:46 -04:00
parent 9606c5208f
commit 4a7dc1a3ba

View File

@@ -69,73 +69,16 @@ pub fn efi_main(_image: Handle, mut st: SystemTable<Boot>) -> Status {
} }
}; };
let fb = uefi_fb::UefiFb::new(); let mut fb = uefi_fb::UefiFb::new();
uefifb_test(&fb)
} // None sets a sane default of 1024x768
fb.set_graphics_mode(None);
fb.fb_blt_fill(BltPixel::new(100, 149, 237), (0, 0), (1024, 768));
fn uefifb_test(fb: &UefiFb) -> Status { let mi = fb.current_mode_info();
// run tests here
info!("GOP Framebuffer test complete");
Status::SUCCESS
}
// Set a larger graphics mode.
fn set_graphics_mode(gop: &mut GraphicsOutput) {
// We know for sure QEMU has a 1024x768 mode.
let mode = gop
.modes()
.find(|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.
fn fill_color(gop: &mut GraphicsOutput) {
let op = BltOp::VideoFill {
// Cornflower blue.
color: BltPixel::new(100, 149, 237),
dest: (0, 0),
dims: (1024, 768),
};
gop.blt(op).expect("Failed to fill screen with color");
}
// Draw directly to the frame buffer.
fn draw_fb(gop: &mut GraphicsOutput) {
// The `virtio-gpu-pci` graphics device we use on aarch64 doesn't
// support `PixelFormat::BltOnly`.
if cfg!(target_arch = "aarch64") {
return;
}
let mi = gop.current_mode_info();
let stride = mi.stride(); let stride = mi.stride();
let (width, height) = mi.resolution(); let (width, height) = mi.resolution();
let mut fb = gop.frame_buffer();
type PixelWriter = unsafe fn(&mut FrameBuffer, usize, [u8; 3]);
unsafe fn write_pixel_rgb(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) {
fb.write_value(pixel_base, rgb);
}
unsafe fn write_pixel_bgr(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) {
fb.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]);
}
let write_pixel: PixelWriter = match mi.pixel_format() {
PixelFormat::Rgb => write_pixel_rgb,
PixelFormat::Bgr => write_pixel_bgr,
_ => {
info!("This pixel format is not supported by the drawing demo");
return;
}
};
let mut fill_rectangle = |(x1, y1), (x2, y2), color| { let mut fill_rectangle = |(x1, y1), (x2, y2), color| {
assert!((x1 < width) && (x2 < width), "Bad X coordinate"); assert!((x1 < width) && (x2 < width), "Bad X coordinate");
assert!((y1 < height) && (y2 < height), "Bad Y coordinate"); assert!((y1 < height) && (y2 < height), "Bad Y coordinate");
@@ -144,7 +87,7 @@ fn draw_fb(gop: &mut GraphicsOutput) {
unsafe { unsafe {
let pixel_index = (row * stride) + column; let pixel_index = (row * stride) + column;
let pixel_base = 4 * pixel_index; let pixel_base = 4 * pixel_index;
write_pixel(&mut fb, pixel_base, color); fb.draw_fb(pixel_base, color);
} }
} }
} }
@@ -152,4 +95,7 @@ fn draw_fb(gop: &mut GraphicsOutput) {
fill_rectangle((50, 30), (150, 600), [250, 128, 64]); fill_rectangle((50, 30), (150, 600), [250, 128, 64]);
fill_rectangle((400, 120), (750, 450), [16, 128, 255]); fill_rectangle((400, 120), (750, 450), [16, 128, 255]);
}
info!("GOP Framebuffer test complete");
Status::SUCCESS
}