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

« back to all changes in this revision

Viewing changes to src/server/graphics/android/hwc11_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 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
 
 *   Kevin DuBois <kevin.dubois@canonical.com>
18
 
 */
19
 
 
20
 
#include "hwc11_device.h"
21
 
#include "hwc_layerlist.h"
22
 
#include "hwc_vsync_coordinator.h"
23
 
#include "framebuffer_bundle.h"
24
 
#include "buffer.h"
25
 
#include "mir/graphics/android/sync_fence.h"
26
 
#include "mir/graphics/android/native_buffer.h"
27
 
#include "mir/graphics/buffer.h"
28
 
 
29
 
#include <EGL/eglext.h>
30
 
#include <boost/throw_exception.hpp>
31
 
#include <stdexcept>
32
 
 
33
 
namespace mg = mir::graphics;
34
 
namespace mga=mir::graphics::android;
35
 
namespace geom = mir::geometry;
36
 
 
37
 
mga::HWC11Device::HWC11Device(std::shared_ptr<hwc_composer_device_1> const& hwc_device,
38
 
                              std::shared_ptr<HWCVsyncCoordinator> const& coordinator)
39
 
    : HWCCommonDevice(hwc_device, coordinator),
40
 
      layer_list({mga::CompositionLayer{true}, mga::FramebufferLayer{}}),
41
 
      sync_ops(std::make_shared<mga::RealSyncFileOps>())
42
 
{
43
 
}
44
 
 
45
 
void mga::HWC11Device::prepare_composition()
46
 
{
47
 
    //note, although we only have a primary display right now,
48
 
    //      set the second display to nullptr, as exynos hwc always derefs displays[1]
49
 
    hwc_display_contents_1_t* displays[HWC_NUM_DISPLAY_TYPES] {layer_list.native_list(), nullptr};
50
 
 
51
 
    if (hwc_device->prepare(hwc_device.get(), 1, displays))
52
 
    {
53
 
        BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc prepare()"));
54
 
    }
55
 
}
56
 
 
57
 
void mga::HWC11Device::gpu_render(EGLDisplay dpy, EGLSurface sur)
58
 
{
59
 
    if (eglSwapBuffers(dpy, sur) == EGL_FALSE)
60
 
    {
61
 
        BOOST_THROW_EXCEPTION(std::runtime_error("eglSwapBuffers failure\n"));
62
 
    }
63
 
}
64
 
 
65
 
void mga::HWC11Device::post(mg::Buffer const& buffer)
66
 
{
67
 
    auto lg = lock_unblanked();
68
 
 
69
 
    auto native_buffer = buffer.native_buffer_handle();
70
 
    layer_list.set_fb_target(native_buffer);
71
 
 
72
 
    hwc_display_contents_1_t* displays[HWC_NUM_DISPLAY_TYPES] {layer_list.native_list(), nullptr};
73
 
    if (hwc_device->set(hwc_device.get(), 1, displays))
74
 
    {
75
 
        BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc set()"));
76
 
    }
77
 
 
78
 
    if (last_display_fence)
79
 
        last_display_fence->wait();
80
 
 
81
 
    int framebuffer_fence = layer_list.framebuffer_fence();
82
 
    native_buffer->update_fence(framebuffer_fence);
83
 
 
84
 
    last_display_fence = std::make_shared<mga::SyncFence>(
85
 
        sync_ops, displays[HWC_DISPLAY_PRIMARY]->retireFenceFd);
86
 
}