Mir
drm_mode_resources.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17  */
18 
19 #ifndef MIR_GRAPHICS_COMMON_KMS_UTILS_DRM_MODE_RESOURCES_H_
20 #define MIR_GRAPHICS_COMMON_KMS_UTILS_DRM_MODE_RESOURCES_H_
21 
22 #include <xf86drm.h>
23 #include <xf86drmMode.h>
24 
25 #include <memory>
26 #include <functional>
27 #include <unordered_map>
28 
29 namespace mir
30 {
31 namespace graphics
32 {
33 namespace kms
34 {
35 
36 typedef std::unique_ptr<drmModeCrtc,std::function<void(drmModeCrtc*)>> DRMModeCrtcUPtr;
37 typedef std::unique_ptr<drmModeEncoder,std::function<void(drmModeEncoder*)>> DRMModeEncoderUPtr;
38 typedef std::unique_ptr<drmModeConnector,std::function<void(drmModeConnector*)>> DRMModeConnectorUPtr;
39 typedef std::unique_ptr<drmModeRes,void(*)(drmModeRes*)> DRMModeResUPtr;
40 typedef std::unique_ptr<drmModePlaneRes,void(*)(drmModePlaneRes*)> DRMModePlaneResUPtr;
41 typedef std::unique_ptr<drmModePlane,std::function<void(drmModePlane*)>> DRMModePlaneUPtr;
42 typedef std::unique_ptr<drmModeObjectProperties,void(*)(drmModeObjectProperties*)> DRMModeObjectPropsUPtr;
43 typedef std::unique_ptr<drmModePropertyRes,void(*)(drmModePropertyPtr)> DRMModePropertyUPtr;
44 
45 DRMModeConnectorUPtr get_connector(int drm_fd, uint32_t id);
46 DRMModeEncoderUPtr get_encoder(int drm_fd, uint32_t id);
47 DRMModeCrtcUPtr get_crtc(int drm_fd, uint32_t id);
48 DRMModePlaneUPtr get_plane(int drm_fd, uint32_t id);
49 
50 class DRMModeResources;
51 class PlaneResources;
52 
53 namespace detail
54 {
55 template<typename DRMUPtr, DRMUPtr(*)(int, uint32_t)>
57 {
58 public:
59  class iterator :
60  public std::iterator<std::input_iterator_tag, DRMUPtr>
61  {
62  public:
63  iterator(iterator const& from);
64  iterator& operator=(iterator const& rhs);
65 
67  iterator operator++(int);
68 
69  bool operator==(iterator const& rhs) const;
70  bool operator!=(iterator const& rhs) const;
71 
72  DRMUPtr& operator*() const;
73  DRMUPtr* operator->() const;
74 
75  private:
76  friend class ObjectCollection;
77  iterator(int drm_fd, uint32_t* id_ptr);
78 
79  int drm_fd;
80  uint32_t* id_ptr;
81  DRMUPtr mutable current;
82  };
83 
84  iterator begin();
85  iterator end();
86 private:
89  ObjectCollection(int drm_fd, uint32_t* begin, uint32_t* end);
90 
91  int const drm_fd;
92  uint32_t* const begin_;
93  uint32_t* const end_;
94 };
95 }
96 
98 {
99 public:
100  struct Prop
101  {
102  uint32_t id;
103  uint64_t value;
104  };
105 
106  ObjectProperties(int drm_fd, uint32_t object_id, uint32_t object_type);
107  ObjectProperties(int drm_fd, DRMModePlaneUPtr const& plane);
108  ObjectProperties(int drm_fd, DRMModeCrtcUPtr const& crtc);
109  ObjectProperties(int drm_fd, DRMModeConnectorUPtr const& connector);
110 
111  uint64_t operator[](char const* name) const;
112  uint32_t id_for(char const* property_name) const;
113 
114  std::unordered_map<std::string, Prop>::const_iterator begin() const;
115  std::unordered_map<std::string, Prop>::const_iterator end() const;
116 
117 private:
118  std::unordered_map<std::string, Prop> const properties_table;
119 };
120 
122 {
123 public:
124  explicit PlaneResources(int drm_fd);
125 
127 private:
128  int const drm_fd;
129  DRMModePlaneResUPtr const resources;
130 };
131 
133 {
134 public:
135  explicit DRMModeResources(int drm_fd);
136 
137  void for_each_connector(std::function<void(DRMModeConnectorUPtr)> const& f) const;
138 
139  void for_each_encoder(std::function<void(DRMModeEncoderUPtr)> const& f) const;
140 
141  void for_each_crtc(std::function<void(DRMModeCrtcUPtr)> const& f) const;
142 
143  size_t num_connectors() const;
144 
145  size_t num_encoders() const;
146 
147  size_t num_crtcs() const;
148 
149  DRMModeConnectorUPtr connector(uint32_t id) const;
150  DRMModeEncoderUPtr encoder(uint32_t id) const;
151  DRMModeCrtcUPtr crtc(uint32_t id) const;
152 
156 
157 private:
158  int const drm_fd;
159  DRMModeResUPtr const resources;
160 };
161 
162 }
163 }
164 }
165 
166 #endif /* MIR_GRAPHICS_COMMON_KMS_UTILS_DRM_MODE_RESOURCES_H_ */
All things Mir.
Definition: atomic_callback.h:25
friend class ObjectCollection
Definition: drm_mode_resources.h:76
std::unique_ptr< drmModePlane, std::function< void(drmModePlane *)> > DRMModePlaneUPtr
Definition: drm_mode_resources.h:41
DRMModePlaneUPtr get_plane(int drm_fd, uint32_t id)
DRMModeEncoderUPtr get_encoder(int drm_fd, uint32_t id)
uint32_t id
Definition: drm_mode_resources.h:102
std::unique_ptr< drmModeObjectProperties, void(*)(drmModeObjectProperties *)> DRMModeObjectPropsUPtr
Definition: drm_mode_resources.h:42
std::unique_ptr< drmModeConnector, std::function< void(drmModeConnector *)> > DRMModeConnectorUPtr
Definition: drm_mode_resources.h:38
Definition: drm_mode_resources.h:132
std::unique_ptr< drmModePropertyRes, void(*)(drmModePropertyPtr)> DRMModePropertyUPtr
Definition: drm_mode_resources.h:43
Definition: drm_mode_resources.h:100
std::unique_ptr< drmModeCrtc, std::function< void(drmModeCrtc *)> > DRMModeCrtcUPtr
Definition: drm_mode_resources.h:36
Definition: drm_mode_resources.h:121
Definition: drm_mode_resources.h:56
DRMModeCrtcUPtr get_crtc(int drm_fd, uint32_t id)
Definition: drm_mode_resources.h:97
uint64_t value
Definition: drm_mode_resources.h:103
DRMModeConnectorUPtr get_connector(int drm_fd, uint32_t id)
std::unique_ptr< drmModePlaneRes, void(*)(drmModePlaneRes *)> DRMModePlaneResUPtr
Definition: drm_mode_resources.h:40
std::unique_ptr< drmModeRes, void(*)(drmModeRes *)> DRMModeResUPtr
Definition: drm_mode_resources.h:39
std::unique_ptr< drmModeEncoder, std::function< void(drmModeEncoder *)> > DRMModeEncoderUPtr
Definition: drm_mode_resources.h:37

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016