state: split connector records
This commit is contained in:
parent
b387c57d57
commit
fb31d5115d
2 changed files with 163 additions and 139 deletions
149
src/state.rs
149
src/state.rs
|
|
@ -1,3 +1,7 @@
|
|||
mod connectors;
|
||||
|
||||
pub use connectors::{ConnectorData, DrmDevData, OutputData};
|
||||
|
||||
use {
|
||||
crate::{
|
||||
acceptor::Acceptor,
|
||||
|
|
@ -15,11 +19,10 @@ use {
|
|||
},
|
||||
async_engine::{AsyncEngine, SpawnedFuture},
|
||||
backend::{
|
||||
Backend, BackendConnectorState, BackendConnectorStateSerials, BackendDrmDevice,
|
||||
BackendEvent, Connector, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds,
|
||||
HardwareCursorUpdate, InputDevice, InputDeviceGroupIds, InputDeviceId, InputDeviceIds,
|
||||
MonitorInfo, TabletIds, TabletInit, TabletPadIds, TabletPadInit, TabletToolIds,
|
||||
transaction::{BackendConnectorTransactionError, ConnectorTransaction},
|
||||
Backend, BackendConnectorStateSerials, BackendEvent, ConnectorId, ConnectorIds,
|
||||
DrmDeviceId, DrmDeviceIds, HardwareCursorUpdate, InputDevice, InputDeviceGroupIds,
|
||||
InputDeviceId, InputDeviceIds, TabletIds, TabletInit, TabletPadIds, TabletPadInit,
|
||||
TabletToolIds, transaction::{BackendConnectorTransactionError, ConnectorTransaction},
|
||||
},
|
||||
backends::dummy::DummyBackend,
|
||||
cli::RunArgs,
|
||||
|
|
@ -60,8 +63,7 @@ use {
|
|||
ext_idle_notification_v1::ExtIdleNotificationV1,
|
||||
ext_session_lock_v1::ExtSessionLockV1,
|
||||
head_management::{
|
||||
HeadManagers, HeadNames,
|
||||
jay_head_manager_session_v1::{HeadManagerEvent, JayHeadManagerSessionV1},
|
||||
HeadNames, jay_head_manager_session_v1::{HeadManagerEvent, JayHeadManagerSessionV1},
|
||||
},
|
||||
data_transfer::{
|
||||
DataOfferIds, DataSourceIds, data_control::DataControlDeviceIds,
|
||||
|
|
@ -85,13 +87,8 @@ use {
|
|||
zwp_idle_inhibitor_v1::{IdleInhibitorId, IdleInhibitorIds, ZwpIdleInhibitorV1},
|
||||
zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2,
|
||||
},
|
||||
wlr_output_manager::{
|
||||
WlrOutputManagerState, zwlr_output_head_v1::ZwlrOutputHeadV1,
|
||||
zwlr_output_manager_v1::WlrOutputManagerId,
|
||||
},
|
||||
wlr_output_manager::WlrOutputManagerState,
|
||||
workspace_manager::WorkspaceManagerState,
|
||||
wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1,
|
||||
wp_drm_lease_device_v1::WpDrmLeaseDeviceV1Global,
|
||||
xdg_activation_token_v1::ActivationToken,
|
||||
zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1,
|
||||
zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1,
|
||||
|
|
@ -119,7 +116,6 @@ use {
|
|||
udmabuf::UdmabufHolder,
|
||||
utils::{
|
||||
asyncevent::AsyncEvent,
|
||||
bindings::Bindings,
|
||||
clonecell::CloneCell,
|
||||
copyhashmap::CopyHashMap,
|
||||
errorfmt::ErrorFmt,
|
||||
|
|
@ -148,7 +144,6 @@ use {
|
|||
},
|
||||
ahash::AHashMap,
|
||||
bstr::ByteSlice,
|
||||
jay_config::PciId,
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
fmt::{Debug, Formatter},
|
||||
|
|
@ -529,130 +524,6 @@ pub struct DeviceHandlerData {
|
|||
pub mods_listener: EventListener<dyn LedsListener>,
|
||||
}
|
||||
|
||||
pub struct ConnectorData {
|
||||
pub id: ConnectorId,
|
||||
pub connector: Rc<dyn Connector>,
|
||||
pub handler: Cell<Option<SpawnedFuture<()>>>,
|
||||
pub connected: Cell<bool>,
|
||||
pub name: Rc<String>,
|
||||
pub description: RefCell<String>,
|
||||
pub drm_dev: Option<Rc<DrmDevData>>,
|
||||
pub async_event: Rc<AsyncEvent>,
|
||||
pub damaged: Cell<bool>,
|
||||
pub damage: RefCell<Vec<Rect>>,
|
||||
pub needs_vblank_emulation: Cell<bool>,
|
||||
pub damage_intersect: Cell<Rect>,
|
||||
pub state: RefCell<BackendConnectorState>,
|
||||
pub head_managers: HeadManagers,
|
||||
pub wlr_output_heads: CopyHashMap<WlrOutputManagerId, Rc<ZwlrOutputHeadV1>>,
|
||||
}
|
||||
|
||||
pub struct OutputData {
|
||||
pub connector: Rc<ConnectorData>,
|
||||
pub monitor_info: Rc<MonitorInfo>,
|
||||
pub node: Option<Rc<OutputNode>>,
|
||||
pub lease_connectors: Rc<Bindings<WpDrmLeaseConnectorV1>>,
|
||||
}
|
||||
|
||||
pub struct DrmDevData {
|
||||
pub dev: Rc<dyn BackendDrmDevice>,
|
||||
pub handler: Cell<Option<SpawnedFuture<()>>>,
|
||||
pub connectors: CopyHashMap<ConnectorId, Rc<ConnectorData>>,
|
||||
pub syspath: Option<String>,
|
||||
pub devnode: Option<String>,
|
||||
pub vendor: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub pci_id: Option<PciId>,
|
||||
pub lease_global: Rc<WpDrmLeaseDeviceV1Global>,
|
||||
}
|
||||
|
||||
impl ConnectorData {
|
||||
pub fn damage(&self) {
|
||||
if !self.damaged.replace(true) {
|
||||
self.connector.damage();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modify_state(
|
||||
&self,
|
||||
state: &State,
|
||||
f: impl FnOnce(&mut BackendConnectorState),
|
||||
) -> Result<(), BackendConnectorTransactionError> {
|
||||
let old = self.state.borrow().clone();
|
||||
let mut s = old.clone();
|
||||
f(&mut s);
|
||||
if old == s {
|
||||
return Ok(());
|
||||
}
|
||||
s.serial = state.backend_connector_state_serials.next();
|
||||
let mut tran = self.connector.create_transaction()?;
|
||||
tran.add(&self.connector, s.clone())?;
|
||||
tran.prepare()?.apply()?.commit();
|
||||
self.set_state(state, s);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_state(&self, state: &State, s: BackendConnectorState) {
|
||||
let old = self.state.borrow().clone();
|
||||
if old.serial >= s.serial {
|
||||
return;
|
||||
}
|
||||
*self.state.borrow_mut() = s.clone();
|
||||
if old.enabled != s.enabled {
|
||||
self.head_managers.handle_enabled_change(state, s.enabled);
|
||||
}
|
||||
if old.active != s.active {
|
||||
self.head_managers.handle_active_change(s.active);
|
||||
}
|
||||
if old.non_desktop_override != s.non_desktop_override {
|
||||
self.head_managers
|
||||
.handle_non_desktop_override_changed(s.non_desktop_override);
|
||||
}
|
||||
if old.vrr != s.vrr {
|
||||
self.head_managers.handle_vrr_change(s.vrr);
|
||||
}
|
||||
if old.tearing != s.tearing {
|
||||
self.head_managers.handle_tearing_enabled_change(s.tearing);
|
||||
}
|
||||
if old.format != s.format {
|
||||
self.head_managers.handle_format_change(s.format);
|
||||
}
|
||||
if (old.color_space, old.eotf) != (s.color_space, s.eotf) {
|
||||
self.head_managers
|
||||
.handle_colors_change(s.color_space, s.eotf);
|
||||
}
|
||||
if old.mode != s.mode {
|
||||
self.head_managers.handle_mode_change(s.mode);
|
||||
for head in self.wlr_output_heads.lock().values() {
|
||||
head.handle_mode_change(s.mode);
|
||||
}
|
||||
}
|
||||
if let Some(output) = state.outputs.get(&self.connector.id())
|
||||
&& let Some(node) = &output.node
|
||||
{
|
||||
node.update_state(old, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DrmDevData {
|
||||
pub fn make_render_device(&self) {
|
||||
log::info!(
|
||||
"Making {} the render device",
|
||||
self.devnode.as_deref().unwrap_or("unknown"),
|
||||
);
|
||||
self.dev.clone().make_render_device();
|
||||
}
|
||||
|
||||
pub fn set_direct_scanout_enabled(&self, _state: &State, enabled: bool) {
|
||||
self.dev.set_direct_scanout_enabled(enabled);
|
||||
}
|
||||
|
||||
pub fn set_flip_margin(&self, _state: &State, margin: u64) {
|
||||
self.dev.set_flip_margin(margin);
|
||||
}
|
||||
}
|
||||
|
||||
struct UpdateTextTexturesVisitor;
|
||||
impl NodeVisitorBase for UpdateTextTexturesVisitor {
|
||||
fn visit_container(&mut self, node: &Rc<ContainerNode>) {
|
||||
|
|
|
|||
153
src/state/connectors.rs
Normal file
153
src/state/connectors.rs
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
use {
|
||||
crate::{
|
||||
backend::{
|
||||
BackendConnectorState, BackendDrmDevice, Connector, ConnectorId, MonitorInfo,
|
||||
transaction::BackendConnectorTransactionError,
|
||||
},
|
||||
ifs::{
|
||||
head_management::HeadManagers,
|
||||
wlr_output_manager::{
|
||||
zwlr_output_head_v1::ZwlrOutputHeadV1,
|
||||
zwlr_output_manager_v1::WlrOutputManagerId,
|
||||
},
|
||||
wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1,
|
||||
wp_drm_lease_device_v1::WpDrmLeaseDeviceV1Global,
|
||||
},
|
||||
rect::Rect,
|
||||
tree::OutputNode,
|
||||
utils::{
|
||||
asyncevent::AsyncEvent, bindings::Bindings, copyhashmap::CopyHashMap,
|
||||
},
|
||||
},
|
||||
jay_config::PciId,
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
|
||||
use super::State;
|
||||
|
||||
pub struct ConnectorData {
|
||||
pub id: ConnectorId,
|
||||
pub connector: Rc<dyn Connector>,
|
||||
pub handler: Cell<Option<crate::async_engine::SpawnedFuture<()>>>,
|
||||
pub connected: Cell<bool>,
|
||||
pub name: Rc<String>,
|
||||
pub description: RefCell<String>,
|
||||
pub drm_dev: Option<Rc<DrmDevData>>,
|
||||
pub async_event: Rc<AsyncEvent>,
|
||||
pub damaged: Cell<bool>,
|
||||
pub damage: RefCell<Vec<Rect>>,
|
||||
pub needs_vblank_emulation: Cell<bool>,
|
||||
pub damage_intersect: Cell<Rect>,
|
||||
pub state: RefCell<BackendConnectorState>,
|
||||
pub head_managers: HeadManagers,
|
||||
pub wlr_output_heads: CopyHashMap<WlrOutputManagerId, Rc<ZwlrOutputHeadV1>>,
|
||||
}
|
||||
|
||||
pub struct OutputData {
|
||||
pub connector: Rc<ConnectorData>,
|
||||
pub monitor_info: Rc<MonitorInfo>,
|
||||
pub node: Option<Rc<OutputNode>>,
|
||||
pub lease_connectors: Rc<Bindings<WpDrmLeaseConnectorV1>>,
|
||||
}
|
||||
|
||||
pub struct DrmDevData {
|
||||
pub dev: Rc<dyn BackendDrmDevice>,
|
||||
pub handler: Cell<Option<crate::async_engine::SpawnedFuture<()>>>,
|
||||
pub connectors: CopyHashMap<ConnectorId, Rc<ConnectorData>>,
|
||||
pub syspath: Option<String>,
|
||||
pub devnode: Option<String>,
|
||||
pub vendor: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub pci_id: Option<PciId>,
|
||||
pub lease_global: Rc<WpDrmLeaseDeviceV1Global>,
|
||||
}
|
||||
|
||||
impl ConnectorData {
|
||||
pub fn damage(&self) {
|
||||
if !self.damaged.replace(true) {
|
||||
self.connector.damage();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modify_state(
|
||||
&self,
|
||||
state: &State,
|
||||
f: impl FnOnce(&mut BackendConnectorState),
|
||||
) -> Result<(), BackendConnectorTransactionError> {
|
||||
let old = self.state.borrow().clone();
|
||||
let mut s = old.clone();
|
||||
f(&mut s);
|
||||
if old == s {
|
||||
return Ok(());
|
||||
}
|
||||
s.serial = state.backend_connector_state_serials.next();
|
||||
let mut tran = self.connector.create_transaction()?;
|
||||
tran.add(&self.connector, s.clone())?;
|
||||
tran.prepare()?.apply()?.commit();
|
||||
self.set_state(state, s);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_state(&self, state: &State, s: BackendConnectorState) {
|
||||
let old = self.state.borrow().clone();
|
||||
if old.serial >= s.serial {
|
||||
return;
|
||||
}
|
||||
*self.state.borrow_mut() = s.clone();
|
||||
if old.enabled != s.enabled {
|
||||
self.head_managers.handle_enabled_change(state, s.enabled);
|
||||
}
|
||||
if old.active != s.active {
|
||||
self.head_managers.handle_active_change(s.active);
|
||||
}
|
||||
if old.non_desktop_override != s.non_desktop_override {
|
||||
self.head_managers
|
||||
.handle_non_desktop_override_changed(s.non_desktop_override);
|
||||
}
|
||||
if old.vrr != s.vrr {
|
||||
self.head_managers.handle_vrr_change(s.vrr);
|
||||
}
|
||||
if old.tearing != s.tearing {
|
||||
self.head_managers.handle_tearing_enabled_change(s.tearing);
|
||||
}
|
||||
if old.format != s.format {
|
||||
self.head_managers.handle_format_change(s.format);
|
||||
}
|
||||
if (old.color_space, old.eotf) != (s.color_space, s.eotf) {
|
||||
self.head_managers
|
||||
.handle_colors_change(s.color_space, s.eotf);
|
||||
}
|
||||
if old.mode != s.mode {
|
||||
self.head_managers.handle_mode_change(s.mode);
|
||||
for head in self.wlr_output_heads.lock().values() {
|
||||
head.handle_mode_change(s.mode);
|
||||
}
|
||||
}
|
||||
if let Some(output) = state.outputs.get(&self.connector.id())
|
||||
&& let Some(node) = &output.node
|
||||
{
|
||||
node.update_state(old, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DrmDevData {
|
||||
pub fn make_render_device(&self) {
|
||||
log::info!(
|
||||
"Making {} the render device",
|
||||
self.devnode.as_deref().unwrap_or("unknown"),
|
||||
);
|
||||
self.dev.clone().make_render_device();
|
||||
}
|
||||
|
||||
pub fn set_direct_scanout_enabled(&self, _state: &State, enabled: bool) {
|
||||
self.dev.set_direct_scanout_enabled(enabled);
|
||||
}
|
||||
|
||||
pub fn set_flip_margin(&self, _state: &State, margin: u64) {
|
||||
self.dev.set_flip_margin(margin);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue