drm/
mode_info.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/// Structure representing connector.
23#[derive(Clone)]
24pub struct ModeInfo {
25    mode_info: ffi::xf86drm_mode::drmModeModeInfo,
26}
27
28/// General methods
29impl ModeInfo {
30    /// `ModeInfo` constructor.
31    pub fn new(mode_info: ffi::xf86drm_mode::drmModeModeInfo) -> Self {
32        ModeInfo { mode_info: mode_info }
33    }
34
35    /// Returns pointer to raw C structure.
36    pub fn as_ptr(&self) -> ffi::xf86drm_mode::drmModeModeInfoPtr {
37        &self.mode_info
38    }
39}
40
41/// Getters for original members
42impl ModeInfo {
43    #[inline]
44    pub fn get_clock(&self) -> u32 {
45        self.mode_info.clock
46    }
47
48    #[inline]
49    pub fn get_hdisplay(&self) -> u16 {
50        self.mode_info.hdisplay
51    }
52
53    #[inline]
54    pub fn get_hsync_start(&self) -> u16 {
55        self.mode_info.hsync_start
56    }
57
58    #[inline]
59    pub fn get_hsync_end(&self) -> u16 {
60        self.mode_info.hsync_end
61    }
62
63    #[inline]
64    pub fn get_htotal(&self) -> u16 {
65        self.mode_info.htotal
66    }
67
68    #[inline]
69    pub fn get_hskew(&self) -> u16 {
70        self.mode_info.hskew
71    }
72
73    #[inline]
74    pub fn get_vdisplay(&self) -> u16 {
75        self.mode_info.vdisplay
76    }
77
78    #[inline]
79    pub fn get_vsync_start(&self) -> u16 {
80        self.mode_info.vsync_start
81    }
82
83    #[inline]
84    pub fn get_vsync_end(&self) -> u16 {
85        self.mode_info.vsync_end
86    }
87
88    #[inline]
89    pub fn get_vtotal(&self) -> u16 {
90        self.mode_info.vtotal
91    }
92
93    #[inline]
94    pub fn get_vscan(&self) -> u16 {
95        self.mode_info.vscan
96    }
97
98    #[inline]
99    pub fn get_vrefresh(&self) -> u32 {
100        self.mode_info.vrefresh
101    }
102
103    #[inline]
104    pub fn get_flags(&self) -> u32 {
105        self.mode_info.flags
106    }
107
108    #[inline]
109    pub fn get_mode_type(&self) -> u32 {
110        self.mode_info.mode_type
111    }
112}
113
114impl std::fmt::Debug for ModeInfo {
115    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
116        write!(f,
117               "ModeInfo {{ width: {}, height: {} }}",
118               self.get_hdisplay(),
119               self.get_vdisplay())
120    }
121}