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 Lesser 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 Lesser General Public License for more details.
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/>.
17
* Kevin DuBois <kevin.dubois@canonical.com>
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"
27
#include <boost/throw_exception.hpp>
30
namespace mg = mir::graphics;
31
namespace mga = mir::graphics::android;
32
namespace geom = mir::geometry;
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),
39
layer_list({mga::CompositionLayer{HWC_SKIP_LAYER}})
43
void mga::HWC10Device::prepare_composition()
45
auto display_list = layer_list.native_list();
46
if (hwc_device->prepare(hwc_device.get(), 1, &display_list) != 0)
48
BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc prepare()"));
52
void mga::HWC10Device::gpu_render(EGLDisplay dpy, EGLSurface sur)
54
auto display_list = layer_list.native_list();
55
display_list->dpy = dpy;
56
display_list->sur = sur;
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)
62
BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc set()"));
66
void mga::HWC10Device::post(mg::Buffer const& buffer)
68
auto lg = lock_unblanked();
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)
74
BOOST_THROW_EXCEPTION(std::runtime_error("error posting with fb device"));
77
coordinator->wait_for_vsync();