Skip to content

Commit

Permalink
Merge pull request #96 from mahkoh/jorth/direct-scanout
Browse files Browse the repository at this point in the history
metal: implement direct scanout
  • Loading branch information
mahkoh authored Feb 19, 2024
2 parents 1ac4f3d + 47e469b commit 60f2c6e
Show file tree
Hide file tree
Showing 49 changed files with 861 additions and 203 deletions.
4 changes: 4 additions & 0 deletions jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ impl Client {
self.send(&ClientMessage::SetGfxApi { device, api });
}

pub fn set_direct_scanout_enabled(&self, device: Option<DrmDevice>, enabled: bool) {
self.send(&ClientMessage::SetDirectScanoutEnabled { device, enabled });
}

pub fn connector_connected(&self, connector: Connector) -> bool {
let res = self.send_with_response(&ClientMessage::ConnectorConnected { connector });
get_response!(res, false, ConnectorConnected { connected });
Expand Down
4 changes: 4 additions & 0 deletions jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ pub enum ClientMessage<'a> {
device: Option<DrmDevice>,
api: GfxApi,
},
SetDirectScanoutEnabled {
device: Option<DrmDevice>,
enabled: bool,
},
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
14 changes: 14 additions & 0 deletions jay-config/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ impl DrmDevice {
pub fn set_gfx_api(self, gfx_api: GfxApi) {
get!().set_gfx_api(Some(self), gfx_api);
}

/// Enables or disables direct scanout of client surfaces for this device.
pub fn set_direct_scanout_enabled(self, enabled: bool) {
get!().set_direct_scanout_enabled(Some(self), enabled);
}
}

/// A graphics API.
Expand All @@ -389,3 +394,12 @@ pub enum GfxApi {
pub fn set_gfx_api(gfx_api: GfxApi) {
get!().set_gfx_api(None, gfx_api);
}

/// Enables or disables direct scanout of client surfaces.
///
/// The default is `true`.
///
/// This setting can be overwritten per-device with [DrmDevice::set_direct_scanout_enabled].
pub fn set_direct_scanout_enabled(enabled: bool) {
get!().set_direct_scanout_enabled(None, enabled);
}
5 changes: 5 additions & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
crate::{
async_engine::SpawnedFuture,
drm_feedback::DrmFeedback,
fixed::Fixed,
gfx_api::GfxFramebuffer,
ifs::wl_seat::wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL},
Expand Down Expand Up @@ -79,6 +80,9 @@ pub trait Connector {
fn damage(&self);
fn drm_dev(&self) -> Option<DrmDeviceId>;
fn set_enabled(&self, enabled: bool);
fn drm_feedback(&self) -> Option<Rc<DrmFeedback>> {
None
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -226,4 +230,5 @@ pub trait BackendDrmDevice {
fn set_gfx_api(&self, api: GfxApi);
fn gtx_api(&self) -> GfxApi;
fn version(&self) -> Result<DrmVersion, DrmError>;
fn set_direct_scanout_enabled(&self, enabled: bool);
}
3 changes: 3 additions & 0 deletions src/backends/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
},
backends::metal::video::{MetalDrmDeviceData, MetalRenderContext, PendingDrmDevice},
dbus::{DbusError, SignalHandler},
drm_feedback::DrmFeedback,
gfx_api::GfxError,
libinput::{
consts::{
Expand Down Expand Up @@ -130,6 +131,7 @@ pub struct MetalBackend {
pause_handler: Cell<Option<SignalHandler>>,
resume_handler: Cell<Option<SignalHandler>>,
ctx: CloneCell<Option<Rc<MetalRenderContext>>>,
default_feedback: CloneCell<Option<Rc<DrmFeedback>>>,
}

impl Debug for MetalBackend {
Expand Down Expand Up @@ -253,6 +255,7 @@ pub async fn create(state: &Rc<State>) -> Result<Rc<MetalBackend>, MetalError> {
pause_handler: Default::default(),
resume_handler: Default::default(),
ctx: Default::default(),
default_feedback: Default::default(),
});
metal.pause_handler.set(Some({
let mtl = metal.clone();
Expand Down
Loading

0 comments on commit 60f2c6e

Please sign in to comment.