Skip to content

Latest commit

 

History

History
361 lines (277 loc) · 10.6 KB

SDL_mirwindow.c

File metadata and controls

361 lines (277 loc) · 10.6 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 2, 2016
Jan 2, 2016
3
Copyright (C) 1997-2016 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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"
#include "SDL_mirevents.h"
#include "SDL_mirwindow.h"
#include "SDL_mirdyn.h"
int
IsSurfaceValid(MIR_Window* mir_window)
{
if (!MIR_mir_surface_is_valid(mir_window->surface)) {
const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
return SDL_SetError("Failed to created a mir surface: %s", error);
}
return 0;
}
Feb 25, 2016
Feb 25, 2016
49
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
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;
}
75
76
77
78
79
int
MIR_CreateWindow(_THIS, SDL_Window* window)
{
MIR_Window* mir_window;
MIR_Data* mir_data;
Feb 21, 2016
Feb 21, 2016
80
81
MirPixelFormat pixel_format;
MirBufferUsage buffer_usage;
Feb 21, 2016
Feb 21, 2016
83
MirSurfaceSpec* spec;
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
101
102
103
104
105
106
107
108
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
109
110
111
mir_data->pixel_format = pixel_format;
if (pixel_format == mir_pixel_format_invalid) {
112
113
114
return SDL_SetError("Failed to find a valid pixel format.");
}
Feb 21, 2016
Feb 21, 2016
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
buffer_usage = mir_buffer_usage_hardware;
if (mir_data->software)
buffer_usage = mir_buffer_usage_software;
spec = MIR_mir_connection_create_spec_for_normal_surface(mir_data->connection,
window->w,
window->h,
pixel_format);
MIR_mir_surface_spec_set_buffer_usage(spec, buffer_usage);
MIR_mir_surface_spec_set_name(spec, "Mir surface");
mir_window->surface = MIR_mir_surface_create_sync(spec);
MIR_mir_surface_set_event_handler(mir_window->surface, MIR_HandleEvent, window);
MIR_mir_surface_spec_release(spec);
132
133
134
135
136
137
138
if (!MIR_mir_surface_is_valid(mir_window->surface)) {
const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
return SDL_SetError("Failed to created a mir surface: %s", error);
}
if (window->flags & SDL_WINDOW_OPENGL) {
EGLNativeWindowType egl_native_window =
Feb 21, 2016
Feb 21, 2016
139
140
(EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
MIR_mir_surface_get_buffer_stream(mir_window->surface));
141
142
143
144
145
146
147
148
149
150
151
152
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
153
mir_data->current_window = mir_window;
154
155
156
157
158
159
160
return 0;
}
void
MIR_DestroyWindow(_THIS, SDL_Window* window)
{
Feb 21, 2016
Feb 21, 2016
161
MIR_Data* mir_data = _this->driverdata;
162
163
164
165
166
167
MIR_Window* mir_window = window->driverdata;
if (mir_data) {
SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
MIR_mir_surface_release_sync(mir_window->surface);
Feb 21, 2016
Feb 21, 2016
168
169
mir_data->current_window = NULL;
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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;
info->info.mir.surface = mir_window->surface;
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
197
MIR_Data* mir_data = _this->driverdata;
198
MIR_Window* mir_window = window->driverdata;
Feb 21, 2016
Feb 21, 2016
199
200
MirSurfaceSpec* spec;
MirSurfaceState state;
201
202
203
204
205
if (IsSurfaceValid(mir_window) < 0)
return;
if (fullscreen) {
Feb 21, 2016
Feb 21, 2016
206
state = mir_surface_state_fullscreen;
Feb 21, 2016
Feb 21, 2016
208
state = mir_surface_state_restored;
Feb 21, 2016
Feb 21, 2016
210
211
212
213
214
215
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, state);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
216
217
218
219
220
}
void
MIR_MaximizeWindow(_THIS, SDL_Window* window)
{
Feb 21, 2016
Feb 21, 2016
221
MIR_Data* mir_data = _this->driverdata;
222
MIR_Window* mir_window = window->driverdata;
Feb 21, 2016
Feb 21, 2016
223
MirSurfaceSpec* spec;
224
225
226
227
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 21, 2016
Feb 21, 2016
228
229
230
231
232
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_maximized);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
233
234
235
236
237
}
void
MIR_MinimizeWindow(_THIS, SDL_Window* window)
{
Feb 21, 2016
Feb 21, 2016
238
MIR_Data* mir_data = _this->driverdata;
239
MIR_Window* mir_window = window->driverdata;
Feb 21, 2016
Feb 21, 2016
240
MirSurfaceSpec* spec;
241
242
243
244
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 21, 2016
Feb 21, 2016
245
246
247
248
249
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_minimized);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
250
251
252
253
254
}
void
MIR_RestoreWindow(_THIS, SDL_Window * window)
{
Feb 21, 2016
Feb 21, 2016
255
MIR_Data* mir_data = _this->driverdata;
256
MIR_Window* mir_window = window->driverdata;
Feb 21, 2016
Feb 21, 2016
257
MirSurfaceSpec* spec;
258
259
260
261
if (IsSurfaceValid(mir_window) < 0)
return;
Feb 21, 2016
Feb 21, 2016
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_restored);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_HideWindow(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_hidden);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
/* You cannot set the x/y of a mir window! So only update w/h */
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_width (spec, window->w);
MIR_mir_surface_spec_set_height(spec, window->h);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowMinimumSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_min_width (spec, window->min_w);
MIR_mir_surface_spec_set_min_height(spec, window->min_h);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowMaximumSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_max_width (spec, window->max_w);
MIR_mir_surface_spec_set_max_height(spec, window->max_h);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
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 : "";
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_name(spec, title);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
357
358
359
360
361
}
#endif /* SDL_VIDEO_DRIVER_MIR */
/* vi: set ts=4 sw=4 expandtab: */