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_authentication.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 enum class DRMNodeToUse
51 {
52  render,
53  card
54 };
55 
57 {
58 public:
59  DRMHelper(DRMNodeToUse const node_to_use) : fd{-1}, node_to_use{node_to_use} {}
60  ~DRMHelper();
61 
62  DRMHelper(const DRMHelper &) = delete;
63  DRMHelper& operator=(const DRMHelper&) = delete;
64 
65  void setup(std::shared_ptr<mir::udev::Context> const& udev);
66  mir::Fd authenticated_fd();
67  void auth_magic(drm_magic_t magic);
68 
69  void drop_master() const;
70  void set_master() const;
71 
72  int fd;
74 
75 private:
76  // TODO: This herustic is temporary; should be replaced with
77  // handling >1 DRM device.
78  int is_appropriate_device(std::shared_ptr<mir::udev::Context> const& udev, mir::udev::Device const& dev);
79 
80  int count_connections(int fd);
81 
82  int open_drm_device(std::shared_ptr<mir::udev::Context> const& udev);
83 };
84 
85 class GBMHelper
86 {
87 public:
88  GBMHelper() : device{0} {}
89  ~GBMHelper();
90 
91  GBMHelper(const GBMHelper&) = delete;
92  GBMHelper& operator=(const GBMHelper&) = delete;
93 
94  void setup(const DRMHelper& drm);
95  void setup(int drm_fd);
96  GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height);
97 
98  gbm_device* device;
99 };
100 
102 {
103 public:
104  EGLHelper(GLConfig const& gl_config);
105  ~EGLHelper() noexcept;
106 
107  EGLHelper(const EGLHelper&) = delete;
108  EGLHelper& operator=(const EGLHelper&) = delete;
109 
110  void setup(GBMHelper const& gbm);
111  void setup(GBMHelper const& gbm, EGLContext shared_context);
112  void setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
113  EGLContext shared_context);
114 
115  bool swap_buffers();
116  bool make_current() const;
117  bool release_current() const;
118 
119  EGLContext context() { return egl_context; }
120 
121  void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
122 private:
123  void setup_internal(GBMHelper const& gbm, bool initialize);
124 
125  EGLint const depth_buffer_bits;
126  EGLint const stencil_buffer_bits;
127  EGLDisplay egl_display;
128  EGLConfig egl_config;
129  EGLContext egl_context;
130  EGLSurface egl_surface;
131  bool should_terminate_egl;
132 };
133 
134 }
135 }
136 }
137 }
138 #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:45
Definition: fd.h:33
Definition: display_helpers.h:56
Definition: wrapper.h:50
GBMHelper()
Definition: display_helpers.h:88
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:59
Definition: display_helpers.h:85
Definition: display_helpers.h:101
unsigned int width
Definition: touchspot_image.c:4
DRMNodeToUse const node_to_use
Definition: display_helpers.h:73
int fd
Definition: display_helpers.h:72
unsigned int height
Definition: touchspot_image.c:5
EGLContext context()
Definition: display_helpers.h:119
Definition: drm_authentication.h:31
gbm_device * device
Definition: display_helpers.h:98
DRMNodeToUse
Definition: display_helpers.h:50
Definition: platform_operation.h:37

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