mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-20 12:38:08 +00:00
GtkGLArea had numerous downsides that forced us to invent unsightly hacks in our renderer to work around them, most chiefly the fact that it holds its own GdkGLContext on the main thread (GL contexts are not at all thread-safe), forcing us to keep our GL calls on the main thread. It also does not interact well with triple-buffering and initialization is forced to be this sort of deferred song-and-dance since we need to wait for the GLArea to initialize its GL context before we can initialize the renderer, the core surface, and then most things in the GTK surface. We instead invent our own custom widget named RenderSurface that takes simple DMABUFs and displays them. The task of obtaining a GL context falls to manual EGL bindings, since we also need EGL to export OpenGL textures into DMABUFs. We keep the EGL context solely on the render thread meaning that the main thread never concerns itself with rendering except when being notified that the renderer has pushed a new frame. What makes this extra significant is that now the entire GTK apprt no longer depends on OpenGL in any way, shape or form. As long as it is being fed DMABUFs, it can render from whichever graphics API you want. This means we can add more backends based on OpenGL ES or more likely Vulkan rather painlessly in the future. **AI disclosure**: I came up with the idea and let Pi implement most of the nitty-gritty details around EGL, as well as replumbing the renderer and cleaning up all the GTK-specific workarounds there. I then carefully vetted every line of code and spent roughly as much time reviewing as coding. Most of the documentation and all commit messages are in my own words.
61 lines
2.2 KiB
Zig
61 lines
2.2 KiB
Zig
//! "apprt" is the "application runtime" package. This abstracts the
|
|
//! application runtime and lifecycle management such as creating windows,
|
|
//! getting user input (mouse/keyboard), etc.
|
|
//!
|
|
//! This enables compile-time interfaces to be built to swap out the underlying
|
|
//! application runtime. For example: pure macOS Cocoa, GTK+, browser, etc.
|
|
//!
|
|
//! The goal is to have different implementations share as much of the core
|
|
//! logic as possible, and to only reach out to platform-specific implementation
|
|
//! code when absolutely necessary.
|
|
const build_config = @import("build_config.zig");
|
|
|
|
const structs = @import("apprt/structs.zig");
|
|
|
|
pub const action = @import("apprt/action.zig");
|
|
pub const ipc = @import("apprt/ipc.zig");
|
|
pub const gtk = @import("apprt/gtk.zig");
|
|
pub const none = @import("apprt/none.zig");
|
|
pub const browser = @import("apprt/browser.zig");
|
|
pub const embedded = @import("apprt/embedded.zig");
|
|
pub const surface = @import("apprt/surface.zig");
|
|
|
|
pub const Action = action.Action;
|
|
pub const Runtime = @import("apprt/runtime.zig").Runtime;
|
|
pub const Target = action.Target;
|
|
|
|
pub const ContentScale = structs.ContentScale;
|
|
pub const Clipboard = structs.Clipboard;
|
|
pub const ClipboardContent = structs.ClipboardContent;
|
|
pub const ClipboardReadResult = structs.ClipboardReadResult;
|
|
pub const ClipboardRequest = structs.ClipboardRequest;
|
|
pub const ClipboardRequestType = structs.ClipboardRequestType;
|
|
pub const ColorScheme = structs.ColorScheme;
|
|
pub const CursorPos = structs.CursorPos;
|
|
pub const IMEPos = structs.IMEPos;
|
|
pub const Selection = structs.Selection;
|
|
pub const SurfaceSize = structs.SurfaceSize;
|
|
|
|
/// The implementation to use for the app runtime. This is comptime chosen
|
|
/// so that every build has exactly one application runtime implementation.
|
|
/// Note: it is very rare to use Runtime directly; most usage will use
|
|
/// Window or something.
|
|
pub const runtime = switch (build_config.artifact) {
|
|
.exe => switch (build_config.app_runtime) {
|
|
.none => none,
|
|
.gtk => gtk,
|
|
},
|
|
.lib => embedded,
|
|
.wasm_module => browser,
|
|
};
|
|
|
|
pub const App = runtime.App;
|
|
pub const Surface = runtime.Surface;
|
|
|
|
test {
|
|
_ = Runtime;
|
|
_ = runtime;
|
|
_ = action;
|
|
_ = structs;
|
|
}
|