mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
renderer/metal: skip frame update if our cell buffer is too small
See the comment in the diff for when this can happen.
This commit is contained in:
@ -740,6 +740,17 @@ pub fn updateFrame(
|
|||||||
self.foreground_color = bg;
|
self.foreground_color = bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If our terminal screen size doesn't match our expected renderer
|
||||||
|
// size then we skip a frame. This can happen if we get resized
|
||||||
|
// before the terminal gets resized. The terminal resize event also
|
||||||
|
// wakes up the renderer so we'll get another chance to update frame
|
||||||
|
// data.
|
||||||
|
if (self.cells.size.rows < state.terminal.rows or
|
||||||
|
self.cells.size.columns < state.terminal.cols)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We used to share terminal state, but we've since learned through
|
// We used to share terminal state, but we've since learned through
|
||||||
// analysis that it is faster to copy the terminal state than to
|
// analysis that it is faster to copy the terminal state than to
|
||||||
// hold the lock while rebuilding GPU cells.
|
// hold the lock while rebuilding GPU cells.
|
||||||
|
@ -61,7 +61,7 @@ pub const Contents = struct {
|
|||||||
|
|
||||||
/// The grid size of the terminal. This is used to determine the
|
/// The grid size of the terminal. This is used to determine the
|
||||||
/// map array index from a coordinate.
|
/// map array index from a coordinate.
|
||||||
cols: usize,
|
size: renderer.GridSize,
|
||||||
|
|
||||||
/// The actual GPU data (on the CPU) for all the cells in the terminal.
|
/// The actual GPU data (on the CPU) for all the cells in the terminal.
|
||||||
/// This only contains the cells that have content set. To determine
|
/// This only contains the cells that have content set. To determine
|
||||||
@ -85,7 +85,7 @@ pub const Contents = struct {
|
|||||||
|
|
||||||
var result: Contents = .{
|
var result: Contents = .{
|
||||||
.map = map,
|
.map = map,
|
||||||
.cols = 0,
|
.size = .{ .rows = 0, .columns = 0 },
|
||||||
.bgs = .{},
|
.bgs = .{},
|
||||||
.text = .{},
|
.text = .{},
|
||||||
.cursor = false,
|
.cursor = false,
|
||||||
@ -119,7 +119,7 @@ pub const Contents = struct {
|
|||||||
|
|
||||||
alloc.free(self.map);
|
alloc.free(self.map);
|
||||||
self.map = map;
|
self.map = map;
|
||||||
self.cols = size.columns;
|
self.size = size;
|
||||||
self.bgs.clearAndFree(alloc);
|
self.bgs.clearAndFree(alloc);
|
||||||
self.text.shrinkAndFree(alloc, text_reserved_len);
|
self.text.shrinkAndFree(alloc, text_reserved_len);
|
||||||
}
|
}
|
||||||
@ -211,12 +211,12 @@ pub const Contents = struct {
|
|||||||
/// update the mapping for the last element in the list.
|
/// update the mapping for the last element in the list.
|
||||||
pub fn clear(self: *Contents, y: terminal.size.CellCountInt) void {
|
pub fn clear(self: *Contents, y: terminal.size.CellCountInt) void {
|
||||||
const start_idx = self.index(.{ .x = 0, .y = y });
|
const start_idx = self.index(.{ .x = 0, .y = y });
|
||||||
const end_idx = start_idx + self.cols;
|
const end_idx = start_idx + self.size.columns;
|
||||||
const maps = self.map[start_idx..end_idx];
|
const maps = self.map[start_idx..end_idx];
|
||||||
for (0..self.cols) |x| {
|
for (0..self.size.columns) |x| {
|
||||||
// It is better to clear from the right left due to the same
|
// It is better to clear from the right left due to the same
|
||||||
// reasons noted for bottom-up clearing in the doc comment.
|
// reasons noted for bottom-up clearing in the doc comment.
|
||||||
const rev_x = self.cols - x - 1;
|
const rev_x = self.size.columns - x - 1;
|
||||||
const map = &maps[rev_x];
|
const map = &maps[rev_x];
|
||||||
|
|
||||||
var it = map.array.iterator();
|
var it = map.array.iterator();
|
||||||
@ -278,7 +278,7 @@ pub const Contents = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn index(self: *const Contents, coord: terminal.Coordinate) usize {
|
fn index(self: *const Contents, coord: terminal.Coordinate) usize {
|
||||||
return coord.y * self.cols + coord.x;
|
return coord.y * self.size.columns + coord.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The mapping of a cell at a specific coordinate to the index in the
|
/// The mapping of a cell at a specific coordinate to the index in the
|
||||||
|
Reference in New Issue
Block a user