libdrm_amdgpu_sys/drm_mode/
crtc.rs1use crate::{bindings, drmModeObjectProperties, LibDrm};
2use bindings::drmModeCrtcPtr;
3pub use bindings::drmModeCrtc;
4
5#[allow(dead_code)]
6#[derive(Clone)]
7struct WrapperDrmModeCrtcPtr {
8 pub(crate) ptr: drmModeCrtcPtr,
9 pub(crate) lib: LibDrm,
10}
11
12impl LibDrm {
13 pub fn get_drm_mode_crtc(&self, fd: i32, crtc_id: u32) -> Option<drmModeCrtc> {
14 #[cfg(feature = "link_drm")]
15 let func = bindings::drmModeGetCrtc;
16 #[cfg(feature = "dynamic_loading")]
17 let func = self.libdrm.drmModeGetCrtc;
18
19 let ptr = unsafe { func(fd, crtc_id) };
20
21 if ptr.is_null() { return None; }
22
23 let wrapper = WrapperDrmModeCrtcPtr { ptr, lib: self.clone() };
24
25 Some(unsafe { wrapper.ptr.read() })
26 }
27
28 pub fn get_drm_mode_crtc_props(
29 &self,
30 fd: i32,
31 crtc_id: u32,
32 ) -> Option<drmModeObjectProperties> {
33 self.get_drm_mode_object_properties(
34 fd,
35 crtc_id,
36 bindings::DRM_MODE_OBJECT_CRTC,
37 )
38 }
39}
40
41impl drmModeCrtc {
42 #[cfg(feature = "link_drm")]
43 pub fn get(fd: i32, crtc_id: u32) -> Option<Self> {
44 let ptr = unsafe { bindings::drmModeGetCrtc(fd, crtc_id) };
45
46 if ptr.is_null() { return None; }
47
48 let wrapper = WrapperDrmModeCrtcPtr { ptr, lib: LibDrm::new().unwrap() };
49
50 Some(unsafe { wrapper.ptr.read() })
51 }
52
53 #[cfg(feature = "link_drm")]
54 pub fn get_crtc_props(&self, fd: i32) -> Option<drmModeObjectProperties> {
55 drmModeObjectProperties::get(
56 fd,
57 self.crtc_id,
58 bindings::DRM_MODE_OBJECT_CRTC,
59 )
60 }
61
62 pub fn mode_valid(&self) -> bool {
63 self.mode_valid == 1
64 }
65}
66
67impl Drop for WrapperDrmModeCrtcPtr {
68 fn drop(&mut self) {
69 #[cfg(feature = "link_drm")]
70 let func = bindings::drmModeFreeCrtc;
71 #[cfg(feature = "dynamic_loading")]
72 let func = self.lib.libdrm.drmModeFreeCrtc;
73
74 unsafe { func(self.ptr); }
75 }
76}