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/>.
16
* Authored by: Alan Griffiths <alan@octopull.co.uk>
19
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
21
#include "nested_output.h"
22
#include "host_connection.h"
23
#include "mir/input/input_dispatcher.h"
24
#include "mir/graphics/pixel_format_utils.h"
26
#include <boost/throw_exception.hpp>
29
namespace mg = mir::graphics;
30
namespace mgn = mir::graphics::nested;
31
namespace geom = mir::geometry;
33
mgn::detail::NestedOutput::NestedOutput(
34
EGLDisplayHandle const& egl_display,
35
std::shared_ptr<HostSurface> const& host_surface,
36
geometry::Rectangle const& area,
37
std::shared_ptr<input::InputDispatcher> const& dispatcher,
38
MirPixelFormat preferred_format) :
39
uses_alpha_{mg::contains_alpha(preferred_format)},
40
egl_display(egl_display),
41
host_surface{host_surface},
42
egl_config{egl_display.choose_windowed_es_config(preferred_format)},
43
egl_context{egl_display, eglCreateContext(egl_display, egl_config, egl_display.egl_context(), nested_egl_context_attribs)},
44
area{area.top_left, area.size},
45
dispatcher{dispatcher},
46
egl_surface{egl_display, host_surface->egl_native_window(), egl_config}
48
MirEventDelegate ed = {event_thunk, this};
49
host_surface->set_event_handler(&ed);
52
geom::Rectangle mgn::detail::NestedOutput::view_area() const
57
void mgn::detail::NestedOutput::make_current()
59
if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) != EGL_TRUE)
60
BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to update EGL surface.\n"));
63
void mgn::detail::NestedOutput::release_current()
65
eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
68
void mgn::detail::NestedOutput::gl_swap_buffers()
70
eglSwapBuffers(egl_display, egl_surface);
73
void mgn::detail::NestedOutput::flip()
77
bool mgn::detail::NestedOutput::post_renderables_if_optimizable(RenderableList const&)
82
MirOrientation mgn::detail::NestedOutput::orientation() const
85
* Always normal orientation. The real rotation is handled by the
88
return mir_orientation_normal;
91
bool mgn::detail::NestedOutput::uses_alpha() const
96
mgn::detail::NestedOutput::~NestedOutput() noexcept
100
void mgn::detail::NestedOutput::event_thunk(
101
MirSurface* /*surface*/,
102
MirEvent const* event,
106
static_cast<mgn::detail::NestedOutput*>(context)->mir_event(*event);
108
catch (std::exception const&)
110
// Just in case: do not allow exceptions to propagate.
113
void mgn::detail::NestedOutput::mir_event(MirEvent const& event)
115
if (event.type == mir_event_type_motion)
117
auto my_event = event;
118
my_event.motion.x_offset += area.top_left.x.as_float();
119
my_event.motion.y_offset += area.top_left.y.as_float();
120
dispatcher->dispatch(my_event);
124
dispatcher->dispatch(event);