clean up the suspend/resume path for the screen and enforce redraw

This commit is contained in:
bunnie 2022-03-29 22:50:25 +08:00
parent c8382a671a
commit 1455ea6d8b
4 changed files with 44 additions and 89 deletions

View file

@ -93,9 +93,6 @@ pub(crate) enum Opcode {
/// draws the sleep screen; assumes requests are vetted by GAM/xous-names /// draws the sleep screen; assumes requests are vetted by GAM/xous-names
DrawSleepScreen, DrawSleepScreen,
/// sets whether a sleep note should be rendered or not on suspend
SetSleepNote,
/// permanently turns on the Devboot mark /// permanently turns on the Devboot mark
Devboot, Devboot,

View file

@ -57,11 +57,11 @@ impl XousDisplay {
.expect("couldn't map control port"); .expect("couldn't map control port");
let mut display = XousDisplay { let mut display = XousDisplay {
fb: fb, fb,
hwfb: hwfb, hwfb,
csr: CSR::new(control.as_mut_ptr() as *mut u32), csr: CSR::new(control.as_mut_ptr() as *mut u32),
susres: RegManager::new(control.as_mut_ptr() as *mut u32), susres: RegManager::new(control.as_mut_ptr() as *mut u32),
srfb: ManagedMem::new(hwfb), srfb: ManagedMem::new(fb),
}; };
display.set_clock(CONFIG_CLOCK_FREQUENCY); display.set_clock(CONFIG_CLOCK_FREQUENCY);
@ -80,14 +80,20 @@ impl XousDisplay {
display display
} }
pub fn suspend(&mut self, draw_note: bool) { pub fn suspend(&mut self) {
while self.busy() { while self.busy() {
// just wait until any pending FB operations are done // just wait until any pending FB operations are done
} }
let fb: *mut [u32; FB_SIZE] = self.fb.as_mut_ptr() as *mut [u32; FB_SIZE];
for lines in 0..FB_LINES {
// set the dirty bits prior to stashing the frame buffer
unsafe {
(*fb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] |= 0x1_0000;
}
}
self.srfb.suspend(); self.srfb.suspend();
self.susres.suspend(); self.susres.suspend();
if draw_note {
let note = crate::sleep_note::LOGO_MAP; let note = crate::sleep_note::LOGO_MAP;
let note_lines = note.len() / FB_WIDTH_WORDS; let note_lines = note.len() / FB_WIDTH_WORDS;
let note_start_line = (FB_LINES - note_lines) / 2; let note_start_line = (FB_LINES - note_lines) / 2;
@ -125,24 +131,11 @@ impl XousDisplay {
// busy wait, blocking suspend until this has happened // busy wait, blocking suspend until this has happened
} }
} }
} pub fn resume(&mut self) {
pub fn resume(&mut self, drew_note: bool) {
self.susres.resume(); self.susres.resume();
self.srfb.resume(); self.srfb.resume();
if drew_note { self.redraw();
let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE];
for lines in 0..FB_LINES {
// set the dirty bits of all lines to force a redraw of the restored data
unsafe {
(*hwfb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] |= 0x1_0000;
}
}
self.update_dirty();
while self.busy() {
// busy wait, blocking resume until this has happened
}
}
} }
pub fn screen_size(&self) -> Point { pub fn screen_size(&self) -> Point {

View file

@ -217,15 +217,6 @@ impl Gfx {
.map(|_| ()) .map(|_| ())
} }
pub fn draw_sleep_note(&self, flag: bool) -> Result<(), xous::Error> {
let arg = if flag { 1 } else { 0 };
send_message(
self.conn,
Message::new_scalar(Opcode::SetSleepNote.to_usize().unwrap(), arg, 0, 0, 0),
)
.map(|_| ())
}
/// this is a one-way door, once you've set it, you can't unset it. /// this is a one-way door, once you've set it, you can't unset it.
pub fn set_devboot(&self, enable: bool) -> Result<(), xous::Error> { pub fn set_devboot(&self, enable: bool) -> Result<(), xous::Error> {
let ena = if enable { 1 } else { 0 }; let ena = if enable { 1 } else { 0 };

View file

@ -111,25 +111,6 @@ fn xmain() -> ! {
draw_boot_logo(&mut display); draw_boot_logo(&mut display);
let fontregion = map_fonts(); let fontregion = map_fonts();
let mut use_sleep_note = true;
if false {
// leave this test case around
// for some reason, the top right quadrant draws an extra pixel inside the fill area
// when a fill color of "Light" is specified. However, if `None` fill is specified, it
// works correctly. This is really puzzling, because the test for filled drawing happens
// after the test for border drawing.
use api::Point;
let mut r = Rectangle::new(Point::new(20, 200), Point::new(151, 301));
r.style = DrawStyle {
fill_color: Some(PixelColor::Light),
stroke_color: Some(PixelColor::Dark),
stroke_width: 1,
};
let rr = RoundedRectangle::new(r, 16);
op::rounded_rectangle(display.native_buffer(), rr, None);
}
let screen_clip = Rectangle::new(Point::new(0, 0), display.screen_size()); let screen_clip = Rectangle::new(Point::new(0, 0), display.screen_size());
display.redraw(); display.redraw();
@ -148,18 +129,11 @@ fn xmain() -> ! {
log::trace!("Message: {:?}", msg); log::trace!("Message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) { match FromPrimitive::from_usize(msg.body.id()) {
Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
display.suspend(use_sleep_note); display.suspend();
susres susres
.suspend_until_resume(token) .suspend_until_resume(token)
.expect("couldn't execute suspend/resume"); .expect("couldn't execute suspend/resume");
display.resume(use_sleep_note); display.resume();
}),
Some(Opcode::SetSleepNote) => xous::msg_scalar_unpack!(msg, set_use, _, _, _, {
if set_use == 0 {
use_sleep_note = false;
} else {
use_sleep_note = true;
}
}), }),
Some(Opcode::DrawClipObject) => { Some(Opcode::DrawClipObject) => {
let buffer = let buffer =