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 
52 {
53 public:
54  DRMHelper() : fd{-1} {}
55  ~DRMHelper();
56 
57  DRMHelper(const DRMHelper &) = delete;
58  DRMHelper& operator=(const DRMHelper&) = delete;
59 
60  void setup(std::shared_ptr<mir::udev::Context> const& udev);
62  void auth_magic(drm_magic_t magic);
63 
64  void drop_master() const;
65  void set_master() const;
66 
67  int fd;
68 
69 private:
70  // TODO: This herustic is temporary; should be replaced with
71  // handling >1 DRM device.
72  int is_appropriate_device(std::shared_ptr<mir::udev::Context> const& udev, mir::udev::Device const& dev);
73 
74  int count_connections(int fd);
75 
76  int open_drm_device(std::shared_ptr<mir::udev::Context> const& udev);
77 };
78 
79 class GBMHelper
80 {
81 public:
82  GBMHelper() : device{0} {}
83  ~GBMHelper();
84 
85  GBMHelper(const GBMHelper&) = delete;
86  GBMHelper& operator=(const GBMHelper&) = delete;
87 
88  void setup(const DRMHelper& drm);
89  void setup(int drm_fd);
90  GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height);
91 
92  gbm_device* device;
93 };
94 
95 class EGLHelper
96 {
97 public:
98  EGLHelper(GLConfig const& gl_config);
99  ~EGLHelper() noexcept;
100 
101  EGLHelper(const EGLHelper&) = delete;
102  EGLHelper& operator=(const EGLHelper&) = delete;
103 
104  void setup(GBMHelper const& gbm);
105  void setup(GBMHelper const& gbm, EGLContext shared_context);
106  void setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
107  EGLContext shared_context);
108 
109  bool swap_buffers();
110  bool make_current() const;
111  bool release_current() const;
112 
113  EGLContext context() { return egl_context; }
114 
115  void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
116 private:
117  void setup_internal(GBMHelper const& gbm, bool initialize);
118 
119  EGLint const depth_buffer_bits;
120  EGLint const stencil_buffer_bits;
121  EGLDisplay egl_display;
122  EGLConfig egl_config;
123  EGLContext egl_context;
124  EGLSurface egl_surface;
125  bool should_terminate_egl;
126 };
127 
128 }
129 }
130 }
131 }
132 #endif /* MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_ */
void initialize(std::shared_ptr< mir::logging::Logger > const &logger)
All things Mir.
Definition: buffer_stream.h:37
bool release_current() const
Definition: display_helpers.cpp:384
void auth_magic(drm_magic_t magic)
Definition: display_helpers.cpp:98
DRMHelper()
Definition: display_helpers.h:54
std::unique_ptr< gbm_surface, std::function< void(gbm_surface *)> > GBMSurfaceUPtr
Definition: display_helpers.h:46
~EGLHelper() noexcept
Definition: display_helpers.cpp:356
Definition: fd.h:33
Definition: display_helpers.h:51
~GBMHelper()
Definition: display_helpers.cpp:290
void setup(const DRMHelper &drm)
Definition: display_helpers.cpp:259
EGLHelper & operator=(const EGLHelper &)=delete
DRMHelper & operator=(const DRMHelper &)=delete
void setup(std::shared_ptr< mir::udev::Context > const &udev)
Definition: display_helpers.cpp:41
Definition: wrapper.h:50
bool swap_buffers()
Definition: display_helpers.cpp:372
GBMHelper()
Definition: display_helpers.h:82
unsigned int width
Definition: black_arrow.c:4
Interface for customizing aspects of the GL config used by the server.
Definition: gl_config.h:30
void report_egl_configuration(std::function< void(EGLDisplay, EGLConfig)>)
Definition: display_helpers.cpp:439
Definition: display_helpers.h:79
Definition: display_helpers.h:95
mir::Fd authenticated_fd()
Definition: display_helpers.cpp:49
int fd
Definition: display_helpers.h:67
bool make_current() const
Definition: display_helpers.cpp:378
void setup(GBMHelper const &gbm)
Definition: display_helpers.cpp:309
unsigned int height
Definition: black_arrow.c:5
void drop_master() const
Definition: display_helpers.cpp:118
GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height)
Definition: display_helpers.cpp:275
EGLContext context()
Definition: display_helpers.h:113
Definition: drm_authentication.h:31
gbm_device * device
Definition: display_helpers.h:92
~DRMHelper()
Definition: display_helpers.cpp:249
EGLHelper(GLConfig const &gl_config)
Definition: display_helpers.cpp:300
GBMHelper & operator=(const GBMHelper &)=delete
void set_master() const
Definition: display_helpers.cpp:138

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015