2023-05-08 03:53:15 -05:00
|
|
|
use {limine::NonNullPtr, virtio_drivers::transport::Transport};
|
2023-05-06 06:50:24 -05:00
|
|
|
|
|
|
|
use {
|
2023-05-08 03:53:15 -05:00
|
|
|
crate::{arch::virtio::AbleosHal, kmain::DEVICE_TREE},
|
2023-05-06 06:50:24 -05:00
|
|
|
able_graphics_library::raw_pixel::Display,
|
2023-05-08 03:53:15 -05:00
|
|
|
embedded_graphics::{pixelcolor::Rgb888, prelude::*},
|
|
|
|
limine::{Framebuffer, FramebufferRequest},
|
2023-05-06 06:50:24 -05:00
|
|
|
spin::{Lazy, Mutex},
|
2023-05-08 03:53:15 -05:00
|
|
|
virtio_drivers::device::gpu::VirtIOGpu,
|
2023-05-06 06:50:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
pub static DISPLAY: Lazy<Mutex<Display>> = Lazy::new(|| {
|
|
|
|
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
|
2023-05-08 03:53:15 -05:00
|
|
|
let fb1: &NonNullPtr<Framebuffer> = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
|
|
|
|
{
|
|
|
|
use crate::alloc::string::ToString;
|
|
|
|
let mut dt = DEVICE_TREE.lock();
|
|
|
|
let mut disp = xml::XMLElement::new("display_0");
|
2023-05-06 07:05:45 -05:00
|
|
|
|
2023-05-08 03:53:15 -05:00
|
|
|
disp.set_attribute("width", fb1.width);
|
|
|
|
disp.set_attribute("height", fb1.height);
|
|
|
|
disp.set_attribute("bits per pixel", fb1.bpp);
|
|
|
|
dt.devices.insert("Displays".to_string(), alloc::vec![disp]);
|
|
|
|
}
|
2023-05-06 06:50:24 -05:00
|
|
|
let m = Mutex::new(Display {
|
|
|
|
fb: fb1.address.as_ptr().unwrap().cast(),
|
|
|
|
size: Size::new(fb1.width as u32, fb1.height as u32),
|
|
|
|
color: Rgb888::WHITE,
|
|
|
|
});
|
|
|
|
log::info!("Graphics initialised");
|
|
|
|
m
|
|
|
|
});
|
|
|
|
|
|
|
|
pub fn init() {
|
|
|
|
Lazy::force(&DISPLAY);
|
|
|
|
}
|
2023-05-06 07:05:45 -05:00
|
|
|
// pub fn virtio_gpu<T: Transport>(transport: T) {
|
|
|
|
// let mut gpu = VirtIOGpu::<AbleosHal, T>::new(transport).expect("failed to create gpu driver");
|
|
|
|
// let (width, height) = gpu.resolution().expect("failed to get resolution");
|
|
|
|
// let width = width as usize;
|
|
|
|
// let height = height as usize;
|
|
|
|
// log::info!("GPU resolution is {}x{}", width, height);
|
|
|
|
// let fb = gpu.setup_framebuffer().expect("failed to get fb");
|
|
|
|
// for y in 0..height {
|
|
|
|
// for x in 0..width {
|
|
|
|
// let idx = (y * width + x) * 4;
|
|
|
|
// fb[idx] = x as u8;
|
|
|
|
// fb[idx + 1] = y as u8;
|
|
|
|
// fb[idx + 2] = (x + y) as u8;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// gpu.flush().expect("failed to flush");
|
|
|
|
// //delay some time
|
|
|
|
// log::info!("virtio-gpu show graphics....");
|
|
|
|
// for _ in 0..100000 {
|
|
|
|
// for _ in 0..100000 {
|
|
|
|
// unsafe {
|
|
|
|
// core::arch::asm!("nop");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2023-05-06 06:50:24 -05:00
|
|
|
|
2023-05-06 07:05:45 -05:00
|
|
|
// log::info!("virtio-gpu test finished");
|
|
|
|
// }
|