mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
core: begin converting to SharedGridSet, renderers still broken
This commit is contained in:
10
src/App.zig
10
src/App.zig
@ -43,7 +43,7 @@ quit: bool,
|
|||||||
|
|
||||||
/// The set of font GroupCache instances shared by surfaces with the
|
/// The set of font GroupCache instances shared by surfaces with the
|
||||||
/// same font configuration.
|
/// same font configuration.
|
||||||
font_group_set: font.GroupCacheSet,
|
font_grid_set: font.SharedGridSet,
|
||||||
|
|
||||||
/// Initialize the main app instance. This creates the main window, sets
|
/// Initialize the main app instance. This creates the main window, sets
|
||||||
/// up the renderer state, compiles the shaders, etc. This is the primary
|
/// up the renderer state, compiles the shaders, etc. This is the primary
|
||||||
@ -54,15 +54,15 @@ pub fn create(
|
|||||||
var app = try alloc.create(App);
|
var app = try alloc.create(App);
|
||||||
errdefer alloc.destroy(app);
|
errdefer alloc.destroy(app);
|
||||||
|
|
||||||
var font_group_set = try font.GroupCacheSet.init(alloc);
|
var font_grid_set = try font.SharedGridSet.init(alloc);
|
||||||
errdefer font_group_set.deinit();
|
errdefer font_grid_set.deinit();
|
||||||
|
|
||||||
app.* = .{
|
app.* = .{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
.surfaces = .{},
|
.surfaces = .{},
|
||||||
.mailbox = .{},
|
.mailbox = .{},
|
||||||
.quit = false,
|
.quit = false,
|
||||||
.font_group_set = font_group_set,
|
.font_grid_set = font_grid_set,
|
||||||
};
|
};
|
||||||
errdefer app.surfaces.deinit(alloc);
|
errdefer app.surfaces.deinit(alloc);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ pub fn destroy(self: *App) void {
|
|||||||
|
|
||||||
// Clean up our font group cache
|
// Clean up our font group cache
|
||||||
// TODO(fontmem): assert all ref counts are zero
|
// TODO(fontmem): assert all ref counts are zero
|
||||||
self.font_group_set.deinit();
|
self.font_grid_set.deinit();
|
||||||
|
|
||||||
self.alloc.destroy(self);
|
self.alloc.destroy(self);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ rt_app: *apprt.runtime.App,
|
|||||||
rt_surface: *apprt.runtime.Surface,
|
rt_surface: *apprt.runtime.Surface,
|
||||||
|
|
||||||
/// The font structures
|
/// The font structures
|
||||||
font_group_key: font.GroupCacheSet.Key,
|
font_grid_key: font.SharedGridSet.Key,
|
||||||
font_size: font.face.DesiredSize,
|
font_size: font.face.DesiredSize,
|
||||||
|
|
||||||
/// The renderer for this surface.
|
/// The renderer for this surface.
|
||||||
@ -321,13 +321,13 @@ pub fn init(
|
|||||||
|
|
||||||
// Setup our font group. This will reuse an existing font group if
|
// Setup our font group. This will reuse an existing font group if
|
||||||
// it was already loaded.
|
// it was already loaded.
|
||||||
const font_group_key, const font_group = try app.font_group_set.groupRef(
|
const font_grid_key, const font_grid = try app.font_grid_set.ref(
|
||||||
config,
|
config,
|
||||||
font_size,
|
font_size,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Pre-calculate our initial cell size ourselves.
|
// Pre-calculate our initial cell size ourselves.
|
||||||
const cell_size = try renderer.CellSize.init(alloc, font_group);
|
const cell_size = font_grid.cellSize();
|
||||||
|
|
||||||
// Convert our padding from points to pixels
|
// Convert our padding from points to pixels
|
||||||
const padding_x: u32 = padding_x: {
|
const padding_x: u32 = padding_x: {
|
||||||
@ -349,7 +349,7 @@ pub fn init(
|
|||||||
const app_mailbox: App.Mailbox = .{ .rt_app = rt_app, .mailbox = &app.mailbox };
|
const app_mailbox: App.Mailbox = .{ .rt_app = rt_app, .mailbox = &app.mailbox };
|
||||||
var renderer_impl = try Renderer.init(alloc, .{
|
var renderer_impl = try Renderer.init(alloc, .{
|
||||||
.config = try Renderer.DerivedConfig.init(alloc, config),
|
.config = try Renderer.DerivedConfig.init(alloc, config),
|
||||||
.font_group = font_group,
|
.font_grid = font_grid,
|
||||||
.padding = .{
|
.padding = .{
|
||||||
.explicit = padding,
|
.explicit = padding,
|
||||||
.balance = config.@"window-padding-balance",
|
.balance = config.@"window-padding-balance",
|
||||||
@ -410,7 +410,7 @@ pub fn init(
|
|||||||
.app = app,
|
.app = app,
|
||||||
.rt_app = rt_app,
|
.rt_app = rt_app,
|
||||||
.rt_surface = rt_surface,
|
.rt_surface = rt_surface,
|
||||||
.font_group_key = font_group_key,
|
.font_grid_key = font_grid_key,
|
||||||
.font_size = font_size,
|
.font_size = font_size,
|
||||||
.renderer = renderer_impl,
|
.renderer = renderer_impl,
|
||||||
.renderer_thread = render_thread,
|
.renderer_thread = render_thread,
|
||||||
@ -530,8 +530,8 @@ pub fn deinit(self: *Surface) void {
|
|||||||
self.alloc.destroy(v);
|
self.alloc.destroy(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up our font group
|
// Clean up our font grid
|
||||||
self.app.font_group_set.groupDeref(self.font_group_key);
|
self.app.font_grid_set.deref(self.font_grid_key);
|
||||||
|
|
||||||
// Clean up our render state
|
// Clean up our render state
|
||||||
if (self.renderer_state.preedit) |p| self.alloc.free(p.codepoints);
|
if (self.renderer_state.preedit) |p| self.alloc.free(p.codepoints);
|
||||||
|
@ -24,6 +24,7 @@ const SharedGrid = @This();
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
const renderer = @import("../renderer.zig");
|
||||||
const font = @import("main.zig");
|
const font = @import("main.zig");
|
||||||
const Atlas = font.Atlas;
|
const Atlas = font.Atlas;
|
||||||
const CodepointResolver = font.CodepointResolver;
|
const CodepointResolver = font.CodepointResolver;
|
||||||
@ -132,6 +133,16 @@ fn reloadMetrics(self: *SharedGrid, thicken: bool) !void {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the grid cell size.
|
||||||
|
///
|
||||||
|
/// This is not thread safe.
|
||||||
|
pub fn cellSize(self: *SharedGrid) renderer.CellSize {
|
||||||
|
return .{
|
||||||
|
.width = self.metrics.cell_width,
|
||||||
|
.height = self.metrics.cell_height,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const CodepointKey = struct {
|
const CodepointKey = struct {
|
||||||
style: Style,
|
style: Style,
|
||||||
codepoint: u32,
|
codepoint: u32,
|
||||||
|
@ -9,7 +9,7 @@ const Config = @import("../config.zig").Config;
|
|||||||
config: renderer.Renderer.DerivedConfig,
|
config: renderer.Renderer.DerivedConfig,
|
||||||
|
|
||||||
/// The font group that should be used.
|
/// The font group that should be used.
|
||||||
font_group: *font.GroupCache,
|
font_grid: *font.SharedGrid,
|
||||||
|
|
||||||
/// Padding options for the viewport.
|
/// Padding options for the viewport.
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
|
@ -17,26 +17,6 @@ const log = std.log.scoped(.renderer_size);
|
|||||||
pub const CellSize = struct {
|
pub const CellSize = struct {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
|
||||||
/// Initialize the cell size information from a font group. This ensures
|
|
||||||
/// that all renderers use the same cell sizing information for the same
|
|
||||||
/// fonts.
|
|
||||||
pub fn init(alloc: Allocator, group: *font.GroupCache) !CellSize {
|
|
||||||
// Get our cell metrics based on a regular font ascii 'M'. Why 'M'?
|
|
||||||
// Doesn't matter, any normal ASCII will do we're just trying to make
|
|
||||||
// sure we use the regular font.
|
|
||||||
const metrics = metrics: {
|
|
||||||
const index = (try group.indexForCodepoint(alloc, 'M', .regular, .text)).?;
|
|
||||||
const face = try group.group.faceFromIndex(index);
|
|
||||||
break :metrics face.metrics;
|
|
||||||
};
|
|
||||||
log.debug("cell dimensions={}", .{metrics});
|
|
||||||
|
|
||||||
return CellSize{
|
|
||||||
.width = metrics.cell_width,
|
|
||||||
.height = metrics.cell_height,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The dimensions of the screen that the grid is rendered to. This is the
|
/// The dimensions of the screen that the grid is rendered to. This is the
|
||||||
|
Reference in New Issue
Block a user