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

« back to all changes in this revision

Viewing changes to src/platform/graphics/android/hwc10_device.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 © 2013 Canonical Ltd.
 
3
 *
 
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.
 
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 Lesser General Public License for more details.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by:
 
17
 *   Kevin DuBois <kevin.dubois@canonical.com>
 
18
 */
 
19
 
 
20
#include "hwc10_device.h"
 
21
#include "hwc_vsync_coordinator.h"
 
22
#include "framebuffer_bundle.h"
 
23
#include "android_format_conversion-inl.h"
 
24
#include "mir/graphics/buffer.h"
 
25
#include "mir/graphics/android/native_buffer.h"
 
26
 
 
27
#include <boost/throw_exception.hpp>
 
28
#include <stdexcept>
 
29
 
 
30
namespace mg = mir::graphics;
 
31
namespace mga = mir::graphics::android;
 
32
namespace geom = mir::geometry;
 
33
 
 
34
mga::HWC10Device::HWC10Device(std::shared_ptr<hwc_composer_device_1> const& hwc_device,
 
35
                              std::shared_ptr<framebuffer_device_t> const& fb_device,
 
36
                              std::shared_ptr<HWCVsyncCoordinator> const& coordinator)
 
37
    : HWCCommonDevice(hwc_device, coordinator),
 
38
      fb_device(fb_device),
 
39
      layer_list({mga::CompositionLayer{HWC_SKIP_LAYER}})
 
40
{
 
41
}
 
42
 
 
43
void mga::HWC10Device::prepare_composition()
 
44
{
 
45
    auto display_list = layer_list.native_list();
 
46
    if (hwc_device->prepare(hwc_device.get(), 1, &display_list) != 0)
 
47
    {
 
48
        BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc prepare()"));
 
49
    }
 
50
}
 
51
 
 
52
void mga::HWC10Device::gpu_render(EGLDisplay dpy, EGLSurface sur)
 
53
{
 
54
    auto display_list = layer_list.native_list();
 
55
    display_list->dpy = dpy;
 
56
    display_list->sur = sur;
 
57
 
 
58
    //set() may affect EGL state by calling eglSwapBuffers.
 
59
    //HWC 1.0 is the only version of HWC that can do this.
 
60
    if (hwc_device->set(hwc_device.get(), 1, &display_list) != 0)
 
61
    {
 
62
        BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc set()"));
 
63
    }
 
64
}
 
65
 
 
66
void mga::HWC10Device::post(mg::Buffer const& buffer)
 
67
{
 
68
    auto lg = lock_unblanked();
 
69
 
 
70
    auto native_buffer = buffer.native_buffer_handle();
 
71
    native_buffer->wait_for_content();
 
72
    if (fb_device->post(fb_device.get(), native_buffer->handle()) != 0)
 
73
    {
 
74
        BOOST_THROW_EXCEPTION(std::runtime_error("error posting with fb device"));
 
75
    }
 
76
 
 
77
    coordinator->wait_for_vsync();
 
78
}