video: Add support for BGRA framebuffers

This commit is contained in:
apio 2022-10-31 16:39:20 +01:00
parent 70d78d86be
commit d49823d5d0
2 changed files with 27 additions and 4 deletions

View File

@ -1,6 +1,8 @@
#![no_std]
#![no_main]
#![feature(core_intrinsics)]
mod video;
mod bootboot;
mod panic;
@ -17,7 +19,7 @@ pub extern "C" fn _start() -> ! {
init::halt_other_cores();
init::check_magic();
video::clear(Color::White);
cpu::halt();

View File

@ -1,6 +1,6 @@
#![allow(dead_code)]
use crate::bootboot::{BOOTBOOT, BOOTBOOT_FB};
use crate::bootboot::{BOOTBOOT, BOOTBOOT_FB, FB_ARGB, FB_BGRA};
use crate::util::get_bootboot;
use BOOTBOOT_FB as FB;
@ -27,10 +27,31 @@ pub enum Color {
White = 0xffffffff,
}
use core::intrinsics::bswap;
impl Color {
fn to_argb(self) -> u32 {
self as u32
}
fn to_bgra(self) -> u32 {
bswap(self as u32)
}
fn to_layout(self, layout: u32) -> u32 {
match layout {
FB_ARGB => self.to_argb(),
FB_BGRA => self.to_bgra(),
_ => panic!("unsupported framebuffer data layout"),
}
}
}
pub fn put_pixel(x: u32, y: u32, color: Color) -> () {
let boot: BOOTBOOT = get_bootboot();
let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64;
unsafe { *(ptr as *mut u32) = color as u32 };
unsafe { *(ptr as *mut u32) = color.to_layout(boot.fb_type as u32) };
}
pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: Color) -> () {
@ -40,7 +61,7 @@ pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: Color) -> () {
let addr: u64 = FB + (boot.fb_scanline * i) as u64 + (x * 4) as u64;
for ptr in (addr..(addr + (width*4) as u64)).step_by(4)
{
unsafe { *(ptr as *mut u32) = color as u32 };
unsafe { *(ptr as *mut u32) = color.to_layout(boot.fb_type as u32) };
}
}
}