apprt/embedded: add draw now API

This commit is contained in:
Mitchell Hashimoto
2024-05-03 20:17:22 -07:00
parent fe7ff998c9
commit e31e25f54d
4 changed files with 22 additions and 1 deletions

View File

@ -504,6 +504,7 @@ ghostty_app_t ghostty_surface_app(ghostty_surface_t);
bool ghostty_surface_transparent(ghostty_surface_t);
bool ghostty_surface_needs_confirm_quit(ghostty_surface_t);
void ghostty_surface_refresh(ghostty_surface_t);
void ghostty_surface_draw(ghostty_surface_t);
void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
void ghostty_surface_set_focus(ghostty_surface_t, bool);
void ghostty_surface_set_occlusion(ghostty_surface_t, bool);

View File

@ -439,7 +439,7 @@ extension Ghostty {
override func updateLayer() {
guard let surface = self.surface else { return }
ghostty_surface_refresh(surface);
ghostty_surface_draw(surface);
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {

View File

@ -553,6 +553,13 @@ pub fn close(self: *Surface) void {
self.rt_surface.close(self.needsConfirmQuit());
}
/// Forces the surface to render. This is useful for when the surface
/// is in the middle of animation (such as a resize, etc.) or when
/// the render timer is managed manually by the apprt.
pub fn draw(self: *Surface) !void {
try self.renderer_thread.draw_now.notify();
}
/// Activate the inspector. This will begin collecting inspection data.
/// This will not affect the GUI. The GUI must use performAction to
/// show/hide the inspector UI.

View File

@ -653,6 +653,13 @@ pub const Surface = struct {
};
}
pub fn draw(self: *Surface) void {
self.core_surface.draw() catch |err| {
log.err("error in draw err={}", .{err});
return;
};
}
pub fn updateContentScale(self: *Surface, x: f64, y: f64) void {
// We are an embedded API so the caller can send us all sorts of
// garbage. We want to make sure that the float values are valid
@ -1525,6 +1532,12 @@ pub const CAPI = struct {
surface.refresh();
}
/// Tell the surface that it needs to schedule a render
/// call as soon as possible (NOW if possible).
export fn ghostty_surface_draw(surface: *Surface) void {
surface.draw();
}
/// Update the size of a surface. This will trigger resize notifications
/// to the pty and the renderer.
export fn ghostty_surface_set_size(surface: *Surface, w: u32, h: u32) void {