mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
renderer: reset font shaper buffer size on font size change
This commit is contained in:
@ -37,6 +37,10 @@ surface_mailbox: apprt.surface.Mailbox,
|
|||||||
/// Current cell dimensions for this grid.
|
/// Current cell dimensions for this grid.
|
||||||
cell_size: renderer.CellSize,
|
cell_size: renderer.CellSize,
|
||||||
|
|
||||||
|
/// Current screen size dimensions for this grid. This is set on the first
|
||||||
|
/// resize event, and is not immediately available.
|
||||||
|
screen_size: ?renderer.ScreenSize,
|
||||||
|
|
||||||
/// Explicit padding.
|
/// Explicit padding.
|
||||||
padding: renderer.Options.Padding,
|
padding: renderer.Options.Padding,
|
||||||
|
|
||||||
@ -242,6 +246,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.surface_mailbox = options.surface_mailbox,
|
.surface_mailbox = options.surface_mailbox,
|
||||||
.cell_size = .{ .width = metrics.cell_width, .height = metrics.cell_height },
|
.cell_size = .{ .width = metrics.cell_width, .height = metrics.cell_height },
|
||||||
|
.screen_size = null,
|
||||||
.padding = options.padding,
|
.padding = options.padding,
|
||||||
.focused = true,
|
.focused = true,
|
||||||
.cursor_visible = true,
|
.cursor_visible = true,
|
||||||
@ -382,7 +387,8 @@ pub fn threadExit(self: *const Metal) void {
|
|||||||
|
|
||||||
/// Returns the grid size for a given screen size. This is safe to call
|
/// Returns the grid size for a given screen size. This is safe to call
|
||||||
/// on any thread.
|
/// on any thread.
|
||||||
fn gridSize(self: *Metal, screen_size: renderer.ScreenSize) renderer.GridSize {
|
fn gridSize(self: *Metal) ?renderer.GridSize {
|
||||||
|
const screen_size = self.screen_size orelse return null;
|
||||||
return renderer.GridSize.init(
|
return renderer.GridSize.init(
|
||||||
screen_size.subPadding(self.padding.explicit),
|
screen_size.subPadding(self.padding.explicit),
|
||||||
self.cell_size,
|
self.cell_size,
|
||||||
@ -433,6 +439,14 @@ pub fn setFontSize(self: *Metal, size: font.face.DesiredSize) !void {
|
|||||||
if (std.meta.eql(self.cell_size, new_cell_size)) return;
|
if (std.meta.eql(self.cell_size, new_cell_size)) return;
|
||||||
self.cell_size = new_cell_size;
|
self.cell_size = new_cell_size;
|
||||||
|
|
||||||
|
// Resize our font shaping buffer to fit the new width.
|
||||||
|
if (self.gridSize()) |grid_size| {
|
||||||
|
var shape_buf = try self.alloc.alloc(font.shape.Cell, grid_size.columns * 2);
|
||||||
|
errdefer self.alloc.free(shape_buf);
|
||||||
|
self.alloc.free(self.font_shaper.cell_buf);
|
||||||
|
self.font_shaper.cell_buf = shape_buf;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the sprite font up
|
// Set the sprite font up
|
||||||
self.font_group.group.sprite = font.sprite.Face{
|
self.font_group.group.sprite = font.sprite.Face{
|
||||||
.width = @floatToInt(u32, self.cell_size.width),
|
.width = @floatToInt(u32, self.cell_size.width),
|
||||||
@ -696,8 +710,12 @@ fn drawCells(
|
|||||||
|
|
||||||
/// Resize the screen.
|
/// Resize the screen.
|
||||||
pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
|
pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
|
||||||
// Recalculate the rows/columns.
|
// Store our screen size
|
||||||
const grid_size = self.gridSize(dim);
|
self.screen_size = dim;
|
||||||
|
|
||||||
|
// Recalculate the rows/columns. This can't fail since we just set
|
||||||
|
// the screen size above.
|
||||||
|
const grid_size = self.gridSize().?;
|
||||||
|
|
||||||
// Determine if we need to pad the window. For "auto" padding, we take
|
// Determine if we need to pad the window. For "auto" padding, we take
|
||||||
// the leftover amounts on the right/bottom that don't fit a full grid cell
|
// the leftover amounts on the right/bottom that don't fit a full grid cell
|
||||||
|
@ -46,6 +46,10 @@ alloc: std.mem.Allocator,
|
|||||||
/// Current cell dimensions for this grid.
|
/// Current cell dimensions for this grid.
|
||||||
cell_size: renderer.CellSize,
|
cell_size: renderer.CellSize,
|
||||||
|
|
||||||
|
/// Current screen size dimensions for this grid. This is set on the first
|
||||||
|
/// resize event, and is not immediately available.
|
||||||
|
screen_size: ?renderer.ScreenSize,
|
||||||
|
|
||||||
/// The current set of cells to render. Each set of cells goes into
|
/// The current set of cells to render. Each set of cells goes into
|
||||||
/// a separate shader call.
|
/// a separate shader call.
|
||||||
cells_bg: std.ArrayListUnmanaged(GPUCell),
|
cells_bg: std.ArrayListUnmanaged(GPUCell),
|
||||||
@ -365,6 +369,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL {
|
|||||||
.cells = .{},
|
.cells = .{},
|
||||||
.cells_lru = CellsLRU.init(0),
|
.cells_lru = CellsLRU.init(0),
|
||||||
.cell_size = .{ .width = metrics.cell_width, .height = metrics.cell_height },
|
.cell_size = .{ .width = metrics.cell_width, .height = metrics.cell_height },
|
||||||
|
.screen_size = null,
|
||||||
.program = program,
|
.program = program,
|
||||||
.vao = vao,
|
.vao = vao,
|
||||||
.ebo = ebo,
|
.ebo = ebo,
|
||||||
@ -606,6 +611,15 @@ pub fn setFontSize(self: *OpenGL, size: font.face.DesiredSize) !void {
|
|||||||
if (std.meta.eql(self.cell_size, new_cell_size)) return;
|
if (std.meta.eql(self.cell_size, new_cell_size)) return;
|
||||||
self.cell_size = new_cell_size;
|
self.cell_size = new_cell_size;
|
||||||
|
|
||||||
|
// Resize our font shaping buffer to fit the new width.
|
||||||
|
if (self.screen_size) |dim| {
|
||||||
|
const grid_size = self.gridSize(dim);
|
||||||
|
var shape_buf = try self.alloc.alloc(font.shape.Cell, grid_size.columns * 2);
|
||||||
|
errdefer self.alloc.free(shape_buf);
|
||||||
|
self.alloc.free(self.font_shaper.cell_buf);
|
||||||
|
self.font_shaper.cell_buf = shape_buf;
|
||||||
|
}
|
||||||
|
|
||||||
// Notify the window that the cell size changed.
|
// Notify the window that the cell size changed.
|
||||||
_ = self.surface_mailbox.push(.{
|
_ = self.surface_mailbox.push(.{
|
||||||
.cell_size = new_cell_size,
|
.cell_size = new_cell_size,
|
||||||
@ -1185,6 +1199,9 @@ pub fn setScreenSize(self: *OpenGL, dim: renderer.ScreenSize) !void {
|
|||||||
if (single_threaded_draw) self.draw_mutex.lock();
|
if (single_threaded_draw) self.draw_mutex.lock();
|
||||||
defer if (single_threaded_draw) self.draw_mutex.unlock();
|
defer if (single_threaded_draw) self.draw_mutex.unlock();
|
||||||
|
|
||||||
|
// Store our screen size
|
||||||
|
self.screen_size = dim;
|
||||||
|
|
||||||
// Recalculate the rows/columns.
|
// Recalculate the rows/columns.
|
||||||
const grid_size = self.gridSize(dim);
|
const grid_size = self.gridSize(dim);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user