Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "mir/udev/wrapper.h"
24 
25 #include <cstddef>
26 #include <memory>
27 
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic warning "-Wall"
30 #include <gbm.h>
31 #pragma GCC diagnostic pop
32 
33 #include <EGL/egl.h>
34 #include <xf86drmMode.h>
35 
36 namespace mir
37 {
38 namespace graphics
39 {
40 class GLConfig;
41 
42 namespace mesa
43 {
44 
45 typedef std::unique_ptr<gbm_surface,std::function<void(gbm_surface*)>> GBMSurfaceUPtr;
46 
47 namespace helpers
48 {
49 
50 class DRMHelper
51 {
52 public:
53  DRMHelper() : fd{-1} {}
54  ~DRMHelper();
55 
56  DRMHelper(const DRMHelper &) = delete;
57  DRMHelper& operator=(const DRMHelper&) = delete;
58 
59  void setup(std::shared_ptr<mir::udev::Context> const& udev);
61  void auth_magic(drm_magic_t magic) const;
62 
63  void drop_master() const;
64  void set_master() const;
65 
66  int fd;
67 
68 private:
69  // TODO: This herustic is temporary; should be replaced with
70  // handling >1 DRM device.
71  int is_appropriate_device(std::shared_ptr<mir::udev::Context> const& udev, mir::udev::Device const& dev);
72 
73  int count_connections(int fd);
74 
75  int open_drm_device(std::shared_ptr<mir::udev::Context> const& udev);
76 };
77 
78 class GBMHelper
79 {
80 public:
81  GBMHelper() : device{0} {}
82  ~GBMHelper();
83 
84  GBMHelper(const GBMHelper&) = delete;
85  GBMHelper& operator=(const GBMHelper&) = delete;
86 
87  void setup(const DRMHelper& drm);
88  void setup(int drm_fd);
90 
91  gbm_device* device;
92 };
93 
94 class EGLHelper
95 {
96 public:
97  EGLHelper(GLConfig const& gl_config);
98  ~EGLHelper() noexcept;
99 
100  EGLHelper(const EGLHelper&) = delete;
101  EGLHelper& operator=(const EGLHelper&) = delete;
102 
103  void setup(GBMHelper const& gbm);
104  void setup(GBMHelper const& gbm, EGLContext shared_context);
105  void setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
106  EGLContext shared_context);
107 
108  bool swap_buffers();
109  bool make_current() const;
110  bool release_current() const;
111 
112  EGLContext context() { return egl_context; }
113 
114  void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
115 private:
116  void setup_internal(GBMHelper const& gbm, bool initialize);
117 
118  EGLint const depth_buffer_bits;
119  EGLint const stencil_buffer_bits;
120  EGLDisplay egl_display;
121  EGLConfig egl_config;
122  EGLContext egl_context;
123  EGLSurface egl_surface;
124  bool should_terminate_egl;
125 };
126 
127 }
128 }
129 }
130 }
131 #endif /* MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_ */
void initialize(std::shared_ptr< mir::logging::Logger > const &logger)
bool release_current() const
Definition: display_helpers.cpp:383
int get_authenticated_fd()
Definition: display_helpers.cpp:49
DRMHelper()
Definition: display_helpers.h:53
std::unique_ptr< gbm_surface, std::function< void(gbm_surface *)> > GBMSurfaceUPtr
Definition: display_helpers.h:45
~EGLHelper() noexcept
Definition: display_helpers.cpp:355
Definition: display_helpers.h:50
~GBMHelper()
Definition: display_helpers.cpp:289
void setup(const DRMHelper &drm)
Definition: display_helpers.cpp:258
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:51
bool swap_buffers()
Definition: display_helpers.cpp:371
GBMHelper()
Definition: display_helpers.h:81
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:438
void auth_magic(drm_magic_t magic) const
Definition: display_helpers.cpp:97
Definition: display_helpers.h:78
Definition: display_helpers.h:94
int fd
Definition: display_helpers.h:66
bool make_current() const
Definition: display_helpers.cpp:377
void setup(GBMHelper const &gbm)
Definition: display_helpers.cpp:308
unsigned int height
Definition: black_arrow.c:5
void drop_master() const
Definition: display_helpers.cpp:117
GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height)
Definition: display_helpers.cpp:274
EGLContext context()
Definition: display_helpers.h:112
gbm_device * device
Definition: display_helpers.h:91
~DRMHelper()
Definition: display_helpers.cpp:248
EGLHelper(GLConfig const &gl_config)
Definition: display_helpers.cpp:299
GBMHelper & operator=(const GBMHelper &)=delete
void set_master() const
Definition: display_helpers.cpp:137

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014