diff --git a/src/backend/drm/legacy/mod.rs b/src/backend/drm/legacy/mod.rs index 66968f0..d1733aa 100644 --- a/src/backend/drm/legacy/mod.rs +++ b/src/backend/drm/legacy/mod.rs @@ -250,52 +250,10 @@ impl Device for LegacyDrmDevice { return Err(Error::DeviceInactive); } - // Try to enumarate the current state to set the initial state variable correctly - - let crtc_info = self.get_crtc(crtc).compat().map_err(|source| Error::Access { - errmsg: "Error loading crtc info", - dev: self.dev_path(), - source, - })?; - - let mode = crtc_info.mode(); - - let mut connectors = HashSet::new(); - let res_handles = ControlDevice::resource_handles(self) - .compat() - .map_err(|source| Error::Access { - errmsg: "Error loading drm resources", - dev: self.dev_path(), - source, - })?; - for &con in res_handles.connectors() { - let con_info = self.get_connector(con).compat().map_err(|source| Error::Access { - errmsg: "Error loading connector info", - dev: self.dev_path(), - source, - })?; - if let Some(enc) = con_info.current_encoder() { - let enc_info = self.get_encoder(enc).compat().map_err(|source| Error::Access { - errmsg: "Error loading encoder info", - dev: self.dev_path(), - source, - })?; - if let Some(current_crtc) = enc_info.crtc() { - if crtc == current_crtc { - connectors.insert(con); - } - } - } - } - - let state = State { mode, connectors }; - let backend = Rc::new(LegacyDrmSurfaceInternal { - dev: self.dev.clone(), - crtc, - state: RwLock::new(state.clone()), - pending: RwLock::new(state), - logger: self.logger.new(o!("crtc" => format!("{:?}", crtc))), - }); + let backend = Rc::new(LegacyDrmSurfaceInternal::new( + self.dev.clone(), crtc, + self.logger.new(o!("crtc" => format!("{:?}", crtc))), + )?); self.backends.borrow_mut().insert(crtc, Rc::downgrade(&backend)); Ok(LegacyDrmSurface(backend)) diff --git a/src/backend/drm/legacy/surface.rs b/src/backend/drm/legacy/surface.rs index 6bdfa1a..83ea1f6 100644 --- a/src/backend/drm/legacy/surface.rs +++ b/src/backend/drm/legacy/surface.rs @@ -266,6 +266,57 @@ impl RawSurface for LegacyDrmSurfaceInternal { } impl LegacyDrmSurfaceInternal { + pub(crate) fn new(dev: Rc>, crtc: crtc::Handle, logger: ::slog::Logger) -> Result, Error> { + // Try to enumarate the current state to set the initial state variable correctly + let crtc_info = dev.get_crtc(crtc).compat().map_err(|source| Error::Access { + errmsg: "Error loading crtc info", + dev: dev.dev_path(), + source, + })?; + + let current_mode = crtc_info.mode(); + + let mut current_connectors = HashSet::new(); + let res_handles = ControlDevice::resource_handles(&*dev) + .compat() + .map_err(|source| Error::Access { + errmsg: "Error loading drm resources", + dev: dev.dev_path(), + source, + })?; + for &con in res_handles.connectors() { + let con_info = dev.get_connector(con).compat().map_err(|source| Error::Access { + errmsg: "Error loading connector info", + dev: dev.dev_path(), + source, + })?; + if let Some(enc) = con_info.current_encoder() { + let enc_info = dev.get_encoder(enc).compat().map_err(|source| Error::Access { + errmsg: "Error loading encoder info", + dev: dev.dev_path(), + source, + })?; + if let Some(current_crtc) = enc_info.crtc() { + if crtc == current_crtc { + current_connectors.insert(con); + } + } + } + } + + let state = State { current_mode, current_connectors }; + + let surface = LegacyDrmSurfaceInternal { + dev, + crtc, + state: RwLock::new(state), + pending: RwLock::new(state.clone()), + logger, + }; + + Ok(surface) + } + fn check_connector(&self, conn: connector::Handle, mode: &Mode) -> Result { let info = self .get_connector(conn)