feat(macos): port Ghostty's macOS code paths (Metal, CoreText, Darwin)
Ports the macOS-specific Zig code behind cfg(target_os = "macos"): - renderer: a GraphicsApi trait with generic::Renderer<G>; Metal backend (all renderer/metal/* files, shaders.metal verbatim, runtime library compile, IOSurface layer, CVDisplayLink), shadertoy -> MSL via naga; OpenGL remains the backend elsewhere. - font: CoreText face, shaper and discovery with build.rs backend selection (coretext default; coretext-freetype / coretext-harfbuzz / coretext-noshape features), no fontconfig/freetype/harfbuzz on Apple. - input: KeymapDarwin via UCKeyTranslate, option-as-alt, mac keycodes. - os: macos, mach, cf_release_thread, NSProcessInfo args and macOS branches; config: macOS defaults, keybinds, Application Support paths. - termio/core: login(1) wrapping, openpty/execvpe, Darwin child exit handling, os_log logging. Compile-checked for aarch64/x86_64-apple-darwin (clippy -D warnings clean) using the cross setup in docs/rewrite/notes/macos-M1.md; cannot run here. The embedded runtime/C API (embedded.zig) is the next step. Also includes the cross-platform integration edits shared by the crash, verification, Windows and macOS work (Cargo target-gating, thread crash-context hooks, apprt-gtk surface/IME refactor, termio/os cfg gates), a cfg fix so ghostty-config builds on wasm32, and an allow for the intentional recursion in the crash overflow test. Test Plan: - cargo test --workspace (3224 passed) - cargo clippy --workspace --all-targets -- -D warnings - cargo check --target aarch64-apple-darwin -p ghostty-renderer (with the documented cross env)
This commit is contained in:
1 parent
3c8fae1089
commit
452b782149
124 files changed
+14936
-1242
No files matched your search
@@ -2,7 +2,9 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{
|
||||
LastTarget,
|
||||
OpenGL,
|
||||
gl::Gl,
|
||||
render_pass::{Attachment, Options as RenderPassOptions, RenderPass},
|
||||
target::Target,
|
||||
};
|
||||
@@ -15,26 +17,31 @@ pub struct Options {}
|
||||
/// A frame being encoded.
|
||||
///
|
||||
/// Upstream holds `*Renderer` and calls `renderer.frameCompleted(health)`
|
||||
/// after presenting; here the frame borrows the graphics API and
|
||||
/// [`Frame::complete`] returns the [`Health`] for the renderer to report.
|
||||
pub struct Frame<'a> {
|
||||
api: &'a mut OpenGL,
|
||||
/// after presenting; here [`Frame::complete`] returns the [`Health`] for the
|
||||
/// renderer to report. The frame holds its own handles (GL context and the
|
||||
/// API's last-presented-target slot) rather than borrowing the API.
|
||||
pub struct Frame {
|
||||
gl: Gl,
|
||||
last_target: LastTarget,
|
||||
target: Arc<Target>,
|
||||
}
|
||||
|
||||
impl<'a> Frame<'a> {
|
||||
impl Frame {
|
||||
/// Begin encoding a frame.
|
||||
///
|
||||
/// The target is presented via the provided API when completed.
|
||||
pub fn begin(_opts: Options, api: &'a mut OpenGL, target: Arc<Target>) -> Frame<'a> {
|
||||
Frame { api, target }
|
||||
pub fn begin(_opts: Options, api: &OpenGL, target: Arc<Target>) -> Frame {
|
||||
Frame {
|
||||
gl: api.gl().expect("OpenGL context not initialized").clone(),
|
||||
last_target: api.last_target_slot(),
|
||||
target,
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a render pass to this frame with the provided attachments.
|
||||
/// Returns a RenderPass which allows render steps to be added.
|
||||
pub fn render_pass<'b>(&self, attachments: &'b [Attachment<'b>]) -> RenderPass<'b> {
|
||||
let gl = self.api.gl().expect("OpenGL context not initialized");
|
||||
RenderPass::begin(gl, RenderPassOptions { attachments })
|
||||
RenderPass::begin(&self.gl, RenderPassOptions { attachments })
|
||||
}
|
||||
|
||||
/// Complete this frame and present the target.
|
||||
@@ -43,13 +50,10 @@ impl<'a> Frame<'a> {
|
||||
///
|
||||
/// NOTE: For OpenGL, `sync` is ignored and we always block.
|
||||
pub fn complete(self, _sync: bool) -> Health {
|
||||
let Some(gl) = self.api.gl().cloned() else {
|
||||
return Health::Unhealthy;
|
||||
};
|
||||
gl.finish();
|
||||
self.gl.finish();
|
||||
|
||||
// If there are any GL errors, consider the frame unhealthy.
|
||||
let health = if gl.get_error().is_ok() {
|
||||
let health = if self.gl.get_error().is_ok() {
|
||||
Health::Healthy
|
||||
} else {
|
||||
Health::Unhealthy
|
||||
@@ -57,7 +61,7 @@ impl<'a> Frame<'a> {
|
||||
|
||||
// If the frame is healthy, present it.
|
||||
if health == Health::Healthy
|
||||
&& let Err(err) = self.api.present(&self.target)
|
||||
&& let Err(err) = super::present_target(&self.gl, &self.last_target, &self.target)
|
||||
{
|
||||
log::error!("Failed to present render target: err={err}");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user