video: Add support for BGRA framebuffers
This commit is contained in:
parent
70d78d86be
commit
d49823d5d0
@ -1,6 +1,8 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
|
|
||||||
mod video;
|
mod video;
|
||||||
mod bootboot;
|
mod bootboot;
|
||||||
mod panic;
|
mod panic;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![allow(dead_code)]
|
#![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 crate::util::get_bootboot;
|
||||||
|
|
||||||
use BOOTBOOT_FB as FB;
|
use BOOTBOOT_FB as FB;
|
||||||
@ -27,10 +27,31 @@ pub enum Color {
|
|||||||
White = 0xffffffff,
|
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) -> () {
|
pub fn put_pixel(x: u32, y: u32, color: Color) -> () {
|
||||||
let boot: BOOTBOOT = get_bootboot();
|
let boot: BOOTBOOT = get_bootboot();
|
||||||
let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64;
|
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) -> () {
|
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;
|
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)
|
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) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user