Cell GPU cache must also key by screen type (primary/alternate)

This commit is contained in:
Mitchell Hashimoto
2022-09-13 10:43:03 -07:00
parent 7bde20a43d
commit d5ee4f8b21
3 changed files with 18 additions and 4 deletions

View File

@ -16,7 +16,13 @@ const lru = @import("lru.zig");
const log = std.log.scoped(.grid);
const CellsLRU = lru.AutoHashMap(terminal.Screen.RowHeader.Id, std.ArrayListUnmanaged(GPUCell));
// The LRU is keyed by (screen, row_id) since we need to cache rows
// separately for alt screens. By storing that in the key, we very likely
// have the cache already for when the primary screen is reactivated.
const CellsLRU = lru.AutoHashMap(struct {
screen: terminal.Terminal.ScreenType,
row_id: terminal.Screen.RowHeader.Id,
}, std.ArrayListUnmanaged(GPUCell));
alloc: std.mem.Allocator,
@ -379,7 +385,10 @@ pub fn rebuildCells(self: *Grid, term: *Terminal) !void {
defer y += 1;
// Get our value from the cache.
const gop = try self.cells_lru.getOrPut(self.alloc, row.getId());
const gop = try self.cells_lru.getOrPut(self.alloc, .{
.screen = term.active_screen,
.row_id = row.getId(),
});
if (!row.isDirty() and gop.found_existing) {
var i: usize = self.cells.items.len;
for (gop.value_ptr.items) |cell| {

View File

@ -27,7 +27,7 @@ const log = std.log.scoped(.terminal);
const TABSTOP_INTERVAL = 8;
/// Screen type is an enum that tracks whether a screen is primary or alternate.
const ScreenType = enum {
pub const ScreenType = enum {
primary,
alternate,
};
@ -172,6 +172,8 @@ pub fn alternateScreen(self: *Terminal, options: AlternateScreenOptions) void {
const tracy = trace(@src());
defer tracy.end();
//log.info("alt screen active={} options={} cursor={}", .{ self.active_screen, options, self.screen.cursor });
// TODO: test
// TODO(mitchellh): what happens if we enter alternate screen multiple times?
// for now, we ignore...
@ -199,6 +201,8 @@ pub fn primaryScreen(self: *Terminal, options: AlternateScreenOptions) void {
const tracy = trace(@src());
defer tracy.end();
//log.info("primary screen active={} options={}", .{ self.active_screen, options });
// TODO: test
// TODO(mitchellh): what happens if we enter alternate screen multiple times?
if (self.active_screen == .primary) return;

View File

@ -51,7 +51,8 @@ pub fn Stream(comptime Handler: type) type {
const actions = self.parser.next(c);
for (actions) |action_opt| {
// if (action_opt) |action| {
// log.info("action: {}", .{action});
// if (action != .print)
// log.info("action: {}", .{action});
// }
switch (action_opt orelse continue) {
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),