Skip to content

Latest commit

 

History

History
423 lines (328 loc) · 12.3 KB

SDL_mirwindow.c

File metadata and controls

423 lines (328 loc) · 12.3 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 2, 2017
Jan 2, 2017
3
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_MIR
#include "../SDL_egl_c.h"
#include "../SDL_sysvideo.h"
Aug 30, 2016
Aug 30, 2016
32
#include "../../events/SDL_keyboard_c.h"
33
34
35
36
37
38
39
40
41
#include "SDL_mirevents.h"
#include "SDL_mirwindow.h"
#include "SDL_mirdyn.h"
int
IsSurfaceValid(MIR_Window* mir_window)
{
Feb 27, 2017
Feb 27, 2017
42
43
if (!MIR_mir_window_is_valid(mir_window->window)) {
const char* error = MIR_mir_window_get_error_message(mir_window->window);
44
45
46
47
48
49
return SDL_SetError("Failed to created a mir surface: %s", error);
}
return 0;
}
Feb 25, 2016
Feb 25, 2016
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
MirPixelFormat
FindValidPixelFormat(MIR_Data* mir_data)
{
unsigned int pf_size = 32;
unsigned int valid_formats;
unsigned int f;
MirPixelFormat formats[pf_size];
MIR_mir_connection_get_available_surface_formats(mir_data->connection, formats,
pf_size, &valid_formats);
for (f = 0; f < valid_formats; f++) {
MirPixelFormat cur_pf = formats[f];
if (cur_pf == mir_pixel_format_abgr_8888 ||
cur_pf == mir_pixel_format_xbgr_8888 ||
cur_pf == mir_pixel_format_argb_8888 ||
cur_pf == mir_pixel_format_xrgb_8888) {
return cur_pf;
}
}
return mir_pixel_format_invalid;
}
76
77
78
79
80
int
MIR_CreateWindow(_THIS, SDL_Window* window)
{
MIR_Window* mir_window;
MIR_Data* mir_data;
Feb 21, 2016
Feb 21, 2016
81
82
MirPixelFormat pixel_format;
MirBufferUsage buffer_usage;
Feb 27, 2017
Feb 27, 2017
84
MirWindowSpec* spec;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
mir_window = SDL_calloc(1, sizeof(MIR_Window));
if (!mir_window)
return SDL_OutOfMemory();
mir_data = _this->driverdata;
window->driverdata = mir_window;
if (window->x == SDL_WINDOWPOS_UNDEFINED)
window->x = 0;
if (window->y == SDL_WINDOWPOS_UNDEFINED)
window->y = 0;
mir_window->mir_data = mir_data;
mir_window->sdl_window = window;
Feb 25, 2016
Feb 25, 2016
102
103
104
105
106
107
108
109
if (window->flags & SDL_WINDOW_OPENGL) {
pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
_this->egl_data->egl_display,
_this->egl_data->egl_config);
}
else {
pixel_format = FindValidPixelFormat(mir_data);
}
Feb 21, 2016
Feb 21, 2016
110
111
112
mir_data->pixel_format = pixel_format;
if (pixel_format == mir_pixel_format_invalid) {
113
114
115
return SDL_SetError("Failed to find a valid pixel format.");
}
Feb 21, 2016
Feb 21, 2016
116
117
118
119
buffer_usage = mir_buffer_usage_hardware;
if (mir_data->software)
buffer_usage = mir_buffer_usage_software;
Feb 27, 2017
Feb 27, 2017
120
121
122
spec = MIR_mir_create_normal_window_spec(mir_data->connection,
window->w,
window->h);
Feb 21, 2016
Feb 21, 2016
123
Feb 27, 2017
Feb 27, 2017
124
125
126
MIR_mir_window_spec_set_buffer_usage(spec, buffer_usage);
MIR_mir_window_spec_set_name(spec, "Mir surface");
MIR_mir_window_spec_set_pixel_format(spec, pixel_format);
Feb 21, 2016
Feb 21, 2016
127
Aug 30, 2016
Aug 30, 2016
128
129
130
if (window->flags & SDL_WINDOW_INPUT_FOCUS)
SDL_SetKeyboardFocus(window);
Feb 27, 2017
Feb 27, 2017
131
132
mir_window->window = MIR_mir_create_window_sync(spec);
MIR_mir_window_set_event_handler(mir_window->window, MIR_HandleEvent, window);
Feb 21, 2016
Feb 21, 2016
133
Feb 27, 2017
Feb 27, 2017
134
MIR_mir_window_spec_release(spec);
Feb 21, 2016
Feb 21, 2016
135
Feb 27, 2017
Feb 27, 2017
136
if (!MIR_mir_window_is_valid(mir_window->window)) {
Jun 8, 2016
Jun 8, 2016
137
return SDL_SetError("Failed to created a mir surface: %s",
Feb 27, 2017
Feb 27, 2017
138
MIR_mir_window_get_error_message(mir_window->window));
139
140
141
142
}
if (window->flags & SDL_WINDOW_OPENGL) {
EGLNativeWindowType egl_native_window =
Feb 21, 2016
Feb 21, 2016
143
(EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
Feb 27, 2017
Feb 27, 2017
144
MIR_mir_window_get_buffer_stream(mir_window->window));
145
146
147
148
149
150
151
152
153
154
155
156
mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);
if (mir_window->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Failed to created a window surface %p",
_this->egl_data->egl_display);
}
}
else {
mir_window->egl_surface = EGL_NO_SURFACE;
}
Feb 21, 2016
Feb 21, 2016
157
mir_data->current_window = mir_window;
158
159
160
161
162
163
164
return 0;
}
void
MIR_DestroyWindow(_THIS, SDL_Window* window)
{
Feb 21, 2016
Feb 21, 2016
165
MIR_Data* mir_data = _this->driverdata;
166
167
168
169
MIR_Window* mir_window = window->driverdata;
if (mir_data) {
SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
Feb 27, 2017
Feb 27, 2017
170
MIR_mir_window_release_sync(mir_window->window);
Feb 21, 2016
Feb 21, 2016
172
173
mir_data->current_window = NULL;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
SDL_free(mir_window);
}
window->driverdata = NULL;
}
SDL_bool
MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info)
{
if (info->version.major == SDL_MAJOR_VERSION &&
info->version.minor == SDL_MINOR_VERSION) {
MIR_Window* mir_window = window->driverdata;
info->subsystem = SDL_SYSWM_MIR;
info->info.mir.connection = mir_window->mir_data->connection;
Feb 27, 2017
Feb 27, 2017
188
189
// Cannot change this to window due to it being in the public API
info->info.mir.surface = mir_window->window;
190
191
192
193
194
195
196
197
198
199
200
201
return SDL_TRUE;
}
return SDL_FALSE;
}
void
MIR_SetWindowFullscreen(_THIS, SDL_Window* window,
SDL_VideoDisplay* display,
SDL_bool fullscreen)
{
Feb 21, 2016
Feb 21, 2016
202
MIR_Data* mir_data = _this->driverdata;
203
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
204
205
MirWindowSpec* spec;
MirWindowState state;
206
207
208
209
210
if (IsSurfaceValid(mir_window) < 0)
return;
if (fullscreen) {
Feb 27, 2017
Feb 27, 2017
211
state = mir_window_state_fullscreen;
Feb 27, 2017
Feb 27, 2017
213
state = mir_window_state_restored;
Feb 21, 2016
Feb 21, 2016
215
Feb 27, 2017
Feb 27, 2017
216
217
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_state(spec, state);
Feb 21, 2016
Feb 21, 2016
218
Feb 27, 2017
Feb 27, 2017
219
220
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
221
222
223
224
225
}
void
MIR_MaximizeWindow(_THIS, SDL_Window* window)
{
Feb 21, 2016
Feb 21, 2016
226
MIR_Data* mir_data = _this->driverdata;
227
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
228
MirWindowSpec* spec;
229
230
231
232
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
233
234
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_state(spec, mir_window_state_maximized);
Feb 21, 2016
Feb 21, 2016
235
Feb 27, 2017
Feb 27, 2017
236
237
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
238
239
240
241
242
}
void
MIR_MinimizeWindow(_THIS, SDL_Window* window)
{
Feb 21, 2016
Feb 21, 2016
243
MIR_Data* mir_data = _this->driverdata;
244
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
245
MirWindowSpec* spec;
246
247
248
249
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
250
251
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_state(spec, mir_window_state_minimized);
Feb 21, 2016
Feb 21, 2016
252
Feb 27, 2017
Feb 27, 2017
253
254
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
255
256
257
258
259
}
void
MIR_RestoreWindow(_THIS, SDL_Window * window)
{
Feb 21, 2016
Feb 21, 2016
260
MIR_Data* mir_data = _this->driverdata;
261
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
262
MirWindowSpec* spec;
263
264
265
266
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
267
268
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_state(spec, mir_window_state_restored);
Feb 21, 2016
Feb 21, 2016
269
Feb 27, 2017
Feb 27, 2017
270
271
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Feb 21, 2016
Feb 21, 2016
272
273
274
275
276
277
278
}
void
MIR_HideWindow(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
279
MirWindowSpec* spec;
Feb 21, 2016
Feb 21, 2016
280
281
282
283
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
284
285
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_state(spec, mir_window_state_hidden);
Feb 21, 2016
Feb 21, 2016
286
Feb 27, 2017
Feb 27, 2017
287
288
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Feb 21, 2016
Feb 21, 2016
289
290
291
292
293
294
295
}
void
MIR_SetWindowSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
296
MirWindowSpec* spec;
Feb 21, 2016
Feb 21, 2016
297
298
299
300
301
if (IsSurfaceValid(mir_window) < 0)
return;
/* You cannot set the x/y of a mir window! So only update w/h */
Feb 27, 2017
Feb 27, 2017
302
303
304
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_width (spec, window->w);
MIR_mir_window_spec_set_height(spec, window->h);
Feb 21, 2016
Feb 21, 2016
305
Feb 27, 2017
Feb 27, 2017
306
307
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Feb 21, 2016
Feb 21, 2016
308
309
310
311
312
313
314
}
void
MIR_SetWindowMinimumSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
315
MirWindowSpec* spec;
Feb 21, 2016
Feb 21, 2016
316
317
318
319
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
320
321
322
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_width (spec, window->min_w);
MIR_mir_window_spec_set_height(spec, window->min_h);
Feb 21, 2016
Feb 21, 2016
323
Feb 27, 2017
Feb 27, 2017
324
325
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Feb 21, 2016
Feb 21, 2016
326
327
328
329
330
331
332
}
void
MIR_SetWindowMaximumSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
Feb 27, 2017
Feb 27, 2017
333
MirWindowSpec* spec;
Feb 21, 2016
Feb 21, 2016
334
335
336
337
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
338
339
340
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_max_width(spec, window->max_w);
MIR_mir_window_spec_set_max_height(spec, window->max_h);
Feb 21, 2016
Feb 21, 2016
341
Feb 27, 2017
Feb 27, 2017
342
343
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Feb 21, 2016
Feb 21, 2016
344
345
346
347
348
349
350
351
}
void
MIR_SetWindowTitle(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
char const* title = window->title ? window->title : "";
Feb 27, 2017
Feb 27, 2017
352
MirWindowSpec* spec;
Feb 21, 2016
Feb 21, 2016
353
354
355
356
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 27, 2017
Feb 27, 2017
357
358
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_name(spec, title);
Feb 21, 2016
Feb 21, 2016
359
Feb 27, 2017
Feb 27, 2017
360
361
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Aug 30, 2016
Aug 30, 2016
364
365
366
367
368
369
void
MIR_SetWindowGrab(_THIS, SDL_Window* window, SDL_bool grabbed)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirPointerConfinementState confined = mir_pointer_unconfined;
Feb 27, 2017
Feb 27, 2017
370
MirWindowSpec* spec;
Aug 30, 2016
Aug 30, 2016
371
372
if (grabbed)
Feb 27, 2017
Feb 27, 2017
373
confined = mir_pointer_confined_to_window;
Aug 30, 2016
Aug 30, 2016
374
Feb 27, 2017
Feb 27, 2017
375
376
spec = MIR_mir_create_window_spec(mir_data->connection);
MIR_mir_window_spec_set_pointer_confinement(spec, confined);
Aug 30, 2016
Aug 30, 2016
377
Feb 27, 2017
Feb 27, 2017
378
379
MIR_mir_window_apply_spec(mir_window->window, spec);
MIR_mir_window_spec_release(spec);
Sep 22, 2016
Sep 22, 2016
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
}
int
MIR_SetWindowGammaRamp(_THIS, SDL_Window* window, Uint16 const* ramp)
{
MirOutput* output = SDL_GetDisplayForWindow(window)->driverdata;
Uint32 ramp_size = 256;
// FIXME Need to apply the changes to the output, once that public API function is around
if (MIR_mir_output_is_gamma_supported(output) == mir_output_gamma_supported) {
MIR_mir_output_set_gamma(output,
ramp + ramp_size * 0,
ramp + ramp_size * 1,
ramp + ramp_size * 2,
ramp_size);
return 0;
}
return -1;
}
int
MIR_GetWindowGammaRamp(_THIS, SDL_Window* window, Uint16* ramp)
{
MirOutput* output = SDL_GetDisplayForWindow(window)->driverdata;
Uint32 ramp_size = 256;
if (MIR_mir_output_is_gamma_supported(output) == mir_output_gamma_supported) {
if (MIR_mir_output_get_gamma_size(output) == ramp_size) {
MIR_mir_output_get_gamma(output,
ramp + ramp_size * 0,
ramp + ramp_size * 1,
ramp + ramp_size * 2,
ramp_size);
return 0;
}
}
Aug 30, 2016
Aug 30, 2016
417
Sep 22, 2016
Sep 22, 2016
418
return -1;
Aug 30, 2016
Aug 30, 2016
419
420
}
421
422
423
#endif /* SDL_VIDEO_DRIVER_MIR */
/* vi: set ts=4 sw=4 expandtab: */