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

« back to all changes in this revision

Viewing changes to src/server/graphics/nested/nested_output.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
Import upstream version 0.13.0+15.10.20150512

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: Alan Griffiths <alan@octopull.co.uk>
17
 
 */
18
 
 
19
 
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
20
 
 
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"
25
 
 
26
 
#include <boost/throw_exception.hpp>
27
 
#include <stdexcept>
28
 
 
29
 
namespace mg = mir::graphics;
30
 
namespace mgn = mir::graphics::nested;
31
 
namespace geom = mir::geometry;
32
 
 
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}
47
 
{
48
 
    MirEventDelegate ed = {event_thunk, this};
49
 
    host_surface->set_event_handler(&ed);
50
 
}
51
 
 
52
 
geom::Rectangle mgn::detail::NestedOutput::view_area() const
53
 
{
54
 
    return area;
55
 
}
56
 
 
57
 
void mgn::detail::NestedOutput::make_current()
58
 
{
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"));
61
 
}
62
 
 
63
 
void mgn::detail::NestedOutput::release_current()
64
 
{
65
 
    eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
66
 
}
67
 
 
68
 
void mgn::detail::NestedOutput::gl_swap_buffers()
69
 
{
70
 
    eglSwapBuffers(egl_display, egl_surface);
71
 
}
72
 
 
73
 
void mgn::detail::NestedOutput::flip()
74
 
{
75
 
}
76
 
 
77
 
bool mgn::detail::NestedOutput::post_renderables_if_optimizable(RenderableList const&)
78
 
{
79
 
    return false;
80
 
}
81
 
 
82
 
MirOrientation mgn::detail::NestedOutput::orientation() const
83
 
{
84
 
    /*
85
 
     * Always normal orientation. The real rotation is handled by the
86
 
     * native display.
87
 
     */
88
 
    return mir_orientation_normal;
89
 
}
90
 
 
91
 
bool mgn::detail::NestedOutput::uses_alpha() const
92
 
{
93
 
    return uses_alpha_;
94
 
}
95
 
 
96
 
mgn::detail::NestedOutput::~NestedOutput() noexcept
97
 
{
98
 
}
99
 
 
100
 
void mgn::detail::NestedOutput::event_thunk(
101
 
    MirSurface* /*surface*/,
102
 
    MirEvent const* event,
103
 
    void* context)
104
 
try
105
 
{
106
 
    static_cast<mgn::detail::NestedOutput*>(context)->mir_event(*event);
107
 
}
108
 
catch (std::exception const&)
109
 
{
110
 
    // Just in case: do not allow exceptions to propagate.
111
 
}
112
 
 
113
 
void mgn::detail::NestedOutput::mir_event(MirEvent const& event)
114
 
{
115
 
    if (event.type == mir_event_type_motion)
116
 
    {
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);
121
 
    }
122
 
    else
123
 
    {
124
 
        dispatcher->dispatch(event);
125
 
    }
126
 
}