diff --git a/graphics/fbcond/src/display.rs b/graphics/fbcond/src/display.rs index e17ecbd204..d47f130e78 100644 --- a/graphics/fbcond/src/display.rs +++ b/graphics/fbcond/src/display.rs @@ -1,6 +1,7 @@ +use console_draw::TextScreen; use graphics_ipc::v2::{Damage, V2GraphicsHandle}; use inputd::ConsumerHandle; -use std::io; +use std::{io, ptr}; pub struct Display { pub input_handle: ConsumerHandle, @@ -57,6 +58,55 @@ impl Display { } } + pub fn handle_resize(map: &mut DisplayMap, text_screen: &mut TextScreen) { + let (width, height) = match map.display_handle.display_size(0) { + Ok((width, height)) => (width, height), + Err(err) => { + eprintln!("fbcond: failed to get display size: {}", err); + (map.inner.width() as u32, map.inner.height() as u32) + } + }; + + if width as usize != map.inner.width() || height as usize != map.inner.height() { + match map.display_handle.create_dumb_framebuffer(width, height) { + Ok(fb) => match map.display_handle.map_dumb_framebuffer(fb, width, height) { + Ok(mut new_map) => { + let count = new_map.ptr().len(); + unsafe { + ptr::write_bytes(new_map.ptr_mut() as *mut u32, 0, count); + } + + text_screen.resize( + &mut console_draw::DisplayMap { + offscreen: map.inner.ptr_mut(), + width: map.inner.width(), + height: map.inner.height(), + }, + &mut console_draw::DisplayMap { + offscreen: new_map.ptr_mut(), + width: new_map.width(), + height: new_map.height(), + }, + ); + + let _ = map.display_handle.destroy_dumb_framebuffer(map.fb); + + map.fb = fb; + map.inner = new_map; + + eprintln!("fbcond: mapped display"); + } + Err(err) => { + eprintln!("fbcond: failed to open display: {}", err); + } + }, + Err(err) => { + eprintln!("fbcond: failed to create framebuffer: {}", err); + } + } + } + } + pub fn sync_rect(&mut self, damage: Damage) { if let Some(map) = &self.map { map.display_handle.update_plane(0, map.fb, damage).unwrap(); diff --git a/graphics/fbcond/src/text.rs b/graphics/fbcond/src/text.rs index e503488bfc..f8ec4d31e1 100644 --- a/graphics/fbcond/src/text.rs +++ b/graphics/fbcond/src/text.rs @@ -122,6 +122,8 @@ impl TextScreen { pub fn write(&mut self, buf: &[u8]) -> Result { if let Some(map) = &mut self.display.map { + Display::handle_resize(map, &mut self.inner); + let damage = self.inner.write( &mut console_draw::DisplayMap { offscreen: map.inner.ptr_mut(),