From befd5175bb5392493f07eff92dfe4b24d81932be Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:41:59 +0100 Subject: [PATCH] Limit visibilities --- src/devices/graphical_debug/debug.rs | 10 +++++----- src/devices/graphical_debug/display.rs | 27 +++++++++++++++++--------- src/devices/graphical_debug/mod.rs | 3 +-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/devices/graphical_debug/debug.rs b/src/devices/graphical_debug/debug.rs index f3daac0807..02e65bdb3c 100644 --- a/src/devices/graphical_debug/debug.rs +++ b/src/devices/graphical_debug/debug.rs @@ -5,7 +5,7 @@ use super::Display; static FONT: &[u8] = include_bytes!("../../../res/unifont.font"); pub struct DebugDisplay { - pub(crate) display: Display, + pub(super) display: Display, x: usize, y: usize, w: usize, @@ -13,7 +13,7 @@ pub struct DebugDisplay { } impl DebugDisplay { - pub fn new(display: Display) -> DebugDisplay { + pub(super) fn new(display: Display) -> DebugDisplay { let w = display.width / 8; let h = display.height / 16; DebugDisplay { @@ -25,7 +25,7 @@ impl DebugDisplay { } } - pub fn write_char(&mut self, c: char) { + fn write_char(&mut self, c: char) { if self.x >= self.w || c == '\n' { self.x = 0; self.y += 1; @@ -63,7 +63,7 @@ impl DebugDisplay { } /// Draw a character - pub fn char(&mut self, x: usize, y: usize, character: char, color: u32) { + fn char(&mut self, x: usize, y: usize, character: char, color: u32) { if x + 8 <= self.display.width && y + 16 <= self.display.height { let mut dst = unsafe { self.display @@ -90,7 +90,7 @@ impl DebugDisplay { } /// Scroll the screen - pub fn scroll(&mut self, lines: usize) { + fn scroll(&mut self, lines: usize) { let offset = cmp::min(self.display.height, lines) * self.display.stride; let size = (self.display.stride * self.display.height) - offset; unsafe { diff --git a/src/devices/graphical_debug/display.rs b/src/devices/graphical_debug/display.rs index 6ed3cad17e..a241ec5bdf 100644 --- a/src/devices/graphical_debug/display.rs +++ b/src/devices/graphical_debug/display.rs @@ -2,16 +2,21 @@ use alloc::boxed::Box; use core::{ptr, slice}; /// A display -pub struct Display { - pub width: usize, - pub height: usize, - pub stride: usize, - pub onscreen: &'static mut [u32], - pub offscreen: Option>, +pub(super) struct Display { + pub(super) width: usize, + pub(super) height: usize, + pub(super) stride: usize, + onscreen: &'static mut [u32], + offscreen: Option>, } impl Display { - pub fn new(width: usize, height: usize, stride: usize, onscreen_ptr: *mut u32) -> Display { + pub(super) fn new( + width: usize, + height: usize, + stride: usize, + onscreen_ptr: *mut u32, + ) -> Display { let size = stride * height; let onscreen = unsafe { ptr::write_bytes(onscreen_ptr, 0, size); @@ -26,7 +31,11 @@ impl Display { } } - pub fn data_mut(&mut self) -> &mut [u32] { + pub(super) fn heap_init(&mut self) { + self.offscreen = Some(self.onscreen.to_vec().into_boxed_slice()); + } + + pub(super) fn data_mut(&mut self) -> &mut [u32] { match &mut self.offscreen { Some(offscreen) => offscreen, None => self.onscreen, @@ -34,7 +43,7 @@ impl Display { } /// Sync from offscreen to onscreen, unsafe because it trusts provided x, y, w, h - pub unsafe fn sync(&mut self, x: usize, y: usize, w: usize, mut h: usize) { + pub(super) unsafe fn sync(&mut self, x: usize, y: usize, w: usize, mut h: usize) { if let Some(offscreen) = &self.offscreen { let mut offset = y * self.stride + x; while h > 0 { diff --git a/src/devices/graphical_debug/mod.rs b/src/devices/graphical_debug/mod.rs index 19003bf95f..8e49d92f3e 100644 --- a/src/devices/graphical_debug/mod.rs +++ b/src/devices/graphical_debug/mod.rs @@ -68,8 +68,7 @@ pub fn init(env: &[u8]) { pub fn init_heap() { if let Some(debug_display) = &mut *DEBUG_DISPLAY.lock() { - debug_display.display.offscreen = - Some(debug_display.display.onscreen.to_vec().into_boxed_slice()); + debug_display.display.heap_init(); } }