~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/platform/graphics/mesa/display_helpers.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-08 02:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: package-import@ubuntu.com-20140108020438-e1npu0pm7qdv5wc4
Tags: upstream-0.1.3+14.04.20140108
Import upstream version 0.1.3+14.04.20140108

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "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
namespace mesa
 
41
{
 
42
 
 
43
typedef std::unique_ptr<gbm_surface,std::function<void(gbm_surface*)>> GBMSurfaceUPtr;
 
44
 
 
45
namespace helpers
 
46
{
 
47
 
 
48
class DRMHelper
 
49
{
 
50
public:
 
51
    DRMHelper() : fd{-1} {}
 
52
    ~DRMHelper();
 
53
 
 
54
    DRMHelper(const DRMHelper &) = delete;
 
55
    DRMHelper& operator=(const DRMHelper&) = delete;
 
56
 
 
57
    void setup(std::shared_ptr<UdevContext> const& udev);
 
58
    int get_authenticated_fd();
 
59
    void auth_magic(drm_magic_t magic) const;
 
60
 
 
61
    void drop_master() const;
 
62
    void set_master() const;
 
63
 
 
64
    int fd;
 
65
 
 
66
private:
 
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);
 
70
 
 
71
    int count_connections(int fd);
 
72
 
 
73
    int open_drm_device(std::shared_ptr<UdevContext> const& udev);
 
74
};
 
75
 
 
76
class GBMHelper
 
77
{
 
78
public:
 
79
    GBMHelper() : device{0} {}
 
80
    ~GBMHelper();
 
81
 
 
82
    GBMHelper(const GBMHelper&) = delete;
 
83
    GBMHelper& operator=(const GBMHelper&) = delete;
 
84
 
 
85
    void setup(const DRMHelper& drm);
 
86
    void setup(int drm_fd);
 
87
    GBMSurfaceUPtr create_scanout_surface(uint32_t width, uint32_t height);
 
88
 
 
89
    gbm_device* device;
 
90
};
 
91
 
 
92
class EGLHelper
 
93
{
 
94
public:
 
95
    EGLHelper()
 
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} {}
 
99
 
 
100
    ~EGLHelper() noexcept;
 
101
 
 
102
    EGLHelper(const EGLHelper&) = delete;
 
103
    EGLHelper& operator=(const EGLHelper&) = delete;
 
104
 
 
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);
 
109
 
 
110
    bool swap_buffers();
 
111
    bool make_current() const;
 
112
    bool release_current() const;
 
113
 
 
114
    EGLContext context() { return egl_context; }
 
115
 
 
116
    void report_egl_configuration(std::function<void(EGLDisplay, EGLConfig)>);
 
117
private:
 
118
    void setup_internal(GBMHelper const& gbm, bool initialize);
 
119
 
 
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_ */