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

@ -26,7 +26,7 @@ use {
logging::LogLevel,
status::MessageFormat,
theme::Color,
video::{Format, GfxApi, TearingMode, Transform, VrrMode},
video::{ColorSpace, Format, GfxApi, TearingMode, TransferFunction, Transform, VrrMode},
xwayland::XScalingMode,
},
std::{
@ -220,6 +220,8 @@ pub struct Output {
pub vrr: Option<Vrr>,
pub tearing: Option<Tearing>,
pub format: Option<Format>,
pub color_space: Option<ColorSpace>,
pub transfer_function: Option<TransferFunction>,
}
#[derive(Debug, Clone)]

View file

@ -19,7 +19,7 @@ use {
},
},
indexmap::IndexMap,
jay_config::video::Transform,
jay_config::video::{ColorSpace, TransferFunction, Transform},
thiserror::Error,
};
@ -49,8 +49,11 @@ impl Parser for OutputParser<'_> {
table: &IndexMap<Spanned<String>, Spanned<Value>>,
) -> ParseResult<Self> {
let mut ext = Extractor::new(self.cx, span, table);
let (name, match_val, x, y, scale, transform, mode, vrr_val, tearing_val, format_val) = ext
.extract((
let (
(name, match_val, x, y, scale, transform, mode, vrr_val, tearing_val, format_val),
(color_space, transfer_function),
) = ext.extract((
(
opt(str("name")),
val("match"),
recover(opt(s32("x"))),
@ -61,7 +64,12 @@ impl Parser for OutputParser<'_> {
opt(val("vrr")),
opt(val("tearing")),
opt(val("format")),
))?;
),
(
recover(opt(str("color-space"))),
recover(opt(str("transfer-function"))),
),
))?;
let transform = match transform {
None => None,
Some(t) => match t.value {
@ -79,6 +87,36 @@ impl Parser for OutputParser<'_> {
}
},
};
let color_space = match color_space {
None => None,
Some(cs) => match cs.value {
"default" => Some(ColorSpace::DEFAULT),
"bt2020" => Some(ColorSpace::BT2020),
_ => {
log::warn!(
"Unknown color space {}: {}",
cs.value,
self.cx.error3(cs.span)
);
None
}
},
};
let transfer_function = match transfer_function {
None => None,
Some(tf) => match tf.value {
"default" => Some(TransferFunction::DEFAULT),
"pq" => Some(TransferFunction::PQ),
_ => {
log::warn!(
"Unknown transfer function {}: {}",
tf.value,
self.cx.error3(tf.span)
);
None
}
},
};
let mode = match mode {
Some(mode) => match mode.parse(&mut ModeParser(self.cx)) {
Ok(m) => Some(m),
@ -144,6 +182,8 @@ impl Parser for OutputParser<'_> {
vrr,
tearing,
format,
color_space,
transfer_function,
})
}
}

View file

@ -30,10 +30,10 @@ use {
switch_to_vt,
theme::{reset_colors, reset_font, reset_sizes, set_font},
video::{
Connector, DrmDevice, connectors, drm_devices, on_connector_connected,
on_connector_disconnected, on_graphics_initialized, on_new_connector,
on_new_drm_device, set_direct_scanout_enabled, set_gfx_api, set_tearing_mode,
set_vrr_cursor_hz, set_vrr_mode,
ColorSpace, Connector, DrmDevice, TransferFunction, connectors, drm_devices,
on_connector_connected, on_connector_disconnected, on_graphics_initialized,
on_new_connector, on_new_drm_device, set_direct_scanout_enabled, set_gfx_api,
set_tearing_mode, set_vrr_cursor_hz, set_vrr_mode,
},
xwayland::set_x_scaling_mode,
},
@ -588,6 +588,11 @@ impl Output {
if let Some(format) = self.format {
c.set_format(format);
}
if self.color_space.is_some() || self.transfer_function.is_some() {
let cs = self.color_space.unwrap_or(ColorSpace::DEFAULT);
let tf = self.transfer_function.unwrap_or(TransferFunction::DEFAULT);
c.set_colors(cs, tf);
}
}
}