Skip displaying unchanged cells
This commit is contained in:
parent
90493fe11e
commit
0bcdbb4210
42
src/main.rs
42
src/main.rs
|
@ -65,17 +65,19 @@ impl GlyphCache {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn lookup(&mut self, cell: &Cell) -> &[u32] {
|
||||
let glyph_info = GlyphInfo {
|
||||
pub fn cell_info(&self, cell: &Cell) -> GlyphInfo {
|
||||
GlyphInfo {
|
||||
c: cell.c,
|
||||
fg: self.color_to_u32(&cell.fg),
|
||||
bg: self.color_to_u32(&cell.bg),
|
||||
flags: cell.flags,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup(&mut self, glyph: &GlyphInfo) -> &[u32] {
|
||||
self.glyphs
|
||||
.entry(glyph_info.clone())
|
||||
.or_insert_with(|| self.renderer.draw(&glyph_info).into_boxed_slice())
|
||||
.entry(glyph.clone())
|
||||
.or_insert_with(|| self.renderer.draw(glyph).into_boxed_slice())
|
||||
}
|
||||
|
||||
// TODO deduplicate
|
||||
|
@ -164,6 +166,7 @@ impl BitmapGlyphRenderer {
|
|||
|
||||
pub struct Graphics {
|
||||
glyph_cache: GlyphCache,
|
||||
cell_cache: HashMap<(usize, usize), GlyphInfo>,
|
||||
width: usize,
|
||||
height: usize,
|
||||
cell_width: usize,
|
||||
|
@ -182,6 +185,7 @@ impl Graphics {
|
|||
Self::load_colors(&mut colors);
|
||||
|
||||
let glyph_cache = GlyphCache::new(colors.clone());
|
||||
let cell_cache = Default::default();
|
||||
|
||||
Self {
|
||||
width,
|
||||
|
@ -189,6 +193,7 @@ impl Graphics {
|
|||
cell_width: glyph_cache.renderer.cell_width,
|
||||
cell_height: glyph_cache.renderer.cell_height,
|
||||
glyph_cache,
|
||||
cell_cache,
|
||||
colors,
|
||||
buffer,
|
||||
}
|
||||
|
@ -259,6 +264,8 @@ impl Graphics {
|
|||
|
||||
self.buffer.clear();
|
||||
self.buffer.resize(width * height, 0);
|
||||
|
||||
self.cell_cache.clear();
|
||||
}
|
||||
|
||||
pub fn redraw(&mut self, term: &Term<TermListener>, context: &mut GraphicsContext<Window>) {
|
||||
|
@ -267,12 +274,19 @@ impl Graphics {
|
|||
(size.width as usize, size.height as usize)
|
||||
};
|
||||
|
||||
let mut buffer = vec![0u32; (width * height) as usize];
|
||||
if width != self.width || height != self.height {
|
||||
self.resize(width, height);
|
||||
}
|
||||
|
||||
let cursor_color = Color::Named(NamedColor::Foreground);
|
||||
let cursor_color = self.color_to_u32(&cursor_color);
|
||||
let buffer = self.buffer.as_mut_slice();
|
||||
let content = term.renderable_content();
|
||||
|
||||
for cell in content.display_iter.into_iter() {
|
||||
let term_row = cell.point.line.0 as usize;
|
||||
let term_col = cell.point.column.0 as usize;
|
||||
let term_coords = (term_row, term_col);
|
||||
|
||||
if (term_row + 1) * self.cell_height >= height
|
||||
|| (term_col + 1) * self.cell_width >= width
|
||||
|
@ -284,7 +298,15 @@ impl Graphics {
|
|||
continue;
|
||||
}
|
||||
|
||||
let glyph = self.glyph_cache.lookup(&cell);
|
||||
let glyph_info = self.glyph_cache.cell_info(&cell);
|
||||
|
||||
if self.cell_cache.get(&term_coords) == Some(&glyph_info) {
|
||||
continue;
|
||||
} else {
|
||||
self.cell_cache.insert(term_coords, glyph_info.clone());
|
||||
}
|
||||
|
||||
let glyph = self.glyph_cache.lookup(&glyph_info);
|
||||
let px_row = term_row * self.cell_height * width;
|
||||
let mut px_start = px_row + term_col * self.cell_width;
|
||||
|
||||
|
@ -303,12 +325,12 @@ impl Graphics {
|
|||
|
||||
let term_row = content.cursor.point.line.0 as usize;
|
||||
let term_col = content.cursor.point.column.0 as usize;
|
||||
let term_coords = (term_row, term_col);
|
||||
|
||||
if (term_row + 1) * self.cell_height < height && (term_col + 1) * self.cell_width < width {
|
||||
let mut px_row = term_row * width * self.cell_height + term_col * self.cell_width;
|
||||
self.cell_cache.remove(&term_coords);
|
||||
|
||||
let cursor_color = Color::Named(NamedColor::Foreground);
|
||||
let cursor_color = self.color_to_u32(&cursor_color);
|
||||
let mut px_row = term_row * width * self.cell_height + term_col * self.cell_width;
|
||||
|
||||
use alacritty_terminal::ansi::CursorShape;
|
||||
match content.cursor.shape {
|
||||
|
|
Loading…
Reference in New Issue