Files
k-os/crates/drivers/framebuffer/mock/src/lib.rs
Gabriel Kaszewski 7c7e3b8748 refactor: apply newtypes throughout userspace API and display types
Every syscall stub now uses proper types from types/ — CapSlot,
EntryPoint, StackPointer, VirtualAddress, PageCount, ProcessId,
PermissionSet, Ticks. The compiler prevents swapping entry/stack,
passing a ProcessId where a CapSlot is expected, or using an
address as a page count.

New display types in types/display.rs:
  - Color(u32) with rgb() constructor
  - ScreenCoord(u16) for x/y positions
  - Dimension(u16) for width/height

Updated throughout:
  - userspace/syscall.rs: all params typed, returns Option instead
    of sentinel usize::MAX
  - server-framework: endpoint param is CapSlot
  - port-framebuffer: trait uses Color, ScreenCoord, Dimension
  - hw-virtio: DmaAddrs uses PhysicalAddress/VirtualAddress,
    GPU commands use Dimension
  - All servers, drivers, bins, apps updated for new signatures
  - permission-manager: process field uses ProcessId
  - PermissionSet: added bits() accessor

89 tests pass, full QEMU boot verified.
2026-10-18 13:45:40 +02:00

65 lines
1.6 KiB
Rust

#![no_std]
use port_framebuffer::Framebuffer;
use types::display::{Color, Dimension, ScreenCoord};
pub struct MockFramebuffer {
width: Dimension,
height: Dimension,
pixels: [(ScreenCoord, ScreenCoord, Color); 4096],
pixel_count: usize,
flushed: bool,
}
impl MockFramebuffer {
pub fn new(width: Dimension, height: Dimension) -> Self {
Self {
width,
height,
pixels: [(ScreenCoord::new(0), ScreenCoord::new(0), Color::from_raw(0)); 4096],
pixel_count: 0,
flushed: false,
}
}
pub fn pixel_count(&self) -> usize {
self.pixel_count
}
pub fn was_flushed(&self) -> bool {
self.flushed
}
pub fn pixel_at(&self, index: usize) -> (ScreenCoord, ScreenCoord, Color) {
self.pixels[index]
}
}
impl Framebuffer for MockFramebuffer {
fn width(&self) -> Dimension { self.width }
fn height(&self) -> Dimension { self.height }
fn write_pixel(&mut self, x: ScreenCoord, y: ScreenCoord, color: Color) {
if self.pixel_count < self.pixels.len() {
self.pixels[self.pixel_count] = (x, y, color);
self.pixel_count += 1;
}
}
fn fill_rect(&mut self, x: ScreenCoord, y: ScreenCoord, w: Dimension, h: Dimension, color: Color) {
for dy in 0..h.raw() {
for dx in 0..w.raw() {
self.write_pixel(ScreenCoord::new(x.raw() + dx), ScreenCoord::new(y.raw() + dy), color);
}
}
}
fn clear(&mut self, _color: Color) {
self.pixel_count = 0;
}
fn flush(&mut self) {
self.flushed = true;
}
}