1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

windows: some minor performance improvements

* Make window invalidation more efficient by avoiding spawning a call
  that spawns a call to invalidate the window.  Just directly mark as
  invalidated.

* Suppress default background erase

* hoist the bg_color calc for quads that don't have Cells outside of
  its loop.

refs: https://github.com/wez/wezterm/issues/546
This commit is contained in:
Wez Furlong 2021-03-21 10:06:43 -07:00
parent 08797e77b5
commit 4767fcc28c
3 changed files with 25 additions and 16 deletions

View File

@ -194,7 +194,7 @@ where
/// It's a bit involved to make this work; more details can be
/// found in the excellent guide here:
/// <https://github.com/sunshowers/borrow-complex-key-example/blob/master/src/lib.rs>
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Debug, Clone, PartialEq, Eq, Hash)]
pub struct BorrowedShapeCacheKey<'a> {
pub style: &'a TextStyle,
pub text: &'a str,

View File

@ -70,7 +70,7 @@ impl super::TermWindow {
*self.has_animation.borrow_mut() = None;
self.check_for_config_reload();
let start = std::time::Instant::now();
let start = Instant::now();
{
let background_alpha = (self.config.window_background_opacity * 255.0) as u8;
@ -93,6 +93,7 @@ impl super::TermWindow {
let result = if pass == 0 {
// Let's try clearing out the atlas and trying again
// self.clear_texture_atlas()
log::trace!("recreate_texture_atlas");
self.recreate_texture_atlas(Some(current_size))
} else {
log::trace!("grow texture atlas to {}", size);
@ -114,9 +115,10 @@ impl super::TermWindow {
}
}
}
log::debug!("paint_impl before call_draw elapsed={:?}", start.elapsed());
self.call_draw(frame).ok();
log::debug!("paint_pane_opengl elapsed={:?}", start.elapsed());
log::debug!("paint_impl elapsed={:?}", start.elapsed());
metrics::histogram!("gui.paint.opengl", start.elapsed());
self.update_title_post_status();
}
@ -885,6 +887,15 @@ impl super::TermWindow {
// the right pane with its prior contents instead of showing the
// cleared lines from the shell in the main screen.
let bg_color = rgbcolor_alpha_to_window_color(
params.palette.resolve_bg(ColorAttribute::Default),
if window_is_transparent {
0x00
} else {
(params.config.text_background_opacity * 255.0) as u8
},
);
for cell_idx in last_cell_idx.unwrap_or(0) + 1..num_cols {
// Even though we don't have a cell for these, they still
// hold the cursor or the selection so we need to compute
@ -900,14 +911,7 @@ impl super::TermWindow {
cursor: params.cursor,
selection: &params.selection,
fg_color: params.foreground,
bg_color: rgbcolor_alpha_to_window_color(
params.palette.resolve_bg(ColorAttribute::Default),
if window_is_transparent {
0x00
} else {
(params.config.text_background_opacity * 255.0) as u8
},
),
bg_color,
palette: params.palette,
is_active_pane: params.pos.is_active,
config: params.config,
@ -1177,6 +1181,7 @@ impl super::TermWindow {
}
pub fn clear_texture_atlas(&mut self) -> anyhow::Result<()> {
log::trace!("clear_texture_atlas");
self.shape_cache.borrow_mut().clear();
if let Some(render_state) = self.render_state.as_mut() {
render_state.clear_texture_atlas(&self.render_metrics)?;

View File

@ -457,8 +457,9 @@ impl WindowOpsMut for WindowInner {
}
fn invalidate(&mut self) {
log::trace!("WindowOpsMut::invalidate");
unsafe {
InvalidateRect(self.hwnd.0, null(), 1);
InvalidateRect(self.hwnd.0, null(), 0);
}
}
@ -609,10 +610,12 @@ impl WindowOps for Window {
}
fn invalidate(&self) -> Future<()> {
Connection::with_window_inner(self.0, |inner| {
inner.invalidate();
Ok(())
})
let hwnd = self.0 .0;
log::trace!("WindowOps::invalidate calling InvalidateRect");
unsafe {
InvalidateRect(hwnd, null(), 0);
}
Future::ok(())
}
fn set_title(&self, title: &str) -> Future<()> {
@ -1909,6 +1912,7 @@ unsafe fn do_wnd_proc(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
| WM_RBUTTONDOWN | WM_RBUTTONUP | WM_MBUTTONDOWN | WM_MBUTTONUP => {
mouse_button(hwnd, msg, wparam, lparam)
}
WM_ERASEBKGND => Some(1),
WM_CLOSE => {
if let Some(inner) = rc_from_hwnd(hwnd) {
let inner = inner.borrow();