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 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 General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Alexandros Frantzis <alexandros.frantzis@canonical.com>
20
#include "mir/graphics/android/sync_fence.h"
21
#include "android_platform.h"
22
#include "android_graphic_buffer_allocator.h"
23
#include "resource_factory.h"
24
#include "android_display.h"
25
#include "internal_client.h"
26
#include "output_builder.h"
27
#include "mir/graphics/platform_ipc_package.h"
28
#include "mir/graphics/android/native_buffer.h"
29
#include "mir/graphics/buffer_initializer.h"
30
#include "mir/graphics/buffer_id.h"
31
#include "mir/graphics/buffer_ipc_packer.h"
32
#include "mir/options/option.h"
34
#include "mir/graphics/null_display_report.h"
35
#include <boost/throw_exception.hpp>
38
namespace mg=mir::graphics;
39
namespace mga=mir::graphics::android;
40
namespace mf=mir::frontend;
41
namespace mo = mir::options;
43
mga::AndroidPlatform::AndroidPlatform(
44
std::shared_ptr<mga::DisplayBuilder> const& display_builder,
45
std::shared_ptr<mg::DisplayReport> const& display_report)
46
: display_builder(display_builder),
47
display_report(display_report)
51
std::shared_ptr<mg::GraphicBufferAllocator> mga::AndroidPlatform::create_buffer_allocator(
52
std::shared_ptr<mg::BufferInitializer> const& buffer_initializer)
54
return std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
57
std::shared_ptr<mga::GraphicBufferAllocator> mga::AndroidPlatform::create_mga_buffer_allocator(
58
std::shared_ptr<mg::BufferInitializer> const& buffer_initializer)
60
return std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
63
std::shared_ptr<mg::Display> mga::AndroidPlatform::create_display(
64
std::shared_ptr<graphics::DisplayConfigurationPolicy> const&)
66
return std::make_shared<mga::AndroidDisplay>(display_builder, display_report);
69
std::shared_ptr<mg::PlatformIPCPackage> mga::AndroidPlatform::get_ipc_package()
71
return std::make_shared<mg::PlatformIPCPackage>();
74
void mga::AndroidPlatform::fill_ipc_package(BufferIPCPacker* packer, graphics::Buffer const* buffer) const
76
auto native_buffer = buffer->native_buffer_handle();
77
auto buffer_handle = native_buffer->handle();
81
for(auto i=0; i<buffer_handle->numFds; i++)
83
packer->pack_fd(buffer_handle->data[offset++]);
85
for(auto i=0; i<buffer_handle->numInts; i++)
87
packer->pack_data(buffer_handle->data[offset++]);
90
packer->pack_stride(buffer->stride());
91
packer->pack_size(buffer->size());
94
EGLNativeDisplayType mga::AndroidPlatform::egl_native_display() const
96
return EGL_DEFAULT_DISPLAY;
99
void mga::AndroidPlatform::initialize(std::shared_ptr<NestedContext> const&)
103
std::shared_ptr<mg::InternalClient> mga::AndroidPlatform::create_internal_client()
105
return std::make_shared<mga::InternalClient>();
108
extern "C" std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& /*options*/, std::shared_ptr<DisplayReport> const& display_report)
110
//todo: could parse an option here
111
auto should_use_fb_fallback = false;
112
auto buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
113
auto display_resource_factory = std::make_shared<mga::ResourceFactory>();
114
auto fb_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
115
auto display_builder = std::make_shared<mga::OutputBuilder>(
116
fb_allocator, display_resource_factory, display_report, should_use_fb_fallback);
117
return std::make_shared<mga::AndroidPlatform>(display_builder, display_report);
120
extern "C" std::shared_ptr<mg::NativePlatform> create_native_platform(std::shared_ptr<mg::DisplayReport> const& display_report)
122
auto should_use_fb_fallback = false;
123
auto buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
124
auto fb_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
125
auto display_resource_factory = std::make_shared<mga::ResourceFactory>();
126
auto display_builder = std::make_shared<mga::OutputBuilder>(
127
fb_allocator, display_resource_factory, display_report, should_use_fb_fallback);
128
return std::make_shared<mga::AndroidPlatform>(display_builder, display_report);