1 #![allow(dead_code)]
2 
3 pub use drm::control::Device as ControlDevice;
4 pub use drm::Device;
5 
6 #[derive(Debug)]
7 /// A simple wrapper for a device node.
8 pub struct Card(std::fs::File);
9 
10 /// Implementing `AsFd` is a prerequisite to implementing the traits found
11 /// in this crate. Here, we are just calling `as_fd()` on the inner File.
12 impl std::os::unix::io::AsFd for Card {
as_fd(&self) -> std::os::unix::io::BorrowedFd<'_>13     fn as_fd(&self) -> std::os::unix::io::BorrowedFd<'_> {
14         self.0.as_fd()
15     }
16 }
17 
18 /// With `AsFd` implemented, we can now implement `drm::Device`.
19 impl Device for Card {}
20 impl ControlDevice for Card {}
21 
22 /// Simple helper methods for opening a `Card`.
23 impl Card {
open(path: &str) -> Self24     pub fn open(path: &str) -> Self {
25         let mut options = std::fs::OpenOptions::new();
26         options.read(true);
27         options.write(true);
28         Card(options.open(path).unwrap())
29     }
30 
open_global() -> Self31     pub fn open_global() -> Self {
32         Self::open("/dev/dri/card0")
33     }
34 }
35 
36 pub mod capabilities {
37     use drm::ClientCapability as CC;
38     pub const CLIENT_CAP_ENUMS: &[CC] = &[CC::Stereo3D, CC::UniversalPlanes, CC::Atomic];
39 
40     use drm::DriverCapability as DC;
41     pub const DRIVER_CAP_ENUMS: &[DC] = &[
42         DC::DumbBuffer,
43         DC::VBlankHighCRTC,
44         DC::DumbPreferredDepth,
45         DC::DumbPreferShadow,
46         DC::Prime,
47         DC::MonotonicTimestamp,
48         DC::ASyncPageFlip,
49         DC::CursorWidth,
50         DC::CursorHeight,
51         DC::AddFB2Modifiers,
52         DC::PageFlipTarget,
53         DC::CRTCInVBlankEvent,
54         DC::SyncObj,
55         DC::TimelineSyncObj,
56     ];
57 }
58 
59 pub mod images {
60     use image;
61 
load_image(name: &str) -> image::RgbaImage62     pub fn load_image(name: &str) -> image::RgbaImage {
63         let path = format!("examples/images/{}", name);
64         image::open(path).unwrap().to_rgba8()
65     }
66 }
67