Mir
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 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_MESA_DISPLAY_HELPERS_H_
20 #define MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_
21 
22 #include "drm_mode_resources.h"
23 #include "drm_authentication.h"
24 #include "mir/udev/wrapper.h"
25 
26 #include <cstddef>
27 #include <memory>
28 
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic warning "-Wall"
31 #include <gbm.h>
32 #pragma GCC diagnostic pop
33 
34 #include <EGL/egl.h>
35 #include <xf86drmMode.h>
36 
37 namespace mir
38 {
39 namespace graphics
40 {
41 class GLConfig;
42 
43 namespace mesa
44 {
45 
46 typedef std::unique_ptr<gbm_surface,std::function<void(gbm_surface*)>> GBMSurfaceUPtr;
47 
48 namespace helpers
49 {
50 
51 enum class DRMNodeToUse
52 {
53  render,
54  card
55 };
56 
58 {
59 public:
60  DRMHelper(DRMNodeToUse const node_to_use) : fd{-1}, node_to_use{node_to_use} {}
61  ~DRMHelper();
62 
63  DRMHelper(const DRMHelper &) = delete;
64  DRMHelper& operator=(const DRMHelper&) = delete;
65 
66  void setup(std::shared_ptr<mir::udev::Context> const& udev);
67  mir::Fd authenticated_fd();
68  void auth_magic(drm_magic_t magic);
69 
70  void drop_master() const;
71  void set_master() const;
72 
73  int fd;
75 
76 private:
77  // TODO: This herustic is temporary; should be replaced with
78  // handling >1 DRM device.
79  int is_appropriate_device(std::shared_ptr<mir::udev::Context> const& udev, mir::udev::Device const& dev);
80 
81  int count_connections(int fd);
82 
83  int open_drm_device(std::shared_ptr<mir::udev::Context> const& udev);
84 };
85 
86 class GBMHelper
87 {
88 public:
89  GBMHelper() : device{0} {}
90  ~GBMHelper();
91 
92  GBMHelper(const GBMHelper&) = delete;
93  GBMHelper& operator=(const GBMHelper&) = delete;
94 
95  void setup(const DRMHelper& drm);
96  void setup(int drm_fd);
97  GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height);
98 
99  gbm_device* device;
100 };
101 
103 {
104 public:
105  EGLHelper(GLConfig const& gl_config);
106  ~EGLHelper() noexcept;
107 
108  EGLHelper(const EGLHelper&) = delete;
109  EGLHelper& operator=(const EGLHelper&) = delete;
110 
111  void setup(GBMHelper const& gbm);
112  void setup(GBMHelper const& gbm, EGLContext shared_context);
113  void setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
114  EGLContext shared_context);
115 
116  bool swap_buffers();
117  bool make_current() const;
118  bool release_current() const;
119 
120  EGLContext context() { return egl_context; }
121 
122  void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
123 private:
124  void setup_internal(GBMHelper const& gbm, bool initialize);
125 
126  EGLint const depth_buffer_bits;
127  EGLint const stencil_buffer_bits;
128  EGLDisplay egl_display;
129  EGLConfig egl_config;
130  EGLContext egl_context;
131  EGLSurface egl_surface;
132  bool should_terminate_egl;
133 };
134 
135 }
136 }
137 }
138 }
139 #endif /* MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_ */
void initialize(std::shared_ptr< mir::logging::Logger > const &logger)
All things Mir.
Definition: atomic_callback.h:25
bool make_current(mrg::RenderTarget *render_target)
Definition: server_example_adorning_compositor.cpp:39
std::unique_ptr< gbm_surface, std::function< void(gbm_surface *)> > GBMSurfaceUPtr
Definition: display_helpers.h:46
Definition: fd.h:33
Definition: display_helpers.h:57
Definition: wrapper.h:50
GBMHelper()
Definition: display_helpers.h:89
Interface for customizing aspects of the GL config used by the server.
Definition: gl_config.h:30
DRMHelper(DRMNodeToUse const node_to_use)
Definition: display_helpers.h:60
Definition: display_helpers.h:86
Definition: display_helpers.h:102
unsigned int width
Definition: touchspot_image.c:4
DRMNodeToUse const node_to_use
Definition: display_helpers.h:74
int fd
Definition: display_helpers.h:73
unsigned int height
Definition: touchspot_image.c:5
EGLContext context()
Definition: display_helpers.h:120
Definition: drm_authentication.h:31
gbm_device * device
Definition: display_helpers.h:99
DRMNodeToUse
Definition: display_helpers.h:51
Definition: platform_operation.h:37

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016