Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(renderer): clip terminal contents to expected grid size (#4523) #5265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/renderer/Metal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1046,19 +1046,6 @@ pub fn updateFrame(
}
}

// If our terminal screen size doesn't match our expected renderer
// size then we skip a frame. This can happen if the terminal state
// is resized between when the renderer mailbox is drained and when
// the state mutex is acquired inside this function.
//
// For some reason this doesn't seem to cause any significant issues
// with flickering while resizing. '\_('-')_/'
if (self.cells.size.rows != state.terminal.rows or
self.cells.size.columns != state.terminal.cols)
{
return;
}

// Get the viewport pin so that we can compare it to the current.
const viewport_pin = state.terminal.screen.pages.pin(.{ .viewport = .{} }).?;

Expand Down Expand Up @@ -2437,12 +2424,22 @@ fn rebuildCells(
}
}

// Go row-by-row to build the cells. We go row by row because we do
// font shaping by row. In the future, we will also do dirty tracking
// by row.
// We rebuild the cells row-by-row because we
// do font shaping and dirty tracking by row.
var row_it = screen.pages.rowIterator(.left_up, .{ .viewport = .{} }, null);
var y: terminal.size.CellCountInt = screen.pages.rows;
// If our cell contents buffer is shorter than the screen viewport,
// we render the rows that fit, starting from the bottom. If instead
// the viewport is shorter than the cell contents buffer, we align
// the top of the viewport with the top of the contents buffer.
var y: terminal.size.CellCountInt = @min(
screen.pages.rows,
self.cells.size.rows,
);
while (row_it.next()) |row| {
// The viewport may have more rows than our cell contents,
// so we need to break from the loop early if we hit y = 0.
if (y == 0) break;

y -= 1;

if (!rebuild) {
Expand Down Expand Up @@ -2501,7 +2498,11 @@ fn rebuildCells(
var shaper_cells: ?[]const font.shape.Cell = null;
var shaper_cells_i: usize = 0;

const row_cells = row.cells(.all);
const row_cells_all = row.cells(.all);

// If our viewport is wider than our cell contents buffer,
// we still only process cells up to the width of the buffer.
const row_cells = row_cells_all[0..@min(row_cells_all.len, self.cells.size.columns)];

for (row_cells, 0..) |*cell, x| {
// If this cell falls within our preedit range then we
Expand Down
38 changes: 20 additions & 18 deletions src/renderer/OpenGL.zig
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,6 @@ pub fn updateFrame(

// Update all our data as tightly as possible within the mutex.
var critical: Critical = critical: {
const grid_size = self.size.grid();

state.mutex.lock();
defer state.mutex.unlock();

Expand Down Expand Up @@ -748,19 +746,6 @@ pub fn updateFrame(
}
}

// If our terminal screen size doesn't match our expected renderer
// size then we skip a frame. This can happen if the terminal state
// is resized between when the renderer mailbox is drained and when
// the state mutex is acquired inside this function.
//
// For some reason this doesn't seem to cause any significant issues
// with flickering while resizing. '\_('-')_/'
if (grid_size.rows != state.terminal.rows or
grid_size.columns != state.terminal.cols)
{
return;
}

// Get the viewport pin so that we can compare it to the current.
const viewport_pin = state.terminal.screen.pages.pin(.{ .viewport = .{} }).?;

Expand Down Expand Up @@ -1276,10 +1261,23 @@ pub fn rebuildCells(
}
}

// Build each cell
const grid_size = self.size.grid();

// We rebuild the cells row-by-row because we do font shaping by row.
var row_it = screen.pages.rowIterator(.left_up, .{ .viewport = .{} }, null);
var y: terminal.size.CellCountInt = screen.pages.rows;
// If our cell contents buffer is shorter than the screen viewport,
// we render the rows that fit, starting from the bottom. If instead
// the viewport is shorter than the cell contents buffer, we align
// the top of the viewport with the top of the contents buffer.
var y: terminal.size.CellCountInt = @min(
screen.pages.rows,
grid_size.rows,
);
while (row_it.next()) |row| {
// The viewport may have more rows than our cell contents,
// so we need to break from the loop early if we hit y = 0.
if (y == 0) break;

y -= 1;

// True if we want to do font shaping around the cursor. We want to
Expand Down Expand Up @@ -1356,7 +1354,11 @@ pub fn rebuildCells(
var shaper_cells: ?[]const font.shape.Cell = null;
var shaper_cells_i: usize = 0;

const row_cells = row.cells(.all);
const row_cells_all = row.cells(.all);

// If our viewport is wider than our cell contents buffer,
// we still only process cells up to the width of the buffer.
const row_cells = row_cells_all[0..@min(row_cells_all.len, grid_size.columns)];

for (row_cells, 0..) |*cell, x| {
// If this cell falls within our preedit range then we
Expand Down