From 6c82fa9d7b39a6ae70f1e233c9123b9d32c30623 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Tue, 7 Jun 2016 21:15:53 -0700 Subject: Only draw when terminal state has changed This is achieved by setting a `dirty` flag when the terminal receives an event that causes visible state to change. The implementation is pretty much crap because most methods know about the flag. Figure out something better later. --- src/main.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 98daddf1..fd22b304 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,26 +193,30 @@ fn main() { gl::Clear(gl::COLOR_BUFFER_BIT); } - { - let _sampler = meter.sampler(); + if terminal.dirty() { + { + let _sampler = meter.sampler(); - renderer.with_api(&props, |mut api| { - // Draw the grid - api.render_grid(terminal.grid(), &mut glyph_cache); + renderer.with_api(&props, |mut api| { + // Draw the grid + api.render_grid(terminal.grid(), &mut glyph_cache); - // Also draw the cursor - api.render_cursor(terminal.cursor(), &mut glyph_cache); - }) - } + // Also draw the cursor + api.render_cursor(terminal.cursor(), &mut glyph_cache); + }) + } - // Draw render timer - let timing = format!("{:.3} usec", meter.average()); - let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 }; - renderer.with_api(&props, |mut api| { - api.render_string(&timing[..], &mut glyph_cache, &color); - }); + // Draw render timer + let timing = format!("{:.3} usec", meter.average()); + let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 }; + renderer.with_api(&props, |mut api| { + api.render_string(&timing[..], &mut glyph_cache, &color); + }); + + terminal.clear_dirty(); - window.swap_buffers().unwrap(); + window.swap_buffers().unwrap(); + } } // TODO handle child cleanup -- cgit