refactor graphics server to use reply_and_receive_next()

This new api allows for scalar-5 returns as well as more
efficient use of the scheduler's quantum by not simply yielding
time when a message is returned; it will fetch the next message
and process it until its time is up.
This commit is contained in:
bunnie 2025-02-26 14:35:33 +08:00
parent 79f803ef58
commit 111d8f8d3d

View file

@ -19,8 +19,6 @@ use poweron_bt as poweron;
mod sleep_note; mod sleep_note;
use blitstr2::fontmap; use blitstr2::fontmap;
use num_traits::FromPrimitive;
use xous::{MemoryRange, msg_blocking_scalar_unpack, msg_scalar_unpack};
use xous_ipc::Buffer; use xous_ipc::Buffer;
#[cfg(any(feature = "precursor", feature = "renode", feature = "cramium-soc"))] #[cfg(any(feature = "precursor", feature = "renode", feature = "cramium-soc"))]
@ -122,7 +120,7 @@ fn map_fonts() -> MemoryRange {
} }
#[cfg(not(target_os = "xous"))] #[cfg(not(target_os = "xous"))]
fn map_fonts() -> MemoryRange { fn map_fonts() -> xous::MemoryRange {
// does nothing // does nothing
let fontlen: u32 = ((fontmap::FONT_TOTAL_LEN as u32 + 8) & 0xFFFF_F000) + 0x1000; let fontlen: u32 = ((fontmap::FONT_TOTAL_LEN as u32 + 8) & 0xFFFF_F000) + 0x1000;
let fontregion = xous::syscall::map_memory(None, None, fontlen as usize, xous::MemoryFlags::R) let fontregion = xous::syscall::map_memory(None, None, fontlen as usize, xous::MemoryFlags::R)
@ -213,82 +211,108 @@ fn wrapped_main(main_thread_token: backend::MainThreadToken) -> ! {
#[cfg(feature = "gfx-testing")] #[cfg(feature = "gfx-testing")]
testing::tests(); testing::tests();
let mut msg_opt = None;
loop { loop {
if !is_panic.load(Ordering::Relaxed) { if !is_panic.load(Ordering::Relaxed) {
// non-panic graphics operations if we are in a panic situation xous::reply_and_receive_next(sid, &mut msg_opt).unwrap();
let mut msg = xous::receive_message(sid).unwrap(); let msg = msg_opt.as_mut().unwrap();
let op = FromPrimitive::from_usize(msg.body.id()); let op = num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(GfxOpcode::InvalidCall);
log::trace!("{:?}", op); log::debug!("{:?}", op);
match op { match op {
#[cfg(not(feature = "cramium-soc"))] #[cfg(not(feature = "cramium-soc"))]
Some(GfxOpcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { GfxOpcode::SuspendResume => {
if let Some(scalar) = msg.body.scalar_message() {
let token = scalar.arg1;
display.suspend(); display.suspend();
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume"); susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
display.resume(); display.resume();
}), } else {
Some(GfxOpcode::DrawClipObject) => { panic!("Incorrect message type");
minigfx::handlers::draw_clip_object(&mut display, &mut msg);
} }
Some(GfxOpcode::DrawClipObjectList) => {
minigfx::handlers::draw_clip_object_list(&mut display, &mut msg);
} }
Some(GfxOpcode::DrawTextView) => { GfxOpcode::DrawClipObject => {
minigfx::handlers::draw_text_view(&mut display, &mut msg); minigfx::handlers::draw_clip_object(&mut display, msg);
} }
Some(GfxOpcode::Flush) => { GfxOpcode::DrawClipObjectList => {
minigfx::handlers::draw_clip_object_list(&mut display, msg);
}
GfxOpcode::DrawTextView => {
minigfx::handlers::draw_text_view(&mut display, msg);
}
GfxOpcode::Flush => {
log::trace!("***gfx flush*** redraw##"); log::trace!("***gfx flush*** redraw##");
display.redraw(); display.redraw();
} }
Some(GfxOpcode::Clear) => { GfxOpcode::Clear => {
let mut r = Rectangle::full_screen(); let mut r = Rectangle::full_screen();
r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0); r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0);
op::rectangle(&mut display, r, screen_clip.into(), false) op::rectangle(&mut display, r, screen_clip.into(), false)
} }
Some(GfxOpcode::Line) => { GfxOpcode::Line => {
minigfx::handlers::line(&mut display, screen_clip.into(), &mut msg); minigfx::handlers::line(&mut display, screen_clip.into(), msg);
} }
Some(GfxOpcode::Rectangle) => { GfxOpcode::Rectangle => {
minigfx::handlers::rectangle(&mut display, screen_clip.into(), &mut msg); minigfx::handlers::rectangle(&mut display, screen_clip.into(), msg);
} }
Some(GfxOpcode::RoundedRectangle) => { GfxOpcode::RoundedRectangle => {
minigfx::handlers::rounded_rectangle(&mut display, screen_clip.into(), &mut msg); minigfx::handlers::rounded_rectangle(&mut display, screen_clip.into(), msg);
} }
#[cfg(feature = "ditherpunk")] #[cfg(feature = "ditherpunk")]
Some(GfxOpcode::Tile) => { GfxOpcode::Tile => {
minigfx::handlers::tile(&mut display, screen_clip.into(), &mut msg); minigfx::handlers::tile(&mut display, screen_clip.into(), msg);
} }
Some(GfxOpcode::Circle) => { GfxOpcode::Circle => {
minigfx::handlers::circle(&mut display, screen_clip.into(), &mut msg); minigfx::handlers::circle(&mut display, screen_clip.into(), msg);
} }
Some(GfxOpcode::ScreenSize) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { GfxOpcode::ScreenSize => {
if let Some(scalar) = msg.body.scalar_message_mut() {
let pt = display.screen_size(); let pt = display.screen_size();
xous::return_scalar2(msg.sender, pt.x as usize, pt.y as usize) scalar.arg1 = pt.x as usize;
.expect("couldn't return ScreenSize request"); scalar.arg2 = pt.y as usize;
}), } else {
Some(GfxOpcode::QueryGlyphProps) => { panic!("Incorrect message type");
minigfx::handlers::query_glyph_props(&mut msg);
} }
Some(GfxOpcode::DrawSleepScreen) => msg_scalar_unpack!(msg, _, _, _, _, { }
GfxOpcode::QueryGlyphProps => {
minigfx::handlers::query_glyph_props(msg);
}
GfxOpcode::DrawSleepScreen => {
if let Some(_scalar) = msg.body.scalar_message() {
display.blit_screen(&logo::LOGO_MAP); display.blit_screen(&logo::LOGO_MAP);
display.redraw(); display.redraw();
}), } else {
Some(GfxOpcode::DrawBootLogo) => msg_scalar_unpack!(msg, _, _, _, _, { panic!("Incorrect message type");
}
}
GfxOpcode::DrawBootLogo => {
if let Some(_scalar) = msg.body.scalar_message() {
display.blit_screen(&poweron::LOGO_MAP); display.blit_screen(&poweron::LOGO_MAP);
display.redraw(); display.redraw();
}), } else {
Some(GfxOpcode::Devboot) => msg_scalar_unpack!(msg, ena, _, _, _, { panic!("Incorrect message type");
}
}
GfxOpcode::Devboot => {
if let Some(scalar) = msg.body.scalar_message() {
let ena = scalar.arg1;
if ena != 0 { if ena != 0 {
display.set_devboot(true); display.set_devboot(true);
} else { } else {
display.set_devboot(false); display.set_devboot(false);
} }
}), } else {
Some(GfxOpcode::RestartBulkRead) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { panic!("Incorrect message type");
}
}
GfxOpcode::RestartBulkRead => {
if let Some(scalar) = msg.body.scalar_message_mut() {
bulkread.from_offset = 0; bulkread.from_offset = 0;
xous::return_scalar(msg.sender, 0) scalar.arg1 = 0;
.expect("couldn't ack that bulk read pointer was reset"); } else {
}), panic!("Incorrect message type");
Some(GfxOpcode::BulkReadFonts) => { }
}
GfxOpcode::BulkReadFonts => {
// this also needs to reflect in root-keys/src/implementation.rs @ sign_loader() // this also needs to reflect in root-keys/src/implementation.rs @ sign_loader()
let fontlen = fontmap::FONT_TOTAL_LEN as u32 let fontlen = fontmap::FONT_TOTAL_LEN as u32
+ 16 // minver + 16 // minver
@ -323,7 +347,9 @@ fn wrapped_main(main_thread_token: backend::MainThreadToken) -> ! {
bulkread.from_offset += readlen as u32; bulkread.from_offset += readlen as u32;
buf.replace(bulkread).unwrap(); buf.replace(bulkread).unwrap();
} }
Some(GfxOpcode::TestPattern) => msg_blocking_scalar_unpack!(msg, duration, _, _, _, { GfxOpcode::TestPattern => {
if let Some(scalar) = msg.body.scalar_message_mut() {
let duration = scalar.arg1;
let mut stashmem = xous::syscall::map_memory( let mut stashmem = xous::syscall::map_memory(
None, None,
None, None,
@ -424,26 +450,29 @@ fn wrapped_main(main_thread_token: backend::MainThreadToken) -> ! {
} }
display.blit_screen(stash); display.blit_screen(stash);
xous::return_scalar(msg.sender, duration).expect("couldn't ack test pattern"); scalar.arg1 = duration;
}), } else {
Some(GfxOpcode::Stash) => { panic!("Incorrect message type");
}
}
GfxOpcode::Stash => {
display.stash(); display.stash();
match msg.body { if let Some(scalar) = msg.body.scalar_message_mut() {
// ack the message if it's a blocking scalar // ack the message if it's a blocking scalar
xous::Message::BlockingScalar(_) => xous::return_scalar(msg.sender, 1).unwrap(), scalar.arg1 = 1;
_ => (),
} }
// no failure if it's not
} }
Some(GfxOpcode::Pop) => { GfxOpcode::Pop => {
display.pop(); display.pop();
match msg.body { if let Some(scalar) = msg.body.scalar_message_mut() {
// ack the message if it's a blocking scalar // ack the message if it's a blocking scalar
xous::Message::BlockingScalar(_) => xous::return_scalar(msg.sender, 1).unwrap(), scalar.arg1 = 1;
_ => (),
} }
// no failure if it's not
} }
Some(GfxOpcode::Quit) => break, GfxOpcode::Quit => break,
None => { GfxOpcode::InvalidCall => {
log::error!("Received invalid GfxOpcode. Ignoring."); log::error!("Received invalid GfxOpcode. Ignoring.");
} }
_ => { _ => {