Files
ghostty-rs/crates/ghostty-renderer/src/opengl/frame.rs
T
ddidderr 452b782149 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)
2026-10-12 06:02:39 +02:00

73 lines
2.2 KiB
Rust

//! Wrapper for handling render frames (`opengl/Frame.zig`).
use std::sync::Arc;
use super::{
LastTarget,
OpenGL,
gl::Gl,
render_pass::{Attachment, Options as RenderPassOptions, RenderPass},
target::Target,
};
use crate::backend::Health;
/// Options for beginning a frame.
#[derive(Debug, Clone, Copy, Default)]
pub struct Options {}
/// A frame being encoded.
///
/// Upstream holds `*Renderer` and calls `renderer.frameCompleted(health)`
/// 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 Frame {
/// Begin encoding a frame.
///
/// The target is presented via the provided API when completed.
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> {
RenderPass::begin(&self.gl, RenderPassOptions { attachments })
}
/// Complete this frame and present the target.
///
/// If `sync` is true, this will block until the frame is presented.
///
/// NOTE: For OpenGL, `sync` is ignored and we always block.
pub fn complete(self, _sync: bool) -> Health {
self.gl.finish();
// If there are any GL errors, consider the frame unhealthy.
let health = if self.gl.get_error().is_ok() {
Health::Healthy
} else {
Health::Unhealthy
};
// If the frame is healthy, present it.
if health == Health::Healthy
&& let Err(err) = super::present_target(&self.gl, &self.last_target, &self.target)
{
log::error!("Failed to present render target: err={err}");
}
// Report the health to the renderer.
health
}
}