drm/
encoder.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;
21use crtc;
22
23/// Type of encoder id.
24pub type EncoderId = u32;
25
26/// Type of encoder type.
27pub type EncoderType = u32;
28
29/// Structure representing encoder.
30pub struct Encoder {
31    encoder: ffi::xf86drm_mode::drmModeEncoderPtr,
32}
33
34/// General methods
35impl Encoder {
36    /// `Encoder` constructor.
37    /// Does not check if passed arguments are valid.
38    pub fn new(encoder: ffi::xf86drm_mode::drmModeEncoderPtr) -> Self {
39        Encoder { encoder: encoder }
40    }
41}
42
43/// Getters for original members
44impl Encoder {
45    #[inline]
46    pub fn get_encoder_id(&self) -> EncoderId {
47        unsafe { (*self.encoder).encoder_id }
48    }
49
50    #[inline]
51    pub fn get_encoder_type(&self) -> EncoderType {
52        unsafe { (*self.encoder).encoder_type }
53    }
54
55    #[inline]
56    pub fn get_crtc_id(&self) -> crtc::CrtcId {
57        unsafe { (*self.encoder).crtc_id }
58    }
59
60    #[inline]
61    pub fn get_possible_crtcs(&self) -> u32 {
62        unsafe { (*self.encoder).possible_crtcs }
63    }
64
65    #[inline]
66    pub fn get_possible_clones(&self) -> u32 {
67        unsafe { (*self.encoder).possible_clones }
68    }
69}
70
71impl Drop for Encoder {
72    fn drop(&mut self) {
73        unsafe { ffi::xf86drm_mode::drmModeFreeEncoder(self.encoder) };
74    }
75}
76
77impl std::fmt::Debug for Encoder {
78    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
79        write!(f, "Encoder {{ id: {}, crtc_id: {} }}", self.get_encoder_id(), self.get_crtc_id())
80    }
81}