~mir-team/miral/release

« back to all changes in this revision

Viewing changes to miral-shell/spinner/miregl.cpp

  • Committer: Bileto Bot
  • Date: 2017-06-21 08:34:34 UTC
  • mfrom: (360.1.1 miral-release)
  • Revision ID: ci-train-bot@canonical.com-20170621083434-e7ftkyg5qr2fzsao
* New upstream release 1.4.0 (https://launchpad.net/miral/+milestone/1.4.0)
  - ABI summary:
    . miral ABI unchanged at 2
  - Enhancements:
    . Support for passing messages to enable Drag & Drop
    . Support for client requested move
    . Port to the undeprecated Mir APIs
    . Added "--cursor-theme" option when configuring a cursor theme
    . Drop support for Mir versions before 0.26
  - Bugs fixed:

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 */
16
16
 
17
17
#include "miregl.h"
 
18
#include <miral/window_specification.h>
18
19
#include <mir/client/window_spec.h>
19
 
#include <mir_toolkit/version.h>
 
20
#include <mir_toolkit/mir_client_library.h>
20
21
 
21
22
#include <cstring>
22
23
 
23
24
#include <GLES2/gl2.h>
24
 
#include <miral/window_specification.h>
25
 
#include <mir/client/window_spec.h>
 
25
 
 
26
using namespace mir::client;
26
27
 
27
28
class MirEglApp
28
29
{
29
30
public:
30
31
    MirEglApp(MirConnection* const connection, MirPixelFormat pixel_format);
31
32
 
32
 
    EGLSurface create_surface(MirWindow* window);
 
33
    EGLSurface create_surface(MirRenderSurface* surface);
33
34
 
34
35
    void make_current(EGLSurface eglsurface) const;
35
36
 
60
61
    return std::make_shared<MirEglApp>(connection, pixel_format);
61
62
}
62
63
 
63
 
namespace
64
 
{
65
 
MirWindow* create_window(MirConnection* const connection, MirWindowParameters const& parameters)
66
 
{
67
 
 
68
 
    auto spec = mir::client::WindowSpec::for_normal_window(
69
 
        connection, parameters.width, parameters.height, parameters.pixel_format)
70
 
        .set_name(parameters.name)
71
 
        .set_buffer_usage(parameters.buffer_usage);
72
 
 
73
 
 
74
 
    if (!parameters.width && !parameters.height)
75
 
        spec.set_fullscreen_on_output(parameters.output_id);
76
 
 
77
 
    auto const window = mir_create_window_sync(spec);
 
64
MirEglSurface::MirEglSurface(
 
65
    std::shared_ptr<MirEglApp> const& mir_egl_app,
 
66
    char const* name,
 
67
    MirOutput const* output)
 
68
:
 
69
    mir_egl_app{mir_egl_app}
 
70
{
 
71
    auto const mode = mir_output_get_current_mode(output);
 
72
    auto const output_id = mir_output_get_id(output);
 
73
    auto const width = mir_output_mode_get_width(mode);
 
74
    auto const height = mir_output_mode_get_height(mode);
 
75
 
 
76
    surface = Surface{mir_connection_create_render_surface_sync(mir_egl_app->connection, width, height)};
 
77
 
 
78
    eglsurface = mir_egl_app->create_surface(surface);
 
79
 
 
80
    window = WindowSpec::for_normal_window(mir_egl_app->connection, width, height)
 
81
        .add_surface(surface, width, height, 0, 0)
 
82
        .set_name(name)
 
83
        .set_fullscreen_on_output(output_id)
 
84
        .create_window();
78
85
 
79
86
    if (!mir_window_is_valid(window))
80
87
        throw std::runtime_error(std::string("Can't create a window ") + mir_window_get_error_message(window));
81
88
 
82
 
    if (parameters.output_id != mir_display_output_id_invalid)
83
 
        mir_window_set_state(window, mir_window_state_fullscreen);
84
 
 
85
 
    return window;
86
 
}
87
 
}
88
 
 
89
 
MirEglSurface::MirEglSurface(
90
 
    std::shared_ptr<MirEglApp> const& mir_egl_app, MirWindowParameters const& parm, int swapinterval) :
91
 
    mir_egl_app{mir_egl_app},
92
 
    window{create_window(mir_egl_app->connection, parm)},
93
 
    eglsurface{mir_egl_app->create_surface(window)},
94
 
    width_{0},
95
 
    height_{0}
96
 
{
97
 
    mir_egl_app->set_swap_interval(eglsurface, swapinterval);
 
89
    mir_egl_app->set_swap_interval(eglsurface, -1);
98
90
}
99
91
 
100
92
MirEglSurface::~MirEglSurface()
101
93
{
102
94
    mir_egl_app->destroy_surface(eglsurface);
103
 
    mir_window_release_sync(window);
104
95
}
105
96
 
106
97
void MirEglSurface::egl_make_current()
139
130
            EGL_NONE
140
131
        };
141
132
 
142
 
    egldisplay = eglGetDisplay((EGLNativeDisplayType) mir_connection_get_egl_native_display(connection));
 
133
    egldisplay = eglGetDisplay((EGLNativeDisplayType)(connection));
143
134
    if (egldisplay == EGL_NO_DISPLAY)
144
135
        throw std::runtime_error("Can't eglGetDisplay");
145
136
 
184
175
    make_current(dummy_surface);
185
176
}
186
177
 
187
 
EGLSurface MirEglApp::create_surface(MirWindow* window)
 
178
EGLSurface MirEglApp::create_surface(MirRenderSurface* surface)
188
179
{
189
180
    auto const eglsurface = eglCreateWindowSurface(
190
181
        egldisplay,
191
182
        eglconfig,
192
 
        (EGLNativeWindowType) mir_buffer_stream_get_egl_native_window(mir_window_get_buffer_stream(window)), NULL);
 
183
        (EGLNativeWindowType)surface, NULL);
193
184
 
194
185
    if (eglsurface == EGL_NO_SURFACE)
195
186
        throw std::runtime_error("eglCreateWindowSurface failed");