Make get_frame_buffer more generic
This commit is contained in:
parent
6708631bbe
commit
c3155975ad
|
@ -44,7 +44,7 @@ impl Screen for Graphics320x200x256 {
|
|||
impl GraphicsWriter<u8> for Graphics320x200x256 {
|
||||
fn clear_screen(&self, color: u8) {
|
||||
unsafe {
|
||||
self.get_frame_buffer().write_bytes(color, Self::SIZE);
|
||||
self.get_frame_buffer::<u8>().write_bytes(color, Self::SIZE);
|
||||
}
|
||||
}
|
||||
fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: u8) {
|
||||
|
@ -55,7 +55,9 @@ impl GraphicsWriter<u8> for Graphics320x200x256 {
|
|||
fn set_pixel(&self, x: usize, y: usize, color: u8) {
|
||||
let offset = (y * WIDTH) + x;
|
||||
unsafe {
|
||||
self.get_frame_buffer().add(offset).write_volatile(color);
|
||||
self.get_frame_buffer::<u8>()
|
||||
.add(offset)
|
||||
.write_volatile(color);
|
||||
}
|
||||
}
|
||||
fn draw_character(&self, x: usize, y: usize, character: char, color: u8) {
|
||||
|
@ -82,6 +84,9 @@ impl GraphicsWriter<u8> for Graphics320x200x256 {
|
|||
// so explicitly set it.
|
||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
||||
}
|
||||
fn get_frame_buffer<T>(&self) -> *mut T {
|
||||
u32::from(VGA.lock().get_frame_buffer()) as *mut T
|
||||
}
|
||||
}
|
||||
|
||||
impl Graphics320x200x256 {
|
||||
|
|
|
@ -44,7 +44,7 @@ impl Screen for Graphics320x240x256 {
|
|||
|
||||
impl GraphicsWriter<u8> for Graphics320x240x256 {
|
||||
fn clear_screen(&self, color: u8) {
|
||||
let frame_buffer = self.get_frame_buffer();
|
||||
let frame_buffer = self.get_frame_buffer::<u8>();
|
||||
VGA.lock()
|
||||
.sequencer_registers
|
||||
.set_plane_mask(PlaneMask::ALL_PLANES);
|
||||
|
@ -58,7 +58,7 @@ impl GraphicsWriter<u8> for Graphics320x240x256 {
|
|||
}
|
||||
}
|
||||
fn set_pixel(&self, x: usize, y: usize, color: u8) {
|
||||
let frame_buffer = self.get_frame_buffer();
|
||||
let frame_buffer = self.get_frame_buffer::<u8>();
|
||||
unsafe {
|
||||
let offset = (WIDTH * y + x) / 4;
|
||||
let plane_mask = 0x1 << (x & 3);
|
||||
|
@ -92,6 +92,9 @@ impl GraphicsWriter<u8> for Graphics320x240x256 {
|
|||
// so explicitly set it.
|
||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
||||
}
|
||||
fn get_frame_buffer<T>(&self) -> *mut T {
|
||||
u32::from(VGA.lock().get_frame_buffer()) as *mut T
|
||||
}
|
||||
}
|
||||
|
||||
impl Graphics320x240x256 {
|
||||
|
|
|
@ -47,7 +47,7 @@ impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
|||
fn clear_screen(&self, color: Color16) {
|
||||
self.set_write_mode_2();
|
||||
unsafe {
|
||||
self.get_frame_buffer()
|
||||
self.get_frame_buffer::<u8>()
|
||||
.write_bytes(u8::from(color), Self::SIZE);
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,9 @@ impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
|||
// so explicitly set it.
|
||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
||||
}
|
||||
fn get_frame_buffer<T>(&self) -> *mut T {
|
||||
u32::from(VGA.lock().get_frame_buffer()) as *mut T
|
||||
}
|
||||
}
|
||||
|
||||
impl Graphics640x480x16 {
|
||||
|
@ -122,7 +125,7 @@ impl Graphics640x480x16 {
|
|||
|
||||
#[inline]
|
||||
fn _set_pixel(self, x: usize, y: usize, color: Color16) {
|
||||
let frame_buffer = self.get_frame_buffer();
|
||||
let frame_buffer = self.get_frame_buffer::<u8>();
|
||||
let offset = x / 8 + y * WIDTH_IN_BYTES;
|
||||
let pixel_mask = 0x80 >> (x & 0x07);
|
||||
VGA.lock()
|
||||
|
|
|
@ -200,7 +200,5 @@ pub trait GraphicsWriter<Color> {
|
|||
/// Sets the graphics device to a `VideoMode`.
|
||||
fn set_mode(&self);
|
||||
/// Returns the frame buffer for this vga mode.
|
||||
fn get_frame_buffer(&self) -> *mut u8 {
|
||||
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
||||
}
|
||||
fn get_frame_buffer<T>(&self) -> *mut T;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue