Skip to content

Latest commit

 

History

History
423 lines (332 loc) · 12.4 KB

SDL_mirvideo.c

File metadata and controls

423 lines (332 loc) · 12.4 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 3, 2018
Jan 3, 2018
3
Copyright (C) 1997-2018 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
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
Jan 31, 2018
Jan 31, 2018
30
#include "SDL_assert.h"
Mar 1, 2017
Mar 1, 2017
31
32
#include "SDL_log.h"
Feb 21, 2016
Feb 21, 2016
33
#include "SDL_mirwindow.h"
34
35
36
37
38
39
#include "SDL_video.h"
#include "SDL_mirframebuffer.h"
#include "SDL_mirmouse.h"
#include "SDL_miropengl.h"
#include "SDL_mirvideo.h"
Aug 28, 2017
Aug 28, 2017
40
#include "SDL_mirvulkan.h"
41
42
43
44
45
#include "SDL_mirdyn.h"
#define MIR_DRIVER_NAME "mir"
Sep 21, 2016
Sep 21, 2016
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
static const Uint32 mir_pixel_format_to_sdl_format[] = {
SDL_PIXELFORMAT_UNKNOWN, /* mir_pixel_format_invalid */
SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
SDL_PIXELFORMAT_BGR888, /* mir_pixel_format_xbgr_8888 */
SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
SDL_PIXELFORMAT_RGB888, /* mir_pixel_format_xrgb_8888 */
SDL_PIXELFORMAT_BGR24, /* mir_pixel_format_bgr_888 */
SDL_PIXELFORMAT_RGB24, /* mir_pixel_format_rgb_888 */
SDL_PIXELFORMAT_RGB565, /* mir_pixel_format_rgb_565 */
SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
SDL_PIXELFORMAT_RGBA4444 /* mir_pixel_format_rgba_4444 */
};
Uint32
MIR_GetSDLPixelFormat(MirPixelFormat format)
{
return mir_pixel_format_to_sdl_format[format];
}
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
static int
MIR_VideoInit(_THIS);
static void
MIR_VideoQuit(_THIS);
static int
MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect);
static void
MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display);
static int
MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode);
static SDL_WindowShaper*
MIR_CreateShaper(SDL_Window* window)
{
/* FIXME Im not sure if mir support this atm, will have to come back to this */
return NULL;
}
static int
MIR_SetWindowShape(SDL_WindowShaper* shaper, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode)
{
return SDL_Unsupported();
}
static int
MIR_ResizeWindowShape(SDL_Window* window)
{
return SDL_Unsupported();
}
static int
MIR_Available()
{
int available = 0;
if (SDL_MIR_LoadSymbols()) {
Mar 1, 2017
Mar 1, 2017
105
106
/* Lets ensure we can connect to the mir server */
Jan 31, 2018
Jan 31, 2018
107
MirConnection* connection = MIR_mir_connect_sync(NULL, SDL_FUNCTION);
Mar 1, 2017
Mar 1, 2017
108
109
110
111
112
113
114
115
116
117
if (!MIR_mir_connection_is_valid(connection)) {
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Unable to connect to the mir server %s",
MIR_mir_connection_get_error_message(connection));
return available;
}
MIR_mir_connection_release(connection);
118
119
120
121
122
123
124
125
126
127
128
129
130
131
available = 1;
SDL_MIR_UnloadSymbols();
}
return available;
}
static void
MIR_DeleteDevice(SDL_VideoDevice* device)
{
SDL_free(device);
SDL_MIR_UnloadSymbols();
}
Sep 21, 2016
Sep 21, 2016
132
static void
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
MIR_PumpEvents(_THIS)
{
}
static SDL_VideoDevice*
MIR_CreateDevice(int device_index)
{
MIR_Data* mir_data;
SDL_VideoDevice* device = NULL;
if (!SDL_MIR_LoadSymbols()) {
return NULL;
}
device = SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_MIR_UnloadSymbols();
SDL_OutOfMemory();
return NULL;
}
mir_data = SDL_calloc(1, sizeof(MIR_Data));
if (!mir_data) {
SDL_free(device);
SDL_MIR_UnloadSymbols();
SDL_OutOfMemory();
return NULL;
}
device->driverdata = mir_data;
/* mirvideo */
device->VideoInit = MIR_VideoInit;
device->VideoQuit = MIR_VideoQuit;
device->GetDisplayBounds = MIR_GetDisplayBounds;
device->GetDisplayModes = MIR_GetDisplayModes;
device->SetDisplayMode = MIR_SetDisplayMode;
device->free = MIR_DeleteDevice;
/* miropengles */
device->GL_SwapWindow = MIR_GL_SwapWindow;
device->GL_MakeCurrent = MIR_GL_MakeCurrent;
device->GL_CreateContext = MIR_GL_CreateContext;
device->GL_DeleteContext = MIR_GL_DeleteContext;
device->GL_LoadLibrary = MIR_GL_LoadLibrary;
device->GL_UnloadLibrary = MIR_GL_UnloadLibrary;
device->GL_GetSwapInterval = MIR_GL_GetSwapInterval;
device->GL_SetSwapInterval = MIR_GL_SetSwapInterval;
device->GL_GetProcAddress = MIR_GL_GetProcAddress;
/* mirwindow */
Aug 28, 2017
Aug 28, 2017
184
device->CreateSDLWindow = MIR_CreateWindow;
Feb 21, 2016
Feb 21, 2016
185
186
187
188
189
190
191
192
193
194
195
196
device->DestroyWindow = MIR_DestroyWindow;
device->GetWindowWMInfo = MIR_GetWindowWMInfo;
device->SetWindowFullscreen = MIR_SetWindowFullscreen;
device->MaximizeWindow = MIR_MaximizeWindow;
device->MinimizeWindow = MIR_MinimizeWindow;
device->RestoreWindow = MIR_RestoreWindow;
device->ShowWindow = MIR_RestoreWindow;
device->HideWindow = MIR_HideWindow;
device->SetWindowSize = MIR_SetWindowSize;
device->SetWindowMinimumSize = MIR_SetWindowMinimumSize;
device->SetWindowMaximumSize = MIR_SetWindowMaximumSize;
device->SetWindowTitle = MIR_SetWindowTitle;
Aug 30, 2016
Aug 30, 2016
197
device->SetWindowGrab = MIR_SetWindowGrab;
Sep 22, 2016
Sep 22, 2016
198
199
device->SetWindowGammaRamp = MIR_SetWindowGammaRamp;
device->GetWindowGammaRamp = MIR_GetWindowGammaRamp;
Aug 28, 2017
Aug 28, 2017
201
device->CreateSDLWindowFrom = NULL;
202
203
204
device->SetWindowIcon = NULL;
device->RaiseWindow = NULL;
device->SetWindowBordered = NULL;
Sep 30, 2016
Sep 30, 2016
205
device->SetWindowResizable = NULL;
206
device->OnWindowEnter = NULL;
Feb 21, 2016
Feb 21, 2016
207
device->SetWindowPosition = NULL;
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* mirframebuffer */
device->CreateWindowFramebuffer = MIR_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = MIR_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = MIR_DestroyWindowFramebuffer;
device->shape_driver.CreateShaper = MIR_CreateShaper;
device->shape_driver.SetWindowShape = MIR_SetWindowShape;
device->shape_driver.ResizeWindowShape = MIR_ResizeWindowShape;
device->PumpEvents = MIR_PumpEvents;
device->SuspendScreenSaver = NULL;
device->StartTextInput = NULL;
device->StopTextInput = NULL;
device->SetTextInputRect = NULL;
device->HasScreenKeyboardSupport = NULL;
device->ShowScreenKeyboard = NULL;
device->HideScreenKeyboard = NULL;
device->IsScreenKeyboardShown = NULL;
device->SetClipboardText = NULL;
device->GetClipboardText = NULL;
device->HasClipboardText = NULL;
device->ShowMessageBox = NULL;
Aug 28, 2017
Aug 28, 2017
237
#if SDL_VIDEO_VULKAN
Aug 28, 2017
Aug 28, 2017
238
239
240
241
242
243
device->Vulkan_LoadLibrary = MIR_Vulkan_LoadLibrary;
device->Vulkan_UnloadLibrary = MIR_Vulkan_UnloadLibrary;
device->Vulkan_GetInstanceExtensions = MIR_Vulkan_GetInstanceExtensions;
device->Vulkan_CreateSurface = MIR_Vulkan_CreateSurface;
#endif
244
245
246
247
248
249
250
251
return device;
}
VideoBootStrap MIR_bootstrap = {
MIR_DRIVER_NAME, "SDL Mir video driver",
MIR_Available, MIR_CreateDevice
};
Sep 21, 2016
Sep 21, 2016
252
253
static SDL_DisplayMode
MIR_ConvertModeToSDLMode(MirOutputMode const* mode, MirPixelFormat format)
Sep 21, 2016
Sep 21, 2016
255
256
257
258
259
260
SDL_DisplayMode sdl_mode = {
.format = MIR_GetSDLPixelFormat(format),
.w = MIR_mir_output_mode_get_width(mode),
.h = MIR_mir_output_mode_get_height(mode),
.refresh_rate = MIR_mir_output_mode_get_refresh_rate(mode),
.driverdata = NULL
Sep 21, 2016
Sep 21, 2016
263
return sdl_mode;
Sep 21, 2016
Sep 21, 2016
267
MIR_AddModeToDisplay(SDL_VideoDisplay* display, MirOutputMode const* mode, MirPixelFormat format)
Sep 21, 2016
Sep 21, 2016
269
270
SDL_DisplayMode sdl_mode = MIR_ConvertModeToSDLMode(mode, format);
SDL_AddDisplayMode(display, &sdl_mode);
Sep 21, 2016
Sep 21, 2016
274
MIR_InitDisplayFromOutput(_THIS, MirOutput* output)
Sep 21, 2016
Sep 21, 2016
276
277
SDL_VideoDisplay display;
int m;
Sep 21, 2016
Sep 21, 2016
279
280
MirPixelFormat format = MIR_mir_output_get_current_pixel_format(output);
int num_modes = MIR_mir_output_get_num_modes(output);
Jan 2, 2017
Jan 2, 2017
281
SDL_DisplayMode current_mode = MIR_ConvertModeToSDLMode(MIR_mir_output_get_current_mode(output), format);
Sep 21, 2016
Sep 21, 2016
283
SDL_zero(display);
Sep 21, 2016
Sep 21, 2016
285
286
// Unfortunate cast, but SDL_AddVideoDisplay will strdup this pointer so its read-only in this case.
display.name = (char*)MIR_mir_output_type_name(MIR_mir_output_get_type(output));
Sep 21, 2016
Sep 21, 2016
288
289
290
291
for (m = 0; m < num_modes; m++) {
MirOutputMode const* mode = MIR_mir_output_get_mode(output, m);
MIR_AddModeToDisplay(&display, mode, format);
}
Sep 21, 2016
Sep 21, 2016
293
294
display.desktop_mode = current_mode;
display.current_mode = current_mode;
Sep 21, 2016
Sep 21, 2016
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
display.driverdata = output;
SDL_AddVideoDisplay(&display);
}
static void
MIR_InitDisplays(_THIS)
{
MIR_Data* mir_data = _this->driverdata;
int num_outputs = MIR_mir_display_config_get_num_outputs(mir_data->display_config);
int d;
for (d = 0; d < num_outputs; d++) {
MirOutput* output = MIR_mir_display_config_get_mutable_output(mir_data->display_config, d);
SDL_bool enabled = MIR_mir_output_is_enabled(output);
MirOutputConnectionState state = MIR_mir_output_get_connection_state(output);
if (enabled && state == mir_output_connection_state_connected) {
MIR_InitDisplayFromOutput(_this, output);
Sep 21, 2016
Sep 21, 2016
318
static int
319
320
321
322
MIR_VideoInit(_THIS)
{
MIR_Data* mir_data = _this->driverdata;
Jan 31, 2018
Jan 31, 2018
323
mir_data->connection = MIR_mir_connect_sync(NULL, SDL_FUNCTION);
Feb 21, 2016
Feb 21, 2016
324
325
326
mir_data->current_window = NULL;
mir_data->software = SDL_FALSE;
mir_data->pixel_format = mir_pixel_format_invalid;
Jun 8, 2016
Jun 8, 2016
328
329
330
331
if (!MIR_mir_connection_is_valid(mir_data->connection)) {
return SDL_SetError("Failed to connect to the mir server: %s",
MIR_mir_connection_get_error_message(mir_data->connection));
}
Sep 21, 2016
Sep 21, 2016
333
334
mir_data->display_config = MIR_mir_connection_create_display_configuration(mir_data->connection);
335
336
337
338
339
340
MIR_InitDisplays(_this);
MIR_InitMouse();
return 0;
}
Sep 21, 2016
Sep 21, 2016
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
static void
MIR_CleanUpDisplayConfig(_THIS)
{
MIR_Data* mir_data = _this->driverdata;
int i;
// SDL_VideoQuit frees the display driverdata, we own it not them
for (i = 0; i < _this->num_displays; ++i) {
_this->displays[i].driverdata = NULL;
}
MIR_mir_display_config_release(mir_data->display_config);
}
static void
356
357
358
359
MIR_VideoQuit(_THIS)
{
MIR_Data* mir_data = _this->driverdata;
Sep 21, 2016
Sep 21, 2016
360
361
MIR_CleanUpDisplayConfig(_this);
362
363
364
365
366
367
368
369
370
371
372
373
374
375
MIR_FiniMouse();
MIR_GL_DeleteContext(_this, NULL);
MIR_GL_UnloadLibrary(_this);
MIR_mir_connection_release(mir_data->connection);
SDL_free(mir_data);
_this->driverdata = NULL;
}
static int
MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect)
{
Sep 21, 2016
Sep 21, 2016
376
MirOutput const* output = display->driverdata;
Sep 21, 2016
Sep 21, 2016
378
379
380
381
rect->x = MIR_mir_output_get_position_x(output);
rect->y = MIR_mir_output_get_position_y(output);
rect->w = display->current_mode.w;
rect->h = display->current_mode.h;
382
383
384
385
386
return 0;
}
static void
Sep 21, 2016
Sep 21, 2016
387
MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* display)
388
389
390
391
{
}
static int
Sep 21, 2016
Sep 21, 2016
392
MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* display, SDL_DisplayMode* mode)
Sep 21, 2016
Sep 21, 2016
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
int m;
MirOutput* output = display->driverdata;
int num_modes = MIR_mir_output_get_num_modes(output);
Uint32 sdl_format = MIR_GetSDLPixelFormat(
MIR_mir_output_get_current_pixel_format(output));
for (m = 0; m < num_modes; m++) {
MirOutputMode const* mir_mode = MIR_mir_output_get_mode(output, m);
int width = MIR_mir_output_mode_get_width(mir_mode);
int height = MIR_mir_output_mode_get_height(mir_mode);
double refresh_rate = MIR_mir_output_mode_get_refresh_rate(mir_mode);
if (mode->format == sdl_format &&
mode->w == width &&
mode->h == height &&
mode->refresh_rate == refresh_rate) {
Sep 21, 2016
Sep 21, 2016
411
// FIXME Currently wont actually *set* anything. Need to wait for applying display changes
Sep 21, 2016
Sep 21, 2016
412
413
414
415
416
417
MIR_mir_output_set_current_mode(output, mir_mode);
return 0;
}
}
return -1;
418
419
420
421
422
}
#endif /* SDL_VIDEO_DRIVER_MIR */
/* vi: set ts=4 sw=4 expandtab: */