Fix bugs in resize in vesad
This commit is contained in:
+1
-1
@@ -25,6 +25,6 @@ fn main() {
|
||||
unsafe { iopl(3).unwrap() };
|
||||
|
||||
let mut bga = Bga::new();
|
||||
print!("{}", format!(" - BGA {}x{}", bga.width(), bga.height()));
|
||||
print!("{}", format!(" - BGA {}x{}\n", bga.width(), bga.height()));
|
||||
}
|
||||
}
|
||||
|
||||
+43
-28
@@ -69,41 +69,56 @@ impl Display {
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, width: usize, height: usize) {
|
||||
println!("Resize display to {}, {}", width, height);
|
||||
if width != self.width || height != self.height {
|
||||
println!("Resize display to {}, {}", width, height);
|
||||
|
||||
let size = width * height;
|
||||
let offscreen = unsafe { heap::allocate(size * 4, 4096) };
|
||||
let size = width * height;
|
||||
let offscreen = unsafe { heap::allocate(size * 4, 4096) };
|
||||
|
||||
{
|
||||
let mut old_ptr = self.offscreen.as_ptr();
|
||||
let mut new_ptr = offscreen as *mut u32;
|
||||
for _y in 0..cmp::min(height, self.height) {
|
||||
unsafe {
|
||||
fast_copy(new_ptr as *mut u8, old_ptr as *const u8, cmp::min(width, self.width) * 4);
|
||||
old_ptr = old_ptr.offset(self.width as isize);
|
||||
new_ptr = new_ptr.offset(width as isize);
|
||||
{
|
||||
let mut old_ptr = self.offscreen.as_ptr();
|
||||
let mut new_ptr = offscreen as *mut u32;
|
||||
|
||||
for _y in 0..cmp::min(height, self.height) {
|
||||
unsafe {
|
||||
fast_copy(new_ptr as *mut u8, old_ptr as *const u8, cmp::min(width, self.width) * 4);
|
||||
if width > self.width {
|
||||
fast_set32(new_ptr.offset(self.width as isize), 0, width - self.width);
|
||||
}
|
||||
old_ptr = old_ptr.offset(self.width as isize);
|
||||
new_ptr = new_ptr.offset(width as isize);
|
||||
}
|
||||
}
|
||||
|
||||
if height > self.height {
|
||||
for _y in self.height..height {
|
||||
unsafe {
|
||||
fast_set32(new_ptr, 0, width);
|
||||
new_ptr = new_ptr.offset(width as isize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
|
||||
let onscreen = self.onscreen.as_mut_ptr();
|
||||
self.onscreen = unsafe { slice::from_raw_parts_mut(onscreen, size) };
|
||||
|
||||
unsafe { heap::deallocate(self.offscreen.as_mut_ptr() as *mut u8, self.offscreen.len() * 4, 4096) };
|
||||
self.offscreen = unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) };
|
||||
} else {
|
||||
println!("Display is already {}, {}", width, height);
|
||||
}
|
||||
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
|
||||
let onscreen = self.onscreen.as_mut_ptr();
|
||||
self.onscreen = unsafe { slice::from_raw_parts_mut(onscreen, size) };
|
||||
|
||||
unsafe { heap::deallocate(self.offscreen.as_mut_ptr() as *mut u8, self.offscreen.len() * 4, 4096) };
|
||||
self.offscreen = unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) };
|
||||
|
||||
self.sync(0, 0, width, height);
|
||||
}
|
||||
|
||||
/// Draw a rectangle
|
||||
pub fn rect(&mut self, x: usize, y: usize, w: usize, h: usize, color: u32) {
|
||||
let start_y = cmp::min(self.height - 1, y);
|
||||
let start_y = cmp::min(self.height, y);
|
||||
let end_y = cmp::min(self.height, y + h);
|
||||
|
||||
let start_x = cmp::min(self.width - 1, x);
|
||||
let start_x = cmp::min(self.width, x);
|
||||
let len = cmp::min(self.width, x + w) - start_x;
|
||||
|
||||
let mut offscreen_ptr = self.offscreen.as_mut_ptr() as usize;
|
||||
@@ -125,10 +140,10 @@ impl Display {
|
||||
|
||||
/// Invert a rectangle
|
||||
pub fn invert(&mut self, x: usize, y: usize, w: usize, h: usize) {
|
||||
let start_y = cmp::min(self.height - 1, y);
|
||||
let start_y = cmp::min(self.height, y);
|
||||
let end_y = cmp::min(self.height, y + h);
|
||||
|
||||
let start_x = cmp::min(self.width - 1, x);
|
||||
let start_x = cmp::min(self.width, x);
|
||||
let len = cmp::min(self.width, x + w) - start_x;
|
||||
|
||||
let mut offscreen_ptr = self.offscreen.as_mut_ptr() as usize;
|
||||
@@ -248,10 +263,10 @@ impl Display {
|
||||
|
||||
/// Copy from offscreen to onscreen
|
||||
pub fn sync(&mut self, x: usize, y: usize, w: usize, h: usize) {
|
||||
let start_y = cmp::min(self.height - 1, y);
|
||||
let start_y = cmp::min(self.height, y);
|
||||
let end_y = cmp::min(self.height, y + h);
|
||||
|
||||
let start_x = cmp::min(self.width - 1, x);
|
||||
let start_x = cmp::min(self.width, x);
|
||||
let len = (cmp::min(self.width, x + w) - start_x) * 4;
|
||||
|
||||
let mut offscreen_ptr = self.offscreen.as_mut_ptr() as usize;
|
||||
|
||||
+4
-1
@@ -158,8 +158,11 @@ impl SchemeMut for DisplayScheme {
|
||||
},
|
||||
EventOption::Resize(resize_event) => {
|
||||
println!("Resizing to {}, {}", resize_event.width, resize_event.height);
|
||||
for (_screen_id, screen) in self.screens.iter_mut() {
|
||||
for (screen_id, screen) in self.screens.iter_mut() {
|
||||
screen.resize(resize_event.width as usize, resize_event.height as usize);
|
||||
if *screen_id == self.active {
|
||||
screen.redraw();
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
|
||||
Reference in New Issue
Block a user