forked from rust-windowing/winit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kosyak
committed
May 17, 2019
1 parent
cd5caf6
commit e5ab8e5
Showing
9 changed files
with
1,059 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ rls/ | |
.vscode/ | ||
*~ | ||
#*# | ||
._.DS_Store | ||
._DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use drm::control::{Device as ControlDevice, connector::Info as ConnectorInfo, Mode, ResourceInfo, | ||
encoder::Info as EncoderInfo, crtc::Info as CrtcInfo}; | ||
|
||
use std::fs::{File, OpenOptions}; | ||
use std::os::unix::io::{AsRawFd, RawFd}; | ||
|
||
#[derive(Debug)] | ||
// This is our customized struct that implements the traits in drm. | ||
pub struct Card(File); | ||
|
||
// Need to implement AsRawFd before we can implement drm::Device | ||
impl AsRawFd for Card { | ||
fn as_raw_fd(&self) -> RawFd { | ||
self.0.as_raw_fd() | ||
} | ||
} | ||
|
||
impl drm::Device for Card {} | ||
impl ControlDevice for Card {} | ||
|
||
impl Card { | ||
pub fn open(path: &str) -> Self { | ||
let mut options = OpenOptions::new(); | ||
options.read(true); | ||
options.write(true); | ||
Card(options.open(path).unwrap()) | ||
} | ||
|
||
pub fn open_global() -> Self { | ||
Self::open("/dev/dri/card0") | ||
} | ||
|
||
// fn open_control() -> Self { | ||
// Self::open("/dev/dri/controlD64") | ||
// } | ||
|
||
pub fn try_clone(&self) -> std::io::Result<Self> { | ||
let file = self.0.try_clone()?; | ||
Ok(Card(file)) | ||
} | ||
|
||
pub fn get_resources(&self) -> (ConnectorInfo, Mode, EncoderInfo, CrtcInfo) { | ||
let resources = self.resource_handles().unwrap(); | ||
|
||
let connector = resources.connectors().iter().find_map(|&c| { | ||
if let Ok(c) = ConnectorInfo::load_from_device(self, c) { | ||
if c.connection_state() == drm::control::connector::State::Connected && | ||
c.size().0 > 0 && c.size().1 > 0 | ||
{ | ||
return Some(c); | ||
} | ||
} | ||
|
||
None | ||
}).unwrap(); | ||
|
||
let connector_clone = connector.clone(); | ||
let modes = connector_clone.modes(); | ||
let modes = &mut modes.to_owned(); | ||
modes.sort_by(|a, b| { | ||
/*if a.is_preferred() != b.is_preferred() { | ||
a.is_preferred().cmp(&b.is_preferred()).reverse() | ||
} else*/ if a.size().0 as u32 * a.size().1 as u32 != b.size().0 as u32 * b.size().1 as u32 { | ||
(a.size().0 as u32 * a.size().1 as u32).cmp(&(b.size().0 as u32 * b.size().1 as u32)).reverse() | ||
} else { | ||
a.vrefresh().cmp(&b.vrefresh()).reverse() | ||
} | ||
}); | ||
|
||
let mode = modes.iter().next().unwrap(); | ||
|
||
let encoder = | ||
EncoderInfo::load_from_device(self, connector.current_encoder().unwrap()).unwrap(); | ||
|
||
let ctrc_handle = encoder.current_crtc().unwrap(); | ||
let crtc = CrtcInfo::load_from_device(self, ctrc_handle).unwrap(); | ||
|
||
(connector, *mode, encoder, crtc) | ||
} | ||
} |
Oops, something went wrong.