mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-29 11:57:57 +00:00
support screen size, rip out shared state
This commit is contained in:
@@ -359,14 +359,24 @@ pub fn threadExit(self: *const OpenGL) void {
|
||||
pub fn render(
|
||||
self: *OpenGL,
|
||||
window: glfw.Window,
|
||||
state: renderer.State,
|
||||
state: *renderer.State,
|
||||
) !void {
|
||||
// Data we extract out of the critical area.
|
||||
const Critical = struct {
|
||||
devmode_data: ?*imgui.DrawData,
|
||||
screen_size: ?renderer.ScreenSize,
|
||||
};
|
||||
|
||||
// Update all our data as tightly as possible within the mutex.
|
||||
var gl_bg = self.background;
|
||||
{
|
||||
const critical: Critical = critical: {
|
||||
state.mutex.lock();
|
||||
defer state.mutex.unlock();
|
||||
|
||||
// If we're resizing, then handle that now.
|
||||
if (state.resize_screen) |size| try self.setScreenSize(size);
|
||||
defer state.resize_screen = null;
|
||||
|
||||
// Setup our cursor state
|
||||
self.cursor_visible = state.cursor.visible and !state.cursor.blink;
|
||||
self.cursor_style = CursorStyle.fromTerminal(state.cursor.style) orelse .box;
|
||||
@@ -384,9 +394,33 @@ pub fn render(
|
||||
self.foreground = bg;
|
||||
}
|
||||
|
||||
// Build our GPU cells
|
||||
try self.rebuildCells(state.terminal);
|
||||
try self.finalizeCells(state.terminal);
|
||||
if (state.devmode) |dm| if (dm.visible) try dm.update();
|
||||
|
||||
// Build our devmode draw data
|
||||
const devmode_data = devmode_data: {
|
||||
if (state.devmode) |dm| {
|
||||
if (dm.visible) {
|
||||
try dm.update();
|
||||
break :devmode_data try dm.render();
|
||||
}
|
||||
}
|
||||
|
||||
break :devmode_data null;
|
||||
};
|
||||
|
||||
break :critical .{
|
||||
.devmode_data = devmode_data,
|
||||
.screen_size = state.resize_screen,
|
||||
};
|
||||
};
|
||||
|
||||
// If we are resizing we need to update the viewport
|
||||
if (critical.screen_size) |size| {
|
||||
// Update our viewport for this context to be the entire window.
|
||||
// OpenGL works in pixels, so we have to use the pixel size.
|
||||
try gl.viewport(0, 0, @intCast(i32, size.width), @intCast(i32, size.height));
|
||||
}
|
||||
|
||||
// Clear the surface
|
||||
@@ -402,11 +436,8 @@ pub fn render(
|
||||
try self.draw();
|
||||
|
||||
// If we have devmode, then render that
|
||||
if (state.devmode) |dm| {
|
||||
if (dm.visible) {
|
||||
const data = try dm.render();
|
||||
imgui.ImplOpenGL3.renderDrawData(data);
|
||||
}
|
||||
if (critical.devmode_data) |data| {
|
||||
imgui.ImplOpenGL3.renderDrawData(data);
|
||||
}
|
||||
|
||||
// Swap our window buffers
|
||||
@@ -783,7 +814,7 @@ pub fn updateCell(
|
||||
|
||||
/// Set the screen size for rendering. This will update the projection
|
||||
/// used for the shader so that the scaling of the grid is correct.
|
||||
pub fn setScreenSize(self: *OpenGL, dim: renderer.ScreenSize) !void {
|
||||
fn setScreenSize(self: *OpenGL, dim: renderer.ScreenSize) !void {
|
||||
// Update the projection uniform within our shader
|
||||
const bind = try self.program.use();
|
||||
defer bind.unbind();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const std = @import("std");
|
||||
const DevMode = @import("../DevMode.zig");
|
||||
const terminal = @import("../terminal/main.zig");
|
||||
const renderer = @import("../renderer.zig");
|
||||
|
||||
/// The mutex that must be held while reading any of the data in the
|
||||
/// members of this state. Note that the state itself is NOT protected
|
||||
@@ -11,7 +12,7 @@ const terminal = @import("../terminal/main.zig");
|
||||
mutex: *std.Thread.Mutex,
|
||||
|
||||
/// A new screen size if the screen was resized.
|
||||
resize: ?Resize = null,
|
||||
resize_screen: ?renderer.ScreenSize,
|
||||
|
||||
/// Cursor configuration for rendering
|
||||
cursor: Cursor,
|
||||
@@ -36,5 +37,3 @@ pub const Cursor = struct {
|
||||
/// the cursor will not be rendered.
|
||||
blink: bool = false,
|
||||
};
|
||||
|
||||
pub const Resize = struct {};
|
||||
|
||||
@@ -31,7 +31,7 @@ window: glfw.Window,
|
||||
renderer: *renderer.OpenGL,
|
||||
|
||||
/// Pointer to the shared state that is used to generate the final render.
|
||||
state: *const renderer.State,
|
||||
state: *renderer.State,
|
||||
|
||||
/// Initialize the thread. This does not START the thread. This only sets
|
||||
/// up all the internal state necessary prior to starting the thread. It
|
||||
@@ -40,7 +40,7 @@ pub fn init(
|
||||
alloc: Allocator,
|
||||
window: glfw.Window,
|
||||
renderer_impl: *renderer.OpenGL,
|
||||
state: *const renderer.State,
|
||||
state: *renderer.State,
|
||||
) !Thread {
|
||||
// We always store allocator pointer on the loop data so that
|
||||
// handles can use our global allocator.
|
||||
@@ -148,7 +148,7 @@ fn renderCallback(h: *libuv.Async) void {
|
||||
return;
|
||||
};
|
||||
|
||||
t.renderer.render(t.window, t.state.*) catch |err|
|
||||
t.renderer.render(t.window, t.state) catch |err|
|
||||
log.warn("error rendering err={}", .{err});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user