From 174e4b9d0b2400e267bf96d1ee542fad7feaedb6 Mon Sep 17 00:00:00 2001 From: Drakulix Date: Sun, 17 Sep 2017 22:54:36 +0200 Subject: [PATCH] Fix encoder detection --- src/backend/drm/mod.rs | 49 ++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index f022815..a72134f 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -398,8 +398,6 @@ impl DrmDevice { where I: Into>, { - use std::collections::hash_set::HashSet; - for backend in self.backends.iter() { if let Some(backend) = backend.upgrade() { if backend.borrow().is_crtc(crtc) { @@ -410,36 +408,25 @@ impl DrmDevice { // check if the given connectors and crtc match let connectors = connectors.into(); - // get all encoders supported by this device - let mut set = self.context - .head() - .head() - .resource_handles()? - .encoders() - .iter() - .cloned() - .collect::>(); - for connector in connectors.iter() { - let info = connector::Info::load_from_device(self.context.head().head(), *connector)?; - // then check for every connector which encoders it does support - let conn_set = info.encoders() - .iter() - .cloned() - .collect::>(); - // and update the list of supported encoders for this combination - set = set.intersection(&conn_set) - .cloned() - .collect::>(); - } - // check if there is any encoder left that can be connected to the crtc - let encoders: Vec = set.iter() - .map(|handle| { - encoder::Info::load_from_device(self.context.head().head(), *handle).map_err(DrmError::from) - }) - .collect::, DrmError>>()?; - if !encoders.iter().any(|enc| enc.supports_crtc(crtc)) { - return Err(DrmError::Crtc(CrtcError::NoSuitableEncoder)); + // check if we have an encoder for every connector + for connector in connectors.iter() { + let con_info = connector::Info::load_from_device(self.context.head().head(), *connector)?; + + // then check for every connector which encoders it does support + let encoders = con_info + .encoders() + .iter() + .map(|encoder| { + encoder::Info::load_from_device(self.context.head().head(), *encoder) + .map_err(DrmError::from) + }) + .collect::, DrmError>>()?; + + // and if any encoder supports the selected crtc + if !encoders.iter().any(|encoder| encoder.supports_crtc(crtc)) { + return Err(DrmError::Crtc(CrtcError::NoSuitableEncoder)); + } } // configuration is valid, the kernel will figure out the rest