~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/server/graphics/android/android_platform.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-08 02:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: package-import@ubuntu.com-20140108020438-e1npu0pm7qdv5wc4
Tags: upstream-0.1.3+14.04.20140108
Import upstream version 0.1.3+14.04.20140108

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by:
17
 
 *   Alexandros Frantzis <alexandros.frantzis@canonical.com>
18
 
 */
19
 
 
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"
33
 
 
34
 
#include "mir/graphics/null_display_report.h"
35
 
#include <boost/throw_exception.hpp>
36
 
#include <stdexcept>
37
 
 
38
 
namespace mg=mir::graphics;
39
 
namespace mga=mir::graphics::android;
40
 
namespace mf=mir::frontend;
41
 
namespace mo = mir::options;
42
 
 
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)
48
 
{
49
 
}
50
 
 
51
 
std::shared_ptr<mg::GraphicBufferAllocator> mga::AndroidPlatform::create_buffer_allocator(
52
 
        std::shared_ptr<mg::BufferInitializer> const& buffer_initializer)
53
 
{
54
 
    return std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
55
 
}
56
 
 
57
 
std::shared_ptr<mga::GraphicBufferAllocator> mga::AndroidPlatform::create_mga_buffer_allocator(
58
 
    std::shared_ptr<mg::BufferInitializer> const& buffer_initializer)
59
 
{
60
 
    return std::make_shared<mga::AndroidGraphicBufferAllocator>(buffer_initializer);
61
 
}
62
 
 
63
 
std::shared_ptr<mg::Display> mga::AndroidPlatform::create_display(
64
 
    std::shared_ptr<graphics::DisplayConfigurationPolicy> const&)
65
 
{
66
 
    return std::make_shared<mga::AndroidDisplay>(display_builder, display_report);
67
 
}
68
 
 
69
 
std::shared_ptr<mg::PlatformIPCPackage> mga::AndroidPlatform::get_ipc_package()
70
 
{
71
 
    return std::make_shared<mg::PlatformIPCPackage>();
72
 
}
73
 
 
74
 
void mga::AndroidPlatform::fill_ipc_package(BufferIPCPacker* packer, graphics::Buffer const* buffer) const
75
 
{
76
 
    auto native_buffer = buffer->native_buffer_handle();
77
 
    auto buffer_handle = native_buffer->handle();
78
 
 
79
 
    int offset = 0;
80
 
    
81
 
    for(auto i=0; i<buffer_handle->numFds; i++)
82
 
    {
83
 
        packer->pack_fd(buffer_handle->data[offset++]);
84
 
    }
85
 
    for(auto i=0; i<buffer_handle->numInts; i++)
86
 
    {
87
 
        packer->pack_data(buffer_handle->data[offset++]);
88
 
    }
89
 
 
90
 
    packer->pack_stride(buffer->stride());
91
 
    packer->pack_size(buffer->size());
92
 
}
93
 
 
94
 
EGLNativeDisplayType mga::AndroidPlatform::egl_native_display() const
95
 
{
96
 
    return EGL_DEFAULT_DISPLAY;
97
 
}
98
 
 
99
 
void mga::AndroidPlatform::initialize(std::shared_ptr<NestedContext> const&)
100
 
{
101
 
}
102
 
 
103
 
std::shared_ptr<mg::InternalClient> mga::AndroidPlatform::create_internal_client()
104
 
{
105
 
    return std::make_shared<mga::InternalClient>();
106
 
}
107
 
 
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)
109
 
{
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);
118
 
}
119
 
 
120
 
extern "C" std::shared_ptr<mg::NativePlatform> create_native_platform(std::shared_ptr<mg::DisplayReport> const& display_report)
121
 
{
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);
129
 
}