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>
20
#include "buffer_allocator.h"
22
#include "internal_client.h"
23
#include "internal_native_display.h"
24
#include "linux_virtual_terminal.h"
25
#include "mir/graphics/platform_ipc_package.h"
26
#include "mir/graphics/buffer_ipc_packer.h"
27
#include "mir/options/option.h"
28
#include "mir/graphics/native_buffer.h"
30
#include "drm_close_threadsafe.h"
32
#include <boost/throw_exception.hpp>
36
#include <sys/ioctl.h>
38
namespace mg = mir::graphics;
39
namespace mgm = mg::mesa;
40
namespace mo = mir::options;
45
struct MesaPlatformIPCPackage : public mg::PlatformIPCPackage
47
MesaPlatformIPCPackage(int drm_auth_fd)
49
ipc_fds.push_back(drm_auth_fd);
52
~MesaPlatformIPCPackage()
54
if (ipc_fds.size() > 0 && ipc_fds[0] >= 0)
55
mgm::drm_close_threadsafe(ipc_fds[0]);
59
struct RealVTFileOperations : public mgm::VTFileOperations
61
int open(char const* pathname, int flags)
63
return ::open(pathname, flags);
71
int ioctl(int d, int request, int val)
73
return ::ioctl(d, request, val);
76
int ioctl(int d, int request, void* p_val)
78
return ::ioctl(d, request, p_val);
81
int tcsetattr(int d, int acts, const struct termios *tcattr)
83
return ::tcsetattr(d, acts, tcattr);
86
int tcgetattr(int d, struct termios *tcattr)
88
return ::tcgetattr(d, tcattr);
94
std::shared_ptr<mgm::InternalNativeDisplay> mgm::Platform::internal_native_display;
95
bool mgm::Platform::internal_display_clients_present;
96
mgm::Platform::Platform(std::shared_ptr<DisplayReport> const& listener,
97
std::shared_ptr<VirtualTerminal> const& vt)
98
: udev{std::make_shared<UdevContext>()},
104
internal_display_clients_present = false;
107
mgm::Platform::~Platform()
109
internal_native_display.reset();
110
internal_display_clients_present = false;
114
std::shared_ptr<mg::GraphicBufferAllocator> mgm::Platform::create_buffer_allocator(
115
const std::shared_ptr<mg::BufferInitializer>& buffer_initializer)
117
return std::make_shared<mgm::BufferAllocator>(gbm.device, buffer_initializer);
120
std::shared_ptr<mg::Display> mgm::Platform::create_display(
121
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy)
123
return std::make_shared<mgm::Display>(
124
this->shared_from_this(),
129
std::shared_ptr<mg::PlatformIPCPackage> mgm::Platform::get_ipc_package()
131
return std::make_shared<MesaPlatformIPCPackage>(drm.get_authenticated_fd());
134
void mgm::Platform::fill_ipc_package(BufferIPCPacker* packer, Buffer const* buffer) const
136
auto native_handle = buffer->native_buffer_handle();
137
for(auto i=0; i<native_handle->data_items; i++)
139
packer->pack_data(native_handle->data[i]);
141
for(auto i=0; i<native_handle->fd_items; i++)
143
packer->pack_fd(native_handle->fd[i]);
146
packer->pack_stride(buffer->stride());
147
packer->pack_flags(native_handle->flags);
148
packer->pack_size(buffer->size());
151
void mgm::Platform::drm_auth_magic(drm_magic_t magic)
153
drm.auth_magic(magic);
156
std::shared_ptr<mg::InternalClient> mgm::Platform::create_internal_client()
158
if (!internal_native_display)
159
internal_native_display = std::make_shared<mgm::InternalNativeDisplay>(get_ipc_package());
160
internal_display_clients_present = true;
161
return std::make_shared<mgm::InternalClient>(internal_native_display);
164
EGLNativeDisplayType mgm::Platform::egl_native_display() const
169
extern "C" std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& options, std::shared_ptr<DisplayReport> const& report)
171
auto real_fops = std::make_shared<RealVTFileOperations>();
172
auto vt = std::make_shared<mgm::LinuxVirtualTerminal>(real_fops, options->get("vt", 0), report);
173
return std::make_shared<mgm::Platform>(report, vt);
176
extern "C" int mir_server_mesa_egl_native_display_is_valid(MirMesaEGLNativeDisplay* display)
178
return ((mgm::Platform::internal_display_clients_present) &&
179
(display == mgm::Platform::internal_native_display.get()));