Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gbm_display_helpers.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU 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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU 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_GBM_GBM_DISPLAY_HELPERS_H_
20 #define MIR_GRAPHICS_GBM_GBM_DISPLAY_HELPERS_H_
21 
22 #include "drm_mode_resources.h"
23 
24 #include <cstddef>
25 #include <memory>
26 
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic warning "-Wall"
29 #include <gbm.h>
30 #pragma GCC diagnostic pop
31 
32 #include <EGL/egl.h>
33 #include <xf86drmMode.h>
34 #include <libudev.h>
35 
36 namespace mir
37 {
38 namespace graphics
39 {
40 namespace gbm
41 {
42 
43 typedef std::unique_ptr<gbm_surface,std::function<void(gbm_surface*)>> GBMSurfaceUPtr;
44 
45 namespace helpers
46 {
47 
48 // TODO (RAOF): This is going to morph into an approximately fully-featured
49 // C++ udev library, and probably a top-level Mir interface.
50 //
51 // For now, do the simple thing.
52 struct UdevHelper
53 {
54 public:
55  UdevHelper();
56  ~UdevHelper() noexcept;
57 
58  UdevHelper(UdevHelper const&) = delete;
59  UdevHelper &operator=(UdevHelper const&) = delete;
60 
61  udev* ctx;
62 };
63 
64 class DRMHelper
65 {
66 public:
67  DRMHelper() : fd{-1} {}
68  ~DRMHelper();
69 
70  DRMHelper(const DRMHelper &) = delete;
71  DRMHelper& operator=(const DRMHelper&) = delete;
72 
73  void setup(UdevHelper const& udev);
75  void auth_magic(drm_magic_t magic) const;
76 
77  void drop_master() const;
78  void set_master() const;
79 
80  int fd;
81 
82 private:
83  // TODO: This herustic is temporary; should be replaced with
84  // handling >1 DRM device.
85  int is_appropriate_device(UdevHelper const& udev, udev_device* dev);
86 
87  int count_connections(int fd);
88 
89  int open_drm_device(UdevHelper const& udev);
90 };
91 
92 class GBMHelper
93 {
94 public:
95  GBMHelper() : device{0} {}
96  ~GBMHelper();
97 
98  GBMHelper(const GBMHelper&) = delete;
99  GBMHelper& operator=(const GBMHelper&) = delete;
100 
101  void setup(const DRMHelper& drm);
102  void setup(int drm_fd);
104 
105  gbm_device* device;
106 };
107 
109 {
110 public:
112  : egl_display{EGL_NO_DISPLAY}, egl_config{0},
113  egl_context{EGL_NO_CONTEXT}, egl_surface{EGL_NO_SURFACE},
114  should_terminate_egl{false} {}
115 
116  ~EGLHelper() noexcept;
117 
118  EGLHelper(const EGLHelper&) = delete;
119  EGLHelper& operator=(const EGLHelper&) = delete;
120 
121  void setup(GBMHelper const& gbm);
122  void setup(GBMHelper const& gbm, EGLContext shared_context);
123  void setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
124  EGLContext shared_context);
125 
126  bool swap_buffers();
127  bool make_current();
128  bool release_current();
129 
130  EGLContext context() { return egl_context; }
131 
132  void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
133 private:
134  void setup_internal(GBMHelper const& gbm, bool initialize);
135 
136  EGLDisplay egl_display;
137  EGLConfig egl_config;
138  EGLContext egl_context;
139  EGLSurface egl_surface;
140  bool should_terminate_egl;
141 };
142 
143 }
144 }
145 }
146 }
147 #endif /* MIR_GRAPHICS_GBM_GBM_DISPLAY_HELPERS_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Wed Oct 30 18:52:19 UTC 2013