mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Revert "renderer/metal: can access grid metrics directly on font grid"
This reverts commit 172179bbff7d3f0df73ba1c29c6906b69ead2619.
This commit is contained in:
@ -66,6 +66,9 @@ config: DerivedConfig,
|
|||||||
/// The mailbox for communicating with the window.
|
/// The mailbox for communicating with the window.
|
||||||
surface_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
|
/// Current font metrics defining our grid.
|
||||||
|
grid_metrics: font.face.Metrics,
|
||||||
|
|
||||||
/// Current screen size dimensions for this grid. This is set on the first
|
/// Current screen size dimensions for this grid. This is set on the first
|
||||||
/// resize event, and is not immediately available.
|
/// resize event, and is not immediately available.
|
||||||
screen_size: ?renderer.ScreenSize,
|
screen_size: ?renderer.ScreenSize,
|
||||||
@ -580,6 +583,18 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
var shaders = try Shaders.init(alloc, gpu_state.device, custom_shaders);
|
var shaders = try Shaders.init(alloc, gpu_state.device, custom_shaders);
|
||||||
errdefer shaders.deinit(alloc);
|
errdefer shaders.deinit(alloc);
|
||||||
|
|
||||||
|
// Initialize all the data that requires a critical font section.
|
||||||
|
const font_critical: struct {
|
||||||
|
metrics: font.Metrics,
|
||||||
|
} = font_critical: {
|
||||||
|
const grid = options.font_grid;
|
||||||
|
grid.lock.lockShared();
|
||||||
|
defer grid.lock.unlockShared();
|
||||||
|
break :font_critical .{
|
||||||
|
.metrics = grid.metrics,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const display_link: ?DisplayLink = switch (builtin.os.tag) {
|
const display_link: ?DisplayLink = switch (builtin.os.tag) {
|
||||||
.macos => if (options.config.vsync)
|
.macos => if (options.config.vsync)
|
||||||
try macos.video.DisplayLink.createWithActiveCGDisplays()
|
try macos.video.DisplayLink.createWithActiveCGDisplays()
|
||||||
@ -593,6 +608,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.config = options.config,
|
.config = options.config,
|
||||||
.surface_mailbox = options.surface_mailbox,
|
.surface_mailbox = options.surface_mailbox,
|
||||||
|
.grid_metrics = font_critical.metrics,
|
||||||
.screen_size = null,
|
.screen_size = null,
|
||||||
.padding = options.padding,
|
.padding = options.padding,
|
||||||
.focused = true,
|
.focused = true,
|
||||||
@ -757,8 +773,8 @@ fn gridSize(self: *Metal) ?renderer.GridSize {
|
|||||||
return renderer.GridSize.init(
|
return renderer.GridSize.init(
|
||||||
screen_size.subPadding(self.padding.explicit),
|
screen_size.subPadding(self.padding.explicit),
|
||||||
.{
|
.{
|
||||||
.width = self.font_grid.metrics.cell_width,
|
.width = self.grid_metrics.cell_width,
|
||||||
.height = self.font_grid.metrics.cell_height,
|
.height = self.grid_metrics.cell_height,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -814,6 +830,11 @@ pub fn setFontGrid(self: *Metal, grid: *font.SharedGrid) void {
|
|||||||
frame.color_modified = 0;
|
frame.color_modified = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get our metrics from the grid. This doesn't require a lock because
|
||||||
|
// the metrics are never recalculated.
|
||||||
|
const metrics = grid.metrics;
|
||||||
|
self.grid_metrics = metrics;
|
||||||
|
|
||||||
// Reset our shaper cache. If our font changed (not just the size) then
|
// Reset our shaper cache. If our font changed (not just the size) then
|
||||||
// the data in the shaper cache may be invalid and cannot be used, so we
|
// the data in the shaper cache may be invalid and cannot be used, so we
|
||||||
// always clear the cache just in case.
|
// always clear the cache just in case.
|
||||||
@ -1703,8 +1724,8 @@ fn prepKittyVirtualPlacement(
|
|||||||
const rp = p.renderPlacement(
|
const rp = p.renderPlacement(
|
||||||
storage,
|
storage,
|
||||||
&image,
|
&image,
|
||||||
self.font_grid.metrics.cell_width,
|
self.grid_metrics.cell_width,
|
||||||
self.font_grid.metrics.cell_height,
|
self.grid_metrics.cell_height,
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering virtual placement err={}", .{err});
|
log.warn("error rendering virtual placement err={}", .{err});
|
||||||
return;
|
return;
|
||||||
@ -1764,7 +1785,7 @@ fn prepKittyPlacement(
|
|||||||
const vp_y = t.screen.pages.pointFromPin(.screen, top.*).?.screen.y;
|
const vp_y = t.screen.pages.pointFromPin(.screen, top.*).?.screen.y;
|
||||||
const img_y = t.screen.pages.pointFromPin(.screen, rect.top_left).?.screen.y;
|
const img_y = t.screen.pages.pointFromPin(.screen, rect.top_left).?.screen.y;
|
||||||
const offset_cells = vp_y - img_y;
|
const offset_cells = vp_y - img_y;
|
||||||
const offset_pixels = offset_cells * self.font_grid.metrics.cell_height;
|
const offset_pixels = offset_cells * self.grid_metrics.cell_height;
|
||||||
break :offset_y @intCast(offset_pixels);
|
break :offset_y @intCast(offset_pixels);
|
||||||
} else 0;
|
} else 0;
|
||||||
|
|
||||||
@ -1792,8 +1813,8 @@ fn prepKittyPlacement(
|
|||||||
image.height -| source_y;
|
image.height -| source_y;
|
||||||
|
|
||||||
// Calculate the width/height of our image.
|
// Calculate the width/height of our image.
|
||||||
const dest_width = if (p.columns > 0) p.columns * self.font_grid.metrics.cell_width else source_width;
|
const dest_width = if (p.columns > 0) p.columns * self.grid_metrics.cell_width else source_width;
|
||||||
const dest_height = if (p.rows > 0) p.rows * self.font_grid.metrics.cell_height else source_height;
|
const dest_height = if (p.rows > 0) p.rows * self.grid_metrics.cell_height else source_height;
|
||||||
|
|
||||||
// Accumulate the placement
|
// Accumulate the placement
|
||||||
if (image.width > 0 and image.height > 0) {
|
if (image.width > 0 and image.height > 0) {
|
||||||
@ -1918,8 +1939,8 @@ pub fn setScreenSize(
|
|||||||
dim,
|
dim,
|
||||||
grid_size,
|
grid_size,
|
||||||
.{
|
.{
|
||||||
.width = self.font_grid.metrics.cell_width,
|
.width = self.grid_metrics.cell_width,
|
||||||
.height = self.font_grid.metrics.cell_height,
|
.height = self.grid_metrics.cell_height,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
@ -1933,8 +1954,8 @@ pub fn setScreenSize(
|
|||||||
.background => .{},
|
.background => .{},
|
||||||
|
|
||||||
.extend => dim.blankPadding(padding, grid_size, .{
|
.extend => dim.blankPadding(padding, grid_size, .{
|
||||||
.width = self.font_grid.metrics.cell_width,
|
.width = self.grid_metrics.cell_width,
|
||||||
.height = self.font_grid.metrics.cell_height,
|
.height = self.grid_metrics.cell_height,
|
||||||
}).add(padding),
|
}).add(padding),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1954,8 +1975,8 @@ pub fn setScreenSize(
|
|||||||
-1 * @as(f32, @floatFromInt(padding.top)),
|
-1 * @as(f32, @floatFromInt(padding.top)),
|
||||||
),
|
),
|
||||||
.cell_size = .{
|
.cell_size = .{
|
||||||
@floatFromInt(self.font_grid.metrics.cell_width),
|
@floatFromInt(self.grid_metrics.cell_width),
|
||||||
@floatFromInt(self.font_grid.metrics.cell_height),
|
@floatFromInt(self.grid_metrics.cell_height),
|
||||||
},
|
},
|
||||||
.grid_size = .{
|
.grid_size = .{
|
||||||
grid_size.columns,
|
grid_size.columns,
|
||||||
@ -2054,7 +2075,7 @@ pub fn setScreenSize(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("screen size screen={} grid={}, cell_width={} cell_height={}", .{ dim, grid_size, self.font_grid.metrics.cell_width, self.font_grid.metrics.cell_height });
|
log.debug("screen size screen={} grid={}, cell_width={} cell_height={}", .{ dim, grid_size, self.grid_metrics.cell_width, self.grid_metrics.cell_height });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the terminal state to GPU cells stored in CPU memory. These
|
/// Convert the terminal state to GPU cells stored in CPU memory. These
|
||||||
@ -2418,7 +2439,7 @@ fn updateCell(
|
|||||||
shaper_run.font_index,
|
shaper_run.font_index,
|
||||||
glyph_index,
|
glyph_index,
|
||||||
.{
|
.{
|
||||||
.grid_metrics = self.font_grid.metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.thicken = self.config.font_thicken,
|
.thicken = self.config.font_thicken,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -2469,7 +2490,7 @@ fn updateCell(
|
|||||||
@intFromEnum(sprite),
|
@intFromEnum(sprite),
|
||||||
.{
|
.{
|
||||||
.cell_width = if (cell.wide == .wide) 2 else 1,
|
.cell_width = if (cell.wide == .wide) 2 else 1,
|
||||||
.grid_metrics = self.font_grid.metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2494,7 +2515,7 @@ fn updateCell(
|
|||||||
@intFromEnum(font.Sprite.strikethrough),
|
@intFromEnum(font.Sprite.strikethrough),
|
||||||
.{
|
.{
|
||||||
.cell_width = if (cell.wide == .wide) 2 else 1,
|
.cell_width = if (cell.wide == .wide) 2 else 1,
|
||||||
.grid_metrics = self.font_grid.metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2551,7 +2572,7 @@ fn addCursor(
|
|||||||
@intFromEnum(sprite),
|
@intFromEnum(sprite),
|
||||||
.{
|
.{
|
||||||
.cell_width = if (wide) 2 else 1,
|
.cell_width = if (wide) 2 else 1,
|
||||||
.grid_metrics = self.font_grid.metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
},
|
},
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering cursor glyph err={}", .{err});
|
log.warn("error rendering cursor glyph err={}", .{err});
|
||||||
@ -2585,7 +2606,7 @@ fn addPreeditCell(
|
|||||||
@intCast(cp.codepoint),
|
@intCast(cp.codepoint),
|
||||||
.regular,
|
.regular,
|
||||||
.text,
|
.text,
|
||||||
.{ .grid_metrics = self.font_grid.metrics },
|
.{ .grid_metrics = self.grid_metrics },
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering preedit glyph err={}", .{err});
|
log.warn("error rendering preedit glyph err={}", .{err});
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user