legacy: move create_surface into Surface constructor
This commit is contained in:
parent
a4203bd216
commit
b6087bf2d2
|
@ -250,52 +250,10 @@ impl<A: AsRawFd + 'static> Device for LegacyDrmDevice<A> {
|
||||||
return Err(Error::DeviceInactive);
|
return Err(Error::DeviceInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to enumarate the current state to set the initial state variable correctly
|
let backend = Rc::new(LegacyDrmSurfaceInternal::new(
|
||||||
|
self.dev.clone(), crtc,
|
||||||
let crtc_info = self.get_crtc(crtc).compat().map_err(|source| Error::Access {
|
self.logger.new(o!("crtc" => format!("{:?}", crtc))),
|
||||||
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))),
|
|
||||||
});
|
|
||||||
|
|
||||||
self.backends.borrow_mut().insert(crtc, Rc::downgrade(&backend));
|
self.backends.borrow_mut().insert(crtc, Rc::downgrade(&backend));
|
||||||
Ok(LegacyDrmSurface(backend))
|
Ok(LegacyDrmSurface(backend))
|
||||||
|
|
|
@ -266,6 +266,57 @@ impl<A: AsRawFd + 'static> RawSurface for LegacyDrmSurfaceInternal<A> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: AsRawFd + 'static> LegacyDrmSurfaceInternal<A> {
|
impl<A: AsRawFd + 'static> LegacyDrmSurfaceInternal<A> {
|
||||||
|
pub(crate) fn new(dev: Rc<Dev<A>>, crtc: crtc::Handle, logger: ::slog::Logger) -> Result<LegacyDrmSurfaceInternal<A>, 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<bool, Error> {
|
fn check_connector(&self, conn: connector::Handle, mode: &Mode) -> Result<bool, Error> {
|
||||||
let info = self
|
let info = self
|
||||||
.get_connector(conn)
|
.get_connector(conn)
|
||||||
|
|
Loading…
Reference in New Issue