From 1455ea6d8ba871b6a280e1a43e5e7e77e27a5e48 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 29 Mar 2022 22:50:25 +0800 Subject: [PATCH] clean up the suspend/resume path for the screen and enforce redraw --- services/graphics-server/src/api.rs | 3 - .../graphics-server/src/backend/betrusted.rs | 91 +++++++++---------- services/graphics-server/src/lib.rs | 9 -- services/graphics-server/src/main.rs | 30 +----- 4 files changed, 44 insertions(+), 89 deletions(-) diff --git a/services/graphics-server/src/api.rs b/services/graphics-server/src/api.rs index f9d3c1490..fd10ac565 100644 --- a/services/graphics-server/src/api.rs +++ b/services/graphics-server/src/api.rs @@ -93,9 +93,6 @@ pub(crate) enum Opcode { /// draws the sleep screen; assumes requests are vetted by GAM/xous-names DrawSleepScreen, - /// sets whether a sleep note should be rendered or not on suspend - SetSleepNote, - /// permanently turns on the Devboot mark Devboot, diff --git a/services/graphics-server/src/backend/betrusted.rs b/services/graphics-server/src/backend/betrusted.rs index 7822be19e..ed28b8d01 100644 --- a/services/graphics-server/src/backend/betrusted.rs +++ b/services/graphics-server/src/backend/betrusted.rs @@ -57,11 +57,11 @@ impl XousDisplay { .expect("couldn't map control port"); let mut display = XousDisplay { - fb: fb, - hwfb: hwfb, + fb, + hwfb, csr: CSR::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); @@ -80,69 +80,62 @@ impl XousDisplay { display } - pub fn suspend(&mut self, draw_note: bool) { + pub fn suspend(&mut self) { while self.busy() { // 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.susres.suspend(); - if draw_note { - let note = crate::sleep_note::LOGO_MAP; - let note_lines = note.len() / FB_WIDTH_WORDS; - let note_start_line = (FB_LINES - note_lines) / 2; - let note_end_line = note_start_line + note_lines; - let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE]; + let note = crate::sleep_note::LOGO_MAP; + let note_lines = note.len() / FB_WIDTH_WORDS; + let note_start_line = (FB_LINES - note_lines) / 2; + let note_end_line = note_start_line + note_lines; + let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE]; - for lines in 0..FB_LINES { - for words in 0..FB_WIDTH_WORDS { - if lines >= note_start_line && lines < note_end_line { - // We're on a line that has the 'Sleeping...' note. - // Draw it into the frame buffer. - let note_index = ((lines - note_start_line) * FB_WIDTH_WORDS) + words; - unsafe { - (*hwfb)[words + lines * FB_WIDTH_WORDS] = note[note_index]; - } - } else { - // We're not on a line that has the note. Clear the pixels, - // since we don't want any secrets to linger in the framebuffer - // and stay visible on the persistent display while the device is - // sleeping. - unsafe { - (*hwfb)[words + lines * FB_WIDTH_WORDS] = 0xFFFF_FFFF; - } + for lines in 0..FB_LINES { + for words in 0..FB_WIDTH_WORDS { + if lines >= note_start_line && lines < note_end_line { + // We're on a line that has the 'Sleeping...' note. + // Draw it into the frame buffer. + let note_index = ((lines - note_start_line) * FB_WIDTH_WORDS) + words; + unsafe { + (*hwfb)[words + lines * FB_WIDTH_WORDS] = note[note_index]; + } + } else { + // We're not on a line that has the note. Clear the pixels, + // since we don't want any secrets to linger in the framebuffer + // and stay visible on the persistent display while the device is + // sleeping. + unsafe { + (*hwfb)[words + lines * FB_WIDTH_WORDS] = 0xFFFF_FFFF; } } - - // set the dirty bits - unsafe { - (*hwfb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] |= 0x1_0000; - } } - self.update_dirty(); - while self.busy() { - // busy wait, blocking suspend until this has happened + // set the dirty bits + unsafe { + (*hwfb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] |= 0x1_0000; } } + + self.update_dirty(); + while self.busy() { + // busy wait, blocking suspend until this has happened + } } - pub fn resume(&mut self, drew_note: bool) { + pub fn resume(&mut self) { self.susres.resume(); self.srfb.resume(); - if drew_note { - 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 - } - } + self.redraw(); } pub fn screen_size(&self) -> Point { diff --git a/services/graphics-server/src/lib.rs b/services/graphics-server/src/lib.rs index f7e6f3188..5a899eec4 100644 --- a/services/graphics-server/src/lib.rs +++ b/services/graphics-server/src/lib.rs @@ -217,15 +217,6 @@ impl Gfx { .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. pub fn set_devboot(&self, enable: bool) -> Result<(), xous::Error> { let ena = if enable { 1 } else { 0 }; diff --git a/services/graphics-server/src/main.rs b/services/graphics-server/src/main.rs index 150c450c4..fa23d2f9e 100644 --- a/services/graphics-server/src/main.rs +++ b/services/graphics-server/src/main.rs @@ -111,25 +111,6 @@ fn xmain() -> ! { draw_boot_logo(&mut display); 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()); display.redraw(); @@ -148,18 +129,11 @@ fn xmain() -> ! { log::trace!("Message: {:?}", msg); match FromPrimitive::from_usize(msg.body.id()) { Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { - display.suspend(use_sleep_note); + display.suspend(); susres .suspend_until_resume(token) .expect("couldn't execute suspend/resume"); - display.resume(use_sleep_note); - }), - Some(Opcode::SetSleepNote) => xous::msg_scalar_unpack!(msg, set_use, _, _, _, { - if set_use == 0 { - use_sleep_note = false; - } else { - use_sleep_note = true; - } + display.resume(); }), Some(Opcode::DrawClipObject) => { let buffer =