2
* Copyright © 2012 Canonical Ltd.
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.
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.
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/>.
16
* Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
19
#ifndef MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_
20
#define MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_
22
#include "drm_mode_resources.h"
23
#include "udev_wrapper.h"
28
#pragma GCC diagnostic push
29
#pragma GCC diagnostic warning "-Wall"
31
#pragma GCC diagnostic pop
34
#include <xf86drmMode.h>
43
typedef std::unique_ptr<gbm_surface,std::function<void(gbm_surface*)>> GBMSurfaceUPtr;
51
DRMHelper() : fd{-1} {}
54
DRMHelper(const DRMHelper &) = delete;
55
DRMHelper& operator=(const DRMHelper&) = delete;
57
void setup(std::shared_ptr<UdevContext> const& udev);
58
int get_authenticated_fd();
59
void auth_magic(drm_magic_t magic) const;
61
void drop_master() const;
62
void set_master() const;
67
// TODO: This herustic is temporary; should be replaced with
68
// handling >1 DRM device.
69
int is_appropriate_device(std::shared_ptr<UdevContext> const& udev, UdevDevice const& dev);
71
int count_connections(int fd);
73
int open_drm_device(std::shared_ptr<UdevContext> const& udev);
79
GBMHelper() : device{0} {}
82
GBMHelper(const GBMHelper&) = delete;
83
GBMHelper& operator=(const GBMHelper&) = delete;
85
void setup(const DRMHelper& drm);
86
void setup(int drm_fd);
87
GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height);
96
: egl_display{EGL_NO_DISPLAY}, egl_config{0},
97
egl_context{EGL_NO_CONTEXT}, egl_surface{EGL_NO_SURFACE},
98
should_terminate_egl{false} {}
100
~EGLHelper() noexcept;
102
EGLHelper(const EGLHelper&) = delete;
103
EGLHelper& operator=(const EGLHelper&) = delete;
105
void setup(GBMHelper const& gbm);
106
void setup(GBMHelper const& gbm, EGLContext shared_context);
107
void setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
108
EGLContext shared_context);
111
bool make_current() const;
112
bool release_current() const;
114
EGLContext context() { return egl_context; }
116
void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
118
void setup_internal(GBMHelper const& gbm, bool initialize);
120
EGLDisplay egl_display;
121
EGLConfig egl_config;
122
EGLContext egl_context;
123
EGLSurface egl_surface;
124
bool should_terminate_egl;
131
#endif /* MIR_GRAPHICS_MESA_DISPLAY_HELPERS_H_ */