mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-22 11:46:11 +03:00
renderer: make Metal apprt-aware
This commit is contained in:
@ -10,6 +10,7 @@ const glfw = @import("glfw");
|
|||||||
const objc = @import("objc");
|
const objc = @import("objc");
|
||||||
const macos = @import("macos");
|
const macos = @import("macos");
|
||||||
const imgui = @import("imgui");
|
const imgui = @import("imgui");
|
||||||
|
const apprt = @import("../apprt.zig");
|
||||||
const font = @import("../font/main.zig");
|
const font = @import("../font/main.zig");
|
||||||
const terminal = @import("../terminal/main.zig");
|
const terminal = @import("../terminal/main.zig");
|
||||||
const renderer = @import("../renderer.zig");
|
const renderer = @import("../renderer.zig");
|
||||||
@ -124,7 +125,7 @@ const GPUCellMode = enum(u8) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Returns the hints that we want for this
|
/// Returns the hints that we want for this
|
||||||
pub fn windowHints() glfw.Window.Hints {
|
pub fn glfwWindowHints() glfw.Window.Hints {
|
||||||
return .{
|
return .{
|
||||||
.client_api = .no_api,
|
.client_api = .no_api,
|
||||||
// .cocoa_graphics_switching = builtin.os.tag == .macos,
|
// .cocoa_graphics_switching = builtin.os.tag == .macos,
|
||||||
@ -134,8 +135,8 @@ pub fn windowHints() glfw.Window.Hints {
|
|||||||
|
|
||||||
/// This is called early right after window creation to setup our
|
/// This is called early right after window creation to setup our
|
||||||
/// window surface as necessary.
|
/// window surface as necessary.
|
||||||
pub fn windowInit(window: glfw.Window) !void {
|
pub fn windowInit(win: apprt.runtime.Window) !void {
|
||||||
_ = window;
|
_ = win;
|
||||||
|
|
||||||
// We don't do anything else here because we want to set everything
|
// We don't do anything else here because we want to set everything
|
||||||
// else up during actual initialization.
|
// else up during actual initialization.
|
||||||
@ -303,9 +304,12 @@ pub fn deinit(self: *Metal) void {
|
|||||||
|
|
||||||
/// This is called just prior to spinning up the renderer thread for
|
/// This is called just prior to spinning up the renderer thread for
|
||||||
/// final main thread setup requirements.
|
/// final main thread setup requirements.
|
||||||
pub fn finalizeWindowInit(self: *const Metal, window: glfw.Window) !void {
|
pub fn finalizeWindowInit(self: *const Metal, win: apprt.runtime.Window) !void {
|
||||||
// Set our window backing layer to be our swapchain
|
// Set our window backing layer to be our swapchain
|
||||||
const nswindow = objc.Object.fromId(glfwNative.getCocoaWindow(window).?);
|
const nswindow = switch (apprt.runtime) {
|
||||||
|
apprt.glfw => objc.Object.fromId(glfwNative.getCocoaWindow(win.window).?),
|
||||||
|
else => @compileError("unsupported apprt for metal"),
|
||||||
|
};
|
||||||
const contentView = objc.Object.fromId(nswindow.getProperty(?*anyopaque, "contentView").?);
|
const contentView = objc.Object.fromId(nswindow.getProperty(?*anyopaque, "contentView").?);
|
||||||
contentView.setProperty("layer", self.swapchain.value);
|
contentView.setProperty("layer", self.swapchain.value);
|
||||||
contentView.setProperty("wantsLayer", true);
|
contentView.setProperty("wantsLayer", true);
|
||||||
@ -319,11 +323,11 @@ pub fn finalizeWindowInit(self: *const Metal, window: glfw.Window) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This is called if this renderer runs DevMode.
|
/// This is called if this renderer runs DevMode.
|
||||||
pub fn initDevMode(self: *const Metal, window: glfw.Window) !void {
|
pub fn initDevMode(self: *const Metal, win: apprt.runtime.Window) !void {
|
||||||
if (DevMode.enabled) {
|
if (DevMode.enabled) {
|
||||||
// Initialize for our window
|
// Initialize for our window
|
||||||
assert(imgui.ImplGlfw.initForOther(
|
assert(imgui.ImplGlfw.initForOther(
|
||||||
@ptrCast(*imgui.ImplGlfw.GLFWWindow, window.handle),
|
@ptrCast(*imgui.ImplGlfw.GLFWWindow, win.window.handle),
|
||||||
true,
|
true,
|
||||||
));
|
));
|
||||||
assert(imgui.ImplMetal.init(self.device.value));
|
assert(imgui.ImplMetal.init(self.device.value));
|
||||||
@ -341,9 +345,9 @@ pub fn deinitDevMode(self: *const Metal) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Callback called by renderer.Thread when it begins.
|
/// Callback called by renderer.Thread when it begins.
|
||||||
pub fn threadEnter(self: *const Metal, window: glfw.Window) !void {
|
pub fn threadEnter(self: *const Metal, win: apprt.runtime.Window) !void {
|
||||||
_ = self;
|
_ = self;
|
||||||
_ = window;
|
_ = win;
|
||||||
|
|
||||||
// Metal requires no per-thread state.
|
// Metal requires no per-thread state.
|
||||||
}
|
}
|
||||||
@ -425,10 +429,10 @@ pub fn setFontSize(self: *Metal, size: font.face.DesiredSize) !void {
|
|||||||
/// The primary render callback that is completely thread-safe.
|
/// The primary render callback that is completely thread-safe.
|
||||||
pub fn render(
|
pub fn render(
|
||||||
self: *Metal,
|
self: *Metal,
|
||||||
window: glfw.Window,
|
win: apprt.runtime.Window,
|
||||||
state: *renderer.State,
|
state: *renderer.State,
|
||||||
) !void {
|
) !void {
|
||||||
_ = window;
|
_ = win;
|
||||||
|
|
||||||
// Data we extract out of the critical area.
|
// Data we extract out of the critical area.
|
||||||
const Critical = struct {
|
const Critical = struct {
|
||||||
|
Reference in New Issue
Block a user