drm/
crtc.rs

1// Copyright 2016 The libdrm-rs project developers
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4// and associated documentation files (the "Software"), to deal in the Software without
5// restriction, including without limitation the rights to use, copy, modify, merge, publish,
6// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7// Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
18use std;
19
20use ffi;
21
22/// Type of CRTC id.
23pub type CrtcId = u32;
24
25/// Structure representing CRTC.
26pub struct Crtc {
27    crtc: ffi::xf86drm_mode::drmModeCrtcPtr,
28}
29
30// General methods
31impl Crtc {
32    /// `Crtc` constructor.
33    /// Does not check if passed arguments are valid.
34    pub fn new(crtc: ffi::xf86drm_mode::drmModeCrtcPtr) -> Self {
35        Crtc { crtc: crtc }
36    }
37}
38
39// Getters for original members
40impl Crtc {
41    #[inline]
42    pub fn get_crtc_id(&self) -> CrtcId {
43        unsafe { (*self.crtc).crtc_id }
44    }
45
46    #[inline]
47    pub fn get_buffer_id(&self) -> u32 {
48        unsafe { (*self.crtc).buffer_id }
49    }
50
51    /// Get X-axis position on the frame buffer.
52    #[inline]
53    pub fn get_x(&self) -> u32 {
54        unsafe { (*self.crtc).x }
55    }
56
57    /// Get Y-axis position on the frame buffer.
58    #[inline]
59    pub fn get_y(&self) -> u32 {
60        unsafe { (*self.crtc).y }
61    }
62
63    #[inline]
64    pub fn get_width(&self) -> u32 {
65        unsafe { (*self.crtc).width }
66    }
67
68    #[inline]
69    pub fn get_height(&self) -> u32 {
70        unsafe { (*self.crtc).height }
71    }
72
73    #[inline]
74    pub fn get_mode_valid(&self) -> bool {
75        unsafe { (*self.crtc).mode_valid != 0 }
76    }
77
78    #[inline]
79    pub fn get_gamma_size(&self) -> isize {
80        unsafe { (*self.crtc).gamma_size as isize }
81    }
82}
83
84impl Drop for Crtc {
85    fn drop(&mut self) {
86        unsafe { ffi::xf86drm_mode::drmModeFreeCrtc(self.crtc) };
87    }
88}
89
90impl std::fmt::Debug for Crtc {
91    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
92        write!(f, "Crtc {{ id: {}, buffer_id: {} }}", self.get_crtc_id(), self.get_buffer_id())
93    }
94}
95