diff --git a/services/gam/src/canvas.rs b/services/gam/src/canvas.rs index ee9735f8e..ee3ca548d 100644 --- a/services/gam/src/canvas.rs +++ b/services/gam/src/canvas.rs @@ -148,6 +148,7 @@ impl Eq for Canvas {} pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut FnvIndexMap) -> bool { // first check if any need defacing, if not, then we're done let mut needs_defacing = false; + let mut defaced = false; // this is set if any drawing actually happens for (_, c) in canvases.iter() { if c.needs_defacing() { needs_defacing = true; @@ -217,6 +218,7 @@ pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut FnvI DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1)), clip_rect).unwrap(); } + defaced = true; } // indicate that the defacement has happened to the canvas state machine @@ -224,7 +226,7 @@ pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut FnvI } } } - needs_defacing + defaced } // we use the "screen" parameter to determine when we can turn off drawing to canvases that are off-screen diff --git a/services/gam/src/main.rs b/services/gam/src/main.rs index 424e1a80c..126662098 100644 --- a/services/gam/src/main.rs +++ b/services/gam/src/main.rs @@ -110,6 +110,8 @@ struct ContextManager { imef_active: bool, kbd: keyboard::Keyboard, main_menu_app_token: Option<[u32; 4]>, // app_token of the main menu, if it has been registered + /// for internal generation of deface states + pub trng: trng::Trng, } impl ContextManager { pub fn new(xns: &xous_names::XousNames) -> Self { @@ -129,6 +131,7 @@ impl ContextManager { imef_active: false, kbd, main_menu_app_token: None, + trng: trng::Trng::new(&xns).expect("couldn't connect to trng"), } } pub(crate) fn claim_token(&mut self, name: &str) -> Option<[u32; 4]> { @@ -428,6 +431,8 @@ impl ContextManager { self.last_context = self.focused_context; self.focused_context = Some(last_token); } + // run the defacement before we redraw all the canvases + deface(gfx, &self.trng, canvases); self.redraw().expect("couldn't redraw the currently focused app"); } } @@ -705,7 +710,9 @@ fn xmain() -> ! { last_time = elapsed_time; if deface(&gfx, &trng, &mut canvases) { - // redraw the trusted foreground apps after a defacement + // we keep this here because it's a fail-safe in case prior routines missed an edge case. shoot out a warning noting the issue. + log::warn!("canvases were not defaced in order. running a defacement, but this could result in drawing optimizations failing."); + // try to redraw the trusted foreground apps after a defacement context_mgr.redraw().expect("couldn't redraw after defacement"); } log::trace!("flushing...");