forked from AbleOS/ableos
71 lines
2.5 KiB
Rust
71 lines
2.5 KiB
Rust
use {limine::NonNullPtr, virtio_drivers::transport::Transport};
|
|
|
|
use {
|
|
crate::{arch::virtio::AbleosHal, kmain::DEVICE_TREE},
|
|
able_graphics_library::raw_pixel::Display,
|
|
embedded_graphics::{pixelcolor::Rgb888, prelude::*},
|
|
limine::{Framebuffer, FramebufferRequest},
|
|
spin::{Lazy, Mutex},
|
|
virtio_drivers::device::gpu::VirtIOGpu,
|
|
};
|
|
|
|
pub static DISPLAY: Lazy<Mutex<Display>> = Lazy::new(|| {
|
|
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
|
|
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");
|
|
|
|
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]);
|
|
}
|
|
let size: usize = (fb1.width * fb1.height).try_into().unwrap();
|
|
let back_buffer: alloc::vec::Vec<u32> = alloc::vec![0; 800*600];
|
|
|
|
let m = Mutex::new(Display {
|
|
fb: fb1.address.as_ptr().unwrap().cast(),
|
|
// bb: fb1.address.as_ptr().unwrap().cast(),
|
|
bb: back_buffer.as_slice().as_ptr() as *mut u32,
|
|
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);
|
|
}
|
|
// 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");
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// log::info!("virtio-gpu test finished");
|
|
// }
|