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>
23
24
#include <GLES2/gl2.h>
24
#include <miral/window_specification.h>
25
#include <mir/client/window_spec.h>
26
using namespace mir::client;
30
31
MirEglApp(MirConnection* const connection, MirPixelFormat pixel_format);
32
EGLSurface create_surface(MirWindow* window);
33
EGLSurface create_surface(MirRenderSurface* surface);
34
35
void make_current(EGLSurface eglsurface) const;
60
61
return std::make_shared<MirEglApp>(connection, pixel_format);
65
MirWindow* create_window(MirConnection* const connection, MirWindowParameters const& parameters)
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);
74
if (!parameters.width && !parameters.height)
75
spec.set_fullscreen_on_output(parameters.output_id);
77
auto const window = mir_create_window_sync(spec);
64
MirEglSurface::MirEglSurface(
65
std::shared_ptr<MirEglApp> const& mir_egl_app,
67
MirOutput const* output)
69
mir_egl_app{mir_egl_app}
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);
76
surface = Surface{mir_connection_create_render_surface_sync(mir_egl_app->connection, width, height)};
78
eglsurface = mir_egl_app->create_surface(surface);
80
window = WindowSpec::for_normal_window(mir_egl_app->connection, width, height)
81
.add_surface(surface, width, height, 0, 0)
83
.set_fullscreen_on_output(output_id)
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));
82
if (parameters.output_id != mir_display_output_id_invalid)
83
mir_window_set_state(window, mir_window_state_fullscreen);
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)},
97
mir_egl_app->set_swap_interval(eglsurface, swapinterval);
89
mir_egl_app->set_swap_interval(eglsurface, -1);
100
92
MirEglSurface::~MirEglSurface()
102
94
mir_egl_app->destroy_surface(eglsurface);
103
mir_window_release_sync(window);
106
97
void MirEglSurface::egl_make_current()
184
175
make_current(dummy_surface);
187
EGLSurface MirEglApp::create_surface(MirWindow* window)
178
EGLSurface MirEglApp::create_surface(MirRenderSurface* surface)
189
180
auto const eglsurface = eglCreateWindowSurface(
192
(EGLNativeWindowType) mir_buffer_stream_get_egl_native_window(mir_window_get_buffer_stream(window)), NULL);
183
(EGLNativeWindowType)surface, NULL);
194
185
if (eglsurface == EGL_NO_SURFACE)
195
186
throw std::runtime_error("eglCreateWindowSurface failed");