ableos/kernel/src/arch/x86_64/graphics.rs

70 lines
2.4 KiB
Rust
Raw Normal View History

2023-05-23 05:16:14 -05:00
use {limine::NonNullPtr};
2023-05-06 06:50:24 -05:00
use {
2023-05-23 05:16:14 -05:00
crate::{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},
};
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];
2023-05-15 02:19:34 -05:00
2023-05-08 03:53:15 -05:00
{
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-23 05:16:14 -05:00
let _size: usize = (fb1.width * fb1.height).try_into().unwrap();
2023-05-15 02:19:34 -05:00
let back_buffer: alloc::vec::Vec<u32> = alloc::vec![0; 800*600];
2023-05-06 06:50:24 -05:00
let m = Mutex::new(Display {
fb: fb1.address.as_ptr().unwrap().cast(),
2023-05-15 02:19:34 -05:00
// bb: fb1.address.as_ptr().unwrap().cast(),
bb: back_buffer.as_slice().as_ptr() as *mut u32,
2023-05-06 06:50:24 -05:00
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");
// }