Skip to content

Commit

Permalink
metal: implement VRR
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Jul 18, 2024
1 parent cd09e57 commit 2d7c13b
Show file tree
Hide file tree
Showing 35 changed files with 1,320 additions and 91 deletions.
2 changes: 2 additions & 0 deletions deploy-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Needs jay-config release.
- Needs jay-toml-config release.
- Needs jay-compositor release.

# 1.4.0
Expand Down
6 changes: 5 additions & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ Jay's shortcut system allows you to execute an action when a key is pressed and

## VR

Jay's supports leasing VR headsets to applications.
Jay supports leasing VR headsets to applications.

## Adaptive Sync

Jay supports adaptive sync with configurable cursor refresh rates.

## Protocol Support

Expand Down
10 changes: 9 additions & 1 deletion jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use {
timer::Timer,
video::{
connector_type::{ConnectorType, CON_UNKNOWN},
Connector, DrmDevice, GfxApi, Mode, Transform,
Connector, DrmDevice, GfxApi, Mode, Transform, VrrMode,
},
Axis, Direction, ModifiedKeySym, PciId, Workspace,
},
Expand Down Expand Up @@ -800,6 +800,14 @@ impl Client {
(width, height)
}

pub fn set_vrr_mode(&self, connector: Option<Connector>, mode: VrrMode) {
self.send(&ClientMessage::SetVrrMode { connector, mode })
}

pub fn set_vrr_cursor_hz(&self, connector: Option<Connector>, hz: f64) {
self.send(&ClientMessage::SetVrrCursorHz { connector, hz })
}

pub fn drm_devices(&self) -> Vec<DrmDevice> {
let res = self.send_with_response(&ClientMessage::GetDrmDevices);
get_response!(res, vec![], GetDrmDevices { devices });
Expand Down
10 changes: 9 additions & 1 deletion jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
logging::LogLevel,
theme::{colors::Colorable, sized::Resizable, Color},
timer::Timer,
video::{connector_type::ConnectorType, Connector, DrmDevice, GfxApi, Transform},
video::{connector_type::ConnectorType, Connector, DrmDevice, GfxApi, Transform, VrrMode},
Axis, Direction, PciId, Workspace,
_private::{PollableId, WireMode},
},
Expand Down Expand Up @@ -487,6 +487,14 @@ pub enum ClientMessage<'a> {
seat: Seat,
enabled: bool,
},
SetVrrMode {
connector: Option<Connector>,
mode: VrrMode,
},
SetVrrCursorHz {
connector: Option<Connector>,
hz: f64,
},
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
49 changes: 49 additions & 0 deletions jay-config/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ impl Connector {
}
get!(String::new()).connector_get_serial_number(self)
}

/// Sets the VRR mode.
pub fn set_vrr_mode(self, mode: VrrMode) {
get!().set_vrr_mode(Some(self), mode)
}

/// Sets the VRR cursor refresh rate.
///
/// Limits the rate at which cursors are updated on screen when VRR is active.
///
/// Setting this to infinity disables the limiter.
pub fn set_vrr_cursor_hz(self, hz: f64) {
get!().set_vrr_cursor_hz(Some(self), hz)
}
}

/// Returns all available DRM devices.
Expand Down Expand Up @@ -531,3 +545,38 @@ pub enum Transform {
/// Flip around the vertical axis, then rotate 270 degrees counter-clockwise.
FlipRotate270,
}

/// The VRR mode of a connector.
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
pub struct VrrMode(pub u32);

impl VrrMode {
/// VRR is never enabled.
pub const NEVER: Self = Self(0);
/// VRR is always enabled.
pub const ALWAYS: Self = Self(1);
/// VRR is enabled when one or more applications are displayed fullscreen.
pub const VARIANT_1: Self = Self(2);
/// VRR is enabled when a single application is displayed fullscreen.
pub const VARIANT_2: Self = Self(3);
/// VRR is enabled when a single game or video is displayed fullscreen.
pub const VARIANT_3: Self = Self(4);
}

/// Sets the default VRR mode.
///
/// This setting can be overwritten on a per-connector basis with [Connector::set_vrr_mode].
pub fn set_vrr_mode(mode: VrrMode) {
get!().set_vrr_mode(None, mode)
}

/// Sets the VRR cursor refresh rate.
///
/// Limits the rate at which cursors are updated on screen when VRR is active.
///
/// Setting this to infinity disables the limiter.
///
/// This setting can be overwritten on a per-connector basis with [Connector::set_vrr_cursor_hz].
pub fn set_vrr_cursor_hz(hz: f64) {
get!().set_vrr_cursor_hz(None, hz)
}
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- Add fine-grained damage tracking.
- Add support for adaptive sync.

# 1.4.0 (2024-07-07)

Expand Down
8 changes: 7 additions & 1 deletion src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub struct MonitorInfo {
pub width_mm: i32,
pub height_mm: i32,
pub non_desktop: bool,
pub vrr_capable: bool,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -108,6 +109,9 @@ pub trait Connector {
fn drm_object_id(&self) -> Option<DrmConnector> {
None
}
fn set_vrr_enabled(&self, enabled: bool) {
let _ = enabled;
}
}

#[derive(Debug)]
Expand All @@ -119,6 +123,7 @@ pub enum ConnectorEvent {
ModeChanged(Mode),
Unavailable,
Available,
VrrChanged(bool),
}

pub trait HardwareCursor: Debug {
Expand All @@ -127,7 +132,8 @@ pub trait HardwareCursor: Debug {
fn set_position(&self, x: i32, y: i32);
fn swap_buffer(&self);
fn set_sync_file(&self, sync_file: Option<SyncFile>);
fn commit(&self);
fn commit(&self, schedule_present: bool);
fn schedule_present(&self) -> bool;
fn size(&self) -> (i32, i32);
}

Expand Down
Loading

0 comments on commit 2d7c13b

Please sign in to comment.