~vanvugt/mir/handoff

« back to all changes in this revision

Viewing changes to src/platforms/mesa/server/x11/platform.cpp

  • Committer: Daniel van Vugt
  • Date: 2015-08-12 09:52:57 UTC
  • mfrom: (2798.1.41 trunk)
  • Revision ID: daniel.van.vugt@canonical.com-20150812095257-58wduov90c2mpiqs
Merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "display.h"
21
21
#include "buffer_allocator.h"
22
22
#include "ipc_operations.h"
23
 
#include "xserver_connection.h"
24
 
#include "mir/udev/wrapper.h"
25
 
 
26
 
#include <boost/throw_exception.hpp>
27
23
 
28
24
namespace mg = mir::graphics;
29
25
namespace mgm = mg::mesa;
30
26
namespace mgx = mg::X;
31
 
namespace mo = mir::options;
32
 
namespace mx = mir::X;
33
 
 
34
 
//TODO: Remove this global by allowing input and graphics drivers to share
35
 
//     some context like the x11 display handle.
36
 
std::shared_ptr<mx::X11Connection> x11_connection;
37
 
 
38
 
mgx::Platform::Platform()
39
 
    : udev{std::make_shared<mir::udev::Context>()},
40
 
       drm{std::make_shared<mesa::helpers::DRMHelper>(mesa::helpers::DRMNodeToUse::render)}
 
27
 
 
28
mgx::Platform::Platform(std::shared_ptr<::Display> const& conn)
 
29
    : x11_connection{conn},
 
30
      udev{std::make_shared<mir::udev::Context>()},
 
31
      drm{std::make_shared<mesa::helpers::DRMHelper>(mesa::helpers::DRMNodeToUse::render)}
41
32
{
42
 
    if (x11_connection)
43
 
        BOOST_THROW_EXCEPTION(std::runtime_error("Cannot create x11 platform more than once"));
44
 
 
45
 
    x11_connection.reset(new mx::X11Connection());
46
 
 
47
 
    if (!x11_connection->dpy)
48
 
        BOOST_THROW_EXCEPTION(std::runtime_error("Cannot open x11 display"));
 
33
    if (!x11_connection)
 
34
        BOOST_THROW_EXCEPTION(std::runtime_error("Need valid x11 display"));
49
35
 
50
36
    drm->setup(udev);
51
37
    gbm.setup(*drm);
61
47
    std::shared_ptr<GLProgramFactory> const&,
62
48
    std::shared_ptr<GLConfig> const& /*gl_config*/)
63
49
{
64
 
    return std::make_shared<mgx::Display>(x11_connection->dpy);
 
50
    return std::make_shared<mgx::Display>(x11_connection.get());
65
51
}
66
52
 
67
53
std::shared_ptr<mg::PlatformIpcOperations> mgx::Platform::make_ipc_operations() const
71
57
 
72
58
EGLNativeDisplayType mgx::Platform::egl_native_display() const
73
59
{
74
 
    return eglGetDisplay(x11_connection->dpy);
75
 
}
76
 
 
77
 
////////////////////////////////////////////////////////////////////////////////////
78
 
// Platform module entry points below
79
 
////////////////////////////////////////////////////////////////////////////////////
80
 
 
81
 
std::shared_ptr<mg::Platform> create_host_platform(
82
 
    std::shared_ptr<mo::Option> const& /*options*/,
83
 
    std::shared_ptr<mir::EmergencyCleanupRegistry> const& /*emergency_cleanup_registry*/,
84
 
    std::shared_ptr<mg::DisplayReport> const& /*report*/)
85
 
{
86
 
    return std::make_shared<mgx::Platform>();
87
 
}
88
 
 
89
 
std::shared_ptr<mg::Platform> create_guest_platform(
90
 
    std::shared_ptr<mg::DisplayReport> const& /*report*/,
91
 
    std::shared_ptr<mg::NestedContext> const&)
92
 
{
93
 
    BOOST_THROW_EXCEPTION(std::runtime_error("Guest platform isn't supported under X"));
94
 
    return nullptr;
95
 
}
96
 
 
97
 
void add_graphics_platform_options(boost::program_options::options_description& /*config*/)
98
 
{
99
 
}
100
 
 
101
 
mg::PlatformPriority probe_graphics_platform(mo::ProgramOption const& /*options*/)
102
 
{
103
 
    auto dpy = XOpenDisplay(nullptr);
104
 
    if (dpy)
105
 
    {
106
 
        XCloseDisplay(dpy);
107
 
 
108
 
        auto udev = std::make_shared<mir::udev::Context>();
109
 
 
110
 
        mir::udev::Enumerator drm_devices{udev};
111
 
        drm_devices.match_subsystem("drm");
112
 
        drm_devices.match_sysname("renderD[0-9]*");
113
 
        drm_devices.scan_devices();
114
 
 
115
 
        for (auto& device : drm_devices)
116
 
        {
117
 
            static_cast<void>(device);
118
 
 
119
 
            return mg::PlatformPriority::best;
120
 
        }
121
 
    }
122
 
    return mg::PlatformPriority::unsupported;
123
 
}
124
 
 
125
 
mir::ModuleProperties const description = {
126
 
    "mesa-x11",
127
 
    MIR_VERSION_MAJOR,
128
 
    MIR_VERSION_MINOR,
129
 
    MIR_VERSION_MICRO
130
 
};
131
 
 
132
 
mir::ModuleProperties const* describe_graphics_module()
133
 
{
134
 
    return &description;
 
60
    return eglGetDisplay(x11_connection.get());
135
61
}