1
0
Fork 0
forked from wry/wry

head-management: add format-setter-v1 extension

This commit is contained in:
Julian Orth 2025-07-14 15:46:57 +02:00
parent e0120ed3bb
commit 15e68fc551
10 changed files with 131 additions and 0 deletions

View file

@ -661,6 +661,7 @@ fn create_dummy_output(state: &Rc<State>) {
format: XRGB8888,
color_space: backend_state.color_space,
transfer_function: backend_state.transfer_function,
supported_formats: Default::default(),
};
let connector_data = Rc::new(ConnectorData {
id,

View file

@ -91,6 +91,7 @@ pub struct HeadState {
pub format: &'static Format,
pub color_space: BackendColorSpace,
pub transfer_function: BackendTransferFunction,
pub supported_formats: RcEq<Vec<&'static Format>>,
}
impl HeadState {
@ -129,6 +130,7 @@ enum HeadOp {
SetNonDesktopOverride(Option<bool>),
SetVrrMode(VrrMode),
SetTearingMode(TearingMode),
SetFormat(&'static Format),
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
@ -481,4 +483,16 @@ impl HeadManagers {
}
}
}
pub fn handle_formats_change(&self, formats: &Rc<Vec<&'static Format>>) {
let state = &mut *self.state.borrow_mut();
state.supported_formats.0 = formats.clone();
for head in self.managers.lock().values() {
skip_in_transaction!(head);
if let Some(ext) = &head.ext.format_setter_v1 {
ext.send_supported_formats(state);
head.session.schedule_done();
}
}
}
}

View file

@ -408,4 +408,5 @@ declare_extensions! {
jay_tearing_mode_info_v1: JayTearingModeInfoV1,
jay_vrr_mode_setter_v1: JayVrrModeSetterV1,
jay_tearing_mode_setter_v1: JayTearingModeSetterV1,
format_setter_v1: FormatSetterV1,
}

View file

@ -7,6 +7,7 @@ pub(super) mod jay_head_ext_connector_info_v1;
pub(super) mod jay_head_ext_core_info_v1;
pub(super) mod jay_head_ext_drm_color_space_info_v1;
pub(super) mod jay_head_ext_format_info_v1;
pub(super) mod jay_head_ext_format_setter_v1;
pub(super) mod jay_head_ext_jay_tearing_mode_info_v1;
pub(super) mod jay_head_ext_jay_tearing_mode_setter_v1;
pub(super) mod jay_head_ext_jay_vrr_mode_info_v1;

View file

@ -0,0 +1,78 @@
use {
crate::{
format::formats,
ifs::head_management::{HeadOp, HeadState},
wire::{
jay_head_ext_format_setter_v1::{
JayHeadExtFormatSetterV1RequestHandler, Reset, SetFormat, SupportedFormat,
},
jay_head_manager_ext_format_setter_v1::JayHeadManagerExtFormatSetterV1RequestHandler,
},
},
isnt::std_1::primitive::IsntSlice2Ext,
std::rc::Rc,
};
impl_format_setter_v1! {
version = 1,
after_announce = after_announce,
after_transaction = after_transaction,
}
impl HeadName {
fn after_announce(&self, shared: &HeadState) {
self.send_supported_formats(shared);
}
fn after_transaction(&self, shared: &HeadState, tran: &HeadState) {
if shared.supported_formats != tran.supported_formats {
self.send_supported_formats(shared);
}
}
pub(in super::super) fn send_supported_formats(&self, state: &HeadState) {
self.client.event(Reset { self_id: self.id });
for format in &*state.supported_formats {
self.client.event(SupportedFormat {
self_id: self.id,
format: format.drm,
});
}
}
}
impl JayHeadManagerExtFormatSetterV1RequestHandler for MgrName {
type Error = ErrorName;
mgr_common_req!();
}
impl JayHeadExtFormatSetterV1RequestHandler for HeadName {
type Error = ErrorName;
head_common_req!();
fn set_format(&self, req: SetFormat, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let Some(format) = formats().get(&req.format) else {
return Err(ErrorName::UnknownFormat(req.format));
};
if self
.common
.transaction_state
.borrow()
.supported_formats
.not_contains(format)
{
return Err(ErrorName::UnsupportedFormat(req.format));
}
self.common.push_op(HeadOp::SetFormat(format))?;
Ok(())
}
}
error! {
#[error("Unknown format {0}")]
UnknownFormat(u32),
#[error("Unsupported format {0}")]
UnsupportedFormat(u32),
}

View file

@ -266,6 +266,7 @@ impl JayHeadManagerSessionV1 {
new.enabled = desired.connector_enabled;
new.mode = desired.mode;
new.non_desktop_override = desired.override_non_desktop;
new.format = desired.format;
if old == new {
continue;
}
@ -387,6 +388,7 @@ impl JayHeadManagerSessionV1RequestHandler for JayHeadManagerSessionV1 {
NON_DESKTOP_INFO = 1 << 7,
VRR_MODE_INFO = 1 << 8,
TEARING_MODE_INFO = 1 << 9,
FORMAT_INFO = 1 << 10,
COMPOSITOR_SPACE_INFO_ENABLED = 1 << 13,
}
for head in self.heads.lock().values() {
@ -440,6 +442,10 @@ impl JayHeadManagerSessionV1RequestHandler for JayHeadManagerSessionV1 {
state.tearing_mode = m;
to_send |= TEARING_MODE_INFO;
}
HeadOp::SetFormat(f) => {
state.format = f;
to_send |= FORMAT_INFO;
}
}
}
if to_send.contains(CORE_INFO)
@ -488,6 +494,11 @@ impl JayHeadManagerSessionV1RequestHandler for JayHeadManagerSessionV1 {
{
i.send_mode(state);
}
if to_send.contains(FORMAT_INFO)
&& let Some(i) = &head.ext.format_info_v1
{
i.send_format(state);
}
}
slf.schedule_transaction_result(req.result, None)?;
Ok(())

View file

@ -67,6 +67,7 @@ pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
format: backend_state.format,
color_space: backend_state.color_space,
transfer_function: backend_state.transfer_function,
supported_formats: Default::default(),
};
let data = Rc::new(ConnectorData {
id,
@ -324,6 +325,7 @@ impl ConnectorHandler {
self.state.refresh_hardware_cursors();
}
ConnectorEvent::FormatsChanged(formats) => {
self.data.head_managers.handle_formats_change(&formats);
on.global.formats.set(formats);
}
ConnectorEvent::State(state) => {

View file

@ -4,6 +4,7 @@ pub fn rc_eq<T: ?Sized>(a: &Rc<T>, b: &Rc<T>) -> bool {
Rc::as_ptr(a) as *const u8 == Rc::as_ptr(b) as *const u8
}
#[derive(Default)]
pub struct RcEq<T>(pub Rc<T>);
impl<T> Clone for RcEq<T> {

View file

@ -0,0 +1,15 @@
request destroy (destructor) {
}
event reset {
}
event supported_format {
format: u32,
}
request set_format {
format: u32,
}

View file

@ -0,0 +1,7 @@
request destroy (destructor) {
}
event head {
head: id(jay_head_ext_format_setter_v1) (new),
}