graphics-server: minifb: use iterators for drawing the screen

This removes the bounds checks that were being performed, and goes for a
pure iterator approach.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-01-07 19:28:37 +08:00 committed by bunnie
parent e12a02b1c5
commit 147100fa38

View file

@ -76,27 +76,19 @@ impl XousDisplay {
} }
fn emulated_to_native(&mut self) { fn emulated_to_native(&mut self) {
for y in 0..HEIGHT { for (dest_row, src_row) in self
for x in 0..WIDTH { .native_buffer
// print!("({}, {}): {} @ {}: ", x, y, (x + y * 44 * 8) / 8, self.emulated_buffer.len()); .chunks_mut(WIDTH as _)
// println!("{:08x}", self.emulated_buffer[(x + y * 44 * 8) / 8]); .zip(self.emulated_buffer.chunks(WIDTH_WORDS as _))
if ((x + y * 11 * 32) / 32) >= self.emulated_buffer.len() { {
panic!( for (dest_cell, src_cell) in dest_row.chunks_mut(32).zip(src_row) {
"Value exceeds src buffer ({}, {}) @ {}", for (bit, dest) in dest_cell.iter_mut().enumerate() {
x, *dest = if src_cell & (1 << bit) != 0 {
y,
self.emulated_buffer.len()
);
}
if (x + y * WIDTH) > self.native_buffer.len() {
panic!("Value exceeds dest buffer");
}
self.native_buffer[x + y * WIDTH] =
if ((self.emulated_buffer[(x + y * 11 * 32) / 32] >> (x % 32)) & 1) > 0 {
DARK_COLOUR DARK_COLOUR
} else { } else {
LIGHT_COLOUR LIGHT_COLOUR
}; };
}
} }
} }
} }