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"
26
#include <boost/throw_exception.hpp>
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;
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;
38
mgx::Platform::Platform()
39
: udev{std::make_shared<mir::udev::Context>()},
40
drm{std::make_shared<mesa::helpers::DRMHelper>(mesa::helpers::DRMNodeToUse::render)}
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)}
43
BOOST_THROW_EXCEPTION(std::runtime_error("Cannot create x11 platform more than once"));
45
x11_connection.reset(new mx::X11Connection());
47
if (!x11_connection->dpy)
48
BOOST_THROW_EXCEPTION(std::runtime_error("Cannot open x11 display"));
34
BOOST_THROW_EXCEPTION(std::runtime_error("Need valid x11 display"));
61
47
std::shared_ptr<GLProgramFactory> const&,
62
48
std::shared_ptr<GLConfig> const& /*gl_config*/)
64
return std::make_shared<mgx::Display>(x11_connection->dpy);
50
return std::make_shared<mgx::Display>(x11_connection.get());
67
53
std::shared_ptr<mg::PlatformIpcOperations> mgx::Platform::make_ipc_operations() const
72
58
EGLNativeDisplayType mgx::Platform::egl_native_display() const
74
return eglGetDisplay(x11_connection->dpy);
77
////////////////////////////////////////////////////////////////////////////////////
78
// Platform module entry points below
79
////////////////////////////////////////////////////////////////////////////////////
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*/)
86
return std::make_shared<mgx::Platform>();
89
std::shared_ptr<mg::Platform> create_guest_platform(
90
std::shared_ptr<mg::DisplayReport> const& /*report*/,
91
std::shared_ptr<mg::NestedContext> const&)
93
BOOST_THROW_EXCEPTION(std::runtime_error("Guest platform isn't supported under X"));
97
void add_graphics_platform_options(boost::program_options::options_description& /*config*/)
101
mg::PlatformPriority probe_graphics_platform(mo::ProgramOption const& /*options*/)
103
auto dpy = XOpenDisplay(nullptr);
108
auto udev = std::make_shared<mir::udev::Context>();
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();
115
for (auto& device : drm_devices)
117
static_cast<void>(device);
119
return mg::PlatformPriority::best;
122
return mg::PlatformPriority::unsupported;
125
mir::ModuleProperties const description = {
132
mir::ModuleProperties const* describe_graphics_module()
60
return eglGetDisplay(x11_connection.get());