2
* Copyright © 2013 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
* Kevin DuBois <kevin.dubois@canonical.com>
20
#include "hwc11_device.h"
21
#include "hwc_layerlist.h"
22
#include "hwc_vsync_coordinator.h"
23
#include "framebuffer_bundle.h"
25
#include "mir/graphics/android/sync_fence.h"
26
#include "mir/graphics/android/native_buffer.h"
27
#include "mir/graphics/buffer.h"
29
#include <EGL/eglext.h>
30
#include <boost/throw_exception.hpp>
33
namespace mg = mir::graphics;
34
namespace mga=mir::graphics::android;
35
namespace geom = mir::geometry;
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>())
45
void mga::HWC11Device::prepare_composition()
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};
51
if (hwc_device->prepare(hwc_device.get(), 1, displays))
53
BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc prepare()"));
57
void mga::HWC11Device::gpu_render(EGLDisplay dpy, EGLSurface sur)
59
if (eglSwapBuffers(dpy, sur) == EGL_FALSE)
61
BOOST_THROW_EXCEPTION(std::runtime_error("eglSwapBuffers failure\n"));
65
void mga::HWC11Device::post(mg::Buffer const& buffer)
67
auto lg = lock_unblanked();
69
auto native_buffer = buffer.native_buffer_handle();
70
layer_list.set_fb_target(native_buffer);
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))
75
BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc set()"));
78
if (last_display_fence)
79
last_display_fence->wait();
81
int framebuffer_fence = layer_list.framebuffer_fence();
82
native_buffer->update_fence(framebuffer_fence);
84
last_display_fence = std::make_shared<mga::SyncFence>(
85
sync_ops, displays[HWC_DISPLAY_PRIMARY]->retireFenceFd);