SDL  2.0
SDL_mirvideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /*
23  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
24 */
25 
26 #include "../../SDL_internal.h"
27 
28 #if SDL_VIDEO_DRIVER_MIR
29 
30 #include "SDL_video.h"
31 
32 #include "SDL_mirframebuffer.h"
33 #include "SDL_mirmouse.h"
34 #include "SDL_miropengl.h"
35 #include "SDL_mirvideo.h"
36 #include "SDL_mirwindow.h"
37 
38 #include "SDL_mirdyn.h"
39 
40 #define MIR_DRIVER_NAME "mir"
41 
42 static int
43 MIR_VideoInit(_THIS);
44 
45 static void
46 MIR_VideoQuit(_THIS);
47 
48 static int
49 MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect);
50 
51 static void
52 MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display);
53 
54 static int
55 MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode);
56 
57 static SDL_WindowShaper*
58 MIR_CreateShaper(SDL_Window* window)
59 {
60  /* FIXME Im not sure if mir support this atm, will have to come back to this */
61  return NULL;
62 }
63 
64 static int
65 MIR_SetWindowShape(SDL_WindowShaper* shaper, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode)
66 {
67  return SDL_Unsupported();
68 }
69 
70 static int
71 MIR_ResizeWindowShape(SDL_Window* window)
72 {
73  return SDL_Unsupported();
74 }
75 
76 static int
77 MIR_Available()
78 {
79  int available = 0;
80 
81  if (SDL_MIR_LoadSymbols()) {
82  /* !!! FIXME: try to make a MirConnection here. */
83  available = 1;
85  }
86 
87  return available;
88 }
89 
90 static void
91 MIR_DeleteDevice(SDL_VideoDevice* device)
92 {
93  SDL_free(device);
95 }
96 
97 void
98 MIR_PumpEvents(_THIS)
99 {
100 }
101 
102 static SDL_VideoDevice*
103 MIR_CreateDevice(int device_index)
104 {
105  MIR_Data* mir_data;
106  SDL_VideoDevice* device = NULL;
107 
108  if (!SDL_MIR_LoadSymbols()) {
109  return NULL;
110  }
111 
112  device = SDL_calloc(1, sizeof(SDL_VideoDevice));
113  if (!device) {
115  SDL_OutOfMemory();
116  return NULL;
117  }
118 
119  mir_data = SDL_calloc(1, sizeof(MIR_Data));
120  if (!mir_data) {
121  SDL_free(device);
123  SDL_OutOfMemory();
124  return NULL;
125  }
126 
127  device->driverdata = mir_data;
128 
129  /* mirvideo */
130  device->VideoInit = MIR_VideoInit;
131  device->VideoQuit = MIR_VideoQuit;
132  device->GetDisplayBounds = MIR_GetDisplayBounds;
133  device->GetDisplayModes = MIR_GetDisplayModes;
134  device->SetDisplayMode = MIR_SetDisplayMode;
135  device->free = MIR_DeleteDevice;
136 
137  /* miropengles */
147 
148  /* mirwindow */
149  device->CreateWindow = MIR_CreateWindow;
156 
157  device->CreateWindowFrom = NULL;
158  device->SetWindowTitle = NULL;
159  device->SetWindowIcon = NULL;
160  device->SetWindowPosition = NULL;
161  device->SetWindowSize = NULL;
162  device->SetWindowMinimumSize = NULL;
163  device->SetWindowMaximumSize = NULL;
164  device->ShowWindow = NULL;
165  device->HideWindow = NULL;
166  device->RaiseWindow = NULL;
167  device->SetWindowBordered = NULL;
168  device->SetWindowGammaRamp = NULL;
169  device->GetWindowGammaRamp = NULL;
170  device->SetWindowGrab = NULL;
171  device->OnWindowEnter = NULL;
172 
173  /* mirframebuffer */
177 
178  device->shape_driver.CreateShaper = MIR_CreateShaper;
179  device->shape_driver.SetWindowShape = MIR_SetWindowShape;
180  device->shape_driver.ResizeWindowShape = MIR_ResizeWindowShape;
181 
182  device->PumpEvents = MIR_PumpEvents;
183 
184  device->SuspendScreenSaver = NULL;
185 
186  device->StartTextInput = NULL;
187  device->StopTextInput = NULL;
188  device->SetTextInputRect = NULL;
189 
190  device->HasScreenKeyboardSupport = NULL;
191  device->ShowScreenKeyboard = NULL;
192  device->HideScreenKeyboard = NULL;
193  device->IsScreenKeyboardShown = NULL;
194 
195  device->SetClipboardText = NULL;
196  device->GetClipboardText = NULL;
197  device->HasClipboardText = NULL;
198 
199  device->ShowMessageBox = NULL;
200 
201  return device;
202 }
203 
204 VideoBootStrap MIR_bootstrap = {
205  MIR_DRIVER_NAME, "SDL Mir video driver",
206  MIR_Available, MIR_CreateDevice
207 };
208 
209 static void
210 MIR_SetCurrentDisplayMode(MirDisplayOutput const* out, SDL_VideoDisplay* display)
211 {
214  .w = out->modes[out->current_mode].horizontal_resolution,
215  .h = out->modes[out->current_mode].vertical_resolution,
216  .refresh_rate = out->modes[out->current_mode].refresh_rate,
217  .driverdata = NULL
218  };
219 
220  display->desktop_mode = mode;
221  display->current_mode = mode;
222 }
223 
224 static void
225 MIR_AddAllModesFromDisplay(MirDisplayOutput const* out, SDL_VideoDisplay* display)
226 {
227  int n_mode;
228  for (n_mode = 0; n_mode < out->num_modes; ++n_mode) {
231  .w = out->modes[n_mode].horizontal_resolution,
232  .h = out->modes[n_mode].vertical_resolution,
233  .refresh_rate = out->modes[n_mode].refresh_rate,
234  .driverdata = NULL
235  };
236 
237  SDL_AddDisplayMode(display, &mode);
238  }
239 }
240 
241 static void
242 MIR_InitDisplays(_THIS)
243 {
244  MIR_Data* mir_data = _this->driverdata;
245  int d;
246 
247  MirDisplayConfiguration* display_config = MIR_mir_connection_create_display_config(mir_data->connection);
248 
249  for (d = 0; d < display_config->num_outputs; d++) {
250  MirDisplayOutput const* out = display_config->outputs + d;
251 
252  SDL_VideoDisplay display;
253  SDL_zero(display);
254 
255  if (out->used &&
256  out->connected &&
257  out->num_modes &&
258  out->current_mode < out->num_modes) {
259 
260  MIR_SetCurrentDisplayMode(out, &display);
261  MIR_AddAllModesFromDisplay(out, &display);
262 
263  SDL_AddVideoDisplay(&display);
264  }
265  }
266 
267  MIR_mir_display_config_destroy(display_config);
268 }
269 
270 int
271 MIR_VideoInit(_THIS)
272 {
273  MIR_Data* mir_data = _this->driverdata;
274 
275  mir_data->connection = MIR_mir_connect_sync(NULL, __PRETTY_FUNCTION__);
276  mir_data->software = SDL_FALSE;
277 
278  if (!MIR_mir_connection_is_valid(mir_data->connection))
279  return SDL_SetError("Failed to connect to the Mir Server");
280 
281  MIR_InitDisplays(_this);
282  MIR_InitMouse();
283 
284  return 0;
285 }
286 
287 void
288 MIR_VideoQuit(_THIS)
289 {
290  MIR_Data* mir_data = _this->driverdata;
291 
292  MIR_FiniMouse();
293 
296 
297  MIR_mir_connection_release(mir_data->connection);
298 
299  SDL_free(mir_data);
300  _this->driverdata = NULL;
301 }
302 
303 static int
304 MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect)
305 {
306  MIR_Data* mir_data = _this->driverdata;
307  int d;
308 
309  MirDisplayConfiguration* display_config = MIR_mir_connection_create_display_config(mir_data->connection);
310 
311  for (d = 0; d < display_config->num_outputs; d++) {
312  MirDisplayOutput const* out = display_config->outputs + d;
313 
314  if (out->used &&
315  out->connected &&
316  out->num_modes &&
317  out->current_mode < out->num_modes) {
318 
319  rect->x = out->position_x;
320  rect->y = out->position_y;
321  rect->w = out->modes->horizontal_resolution;
322  rect->h = out->modes->vertical_resolution;
323  }
324  }
325 
326  MIR_mir_display_config_destroy(display_config);
327 
328  return 0;
329 }
330 
331 static void
332 MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display)
333 {
334 }
335 
336 static int
337 MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode)
338 {
339  return 0;
340 }
341 
342 #endif /* SDL_VIDEO_DRIVER_MIR */
343 
344 /* vi: set ts=4 sw=4 expandtab: */
345 
#define MIR_GL_GetSwapInterval
Definition: SDL_miropengl.h:34
void(* RestoreWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:208
void MIR_MinimizeWindow(_THIS, SDL_Window *window)
int MIR_CreateWindowFramebuffer(_THIS, SDL_Window *sdl_window, Uint32 *format, void **pixels, int *pitch)
void MIR_GL_UnloadLibrary(_THIS)
SDL_bool(* IsScreenKeyboardShown)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:263
int MIR_CreateWindow(_THIS, SDL_Window *window)
int(* CreateWindowFrom)(_THIS, SDL_Window *window, const void *data)
Definition: SDL_sysvideo.h:196
SDL_Rect rect
Definition: testrelative.c:27
SDL_Window * window
void(* free)(_THIS)
Definition: SDL_sysvideo.h:345
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
int(* GL_SetSwapInterval)(_THIS, int interval)
Definition: SDL_sysvideo.h:240
void(* ShowWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:203
The structure that defines a display mode.
Definition: SDL_video.h:53
void MIR_FiniMouse()
void(* StartTextInput)(_THIS)
Definition: SDL_sysvideo.h:255
void(* SetWindowSize)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:200
void MIR_DestroyWindow(_THIS, SDL_Window *window)
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:242
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
Definition: SDL_video.c:593
int(* GL_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:234
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Definition: SDL_sysvideo.h:189
#define MIR_GL_SetSwapInterval
Definition: SDL_miropengl.h:35
void(* SetWindowBordered)(_THIS, SDL_Window *window, SDL_bool bordered)
Definition: SDL_sysvideo.h:209
static SDL_VideoDevice * _this
Definition: SDL_video.c:114
void SDL_MIR_UnloadSymbols(void)
void(* HideWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:204
MirConnection * connection
Definition: SDL_mirvideo.h:34
void(* RaiseWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:205
int(* SetWindowShape)(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
Definition: SDL_sysvideo.h:59
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:257
SDL_bool software
Definition: SDL_mirvideo.h:35
void * SDL_calloc(size_t nmemb, size_t size)
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
Definition: SDL_sysvideo.h:227
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:237
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
SDL_GLContext MIR_GL_CreateContext(_THIS, SDL_Window *window)
#define _THIS
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
Definition: SDL_sysvideo.h:238
void MIR_RestoreWindow(_THIS, SDL_Window *window)
void SDL_free(void *mem)
void MIR_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
void MIR_MaximizeWindow(_THIS, SDL_Window *window)
void(* SetWindowMinimumSize)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:201
SDL_DisplayMode current_mode
Definition: SDL_sysvideo.h:127
GLenum mode
int(* GetDisplayBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
Definition: SDL_sysvideo.h:171
void(* DestroyWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:214
void(* StopTextInput)(_THIS)
Definition: SDL_sysvideo.h:256
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
int MIR_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
int MIR_UpdateWindowFramebuffer(_THIS, SDL_Window *sdl_window, const SDL_Rect *rects, int numrects)
void(* SetWindowIcon)(_THIS, SDL_Window *window, SDL_Surface *icon)
Definition: SDL_sysvideo.h:198
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
SDL_bool(* HasScreenKeyboardSupport)(_THIS)
Definition: SDL_sysvideo.h:260
void(* DestroyWindowFramebuffer)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:217
void MIR_DestroyWindowFramebuffer(_THIS, SDL_Window *sdl_window)
void(* GL_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:236
void * MIR_GL_GetProcAddress(_THIS, const char *proc)
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
Definition: SDL_sysvideo.h:181
int(* ShowMessageBox)(_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid)
Definition: SDL_sysvideo.h:271
void(* SetWindowMaximumSize)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:202
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_DisplayMode desktop_mode
Definition: SDL_sysvideo.h:126
void(* VideoQuit)(_THIS)
Definition: SDL_sysvideo.h:161
#define SDL_SetError
#define MIR_GL_DeleteContext
Definition: SDL_miropengl.h:33
SDL_WindowShaper *(* CreateShaper)(SDL_Window *window)
Definition: SDL_sysvideo.h:58
int(* ResizeWindowShape)(SDL_Window *window)
Definition: SDL_sysvideo.h:60
void(* SetWindowPosition)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:199
int h
Definition: SDL_rect.h:67
void(* ShowScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:261
int(* CreateWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:195
The type used to identify a window.
Definition: SDL_sysvideo.h:71
int(* GetWindowGammaRamp)(_THIS, SDL_Window *window, Uint16 *ramp)
Definition: SDL_sysvideo.h:212
void(* MinimizeWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:207
SDL_bool(* HasClipboardText)(_THIS)
Definition: SDL_sysvideo.h:268
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:709
SDL_ShapeDriver shape_driver
Definition: SDL_sysvideo.h:224
int(* VideoInit)(_THIS)
Definition: SDL_sysvideo.h:155
void(* SetWindowFullscreen)(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
Definition: SDL_sysvideo.h:210
A struct that tags the SDL_WindowShapeParams union with an enum describing the type of its contents...
Definition: SDL_shape.h:100
int(* UpdateWindowFramebuffer)(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
Definition: SDL_sysvideo.h:216
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
Definition: SDL_sysvideo.h:243
char *(* GetClipboardText)(_THIS)
Definition: SDL_sysvideo.h:267
Uint32 format
Definition: SDL_video.h:55
void(* SetWindowTitle)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:197
int(* GL_GetSwapInterval)(_THIS)
Definition: SDL_sysvideo.h:241
void(* MaximizeWindow)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:206
int(* SetClipboardText)(_THIS, const char *text)
Definition: SDL_sysvideo.h:266
int(* SetWindowGammaRamp)(_THIS, SDL_Window *window, const Uint16 *ramp)
Definition: SDL_sysvideo.h:211
void(* OnWindowEnter)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:218
void(* SuspendScreenSaver)(_THIS)
Definition: SDL_sysvideo.h:252
void(* SetWindowGrab)(_THIS, SDL_Window *window, SDL_bool grabbed)
Definition: SDL_sysvideo.h:213
void MIR_GL_SwapWindow(_THIS, SDL_Window *window)
int y
Definition: SDL_rect.h:66
#define SDL_Unsupported()
Definition: SDL_error.h:53
int SDL_MIR_LoadSymbols(void)
int(* CreateWindowFramebuffer)(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
Definition: SDL_sysvideo.h:215
SDL_bool MIR_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
int MIR_GL_LoadLibrary(_THIS, const char *path)
void MIR_InitMouse()
void *(* GL_GetProcAddress)(_THIS, const char *proc)
Definition: SDL_sysvideo.h:235
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
void(* PumpEvents)(_THIS)
Definition: SDL_sysvideo.h:249
void(* HideScreenKeyboard)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:262