1
0
Fork 0
forked from wry/wry

metal: allow configuring color space and transfer function

This commit is contained in:
Julian Orth 2025-03-11 14:54:35 +01:00
parent 04f280aabe
commit bb56efb968
38 changed files with 1365 additions and 160 deletions

View file

@ -25,7 +25,8 @@ use {
theme::{Color, colors::Colorable, sized::Resizable},
timer::Timer,
video::{
Connector, DrmDevice, Format, GfxApi, Mode, TearingMode, Transform, VrrMode,
ColorSpace, Connector, DrmDevice, Format, GfxApi, Mode, TearingMode, TransferFunction,
Transform, VrrMode,
connector_type::{CON_UNKNOWN, ConnectorType},
},
xwayland::XScalingMode,
@ -781,6 +782,19 @@ impl Client {
self.send(&ClientMessage::ConnectorSetFormat { connector, format });
}
pub fn connector_set_colors(
&self,
connector: Connector,
color_space: ColorSpace,
transfer_function: TransferFunction,
) {
self.send(&ClientMessage::ConnectorSetColors {
connector,
color_space,
transfer_function,
});
}
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 });

View file

@ -11,8 +11,8 @@ use {
theme::{Color, colors::Colorable, sized::Resizable},
timer::Timer,
video::{
Connector, DrmDevice, Format, GfxApi, TearingMode, Transform, VrrMode,
connector_type::ConnectorType,
ColorSpace, Connector, DrmDevice, Format, GfxApi, TearingMode, TransferFunction,
Transform, VrrMode, connector_type::ConnectorType,
},
xwayland::XScalingMode,
},
@ -533,6 +533,11 @@ pub enum ClientMessage<'a> {
SetColorManagementEnabled {
enabled: bool,
},
ConnectorSetColors {
connector: Connector,
color_space: ColorSpace,
transfer_function: TransferFunction,
},
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -272,6 +272,19 @@ impl Connector {
pub fn set_format(self, format: Format) {
get!().connector_set_format(self, format);
}
/// Sets the color space and transfer function of the connector.
///
/// By default, the default values are used which usually means sRGB color space with
/// sRGB transfer function.
///
/// If the output supports it, HDR10 can be enabled by setting the color space to
/// BT.2020 and the transfer function to PQ.
///
/// Note that some displays might ignore incompatible settings.
pub fn set_colors(self, color_space: ColorSpace, transfer_function: TransferFunction) {
get!().connector_set_colors(self, color_space, transfer_function);
}
}
/// Returns all available DRM devices.
@ -662,3 +675,25 @@ impl Format {
pub const ABGR16161616F: Self = Self(26);
pub const XBGR16161616F: Self = Self(27);
}
/// A color space.
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct ColorSpace(pub u32);
impl ColorSpace {
/// The default color space (usually sRGB).
pub const DEFAULT: Self = Self(0);
/// The BT.2020 color space.
pub const BT2020: Self = Self(1);
}
/// A transfer function.
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct TransferFunction(pub u32);
impl TransferFunction {
/// The default transfer function (usually sRGB).
pub const DEFAULT: Self = Self(0);
/// The PQ transfer function.
pub const PQ: Self = Self(1);
}