improve redraw performance on menu

it helps to actually redraw the menu instead of relying
upon status updates to redo the Ux.
This commit is contained in:
bunnie 2021-06-20 00:44:59 +08:00
parent c0d4cbe81d
commit f4fbe84b78
3 changed files with 19 additions and 5 deletions

View file

@ -522,6 +522,7 @@ impl Menu {
break; break;
} }
} }
self.gam.redraw().unwrap();
} }
fn num_items(&self) -> usize { fn num_items(&self) -> usize {
let mut items = 0; let mut items = 0;
@ -558,6 +559,7 @@ impl Menu {
} }
self.index = 0; // reset the index to 0 self.index = 0; // reset the index to 0
} }
self.gam.redraw().unwrap();
}, },
'←' => { '←' => {
// placeholder // placeholder
@ -569,9 +571,11 @@ impl Menu {
} }
'↑' => { '↑' => {
self.prev_item(); self.prev_item();
self.gam.redraw().unwrap();
} }
'↓' => { '↓' => {
self.next_item(); self.next_item();
self.gam.redraw().unwrap();
} }
_ => {} _ => {}
} }

View file

@ -50,7 +50,7 @@ pub fn pump_thread(conn: usize) {
Ok(xous::Result::Ok) => {}, Ok(xous::Result::Ok) => {},
_ => panic!("unhandled error in status pump thread") _ => panic!("unhandled error in status pump thread")
} }
ticktimer.sleep_ms(250).unwrap(); ticktimer.sleep_ms(1000).unwrap();
} }
} }
@ -183,6 +183,8 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
} else { } else {
write!(&mut security_tv, " USB secured").unwrap(); write!(&mut security_tv, " USB secured").unwrap();
} }
// only post the view if something has actually changed
gam.post_textview(&mut security_tv).unwrap();
} }
let elapsed_time = ticktimer.elapsed_ms(); let elapsed_time = ticktimer.elapsed_ms();
let now_seconds: usize = ((elapsed_time / 1000) % 60) as usize; let now_seconds: usize = ((elapsed_time / 1000) % 60) as usize;
@ -235,7 +237,7 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
} }
last_seconds = now_seconds; last_seconds = now_seconds;
uptime_tv.clear_str(); uptime_tv.clear_str();
if (stats_phase > 3) && datetime.is_some() { if (stats_phase >= 2) && datetime.is_some() {
let dt = datetime.unwrap(); let dt = datetime.unwrap();
let day = match dt.weekday { let day = match dt.weekday {
rtc::Weekday::Monday => "Mon", rtc::Weekday::Monday => "Mon",
@ -257,9 +259,8 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
log::trace!("|status: requesting draw of '{}'", uptime_tv); log::trace!("|status: requesting draw of '{}'", uptime_tv);
gam.post_textview(&mut uptime_tv).expect("|status: can't draw uptime"); gam.post_textview(&mut uptime_tv).expect("|status: can't draw uptime");
gam.post_textview(&mut battstats_tv).expect("|status: can't draw battery stats"); gam.post_textview(&mut battstats_tv).expect("|status: can't draw battery stats");
gam.post_textview(&mut security_tv).unwrap();
gam.redraw().expect("|status: couldn't redraw"); gam.redraw().expect("|status: couldn't redraw");
stats_phase = (stats_phase + 1) % 8; stats_phase = (stats_phase + 1) % 4;
} }
if elapsed_time - last_time > batt_interval { if elapsed_time - last_time > batt_interval {
//info!("|status: size of TextView type: {} bytes", core::mem::size_of::<TextView>()); //info!("|status: size of TextView type: {} bytes", core::mem::size_of::<TextView>());

View file

@ -128,7 +128,12 @@ impl XousDisplay {
pub fn screen_size(&self) -> Point { Point::new(FB_WIDTH_PIXELS as i16, FB_LINES as i16) } pub fn screen_size(&self) -> Point { Point::new(FB_WIDTH_PIXELS as i16, FB_LINES as i16) }
pub fn redraw(&mut self) { pub fn redraw(&mut self) {
while self.busy() {xous::yield_slice()} let mut busy_count = 0;
let mut dirty_count = 0;
while self.busy() {
xous::yield_slice();
busy_count += 1;
}
let fb: *mut [u32; FB_SIZE] = self.fb.as_mut_ptr() as *mut [u32; FB_SIZE]; let fb: *mut [u32; FB_SIZE] = self.fb.as_mut_ptr() as *mut [u32; FB_SIZE];
let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE]; let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE];
for words in 0..FB_SIZE { for words in 0..FB_SIZE {
@ -140,10 +145,14 @@ impl XousDisplay {
// clear all the dirty bits, under the theory that it's time-wise cheaper on average // clear all the dirty bits, under the theory that it's time-wise cheaper on average
// to visit every line and clear the dirty bits than it is to do an update_all() // to visit every line and clear the dirty bits than it is to do an update_all()
for lines in 0..FB_LINES { for lines in 0..FB_LINES {
if unsafe{(*fb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] & 0xFFFF_0000} != 0x0 {
dirty_count += 1;
}
unsafe { unsafe {
(*fb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] &= 0x0000_FFFF; (*fb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] &= 0x0000_FFFF;
} }
} }
log::trace!("redraw {}/{}", busy_count, dirty_count);
} }
// note: this API is used by emulation, don't remove calls to it // note: this API is used by emulation, don't remove calls to it