renderer/metal: stop/start display link on occlusion

This commit is contained in:
Mitchell Hashimoto
2024-05-03 20:54:13 -07:00
parent 6ae1784f4b
commit ac813c9244
3 changed files with 30 additions and 0 deletions

View File

@ -737,6 +737,25 @@ pub fn setFocus(self: *Metal, focus: bool) !void {
} }
} }
/// Callback when the window is visible or occluded.
///
/// Must be called on the render thread.
pub fn setVisible(self: *Metal, visible: bool) void {
// If we're not visible, then we want to stop the display link
// because it is a waste of resources and we can move to pure
// change-driven updates.
if (comptime DisplayLink != void) link: {
const display_link = self.display_link orelse break :link;
if (visible and self.focused) {
log.warn("starting display link because window is visible", .{});
display_link.start() catch {};
} else {
log.warn("stopping display link because window is not visible", .{});
display_link.stop() catch {};
}
}
}
/// Set the new font size. /// Set the new font size.
/// ///
/// Must be called on the render thread. /// Must be called on the render thread.

View File

@ -579,6 +579,14 @@ pub fn setFocus(self: *OpenGL, focus: bool) !void {
self.focused = focus; self.focused = focus;
} }
/// Callback when the window is visible or occluded.
///
/// Must be called on the render thread.
pub fn setVisible(self: *OpenGL, visible: bool) void {
_ = self;
_ = visible;
}
/// Set the new font size. /// Set the new font size.
/// ///
/// Must be called on the render thread. /// Must be called on the render thread.

View File

@ -272,6 +272,9 @@ fn drainMailbox(self: *Thread) !void {
// still be happening. // still be happening.
if (v) self.drawFrame(); if (v) self.drawFrame();
// Notify the renderer so it can update any state.
self.renderer.setVisible(v);
// Note that we're explicitly today not stopping any // Note that we're explicitly today not stopping any
// cursor timers, draw timers, etc. These things have very // cursor timers, draw timers, etc. These things have very
// little resource cost and properly maintaining their active // little resource cost and properly maintaining their active