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: Kevin DuBois<kevin.dubois@canonical.com>
19
#include "mir_toolkit/mir_client_library.h"
20
#include "client_platform.h"
21
#include "client_buffer_factory.h"
22
#include "mesa_native_display_container.h"
23
#include "buffer_file_ops.h"
24
#include "native_surface.h"
25
#include "../mir_connection.h"
26
#include "../client_buffer_factory.h"
27
#include "../native_client_platform_factory.h"
32
namespace mcl=mir::client;
33
namespace mclm=mir::client::mesa;
34
namespace geom=mir::geometry;
39
struct RealBufferFileOps : public mclm::BufferFileOps
41
int close(int fd) const
43
while (::close(fd) == -1)
45
// Retry on EINTR, return error on anything else
52
void* map(int fd, off_t offset, size_t size) const
54
return mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED,
58
void unmap(void* addr, size_t size) const
64
struct NativeDisplayDeleter
66
NativeDisplayDeleter(mcl::EGLNativeDisplayContainer& container)
67
: container(container)
70
void operator() (EGLNativeDisplayType* p)
72
auto display = *(reinterpret_cast<MirEGLNativeDisplayType*>(p));
73
container.release(display);
77
mcl::EGLNativeDisplayContainer& container;
82
std::shared_ptr<mcl::ClientPlatform>
83
mcl::NativeClientPlatformFactory::create_client_platform(mcl::ClientContext* context)
85
auto buffer_file_ops = std::make_shared<RealBufferFileOps>();
86
return std::make_shared<mclm::ClientPlatform>(
87
context, buffer_file_ops, mcl::EGLNativeDisplayContainer::instance());
90
mclm::ClientPlatform::ClientPlatform(
91
ClientContext* const context,
92
std::shared_ptr<BufferFileOps> const& buffer_file_ops,
93
mcl::EGLNativeDisplayContainer& display_container)
95
buffer_file_ops{buffer_file_ops},
96
display_container(display_container)
100
std::shared_ptr<mcl::ClientBufferFactory> mclm::ClientPlatform::create_buffer_factory()
102
return std::make_shared<mclm::ClientBufferFactory>(buffer_file_ops);
107
struct NativeWindowDeleter
109
NativeWindowDeleter(mclm::NativeSurface* window)
112
void operator()(EGLNativeWindowType* type)
119
mclm::NativeSurface* window;
123
std::shared_ptr<EGLNativeWindowType> mclm::ClientPlatform::create_egl_native_window(ClientSurface* client_surface)
125
//TODO: this is awkward on both android and gbm...
126
auto native_window = new NativeSurface(*client_surface);
127
auto egl_native_window = new EGLNativeWindowType;
128
*egl_native_window = native_window;
129
NativeWindowDeleter deleter(native_window);
130
return std::shared_ptr<EGLNativeWindowType>(egl_native_window, deleter);
133
std::shared_ptr<EGLNativeDisplayType> mclm::ClientPlatform::create_egl_native_display()
135
MirEGLNativeDisplayType *mir_native_display = new MirEGLNativeDisplayType;
136
*mir_native_display = display_container.create(context->mir_connection());
137
auto egl_native_display = reinterpret_cast<EGLNativeDisplayType*>(mir_native_display);
139
return std::shared_ptr<EGLNativeDisplayType>(egl_native_display, NativeDisplayDeleter(display_container));
142
MirPlatformType mclm::ClientPlatform::platform_type() const
144
return mir_platform_type_gbm;
147
MirNativeBuffer* mclm::ClientPlatform::convert_native_buffer(graphics::NativeBuffer* buf) const
149
//MirNativeBuffer is type-compatible with the MirNativeBuffer