1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-14 03:16:09 +03:00

always use own box glyphs for pane splits

This section of the code wasn't looking up the custom glyphs
and would always use the font.  We can make rendering a little
more efficient if we skip the font resolution for this case,
and the code is much simpler if we just use our own box drawing
glyphs, so that's what we're doing here.

refs: #584
This commit is contained in:
Wez Furlong 2021-06-26 09:18:44 -07:00
parent 843dd88bb5
commit 0b5444ccfd

View File

@ -515,11 +515,12 @@ impl super::TermWindow {
let mut vb = gl_state.glyph_vertex_buffer.borrow_mut(); let mut vb = gl_state.glyph_vertex_buffer.borrow_mut();
let mut quads = gl_state.quads.map(&mut vb); let mut quads = gl_state.quads.map(&mut vb);
let config = &self.config; let config = &self.config;
let text = if split.direction == SplitDirection::Horizontal { let block = BlockKey::from_char(if split.direction == SplitDirection::Horizontal {
"" '\u{2502}'
} else { } else {
"" '\u{2500}'
}; })
.expect("to have box drawing glyph");
let palette = pane.palette(); let palette = pane.palette();
let foreground = rgbcolor_to_window_color(palette.split); let foreground = rgbcolor_to_window_color(palette.split);
let background = rgbcolor_alpha_to_window_color( let background = rgbcolor_alpha_to_window_color(
@ -531,114 +532,41 @@ impl super::TermWindow {
}, },
); );
let style = self.fonts.match_style(&config, &CellAttributes::default());
let glyph_info = {
let key = BorrowedShapeCacheKey { style, text };
match self.lookup_cached_shape(&key) {
Some(Ok(info)) => info,
Some(Err(err)) => return Err(err),
None => {
let font = self.fonts.resolve_font(style)?;
let window = self.window.as_ref().unwrap().clone();
match font.shape(
text,
move || window.notify(TermWindowNotif::InvalidateShapeCache),
BlockKey::filter_out_synthetic,
) {
Ok(info) => {
let line = Line::from_text(&text, &CellAttributes::default());
let clusters = line.cluster();
let glyphs = self.glyph_infos_to_glyphs(
&clusters[0],
&line,
&style,
&mut gl_state.glyph_cache.borrow_mut(),
&info,
)?;
let shaped = ShapedInfo::process(
&self.render_metrics,
&clusters[0],
&info,
&glyphs,
);
self.shape_cache
.borrow_mut()
.put(key.to_owned(), Ok(Rc::new(shaped)));
self.lookup_cached_shape(&key).unwrap().unwrap()
}
Err(err) => {
if err.root_cause().downcast_ref::<ClearShapeCache>().is_some() {
return Err(err);
}
let res = anyhow!("shaper error: {}", err);
self.shape_cache.borrow_mut().put(key.to_owned(), Err(err));
return Err(res);
}
}
}
}
};
let first_row_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom { let first_row_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
1 1
} else { } else {
0 0
}; };
let white_space = gl_state.util_sprites.white_space.texture_coords();
for info in glyph_info.iter() { let x_y_iter: Box<dyn Iterator<Item = (usize, usize)>> =
let glyph = &info.glyph; if split.direction == SplitDirection::Horizontal {
let left = info.pos.x_offset.get() as f32 + info.pos.bearing_x;
let top = ((PixelLength::new(self.render_metrics.cell_size.height as f64)
+ self.render_metrics.descender)
- (glyph.y_offset + glyph.bearing_y))
.get() as f32;
let texture = glyph
.texture
.as_ref()
.unwrap_or(&gl_state.util_sprites.white_space);
let underline_tex_rect = gl_state.util_sprites.white_space.texture_coords();
let x_y_iter: Box<dyn Iterator<Item = (usize, usize)>> = if split.direction
== SplitDirection::Horizontal
{
Box::new(std::iter::repeat(split.left).zip(split.top..split.top + split.size)) Box::new(std::iter::repeat(split.left).zip(split.top..split.top + split.size))
} else { } else {
Box::new((split.left..split.left + split.size).zip(std::iter::repeat(split.top))) Box::new((split.left..split.left + split.size).zip(std::iter::repeat(split.top)))
}; };
for (x, y) in x_y_iter { for (x, y) in x_y_iter {
let slice = SpriteSlice { let sprite = gl_state
cell_idx: 0, .glyph_cache
num_cells: info.pos.num_cells as usize, .borrow_mut()
cell_width: self.render_metrics.cell_size.width as usize, .cached_block(block)?
scale: glyph.scale as f32, .texture_coords();
left_offset: left,
};
let pixel_rect = slice.pixel_rect(texture); let mut quad = match quads.cell(x, y + first_row_offset) {
let texture_rect = texture.texture.to_texture_coords(pixel_rect); Ok(quad) => quad,
Err(_) => break,
};
let bottom = (pixel_rect.size.height as f32 * glyph.scale as f32) + top quad.set_fg_color(foreground);
- self.render_metrics.cell_size.height as f32; quad.set_underline_color(foreground);
let right = pixel_rect.size.width as f32 + left quad.set_bg_color(background);
- self.render_metrics.cell_size.width as f32; quad.set_hsv(None);
quad.set_texture(sprite);
let mut quad = match quads.cell(x, y + first_row_offset) { quad.set_texture_adjust(0., 0., 0., 0.);
Ok(quad) => quad, quad.set_underline(white_space);
Err(_) => break, quad.set_has_color(false);
}; quad.set_cursor(white_space);
quad.set_cursor_color(background);
quad.set_fg_color(foreground);
quad.set_underline_color(foreground);
quad.set_bg_color(background);
quad.set_hsv(None);
quad.set_texture(texture_rect);
quad.set_texture_adjust(left, top, right, bottom);
quad.set_underline(underline_tex_rect);
quad.set_has_color(glyph.has_color);
quad.set_cursor(underline_tex_rect);
quad.set_cursor_color(background);
}
} }
Ok(()) Ok(())
} }