backend: remove Copy from BackendConnectorState
This commit is contained in:
parent
6db1f84cb2
commit
11b3f08514
14 changed files with 45 additions and 32 deletions
|
|
@ -617,7 +617,7 @@ linear_ids!(
|
||||||
u64
|
u64
|
||||||
);
|
);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct BackendConnectorState {
|
pub struct BackendConnectorState {
|
||||||
pub serial: BackendConnectorStateSerial,
|
pub serial: BackendConnectorStateSerial,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ impl ConnectorTransaction {
|
||||||
Entry::Occupied(v) => v.into_mut(),
|
Entry::Occupied(v) => v.into_mut(),
|
||||||
Entry::Vacant(v) => v.insert(connector.create_transaction()?),
|
Entry::Vacant(v) => v.insert(connector.create_transaction()?),
|
||||||
};
|
};
|
||||||
tran.add(connector, state)?;
|
tran.add(connector, state.clone())?;
|
||||||
self.common.states.insert(connector.id(), state);
|
self.common.states.insert(connector.id(), state);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ impl MetalDrmDeviceData {
|
||||||
ConnectorConfig {
|
ConnectorConfig {
|
||||||
obj: connector.clone(),
|
obj: connector.clone(),
|
||||||
new: dd.drm_state.clone(),
|
new: dd.drm_state.clone(),
|
||||||
state: *dd.persistent.state.borrow(),
|
state: dd.persistent.state.borrow().clone(),
|
||||||
requested: false,
|
requested: false,
|
||||||
changed: Default::default(),
|
changed: Default::default(),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -637,7 +637,7 @@ impl MetalConnector {
|
||||||
| FrontState::Connected { non_desktop: true } => return,
|
| FrontState::Connected { non_desktop: true } => return,
|
||||||
FrontState::Connected { non_desktop: false } => {}
|
FrontState::Connected { non_desktop: false } => {}
|
||||||
}
|
}
|
||||||
let mut state = *self.display.borrow().persistent.state.borrow();
|
let mut state = self.display.borrow().persistent.state.borrow().clone();
|
||||||
state.serial = self.state.backend_connector_state_serials.next();
|
state.serial = self.state.backend_connector_state_serials.next();
|
||||||
self.send_event(ConnectorEvent::State(state));
|
self.send_event(ConnectorEvent::State(state));
|
||||||
}
|
}
|
||||||
|
|
@ -1928,7 +1928,7 @@ impl MetalBackend {
|
||||||
if dd.supports_bt2020 {
|
if dd.supports_bt2020 {
|
||||||
color_spaces.push(BackendColorSpace::Bt2020);
|
color_spaces.push(BackendColorSpace::Bt2020);
|
||||||
}
|
}
|
||||||
let mut state = *dd.persistent.state.borrow();
|
let mut state = dd.persistent.state.borrow().clone();
|
||||||
state.serial = self.state.backend_connector_state_serials.next();
|
state.serial = self.state.backend_connector_state_serials.next();
|
||||||
connector.send_event(ConnectorEvent::Connected(MonitorInfo {
|
connector.send_event(ConnectorEvent::Connected(MonitorInfo {
|
||||||
modes,
|
modes,
|
||||||
|
|
@ -2573,7 +2573,7 @@ impl MetalBackend {
|
||||||
let mut tran = dev.create_transaction();
|
let mut tran = dev.create_transaction();
|
||||||
for c in dev.connectors.lock().values() {
|
for c in dev.connectors.lock().values() {
|
||||||
let dd = &*c.display.borrow();
|
let dd = &*c.display.borrow();
|
||||||
let mut state = *dd.persistent.state.borrow();
|
let mut state = dd.persistent.state.borrow().clone();
|
||||||
let mut changed_any = false;
|
let mut changed_any = false;
|
||||||
if disable_non_default_format && state.format != XRGB8888 {
|
if disable_non_default_format && state.format != XRGB8888 {
|
||||||
state.format = XRGB8888;
|
state.format = XRGB8888;
|
||||||
|
|
|
||||||
|
|
@ -506,7 +506,7 @@ impl XBackend {
|
||||||
next_image: Default::default(),
|
next_image: Default::default(),
|
||||||
cb: CloneCell::new(None),
|
cb: CloneCell::new(None),
|
||||||
images,
|
images,
|
||||||
state: Cell::new(state),
|
state: RefCell::new(state),
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
let class = "jay\0jay\0";
|
let class = "jay\0jay\0";
|
||||||
|
|
@ -604,7 +604,7 @@ impl XBackend {
|
||||||
color_spaces: vec![],
|
color_spaces: vec![],
|
||||||
primaries: Primaries::SRGB,
|
primaries: Primaries::SRGB,
|
||||||
luminance: None,
|
luminance: None,
|
||||||
state: output.state.get(),
|
state: output.state.borrow().clone(),
|
||||||
}));
|
}));
|
||||||
output.changed();
|
output.changed();
|
||||||
self.present(output).await;
|
self.present(output).await;
|
||||||
|
|
@ -983,11 +983,11 @@ impl XBackend {
|
||||||
old.tex.set(new.tex.get());
|
old.tex.set(new.tex.get());
|
||||||
old.pixmap.set(new.pixmap.get());
|
old.pixmap.set(new.pixmap.get());
|
||||||
}
|
}
|
||||||
let mut state = output.state.get();
|
let mut state = output.state.borrow().clone();
|
||||||
state.serial = self.state.backend_connector_state_serials.next();
|
state.serial = self.state.backend_connector_state_serials.next();
|
||||||
state.mode.width = width;
|
state.mode.width = width;
|
||||||
state.mode.height = height;
|
state.mode.height = height;
|
||||||
output.state.set(state);
|
*output.state.borrow_mut() = state.clone();
|
||||||
output.events.push(ConnectorEvent::State(state));
|
output.events.push(ConnectorEvent::State(state));
|
||||||
output.changed();
|
output.changed();
|
||||||
}
|
}
|
||||||
|
|
@ -1057,7 +1057,7 @@ struct XOutput {
|
||||||
next_image: NumCell<usize>,
|
next_image: NumCell<usize>,
|
||||||
images: [XImage; 2],
|
images: [XImage; 2],
|
||||||
cb: CloneCell<Option<Rc<dyn Fn()>>>,
|
cb: CloneCell<Option<Rc<dyn Fn()>>>,
|
||||||
state: Cell<BackendConnectorState>,
|
state: RefCell<BackendConnectorState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XImage {
|
struct XImage {
|
||||||
|
|
@ -1133,7 +1133,7 @@ struct XTransaction {
|
||||||
impl XTransaction {
|
impl XTransaction {
|
||||||
fn send_state(&self) {
|
fn send_state(&self) {
|
||||||
for con in self.connectors.values() {
|
for con in self.connectors.values() {
|
||||||
let mut state = con.state.get();
|
let mut state = con.state.borrow().clone();
|
||||||
state.serial = con.backend.state.backend_connector_state_serials.next();
|
state.serial = con.backend.state.backend_connector_state_serials.next();
|
||||||
con.events.push(ConnectorEvent::State(state));
|
con.events.push(ConnectorEvent::State(state));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,15 @@ use {
|
||||||
video::{GfxApi, Transform},
|
video::{GfxApi, Transform},
|
||||||
workspace::WorkspaceDisplayOrder,
|
workspace::WorkspaceDisplayOrder,
|
||||||
},
|
},
|
||||||
std::{cell::Cell, env, future::Future, ops::Deref, rc::Rc, sync::Arc, time::Duration},
|
std::{
|
||||||
|
cell::{Cell, RefCell},
|
||||||
|
env,
|
||||||
|
future::Future,
|
||||||
|
ops::Deref,
|
||||||
|
rc::Rc,
|
||||||
|
sync::Arc,
|
||||||
|
time::Duration,
|
||||||
|
},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
uapi::c,
|
uapi::c,
|
||||||
};
|
};
|
||||||
|
|
@ -694,7 +702,7 @@ fn create_dummy_output(state: &Rc<State>) {
|
||||||
damage: Default::default(),
|
damage: Default::default(),
|
||||||
needs_vblank_emulation: Cell::new(false),
|
needs_vblank_emulation: Cell::new(false),
|
||||||
damage_intersect: Default::default(),
|
damage_intersect: Default::default(),
|
||||||
state: Cell::new(backend_state),
|
state: RefCell::new(backend_state),
|
||||||
head_managers: HeadManagers::new(head_name, head_state),
|
head_managers: HeadManagers::new(head_name, head_state),
|
||||||
wlr_output_heads: Default::default(),
|
wlr_output_heads: Default::default(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -258,8 +258,8 @@ impl JayHeadManagerSessionV1 {
|
||||||
let Some(connector) = self.client.state.connectors.get(&head.common.id) else {
|
let Some(connector) = self.client.state.connectors.get(&head.common.id) else {
|
||||||
return Err(HeadTransactionError::HeadRemoved(head.common.id));
|
return Err(HeadTransactionError::HeadRemoved(head.common.id));
|
||||||
};
|
};
|
||||||
let old = connector.state.get();
|
let old = connector.state.borrow().clone();
|
||||||
let mut new = old;
|
let mut new = old.clone();
|
||||||
new.enabled = desired.connector_enabled;
|
new.enabled = desired.connector_enabled;
|
||||||
new.mode = desired.mode;
|
new.mode = desired.mode;
|
||||||
new.non_desktop_override = desired.override_non_desktop;
|
new.non_desktop_override = desired.override_non_desktop;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ impl JayRandr {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_connector(&self, data: &ConnectorData) {
|
fn send_connector(&self, data: &ConnectorData) {
|
||||||
let state = data.state.get();
|
let state_enabled = data.state.borrow().enabled;
|
||||||
self.client.event(Connector {
|
self.client.event(Connector {
|
||||||
self_id: self.id,
|
self_id: self.id,
|
||||||
id: data.connector.id().raw() as _,
|
id: data.connector.id().raw() as _,
|
||||||
|
|
@ -81,7 +81,7 @@ impl JayRandr {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|d| d.dev.id().raw() as _)
|
.map(|d| d.dev.id().raw() as _)
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
enabled: state.enabled as _,
|
enabled: state_enabled as _,
|
||||||
name: &data.name,
|
name: &data.name,
|
||||||
});
|
});
|
||||||
let Some(output) = self.client.state.outputs.get(&data.connector.id()) else {
|
let Some(output) = self.client.state.outputs.get(&data.connector.id()) else {
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ impl WlOutputGlobal {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (x, y) = persistent_state.pos.get();
|
let (x, y) = persistent_state.pos.get();
|
||||||
let scale = persistent_state.scale.get();
|
let scale = persistent_state.scale.get();
|
||||||
let connector_state = connector.state.get();
|
let connector_state = connector.state.borrow();
|
||||||
let (width, height) = calculate_logical_size(
|
let (width, height) = calculate_logical_size(
|
||||||
(connector_state.mode.width, connector_state.mode.height),
|
(connector_state.mode.width, connector_state.mode.height),
|
||||||
persistent_state.transform.get(),
|
persistent_state.transform.get(),
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ impl ZwlrOutputConfigurationV1 {
|
||||||
}
|
}
|
||||||
let mut tran = ConnectorTransaction::new(&self.client.state);
|
let mut tran = ConnectorTransaction::new(&self.client.state);
|
||||||
for output in self.client.state.outputs.lock().values() {
|
for output in self.client.state.outputs.lock().values() {
|
||||||
let mut state = output.connector.state.get();
|
let mut state = output.connector.state.borrow().clone();
|
||||||
match self.enabled_outputs.get(&output.connector.id) {
|
match self.enabled_outputs.get(&output.connector.id) {
|
||||||
None => {
|
None => {
|
||||||
if self.configured_outputs.not_contains(&output.connector.id) {
|
if self.configured_outputs.not_contains(&output.connector.id) {
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ impl ZwlrOutputManagerV1 {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mi = &output.monitor_info;
|
let mi = &output.monitor_info;
|
||||||
let state = output.connector.state.get();
|
let state_mode = output.connector.state.borrow().mode;
|
||||||
let head_id = self.client.state.wlr_output_managers.head_ids.next();
|
let head_id = self.client.state.wlr_output_managers.head_ids.next();
|
||||||
let mut modes_list = vec![];
|
let mut modes_list = vec![];
|
||||||
let mut modes = AHashMap::new();
|
let mut modes = AHashMap::new();
|
||||||
|
|
@ -140,7 +140,7 @@ impl ZwlrOutputManagerV1 {
|
||||||
if modes.contains_key(mode) {
|
if modes.contains_key(mode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let current = !have_current && *mode == state.mode;
|
let current = !have_current && *mode == state_mode;
|
||||||
if current {
|
if current {
|
||||||
have_current = true;
|
have_current = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/state.rs
12
src/state.rs
|
|
@ -420,7 +420,7 @@ pub struct ConnectorData {
|
||||||
pub damage: RefCell<Vec<Rect>>,
|
pub damage: RefCell<Vec<Rect>>,
|
||||||
pub needs_vblank_emulation: Cell<bool>,
|
pub needs_vblank_emulation: Cell<bool>,
|
||||||
pub damage_intersect: Cell<Rect>,
|
pub damage_intersect: Cell<Rect>,
|
||||||
pub state: Cell<BackendConnectorState>,
|
pub state: RefCell<BackendConnectorState>,
|
||||||
pub head_managers: HeadManagers,
|
pub head_managers: HeadManagers,
|
||||||
pub wlr_output_heads: CopyHashMap<WlrOutputManagerId, Rc<ZwlrOutputHeadV1>>,
|
pub wlr_output_heads: CopyHashMap<WlrOutputManagerId, Rc<ZwlrOutputHeadV1>>,
|
||||||
}
|
}
|
||||||
|
|
@ -456,26 +456,26 @@ impl ConnectorData {
|
||||||
state: &State,
|
state: &State,
|
||||||
f: impl FnOnce(&mut BackendConnectorState),
|
f: impl FnOnce(&mut BackendConnectorState),
|
||||||
) -> Result<(), BackendConnectorTransactionError> {
|
) -> Result<(), BackendConnectorTransactionError> {
|
||||||
let old = self.state.get();
|
let old = self.state.borrow().clone();
|
||||||
let mut s = old;
|
let mut s = old.clone();
|
||||||
f(&mut s);
|
f(&mut s);
|
||||||
if old == s {
|
if old == s {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
s.serial = state.backend_connector_state_serials.next();
|
s.serial = state.backend_connector_state_serials.next();
|
||||||
let mut tran = self.connector.create_transaction()?;
|
let mut tran = self.connector.create_transaction()?;
|
||||||
tran.add(&self.connector, s)?;
|
tran.add(&self.connector, s.clone())?;
|
||||||
tran.prepare()?.apply()?.commit();
|
tran.prepare()?.apply()?.commit();
|
||||||
self.set_state(state, s);
|
self.set_state(state, s);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_state(&self, state: &State, s: BackendConnectorState) {
|
pub fn set_state(&self, state: &State, s: BackendConnectorState) {
|
||||||
let old = self.state.get();
|
let old = self.state.borrow().clone();
|
||||||
if old.serial >= s.serial {
|
if old.serial >= s.serial {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.state.set(s);
|
*self.state.borrow_mut() = s.clone();
|
||||||
if old.enabled != s.enabled {
|
if old.enabled != s.enabled {
|
||||||
self.head_managers.handle_enabled_change(s.enabled);
|
self.head_managers.handle_enabled_change(s.enabled);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,12 @@ use {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
jay_config::video::Transform,
|
jay_config::video::Transform,
|
||||||
std::{cell::Cell, collections::VecDeque, fmt, rc::Rc},
|
std::{
|
||||||
|
cell::{Cell, RefCell},
|
||||||
|
collections::VecDeque,
|
||||||
|
fmt,
|
||||||
|
rc::Rc,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
|
pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
|
||||||
|
|
@ -83,7 +88,7 @@ pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
|
||||||
damage: Default::default(),
|
damage: Default::default(),
|
||||||
needs_vblank_emulation: Cell::new(false),
|
needs_vblank_emulation: Cell::new(false),
|
||||||
damage_intersect: Default::default(),
|
damage_intersect: Default::default(),
|
||||||
state: Cell::new(backend_state),
|
state: RefCell::new(backend_state),
|
||||||
head_managers: HeadManagers::new(state.head_names.next(), head_state),
|
head_managers: HeadManagers::new(state.head_names.next(), head_state),
|
||||||
wlr_output_heads: Default::default(),
|
wlr_output_heads: Default::default(),
|
||||||
});
|
});
|
||||||
|
|
@ -144,7 +149,7 @@ impl ConnectorHandler {
|
||||||
async fn handle_connected(&self, info: MonitorInfo) {
|
async fn handle_connected(&self, info: MonitorInfo) {
|
||||||
log::info!("Connector {} connected", self.data.connector.kernel_id());
|
log::info!("Connector {} connected", self.data.connector.kernel_id());
|
||||||
self.data.connected.set(true);
|
self.data.connected.set(true);
|
||||||
self.data.set_state(&self.state, info.state);
|
self.data.set_state(&self.state, info.state.clone());
|
||||||
*self.data.description.borrow_mut() = create_description(&info);
|
*self.data.description.borrow_mut() = create_description(&info);
|
||||||
let name = self.state.globals.name();
|
let name = self.state.globals.name();
|
||||||
if info.non_desktop_effective {
|
if info.non_desktop_effective {
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ impl Idle {
|
||||||
fn try_set_idle(&self, idle: bool) -> Result<(), BackendConnectorTransactionError> {
|
fn try_set_idle(&self, idle: bool) -> Result<(), BackendConnectorTransactionError> {
|
||||||
let mut tran = ConnectorTransaction::new(&self.state);
|
let mut tran = ConnectorTransaction::new(&self.state);
|
||||||
for connector in self.state.connectors.lock().values() {
|
for connector in self.state.connectors.lock().values() {
|
||||||
let mut state = connector.state.get();
|
let mut state = connector.state.borrow().clone();
|
||||||
state.active = !idle;
|
state.active = !idle;
|
||||||
tran.add(&connector.connector, state)?;
|
tran.add(&connector.connector, state)?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue