Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metal: allow configuring framebuffer formats #253

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 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, TearingMode, Transform, VrrMode,
Connector, DrmDevice, Format, GfxApi, Mode, TearingMode, Transform, VrrMode,
},
Axis, Direction, ModifiedKeySym, PciId, Workspace,
},
Expand Down Expand Up @@ -754,6 +754,10 @@ impl Client {
self.send(&ClientMessage::ConnectorSetScale { connector, scale });
}

pub fn connector_set_format(&self, connector: Connector, format: Format) {
self.send(&ClientMessage::ConnectorSetFormat { connector, format });
}

pub fn connector_get_scale(&self, connector: Connector) -> f64 {
let res = self.send_with_response(&ClientMessage::ConnectorGetScale { connector });
get_response!(res, 1.0, ConnectorGetScale { scale });
Expand Down
8 changes: 6 additions & 2 deletions jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use {
theme::{colors::Colorable, sized::Resizable, Color},
timer::Timer,
video::{
connector_type::ConnectorType, Connector, DrmDevice, GfxApi, TearingMode, Transform,
VrrMode,
connector_type::ConnectorType, Connector, DrmDevice, Format, GfxApi, TearingMode,
Transform, VrrMode,
},
Axis, Direction, PciId, Workspace,
_private::{PollableId, WireMode},
Expand Down Expand Up @@ -509,6 +509,10 @@ pub enum ClientMessage<'a> {
SetEiSocketEnabled {
enabled: bool,
},
ConnectorSetFormat {
connector: Connector,
format: Format,
},
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
40 changes: 40 additions & 0 deletions jay-config/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ impl Connector {
pub fn set_tearing_mode(self, mode: TearingMode) {
get!().set_tearing_mode(Some(self), mode)
}

/// Sets the format to use for framebuffers.
pub fn set_format(self, format: Format) {
get!().connector_set_format(self, format);
}
}

/// Returns all available DRM devices.
Expand Down Expand Up @@ -612,3 +617,38 @@ impl TearingMode {
pub fn set_tearing_mode(mode: TearingMode) {
get!().set_tearing_mode(None, mode)
}

/// A graphics format.
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Format(pub u32);

impl Format {
pub const ARGB8888: Self = Self(0);
pub const XRGB8888: Self = Self(1);
pub const ABGR8888: Self = Self(2);
pub const XBGR8888: Self = Self(3);
pub const R8: Self = Self(4);
pub const GR88: Self = Self(5);
pub const RGB888: Self = Self(6);
pub const BGR888: Self = Self(7);
pub const RGBA4444: Self = Self(8);
pub const RGBX4444: Self = Self(9);
pub const BGRA4444: Self = Self(10);
pub const BGRX4444: Self = Self(11);
pub const RGB565: Self = Self(12);
pub const BGR565: Self = Self(13);
pub const RGBA5551: Self = Self(14);
pub const RGBX5551: Self = Self(15);
pub const BGRA5551: Self = Self(16);
pub const BGRX5551: Self = Self(17);
pub const ARGB1555: Self = Self(18);
pub const XRGB1555: Self = Self(19);
pub const ARGB2101010: Self = Self(20);
pub const XRGB2101010: Self = Self(21);
pub const ABGR2101010: Self = Self(22);
pub const XBGR2101010: Self = Self(23);
pub const ABGR16161616: Self = Self(24);
pub const XBGR16161616: Self = Self(25);
pub const ABGR16161616F: Self = Self(26);
pub const XBGR16161616F: Self = Self(27);
}
24 changes: 15 additions & 9 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ use {
async_engine::SpawnedFuture,
drm_feedback::DrmFeedback,
fixed::Fixed,
format::Format,
gfx_api::{GfxFramebuffer, SyncFile},
ifs::wl_seat::{
tablet::{
PadButtonState, TabletInit, TabletPadId, TabletPadInit, TabletRingEventSource,
TabletStripEventSource, TabletToolChanges, TabletToolId, TabletToolInit,
ToolButtonState,
ifs::{
wl_output::OutputId,
wl_seat::{
tablet::{
PadButtonState, TabletInit, TabletPadId, TabletPadInit, TabletRingEventSource,
TabletStripEventSource, TabletToolChanges, TabletToolId, TabletToolInit,
ToolButtonState,
},
wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL},
},
wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL},
},
libinput::consts::DeviceCapability,
video::drm::{ConnectorType, DrmConnector, DrmError, DrmVersion},
Expand Down Expand Up @@ -64,9 +68,7 @@ pub struct Mode {
#[derive(Clone, Debug)]
pub struct MonitorInfo {
pub modes: Vec<Mode>,
pub manufacturer: String,
pub product: String,
pub serial_number: String,
pub output_id: Rc<OutputId>,
pub initial_mode: Mode,
pub width_mm: i32,
pub height_mm: i32,
Expand Down Expand Up @@ -115,6 +117,9 @@ pub trait Connector {
fn set_tearing_enabled(&self, enabled: bool) {
let _ = enabled;
}
fn set_fb_format(&self, format: &'static Format) {
let _ = format;
}
}

#[derive(Debug)]
Expand All @@ -127,6 +132,7 @@ pub enum ConnectorEvent {
Unavailable,
Available,
VrrChanged(bool),
FormatsChanged(Rc<Vec<&'static Format>>, &'static Format),
}

pub trait HardwareCursor: Debug {
Expand Down
10 changes: 8 additions & 2 deletions src/backends/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ use {
},
backends::metal::video::{
MetalDrmDeviceData, MetalLeaseData, MetalRenderContext, PendingDrmDevice,
PersistentDisplayData,
},
dbus::{DbusError, SignalHandler},
drm_feedback::DrmFeedback,
gfx_api::GfxError,
ifs::wl_seat::tablet::{
TabletId, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadInit,
ifs::{
wl_output::OutputId,
wl_seat::tablet::{
TabletId, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadInit,
},
},
libinput::{
consts::{
Expand Down Expand Up @@ -144,6 +148,7 @@ pub struct MetalBackend {
resume_handler: Cell<Option<SignalHandler>>,
ctx: CloneCell<Option<Rc<MetalRenderContext>>>,
default_feedback: CloneCell<Option<Rc<DrmFeedback>>>,
persistent_display_data: CopyHashMap<Rc<OutputId>, Rc<PersistentDisplayData>>,
}

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