From 887152a13d90e6245a494a2f66740a908ed0fe2b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 1 Aug 2021 11:20:10 -0700 Subject: [PATCH] Improve UX when we run out of texture space Rather than leaving the frame un-rendered, this commit arranges to make one last pass but with all image quad assignments skipped. This should at least make a reasonable effort at displaying text on the screen. refs: https://github.com/wez/wezterm/issues/879 --- wezterm-gui/src/termwindow/mod.rs | 4 ++++ wezterm-gui/src/termwindow/render.rs | 29 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 0e1e2a278..e19091957 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -223,6 +223,9 @@ pub struct TermWindow { event_states: HashMap, has_animation: RefCell>, + /// We use this to attempt to do something reasonable + /// if we run out of texture space + allow_images: bool, scheduled_animation: RefCell>, gl: Option>, @@ -483,6 +486,7 @@ impl TermWindow { event_states: HashMap::new(), has_animation: RefCell::new(None), scheduled_animation: RefCell::new(None), + allow_images: true, }; let tw = Rc::new(RefCell::new(myself)); diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index ed16fc831..571412440 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -86,6 +86,8 @@ impl super::TermWindow { // If nothing on screen needs animating, then we can avoid // invalidating as frequently *self.has_animation.borrow_mut() = None; + // Start with the assumption that we should allow images to render + self.allow_images = true; let start = Instant::now(); @@ -138,12 +140,21 @@ impl super::TermWindow { }; if let Err(err) = result { - log::error!( - "Failed to {} texture: {}", - if pass == 0 { "clear" } else { "resize" }, - err - ); - break; + if self.allow_images { + self.allow_images = false; + log::info!( + "Not enough texture space ({:#}); \ + will retry render with images disabled", + err + ); + } else { + log::error!( + "Failed to {} texture: {}", + if pass == 0 { "clear" } else { "resize" }, + err + ); + break; + } } } else if err.root_cause().downcast_ref::().is_some() { self.shape_cache.borrow_mut().clear(); @@ -260,7 +271,7 @@ impl super::TermWindow { }, ); - if pos.index == 0 { + if pos.index == 0 && self.allow_images { // Render the window background image if let Some(im) = self.window_background.as_ref() { let mut quad = quads.allocate()?; @@ -1214,6 +1225,10 @@ impl super::TermWindow { hsv: Option, glyph_color: LinearRgba, ) -> anyhow::Result<()> { + if !self.allow_images { + return Ok(()); + } + let padding = self .render_metrics .cell_size