Merge lp:~brandontschaefer/libsdl/mir-support1.2 into lp:ubuntu/wily/libsdl1.2

Proposed by Brandon Schaefer
Status: Rejected
Rejected by: Martin Pitt
Proposed branch: lp:~brandontschaefer/libsdl/mir-support1.2
Merge into: lp:ubuntu/wily/libsdl1.2
Diff against target: 1642 lines (+1610/-2)
3 files modified
debian/control (+8/-2)
debian/patches/mir_support.patch (+1601/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~brandontschaefer/libsdl/mir-support1.2
Reviewer Review Type Date Requested Status
Martin Pitt Disapprove
Review via email: mp+294572@code.launchpad.net

Commit message

Adds a patch for mir support.

Description of the change

Adds a patch for mir support.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

Is wily the correct branch to merge this into? It will be reaching End of Life next month.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

There doesnt seem to be a newer version of libsdl1.2 hanging around. wily/xenial both just copy from the wily branch. Im more then happy to merge into a newer one!

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

It would probably be better to just file a bug at https://bugs.launchpad.net/ubuntu/+source/libsdl2/+filebug and attach your patch to it (there is a newer version of libsdl2 in yakkety, but I have no idea how much has actually changed).

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

This would be aimed at changing libsdl 1.2, i've a bug against libsdl....

Revision history for this message
Martin Pitt (pitti) wrote :

Wily has a remaining lifetime of a week or two, there's no point in starting such invasive changes on it now -- landing and SRUing these will already take longer than that.

review: Disapprove
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Hmm what branch should I MP against? https://code.launchpad.net/ubuntu/+source/libsdl1.2

Where should I put a patch? Not really sure how to get this in when there doesnt seem to be a branch to propose against.

Unmerged revisions

53. By Brandon Schaefer

* Change control our selfs

52. By Brandon Schaefer

* Add mir support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-08-12 13:48:35 +0000
3+++ debian/control 2016-05-12 22:16:09 +0000
4@@ -22,7 +22,10 @@
5 libasound2-dev [linux-any],
6 libcaca-dev,
7 libusbhid-dev [kfreebsd-any],
8- libglu1-mesa-dev
9+ libglu1-mesa-dev,
10+ libxkbcommon-dev,
11+ libegl1-mesa-dev,
12+ libmirclient-dev
13 Vcs-Git: git://anonscm.debian.org/pkg-sdl/packages/libsdl1.2.git
14 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-sdl/packages/libsdl1.2.git
15 Homepage: http://www.libsdl.org/
16@@ -67,7 +70,10 @@
17 libpulse-dev,
18 libusbhid-dev [kfreebsd-any],
19 libx11-dev,
20- libxext-dev
21+ libxext-dev,
22+ libxkbcommon-dev,
23+ libegl1-mesa-dev,
24+ libmirclient-dev
25 Replaces: libsdl-dev
26 Conflicts: libsdl-dev
27 Provides: libsdl-dev
28
29=== added file 'debian/patches/mir_support.patch'
30--- debian/patches/mir_support.patch 1970-01-01 00:00:00 +0000
31+++ debian/patches/mir_support.patch 2016-05-12 22:16:09 +0000
32@@ -0,0 +1,1601 @@
33+--- a/configure.in
34++++ b/configure.in
35+@@ -961,6 +961,43 @@
36+ fi
37+ }
38+
39++CheckMir()
40++{
41++ AC_ARG_ENABLE(video-mir,
42++ AC_HELP_STRING([--enable-video-mir], [use Mir video driver [[default=yes]]]),
43++ , enable_video_mir=yes)
44++
45++ if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
46++ AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
47++
48++ if test x$PKG_CONFIG != xno; then
49++ AC_MSG_CHECKING(for Mir support)
50++ video_mir=no
51++ tmp_CFLAGS="$CFLAGS"
52++ CFLAGS="$EXTRA_CFLAGS `$PKG_CONFIG --cflags egl mirclient xkbcommon`"
53++
54++ AC_TRY_COMPILE([
55++ #include <EGL/egl.h>
56++ #include <mir_toolkit/mir_client_library.h>
57++ #include <xkbcommon/xkbcommon.h>
58++ ],[
59++ ],[
60++ video_mir=yes
61++ ])
62++ CFLAGS="$tmp_CFLAGS"
63++ AC_MSG_RESULT($video_mir)
64++
65++ if test x$video_mir = xyes; then
66++ AC_DEFINE(SDL_VIDEO_DRIVER_MIR)
67++ SOURCES="$SOURCES $srcdir/src/video/mir/*.c"
68++ EXTRA_CFLAGS="$EXTRA_CFLAGS `$PKG_CONFIG --cflags egl mirclient xkbcommon`"
69++ EXTRA_LDFLAGS="$EXTRA_LDFLAGS `$PKG_CONFIG --libs egl mirclient xkbcommon`"
70++ have_video=yes
71++ fi
72++ fi
73++ fi
74++}
75++
76+ dnl Find the X11 include and library directories
77+ CheckX11()
78+ {
79+@@ -2360,6 +2397,7 @@
80+ CheckESD
81+ CheckPulseAudio
82+ CheckNAS
83++ CheckMir
84+ CheckX11
85+ CheckNANOX
86+ CheckFBCON
87+--- a/include/SDL_config.h.in
88++++ b/include/SDL_config.h.in
89+@@ -281,6 +281,7 @@
90+ #undef SDL_VIDEO_DRIVER_VGL
91+ #undef SDL_VIDEO_DRIVER_WINDIB
92+ #undef SDL_VIDEO_DRIVER_WSCONS
93++#undef SDL_VIDEO_DRIVER_MIR
94+ #undef SDL_VIDEO_DRIVER_X11
95+ #undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
96+ #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
97+--- a/src/video/SDL_sysvideo.h
98++++ b/src/video/SDL_sysvideo.h
99+@@ -320,6 +320,9 @@
100+ #if SDL_VIDEO_DRIVER_QUARTZ
101+ extern VideoBootStrap QZ_bootstrap;
102+ #endif
103++#if SDL_VIDEO_DRIVER_MIR
104++extern VideoBootStrap Mir_bootstrap;
105++#endif
106+ #if SDL_VIDEO_DRIVER_X11
107+ extern VideoBootStrap X11_bootstrap;
108+ #endif
109+--- a/src/video/SDL_video.c
110++++ b/src/video/SDL_video.c
111+@@ -36,6 +36,9 @@
112+ #if SDL_VIDEO_DRIVER_QUARTZ
113+ &QZ_bootstrap,
114+ #endif
115++#if SDL_VIDEO_DRIVER_MIR
116++ &Mir_bootstrap,
117++#endif
118+ #if SDL_VIDEO_DRIVER_X11
119+ &X11_bootstrap,
120+ #endif
121+--- /dev/null
122++++ b/src/video/mir/SDL_mirbuffer.c
123+@@ -0,0 +1,58 @@
124++#include "SDL_mirbuffer.h"
125++#include "SDL_endian.h"
126++
127++static void RedrawRegion(_THIS, const MirGraphicsRegion* region)
128++{
129++ Uint32 w, h;
130++
131++ int d_stride = region->stride;
132++ int s_stride = SDL_VideoSurface->pitch;
133++
134++ char* dest = region->vaddr;
135++ char* src = (char*)SDL_VideoSurface->pixels;
136++
137++ int bytes_per_pixel = SDL_VideoSurface->format->BytesPerPixel;
138++ int bytes_per_row = bytes_per_pixel * SDL_VideoSurface->w;
139++ Uint32 alpha_index = (SDL_BYTEORDER == SDL_BIG_ENDIAN) ? 0 : bytes_per_pixel - 1;
140++
141++ SDL_bool lp_bug_1423462_workaround = false;
142++
143++ if (bytes_per_pixel == 4 && region->pixel_format == this->hidden->opaque_pixel_format)
144++ lp_bug_1423462_workaround = true;
145++
146++ for (h = 0; h < SDL_VideoSurface->h; h++)
147++ {
148++ memcpy(dest, src, bytes_per_row);
149++ if (lp_bug_1423462_workaround)
150++ {
151++ for (w = 0; w < SDL_VideoSurface->w; ++w)
152++ {
153++ // FIXME Mir should ignore alpha in x* formats
154++ dest[(w * bytes_per_pixel) + alpha_index] = 0xff;
155++ }
156++ }
157++
158++ dest += d_stride;
159++ src += s_stride;
160++ }
161++}
162++
163++void Mir_UpdateRects(_THIS, int numrects, SDL_Rect* rects)
164++{
165++ if (!mir_surface_is_valid(this->hidden->surface))
166++ {
167++ const char* error = mir_surface_get_error_message(this->hidden->surface);
168++ fprintf(stderr, "Failed to created a mir surface: %s", error);
169++ return;
170++ }
171++
172++ MirGraphicsRegion region;
173++ MirBufferStream *bs;
174++
175++ bs = mir_surface_get_buffer_stream(this->hidden->surface);
176++ mir_buffer_stream_get_graphics_region(bs, &region);
177++
178++ RedrawRegion(this, &region);
179++
180++ mir_buffer_stream_swap_buffers_sync(bs);
181++}
182+--- /dev/null
183++++ b/src/video/mir/SDL_mirbuffer.h
184+@@ -0,0 +1,32 @@
185++/*
186++ SDL - Simple DirectMedia Layer
187++ Copyright (C) 2013 Canonical Ltd
188++
189++ This library is free software; you can redistribute it and/or
190++ modify it under the terms of the GNU Lesser General Public
191++ License as published by the Free Software Foundation; either
192++ version 2.1 of the License, or (at your option) any later version.
193++
194++ This library is distributed in the hope that it will be useful,
195++ but WITHOUT ANY WARRANTY; without even the implied warranty of
196++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
197++ Lesser General Public License for more details.
198++
199++ You should have received a copy of the GNU Lesser General Public
200++ License along with this library; if not, write to the Free Software
201++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
202++
203++ Brandon Schaefer
204++ brandon.schaefer@canonical.com
205++*/
206++
207++#include "SDL_config.h"
208++
209++#ifndef _SDL_mirbuffer_h
210++#define _SDL_mirbuffer_h
211++
212++#include "SDL_mirvideo.h"
213++
214++extern void Mir_UpdateRects(_THIS, int numrects, SDL_Rect* rects);
215++
216++#endif // _SDL_mirbuffer_h
217+--- /dev/null
218++++ b/src/video/mir/SDL_mirevents.c
219+@@ -0,0 +1,266 @@
220++/*
221++ SDL - Simple DirectMedia Layer
222++ Copyright (C) 2013 Canonical Ltd
223++
224++ This library is free software; you can redistribute it and/or
225++ modify it under the terms of the GNU Lesser General Public
226++ License as published by the Free Software Foundation; either
227++ version 2.1 of the License, or (at your option) any later version.
228++
229++ This library is distributed in the hope that it will be useful,
230++ but WITHOUT ANY WARRANTY; without even the implied warranty of
231++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
232++ Lesser General Public License for more details.
233++
234++ You should have received a copy of the GNU Lesser General Public
235++ License along with this library; if not, write to the Free Software
236++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
237++
238++ Brandon Schaefer
239++ brandon.schaefer@canonical.com
240++*/
241++
242++#include "SDL_mirevents.h"
243++
244++#include "../../events/SDL_events_c.h"
245++#include <xkbcommon/xkbcommon.h>
246++
247++#define MIN_KEYCODE 8
248++
249++static SDLKey MISC_keymap[256];
250++
251++static void Mir_InitKeymap()
252++{
253++ int i;
254++
255++ // Taken mostly from SDL_x11events.c, switched to xkbcommon keysym
256++ for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )
257++ MISC_keymap[i] = SDLK_UNKNOWN;
258++
259++ MISC_keymap[XKB_KEY_BackSpace&0xFF] = SDLK_BACKSPACE;
260++ MISC_keymap[XKB_KEY_Tab&0xFF] = SDLK_TAB;
261++ MISC_keymap[XKB_KEY_Clear&0xFF] = SDLK_CLEAR;
262++ MISC_keymap[XKB_KEY_Return&0xFF] = SDLK_RETURN;
263++ MISC_keymap[XKB_KEY_Pause&0xFF] = SDLK_PAUSE;
264++ MISC_keymap[XKB_KEY_Escape&0xFF] = SDLK_ESCAPE;
265++ MISC_keymap[XKB_KEY_Delete&0xFF] = SDLK_DELETE;
266++
267++ MISC_keymap[XKB_KEY_KP_0&0xFF] = SDLK_KP0;
268++ MISC_keymap[XKB_KEY_KP_1&0xFF] = SDLK_KP1;
269++ MISC_keymap[XKB_KEY_KP_2&0xFF] = SDLK_KP2;
270++ MISC_keymap[XKB_KEY_KP_3&0xFF] = SDLK_KP3;
271++ MISC_keymap[XKB_KEY_KP_4&0xFF] = SDLK_KP4;
272++ MISC_keymap[XKB_KEY_KP_5&0xFF] = SDLK_KP5;
273++ MISC_keymap[XKB_KEY_KP_6&0xFF] = SDLK_KP6;
274++ MISC_keymap[XKB_KEY_KP_7&0xFF] = SDLK_KP7;
275++ MISC_keymap[XKB_KEY_KP_8&0xFF] = SDLK_KP8;
276++ MISC_keymap[XKB_KEY_KP_9&0xFF] = SDLK_KP9;
277++ MISC_keymap[XKB_KEY_KP_Insert&0xFF] = SDLK_KP0;
278++ MISC_keymap[XKB_KEY_KP_End&0xFF] = SDLK_KP1;
279++ MISC_keymap[XKB_KEY_KP_Down&0xFF] = SDLK_KP2;
280++ MISC_keymap[XKB_KEY_KP_Page_Down&0xFF] = SDLK_KP3;
281++ MISC_keymap[XKB_KEY_KP_Left&0xFF] = SDLK_KP4;
282++ MISC_keymap[XKB_KEY_KP_Begin&0xFF] = SDLK_KP5;
283++ MISC_keymap[XKB_KEY_KP_Right&0xFF] = SDLK_KP6;
284++ MISC_keymap[XKB_KEY_KP_Home&0xFF] = SDLK_KP7;
285++ MISC_keymap[XKB_KEY_KP_Up&0xFF] = SDLK_KP8;
286++ MISC_keymap[XKB_KEY_KP_Page_Up&0xFF] = SDLK_KP9;
287++ MISC_keymap[XKB_KEY_KP_Delete&0xFF] = SDLK_KP_PERIOD;
288++ MISC_keymap[XKB_KEY_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
289++ MISC_keymap[XKB_KEY_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
290++ MISC_keymap[XKB_KEY_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
291++ MISC_keymap[XKB_KEY_KP_Subtract&0xFF] = SDLK_KP_MINUS;
292++ MISC_keymap[XKB_KEY_KP_Add&0xFF] = SDLK_KP_PLUS;
293++ MISC_keymap[XKB_KEY_KP_Enter&0xFF] = SDLK_KP_ENTER;
294++ MISC_keymap[XKB_KEY_KP_Equal&0xFF] = SDLK_KP_EQUALS;
295++
296++ MISC_keymap[XKB_KEY_Up&0xFF] = SDLK_UP;
297++ MISC_keymap[XKB_KEY_Down&0xFF] = SDLK_DOWN;
298++ MISC_keymap[XKB_KEY_Right&0xFF] = SDLK_RIGHT;
299++ MISC_keymap[XKB_KEY_Left&0xFF] = SDLK_LEFT;
300++ MISC_keymap[XKB_KEY_Insert&0xFF] = SDLK_INSERT;
301++ MISC_keymap[XKB_KEY_Home&0xFF] = SDLK_HOME;
302++ MISC_keymap[XKB_KEY_End&0xFF] = SDLK_END;
303++ MISC_keymap[XKB_KEY_Page_Up&0xFF] = SDLK_PAGEUP;
304++ MISC_keymap[XKB_KEY_Page_Down&0xFF] = SDLK_PAGEDOWN;
305++
306++ MISC_keymap[XKB_KEY_F1&0xFF] = SDLK_F1;
307++ MISC_keymap[XKB_KEY_F2&0xFF] = SDLK_F2;
308++ MISC_keymap[XKB_KEY_F3&0xFF] = SDLK_F3;
309++ MISC_keymap[XKB_KEY_F4&0xFF] = SDLK_F4;
310++ MISC_keymap[XKB_KEY_F5&0xFF] = SDLK_F5;
311++ MISC_keymap[XKB_KEY_F6&0xFF] = SDLK_F6;
312++ MISC_keymap[XKB_KEY_F7&0xFF] = SDLK_F7;
313++ MISC_keymap[XKB_KEY_F8&0xFF] = SDLK_F8;
314++ MISC_keymap[XKB_KEY_F9&0xFF] = SDLK_F9;
315++ MISC_keymap[XKB_KEY_F10&0xFF] = SDLK_F10;
316++ MISC_keymap[XKB_KEY_F11&0xFF] = SDLK_F11;
317++ MISC_keymap[XKB_KEY_F12&0xFF] = SDLK_F12;
318++ MISC_keymap[XKB_KEY_F13&0xFF] = SDLK_F13;
319++ MISC_keymap[XKB_KEY_F14&0xFF] = SDLK_F14;
320++ MISC_keymap[XKB_KEY_F15&0xFF] = SDLK_F15;
321++
322++ MISC_keymap[XKB_KEY_Num_Lock&0xFF] = SDLK_NUMLOCK;
323++ MISC_keymap[XKB_KEY_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
324++ MISC_keymap[XKB_KEY_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
325++ MISC_keymap[XKB_KEY_Shift_R&0xFF] = SDLK_RSHIFT;
326++ MISC_keymap[XKB_KEY_Shift_L&0xFF] = SDLK_LSHIFT;
327++ MISC_keymap[XKB_KEY_Control_R&0xFF] = SDLK_RCTRL;
328++ MISC_keymap[XKB_KEY_Control_L&0xFF] = SDLK_LCTRL;
329++ MISC_keymap[XKB_KEY_Alt_R&0xFF] = SDLK_RALT;
330++ MISC_keymap[XKB_KEY_Alt_L&0xFF] = SDLK_LALT;
331++ MISC_keymap[XKB_KEY_Meta_R&0xFF] = SDLK_RMETA;
332++ MISC_keymap[XKB_KEY_Meta_L&0xFF] = SDLK_LMETA;
333++ MISC_keymap[XKB_KEY_Super_L&0xFF] = SDLK_LSUPER;
334++ MISC_keymap[XKB_KEY_Super_R&0xFF] = SDLK_RSUPER;
335++ MISC_keymap[XKB_KEY_Mode_switch&0xFF] = SDLK_MODE;
336++ MISC_keymap[XKB_KEY_Multi_key&0xFF] = SDLK_COMPOSE;
337++
338++ MISC_keymap[XKB_KEY_Help&0xFF] = SDLK_HELP;
339++ MISC_keymap[XKB_KEY_Print&0xFF] = SDLK_PRINT;
340++ MISC_keymap[XKB_KEY_Sys_Req&0xFF] = SDLK_SYSREQ;
341++ MISC_keymap[XKB_KEY_Break&0xFF] = SDLK_BREAK;
342++ MISC_keymap[XKB_KEY_Menu&0xFF] = SDLK_MENU;
343++ MISC_keymap[XKB_KEY_Hyper_R&0xFF] = SDLK_MENU;
344++}
345++
346++void Mir_InitOSKeymap(_THIS)
347++{
348++ Mir_InitKeymap();
349++}
350++
351++static void HandleMouseButton(Uint8 state, MirPointerEvent const* pointer)
352++{
353++ uint32_t sdl_button = SDL_BUTTON_LEFT;
354++ MirPointerButton button_state = mir_pointer_button_primary;
355++
356++ static uint32_t old_button_states = 0;
357++ uint32_t new_button_states = mir_pointer_event_buttons(pointer);
358++
359++ // XOR on our old button states vs our new states to get the newley pressed/released button
360++ button_state = new_button_states ^ old_button_states;
361++
362++ switch (button_state) {
363++ case mir_pointer_button_primary:
364++ sdl_button = SDL_BUTTON_LEFT;
365++ break;
366++ case mir_pointer_button_secondary:
367++ sdl_button = SDL_BUTTON_RIGHT;
368++ break;
369++ case mir_pointer_button_tertiary:
370++ sdl_button = SDL_BUTTON_MIDDLE;
371++ break;
372++ case mir_pointer_button_forward:
373++ sdl_button = SDL_BUTTON_X1;
374++ break;
375++ case mir_pointer_button_back:
376++ sdl_button = SDL_BUTTON_X2;
377++ break;
378++ default:
379++ break;
380++ }
381++
382++ old_button_states = new_button_states;
383++
384++ SDL_PrivateMouseButton(state, sdl_button, 0, 0);
385++}
386++
387++static void HandleMotion(MirPointerEvent const* pointer)
388++{
389++ int x = (int)mir_pointer_event_axis_value(pointer, mir_pointer_axis_x);
390++ int y = (int)mir_pointer_event_axis_value(pointer, mir_pointer_axis_y);
391++ SDL_PrivateMouseMotion(0, 0, x, y);
392++}
393++
394++static void Mir_HandlePointerEvent(MirSurface const* surface, MirPointerEvent const* pointer)
395++{
396++ switch (mir_pointer_event_action(pointer))
397++ {
398++ case(mir_pointer_action_motion):
399++ HandleMotion(pointer);
400++ break;
401++ case(mir_pointer_action_button_down):
402++ HandleMouseButton(SDL_PRESSED, pointer);
403++ break;
404++ case(mir_pointer_action_button_up):
405++ HandleMouseButton(SDL_RELEASED, pointer);
406++ break;
407++ case(mir_pointer_action_enter):
408++ case(mir_pointer_action_leave):
409++ break;
410++ default:
411++ break;
412++ }
413++}
414++
415++static void Mir_HandleKeyEvent(MirSurface const* surface, MirKeyboardEvent const* key_event)
416++{
417++ xkb_keysym_t key_code;
418++ MirKeyboardAction action;
419++ SDLKey key = SDLK_UNKNOWN;
420++ Uint8 key_state = 0;
421++ int scan_code;
422++ char text[8];
423++ int size = 0;
424++
425++ action = mir_keyboard_event_action(key_event);
426++ key_code = mir_keyboard_event_key_code(key_event);
427++ scan_code = mir_keyboard_event_scan_code(key_event);
428++
429++ if (action == mir_keyboard_action_down)
430++ key_state = SDL_PRESSED;
431++ else if (action == mir_keyboard_action_up)
432++ key_state = SDL_RELEASED;
433++
434++ switch (key_code >> 8)
435++ {
436++ case(0x00):
437++ key = key_code & 0xFF;
438++ break;
439++ case(0xFF):
440++ key = MISC_keymap[key_code & 0xFF];
441++ break;
442++ default:
443++ break;
444++ }
445++
446++ size = xkb_keysym_to_utf8(key_code, text, sizeof text);
447++
448++ SDL_keysym keysym;
449++ keysym.sym = key;
450++ keysym.scancode = scan_code + MIN_KEYCODE;
451++ keysym.mod = KMOD_NONE;
452++ memcpy(&keysym.unicode, text, size);
453++
454++ SDL_PrivateKeyboard(key_state, &keysym);
455++}
456++
457++static void Mir_HandleInputEvent(MirSurface* surface, MirInputEvent const* event)
458++{
459++ switch (mir_input_event_get_type(event))
460++ {
461++ case(mir_input_event_type_key):
462++ Mir_HandleKeyEvent(surface, mir_input_event_get_keyboard_event(event));
463++ break;
464++ case(mir_input_event_type_touch):
465++ break;
466++ case(mir_input_event_type_pointer):
467++ Mir_HandlePointerEvent(surface, mir_input_event_get_pointer_event(event));
468++ break;
469++ default:
470++ break;
471++ }
472++}
473++
474++void Mir_HandleSurfaceEvent(MirSurface* surface,
475++ MirEvent const* event, void* context)
476++{
477++ switch (mir_event_get_type(event))
478++ {
479++ case(mir_event_type_input):
480++ Mir_HandleInputEvent(surface, mir_event_get_input_event(event));
481++ break;
482++ default:
483++ break;
484++ }
485++}
486+--- /dev/null
487++++ b/src/video/mir/SDL_mirevents.h
488+@@ -0,0 +1,33 @@
489++/*
490++ SDL - Simple DirectMedia Layer
491++ Copyright (C) 2013 Canonical Ltd
492++
493++ This library is free software; you can redistribute it and/or
494++ modify it under the terms of the GNU Lesser General Public
495++ License as published by the Free Software Foundation; either
496++ version 2.1 of the License, or (at your option) any later version.
497++
498++ This library is distributed in the hope that it will be useful,
499++ but WITHOUT ANY WARRANTY; without even the implied warranty of
500++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
501++ Lesser General Public License for more details.
502++
503++ You should have received a copy of the GNU Lesser General Public
504++ License along with this library; if not, write to the Free Software
505++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
506++
507++ Brandon Schaefer
508++ brandon.schaefer@canonical.com
509++*/
510++#include "SDL_config.h"
511++
512++#ifndef _SDL_mirevents_h
513++#define _SDL_mirevents_h
514++
515++#include "SDL_mirvideo.h"
516++
517++extern void Mir_InitOSKeymap(_THIS);
518++extern void Mir_HandleSurfaceEvent(MirSurface* surface,
519++ MirEvent const* event, void* context);
520++
521++#endif // _SDL_mirevents_h
522+--- /dev/null
523++++ b/src/video/mir/SDL_mirgl.c
524+@@ -0,0 +1,218 @@
525++/*
526++ SDL - Simple DirectMedia Layer
527++ Copyright (C) 2013 Canonical Ltd
528++
529++ This library is free software; you can redistribute it and/or
530++ modify it under the terms of the GNU Lesser General Public
531++ License as published by the Free Software Foundation; either
532++ version 2.1 of the License, or (at your option) any later version.
533++
534++ This library is distributed in the hope that it will be useful,
535++ but WITHOUT ANY WARRANTY; without even the implied warranty of
536++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
537++ Lesser General Public License for more details.
538++
539++ You should have received a copy of the GNU Lesser General Public
540++ License along with this library; if not, write to the Free Software
541++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
542++
543++ Brandon Schaefer
544++ brandon.schaefer@canonical.com
545++*/
546++
547++#include "SDL_mirgl.h"
548++
549++int Mir_GL_CreateESurface(_THIS)
550++{
551++ if (Mir_GL_LoadLibrary(this, NULL) < 0)
552++ return -1;
553++
554++ EGLNativeWindowType egl_nwin = (EGLNativeWindowType)
555++ mir_buffer_stream_get_egl_native_window(mir_surface_get_buffer_stream(this->hidden->surface));
556++
557++ this->gl_data->esurface = eglCreateWindowSurface(this->gl_data->edpy,
558++ this->gl_data->econf,
559++ egl_nwin, NULL);
560++
561++ if (this->gl_data->esurface == EGL_NO_SURFACE)
562++ {
563++ SDL_SetError("Error Could not create EGL Surface");
564++ return -1;
565++ }
566++
567++ return 0;
568++}
569++
570++int Mir_GL_LoadLibrary(_THIS, const char* path)
571++{
572++ if (this->gl_config.dll_handle != NULL)
573++ return 0;
574++
575++ int major, minor;
576++ EGLint neglconfigs;
577++
578++ EGLenum renderable_type = EGL_OPENGL_BIT;
579++ EGLenum rendering_api = EGL_OPENGL_API;
580++
581++ EGLint attribs[] =
582++ {
583++ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
584++ EGL_RENDERABLE_TYPE, renderable_type,
585++ EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
586++ EGL_BUFFER_SIZE, this->gl_config.buffer_size,
587++ EGL_RED_SIZE, this->gl_config.red_size,
588++ EGL_GREEN_SIZE, this->gl_config.green_size,
589++ EGL_BLUE_SIZE, this->gl_config.blue_size,
590++ EGL_ALPHA_SIZE, this->gl_config.alpha_size,
591++ EGL_DEPTH_SIZE, this->gl_config.depth_size,
592++ EGL_STENCIL_SIZE, this->gl_config.stencil_size,
593++ EGL_NONE,
594++ };
595++
596++ this->gl_data->edpy = eglGetDisplay(
597++ mir_connection_get_egl_native_display(this->hidden->connection));
598++
599++ if (!eglInitialize(this->gl_data->edpy, &major, &minor))
600++ {
601++ SDL_SetError("Failed to initialize EGL");
602++ return -1;
603++ }
604++
605++ eglBindAPI(rendering_api);
606++
607++ if (!eglChooseConfig(this->gl_data->edpy, attribs,
608++ &this->gl_data->econf, 1, &neglconfigs))
609++ {
610++ SDL_SetError("Failed to choose econfig");
611++ return -1;
612++ }
613++
614++ if (neglconfigs != 1)
615++ {
616++ SDL_SetError("Failed to choose econfig");
617++ return -1;
618++ }
619++
620++ this->gl_config.driver_loaded = 1;
621++
622++ return 0;
623++}
624++
625++void* Mir_GL_GetProcAddress(_THIS, const char* proc)
626++{
627++ return eglGetProcAddress(proc);
628++}
629++
630++int Mir_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
631++{
632++ switch (attrib)
633++ {
634++ case SDL_GL_DOUBLEBUFFER:
635++ *value=this->gl_config.double_buffer;
636++ break;
637++ case SDL_GL_STENCIL_SIZE:
638++ *value=this->gl_config.stencil_size;
639++ break;
640++ case SDL_GL_DEPTH_SIZE:
641++ *value=this->gl_config.depth_size;
642++ break;
643++ case SDL_GL_RED_SIZE:
644++ *value=this->gl_config.red_size;
645++ break;
646++ case SDL_GL_GREEN_SIZE:
647++ *value=this->gl_config.green_size;
648++ break;
649++ case SDL_GL_BLUE_SIZE:
650++ *value=this->gl_config.blue_size;
651++ break;
652++ case SDL_GL_ALPHA_SIZE:
653++ *value=this->gl_config.alpha_size;
654++ break;
655++ case SDL_GL_ACCUM_RED_SIZE:
656++ *value=this->gl_config.accum_red_size;
657++ break;
658++ case SDL_GL_ACCUM_GREEN_SIZE:
659++ *value=this->gl_config.accum_green_size;
660++ break;
661++ case SDL_GL_ACCUM_BLUE_SIZE:
662++ *value=this->gl_config.accum_blue_size;
663++ break;
664++ case SDL_GL_ACCUM_ALPHA_SIZE:
665++ *value=this->gl_config.accum_alpha_size;
666++ break;
667++ case SDL_GL_STEREO:
668++ *value=this->gl_config.stereo;
669++ break;
670++ default:
671++ *value=0;
672++ return(-1);
673++ }
674++
675++ return 0;
676++}
677++
678++int Mir_GL_MakeCurrent(_THIS)
679++{
680++ EGLSurface* surface = this->gl_data->esurface;
681++
682++ if (!eglMakeCurrent(this->gl_data->edpy, surface, surface, this->gl_data->context))
683++ {
684++ SDL_SetError("Unable to make EGL context current");
685++ return -1;
686++ }
687++
688++ return 0;
689++}
690++
691++int Mir_GL_CreateContext(_THIS)
692++{
693++ int client_version = 2;
694++
695++ const EGLint context_atrribs[] = {
696++ EGL_CONTEXT_CLIENT_VERSION, client_version, EGL_NONE
697++ };
698++
699++ this->gl_data->context = eglCreateContext(this->gl_data->edpy, this->gl_data->econf,
700++ EGL_NO_CONTEXT, context_atrribs);
701++
702++ if (this->gl_data->context == EGL_NO_CONTEXT)
703++ {
704++ SDL_SetError("Could not create EGL context");
705++ return -1;
706++ }
707++
708++ if (Mir_GL_MakeCurrent(this) < 0)
709++ {
710++ return -1;
711++ }
712++
713++ return 0;
714++}
715++
716++void Mir_GL_DeleteContext(_THIS)
717++{
718++ eglDestroyContext(this->gl_data->edpy, this->gl_data->context);
719++ eglDestroySurface(this->gl_data->edpy, this->gl_data->esurface);
720++
721++ eglMakeCurrent(this->gl_data->edpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
722++ eglReleaseThread();
723++
724++ this->gl_data->context = 0;
725++ this->gl_data->esurface = NULL;
726++}
727++
728++void Mir_GL_UnloadLibrary(_THIS)
729++{
730++ if (this->gl_config.driver_loaded)
731++ {
732++ eglTerminate(this->gl_data->edpy);
733++
734++ this->gl_config.dll_handle = NULL;
735++ this->gl_config.driver_loaded = 0;
736++ }
737++}
738++
739++void Mir_GL_SwapBuffers(_THIS)
740++{
741++ eglSwapBuffers(this->gl_data->edpy, this->gl_data->esurface);
742++}
743+--- /dev/null
744++++ b/src/video/mir/SDL_mirgl.h
745+@@ -0,0 +1,55 @@
746++/*
747++ SDL - Simple DirectMedia Layer
748++ Copyright (C) 2013 Canonical Ltd
749++
750++ This library is free software; you can redistribute it and/or
751++ modify it under the terms of the GNU Lesser General Public
752++ License as published by the Free Software Foundation; either
753++ version 2.1 of the License, or (at your option) any later version.
754++
755++ This library is distributed in the hope that it will be useful,
756++ but WITHOUT ANY WARRANTY; without even the implied warranty of
757++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
758++ Lesser General Public License for more details.
759++
760++ You should have received a copy of the GNU Lesser General Public
761++ License along with this library; if not, write to the Free Software
762++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
763++
764++ Brandon Schaefer
765++ brandon.schaefer@canonical.com
766++*/
767++
768++#include "SDL_config.h"
769++
770++#ifndef _SDL_mirgl_h
771++#define _SDL_mirgl_h
772++
773++#if SDL_VIDEO_OPENGL
774++#include <EGL/egl.h>
775++#include "SDL_mirvideo.h"
776++#endif // SDL_VIDEO_OPENGL
777++
778++struct SDL_PrivateGLData
779++{
780++#if SDL_VIDEO_OPENGL
781++ EGLDisplay edpy;
782++ EGLContext context;
783++ EGLConfig econf;
784++ EGLSurface esurface;
785++#endif // SDL_VIDEO_OPENGL
786++};
787++
788++extern int Mir_GL_CreateESurface(_THIS);
789++extern int Mir_GL_CreateContext(_THIS);
790++extern void Mir_GL_DeleteContext(_THIS);
791++extern void Mir_GL_UnloadLibrary(_THIS);
792++#if SDL_VIDEO_OPENGL
793++extern int Mir_GL_LoadLibrary(_THIS, const char* path);
794++extern void *Mir_GL_GetProcAddress(_THIS, const char* proc);
795++extern int Mir_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
796++extern int Mir_GL_MakeCurrent(_THIS);
797++extern void Mir_GL_SwapBuffers(_THIS);
798++#endif // SDL_VIDEO_OPENGL
799++
800++#endif
801+--- /dev/null
802++++ b/src/video/mir/SDL_mirhw.c
803+@@ -0,0 +1,46 @@
804++/*
805++ SDL - Simple DirectMedia Layer
806++ Copyright (C) 2013 Canonical Ltd
807++
808++ This library is free software; you can redistribute it and/or
809++ modify it under the terms of the GNU Lesser General Public
810++ License as published by the Free Software Foundation; either
811++ version 2.1 of the License, or (at your option) any later version.
812++
813++ This library is distributed in the hope that it will be useful,
814++ but WITHOUT ANY WARRANTY; without even the implied warranty of
815++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
816++ Lesser General Public License for more details.
817++
818++ You should have received a copy of the GNU Lesser General Public
819++ License along with this library; if not, write to the Free Software
820++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
821++
822++ Brandon Schaefer
823++ brandon.schaefer@canonical.com
824++*/
825++
826++#include "SDL_mirhw.h"
827++
828++int Mir_AllocHWSurface(_THIS, SDL_Surface* surface)
829++{
830++ return -1;
831++}
832++
833++void Mir_FreeHWSurface(_THIS, SDL_Surface* surface)
834++{
835++}
836++
837++int Mir_LockHWSurface(_THIS, SDL_Surface* surface)
838++{
839++ return 0;
840++}
841++
842++void Mir_UnlockHWSurface(_THIS, SDL_Surface* surface)
843++{
844++}
845++
846++int Mir_FlipHWSurface(_THIS, SDL_Surface* surface)
847++{
848++ return 0;
849++}
850+--- /dev/null
851++++ b/src/video/mir/SDL_mirhw.h
852+@@ -0,0 +1,36 @@
853++/*
854++ SDL - Simple DirectMedia Layer
855++ Copyright (C) 2013 Canonical Ltd
856++
857++ This library is free software; you can redistribute it and/or
858++ modify it under the terms of the GNU Lesser General Public
859++ License as published by the Free Software Foundation; either
860++ version 2.1 of the License, or (at your option) any later version.
861++
862++ This library is distributed in the hope that it will be useful,
863++ but WITHOUT ANY WARRANTY; without even the implied warranty of
864++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
865++ Lesser General Public License for more details.
866++
867++ You should have received a copy of the GNU Lesser General Public
868++ License along with this library; if not, write to the Free Software
869++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
870++
871++ Brandon Schaefer
872++ brandon.schaefer@canonical.com
873++*/
874++
875++#include "SDL_config.h"
876++
877++#ifndef _SDL_mirhw_h
878++#define _SDL_mirhw_h
879++
880++#include "SDL_mirvideo.h"
881++
882++extern int Mir_AllocHWSurface(_THIS, SDL_Surface* surface);
883++extern void Mir_FreeHWSurface(_THIS, SDL_Surface* surface);
884++extern int Mir_LockHWSurface(_THIS, SDL_Surface* surface);
885++extern void Mir_UnlockHWSurface(_THIS, SDL_Surface* surface);
886++extern int Mir_FlipHWSurface(_THIS, SDL_Surface* surface);
887++
888++#endif //_SDL_mirhw_h
889+--- /dev/null
890++++ b/src/video/mir/SDL_mirmouse.c
891+@@ -0,0 +1,62 @@
892++/*
893++ SDL - Simple DirectMedia Layer
894++ Copyright (C) 2013 Canonical Ltd
895++
896++ This library is free software; you can redistribute it and/or
897++ modify it under the terms of the GNU Lesser General Public
898++ License as published by the Free Software Foundation; either
899++ version 2.1 of the License, or (at your option) any later version.
900++
901++ This library is distributed in the hope that it will be useful,
902++ but WITHOUT ANY WARRANTY; without even the implied warranty of
903++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
904++ Lesser General Public License for more details.
905++
906++ You should have received a copy of the GNU Lesser General Public
907++ License along with this library; if not, write to the Free Software
908++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
909++
910++ Brandon Schaefer
911++ brandon.schaefer@canonical.com
912++*/
913++
914++#include "SDL_mirmouse.h"
915++
916++#include "../SDL_cursor_c.h"
917++
918++struct WMcursor {
919++};
920++
921++void Mir_FreeWMCursor(_THIS, WMcursor* cursor)
922++{
923++ SDL_free(cursor);
924++ cursor = NULL;
925++}
926++
927++WMcursor* Mir_CreateWMCursor(_THIS, Uint8* data, Uint8* mask,
928++ int w, int h, int hot_x, int hot_y)
929++{
930++ WMcursor* cursor;
931++
932++ cursor = (WMcursor*)SDL_calloc(1, sizeof(WMcursor));
933++ if (!cursor)
934++ {
935++ SDL_OutOfMemory();
936++ return NULL;
937++ }
938++
939++ return cursor;
940++}
941++
942++int Mir_ShowWMCursor(_THIS, WMcursor* cursor)
943++{
944++ return 1;
945++}
946++
947++void Mir_WrapWMCursor(_THIS, Uint16 x, Uint16 y)
948++{
949++}
950++
951++void Mir_CheckMouseMode(_THIS)
952++{
953++}
954+--- /dev/null
955++++ b/src/video/mir/SDL_mirmouse.h
956+@@ -0,0 +1,37 @@
957++/*
958++ SDL - Simple DirectMedia Layer
959++ Copyright (C) 2013 Canonical Ltd
960++
961++ This library is free software; you can redistribute it and/or
962++ modify it under the terms of the GNU Lesser General Public
963++ License as published by the Free Software Foundation; either
964++ version 2.1 of the License, or (at your option) any later version.
965++
966++ This library is distributed in the hope that it will be useful,
967++ but WITHOUT ANY WARRANTY; without even the implied warranty of
968++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
969++ Lesser General Public License for more details.
970++
971++ You should have received a copy of the GNU Lesser General Public
972++ License along with this library; if not, write to the Free Software
973++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
974++
975++ Brandon Schaefer
976++ brandon.schaefer@canonical.com
977++*/
978++
979++#include "SDL_config.h"
980++
981++#ifndef _SDL_mirmouse_h
982++#define _SDL_mirmouse_h
983++
984++#include "SDL_mirvideo.h"
985++
986++extern void Mir_FreeWMCursor(_THIS, WMcursor* cursor);
987++extern WMcursor* Mir_CreateWMCursor(_THIS, Uint8* data, Uint8* mask,
988++ int w, int h, int hot_x, int hot_y);
989++extern int Mir_ShowWMCursor(_THIS, WMcursor* cursor);
990++extern void Mir_WrapWMCursor(_THIS, Uint16 x, Uint16 y);
991++extern void Mir_CheckMouseMode(_THIS);
992++
993++#endif // _SDL_mirmouse_h
994+--- /dev/null
995++++ b/src/video/mir/SDL_mirvideo.c
996+@@ -0,0 +1,590 @@
997++/*
998++ SDL - Simple DirectMedia Layer
999++ Copyright (C) 2013 Canonical Ltd
1000++
1001++ This library is free software; you can redistribute it and/or
1002++ modify it under the terms of the GNU Lesser General Public
1003++ License as published by the Free Software Foundation; either
1004++ version 2.1 of the License, or (at your option) any later version.
1005++
1006++ This library is distributed in the hope that it will be useful,
1007++ but WITHOUT ANY WARRANTY; without even the implied warranty of
1008++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1009++ Lesser General Public License for more details.
1010++
1011++ You should have received a copy of the GNU Lesser General Public
1012++ License along with this library; if not, write to the Free Software
1013++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1014++
1015++ Brandon Schaefer
1016++ brandon.schaefer@canonical.com
1017++*/
1018++
1019++#include "SDL_config.h"
1020++
1021++
1022++#include "SDL_video.h"
1023++#include "../SDL_pixels_c.h"
1024++#include "../SDL_sysvideo.h"
1025++
1026++#include "SDL_mirbuffer.h"
1027++#include "SDL_mirevents.h"
1028++#include "SDL_mirgl.h"
1029++#include "SDL_mirhw.h"
1030++#include "SDL_mirmouse.h"
1031++#include "SDL_mirvideo.h"
1032++
1033++static int Mir_VideoInit(_THIS, SDL_PixelFormat* vformat);
1034++static void Mir_VideoQuit(_THIS);
1035++static SDL_Surface* Mir_SetVideoMode(_THIS, SDL_Surface* current, int width,
1036++ int height, int bpp, Uint32 flags);
1037++
1038++SDL_Rect** Mir_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
1039++{
1040++ return this->hidden->modelist;
1041++}
1042++
1043++static int Mir_Available(void)
1044++{
1045++ return 1;
1046++}
1047++
1048++void Mir_PumpEvents(_THIS)
1049++{
1050++}
1051++
1052++static int Mir_ToggleFullScreen(_THIS, int on)
1053++{
1054++ if (!mir_surface_is_valid(this->hidden->surface))
1055++ {
1056++ const char* error = mir_surface_get_error_message(this->hidden->surface);
1057++ SDL_SetError("Failed to created a mir surface: %s", error);
1058++ mir_surface_release_sync(this->hidden->surface);
1059++ return 0;
1060++ }
1061++
1062++ if (on)
1063++ {
1064++ mir_surface_set_state(this->hidden->surface, mir_surface_state_fullscreen);
1065++ }
1066++ else
1067++ {
1068++ mir_surface_set_state(this->hidden->surface, mir_surface_state_restored);
1069++ }
1070++
1071++ return 1;
1072++}
1073++
1074++static void Mir_DeleteDevice(SDL_VideoDevice* device)
1075++{
1076++ if (device)
1077++ {
1078++ if (device->hidden)
1079++ SDL_free(device->hidden);
1080++
1081++ if (device->gl_data)
1082++ SDL_free(device->gl_data);
1083++
1084++ SDL_free(device);
1085++ }
1086++}
1087++
1088++static SDL_VideoDevice* Mir_CreateDevice(int devindex)
1089++{
1090++ SDL_VideoDevice *device = NULL;
1091++ device = (SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice));
1092++
1093++ if (!device)
1094++ {
1095++ SDL_OutOfMemory();
1096++ return 0;
1097++ }
1098++
1099++ device->hidden = (struct SDL_PrivateVideoData*)
1100++ SDL_calloc(1, (sizeof *device->hidden));
1101++
1102++ if (!device->hidden)
1103++ {
1104++ Mir_DeleteDevice(device);
1105++ SDL_OutOfMemory();
1106++ return 0;
1107++ }
1108++
1109++#if SDL_VIDEO_OPENGL
1110++ device->gl_data = (struct SDL_PrivateGLData*)
1111++ SDL_calloc(1, (sizeof *device->gl_data));
1112++
1113++ if (!device->gl_data)
1114++ {
1115++ Mir_DeleteDevice(device);
1116++ SDL_OutOfMemory();
1117++ return 0;
1118++ }
1119++#endif // SDL_VIDEO_OPENGL
1120++
1121++ device->hidden->connection = NULL;
1122++ device->hidden->surface = NULL;
1123++
1124++ device->handles_any_size = 1;
1125++ device->input_grab = 0;
1126++
1127++ device->VideoInit = Mir_VideoInit;
1128++ device->VideoQuit = Mir_VideoQuit;
1129++ device->SetVideoMode = Mir_SetVideoMode;
1130++ device->InitOSKeymap = Mir_InitOSKeymap;
1131++ device->ListModes = Mir_ListModes;
1132++ device->UpdateMouse = NULL;
1133++ device->free = Mir_DeleteDevice;
1134++
1135++ device->ToggleFullScreen = Mir_ToggleFullScreen;
1136++
1137++ device->AllocHWSurface = Mir_AllocHWSurface;
1138++ device->LockHWSurface = Mir_LockHWSurface;
1139++ device->UnlockHWSurface = Mir_UnlockHWSurface;
1140++ device->FlipHWSurface = Mir_FlipHWSurface;
1141++ device->FreeHWSurface = Mir_FreeHWSurface;
1142++
1143++ device->CheckHWBlit = NULL;
1144++ device->SetHWColorKey = NULL;
1145++ device->UpdateRects = NULL;
1146++ device->FillHWRect = NULL;
1147++ device->SetHWColorKey = NULL;
1148++ device->SetHWAlpha = NULL;
1149++ device->GetGammaRamp = NULL;
1150++ device->SetCaption = NULL;
1151++ device->GrabInput = NULL;
1152++
1153++ device->FreeWMCursor = Mir_FreeWMCursor;
1154++ device->CreateWMCursor = Mir_CreateWMCursor;
1155++ device->ShowWMCursor = Mir_ShowWMCursor;
1156++ device->WarpWMCursor = Mir_WrapWMCursor;
1157++ device->CheckMouseMode = Mir_CheckMouseMode;
1158++ device->MoveWMCursor = NULL;
1159++
1160++#if SDL_VIDEO_OPENGL
1161++ device->GL_LoadLibrary = Mir_GL_LoadLibrary;
1162++ device->GL_GetProcAddress = Mir_GL_GetProcAddress;
1163++ device->GL_GetAttribute = Mir_GL_GetAttribute;
1164++ device->GL_MakeCurrent = Mir_GL_MakeCurrent;
1165++ device->GL_SwapBuffers = Mir_GL_SwapBuffers;
1166++#endif // SDL_VIDEO_OPENGL
1167++
1168++ device->PumpEvents = Mir_PumpEvents;
1169++
1170++ return device;
1171++}
1172++
1173++VideoBootStrap Mir_bootstrap = {
1174++ "mir", "Mir Video Driver",
1175++ Mir_Available, Mir_CreateDevice
1176++};
1177++
1178++SDL_Surface* Mir_SetVideoMode(_THIS, SDL_Surface* current,
1179++ int width, int height, int bpp, Uint32 flags)
1180++{
1181++ if (this->hidden->surface && mir_surface_is_valid(this->hidden->surface))
1182++ {
1183++ mir_surface_release_sync(this->hidden->surface);
1184++ this->hidden->surface = NULL;
1185++ }
1186++
1187++ Uint32 output_id = mir_display_output_id_invalid;
1188++
1189++ if (flags & SDL_FULLSCREEN)
1190++ {
1191++ MirDisplayConfiguration* display_config =
1192++ mir_connection_create_display_config(this->hidden->connection);
1193++
1194++ Uint32 fallback_output_id = mir_display_output_id_invalid;
1195++ Uint32 d;
1196++ Uint32 m;
1197++
1198++ this->hidden->mode_changed = SDL_FALSE;
1199++
1200++ for (d = 0; d < display_config->num_outputs; ++d)
1201++ {
1202++ MirDisplayOutput const* out = display_config->outputs + d;
1203++ if (out->used && out->connected)
1204++ {
1205++ if (out->modes[out->current_mode].horizontal_resolution == width &&
1206++ out->modes[out->current_mode].vertical_resolution == height)
1207++ {
1208++ output_id = out->output_id;
1209++ break;
1210++ }
1211++
1212++ if (fallback_output_id == mir_display_output_id_invalid &&
1213++ out->modes[out->current_mode].horizontal_resolution >= width &&
1214++ out->modes[out->current_mode].vertical_resolution >= height)
1215++ {
1216++ fallback_output_id = out->output_id;
1217++ }
1218++ }
1219++ }
1220++
1221++ if (output_id == mir_display_output_id_invalid)
1222++ {
1223++ for (d = 0; d < display_config->num_outputs; ++d)
1224++ {
1225++ MirDisplayOutput* out = display_config->outputs + d;
1226++ if (out->used && out->connected)
1227++ {
1228++ for (m = 0; m < out->num_modes; ++m)
1229++ {
1230++ if (out->modes[m].horizontal_resolution == width &&
1231++ out->modes[m].vertical_resolution == height)
1232++ {
1233++ this->hidden->mode_changed = SDL_TRUE;
1234++ output_id = out->output_id;
1235++ out->current_mode = m;
1236++
1237++ mir_wait_for(
1238++ mir_connection_apply_display_config(this->hidden->connection,
1239++ display_config)
1240++ );
1241++ break;
1242++ }
1243++ }
1244++ }
1245++ }
1246++ }
1247++
1248++ if (fallback_output_id == mir_display_output_id_invalid)
1249++ {
1250++ /* There's no native resolution for the requested format, so let's
1251++ * just ensure we've an output large enough to show it */
1252++
1253++ for (d = 0; d < display_config->num_outputs; ++d)
1254++ {
1255++ MirDisplayOutput* out = display_config->outputs + d;
1256++ if (out->used && out->connected)
1257++ {
1258++ for (m = 0; m < out->num_modes; ++m)
1259++ {
1260++ if (out->modes[m].horizontal_resolution >= width &&
1261++ out->modes[m].vertical_resolution >= height)
1262++ {
1263++ this->hidden->mode_changed = SDL_TRUE;
1264++ fallback_output_id = out->output_id;
1265++ out->current_mode = m;
1266++
1267++ mir_wait_for(
1268++ mir_connection_apply_display_config(this->hidden->connection,
1269++ display_config)
1270++ );
1271++ break;
1272++ }
1273++ }
1274++ }
1275++ }
1276++
1277++ /* Setting output_id = fallback_output_id here seems to cause
1278++ * troubles to mir in creating a new surface */
1279++ }
1280++
1281++ mir_display_config_destroy(display_config);
1282++
1283++ if (output_id == mir_display_output_id_invalid &&
1284++ fallback_output_id == mir_display_output_id_invalid)
1285++ {
1286++ SDL_SetError("Impossible to find a valid output for mode %dx%d",
1287++ width, height);
1288++ return NULL;
1289++ }
1290++ }
1291++ else if (this->hidden->mode_changed)
1292++ {
1293++ Uint32 d;
1294++ SDL_bool any_changed = SDL_FALSE;
1295++
1296++ MirDisplayConfiguration* display_config =
1297++ mir_connection_create_display_config(this->hidden->connection);
1298++
1299++ for (d = 0; d < display_config->num_outputs; ++d)
1300++ {
1301++ MirDisplayOutput* out = display_config->outputs + d;
1302++ if (out->used && out->connected)
1303++ {
1304++ if (out->current_mode != out->preferred_mode)
1305++ {
1306++ out->current_mode = out->preferred_mode;
1307++ any_changed = SDL_TRUE;
1308++ }
1309++ }
1310++ }
1311++
1312++ if (any_changed)
1313++ {
1314++ mir_wait_for(
1315++ mir_connection_apply_display_config(this->hidden->connection,
1316++ display_config)
1317++ );
1318++ }
1319++
1320++ this->hidden->mode_changed = SDL_FALSE;
1321++ mir_display_config_destroy(display_config);
1322++ }
1323++
1324++ MirPixelFormat pixel_format = (current->flags & SDL_SRCALPHA) ?
1325++ this->hidden->alpha_pixel_format :
1326++ this->hidden->opaque_pixel_format;
1327++
1328++ MirSurfaceSpec* spec =
1329++ mir_connection_create_spec_for_normal_surface(this->hidden->connection,
1330++ width, height, pixel_format);
1331++
1332++ MirBufferUsage buffer_usage = (flags & SDL_OPENGL) ? mir_buffer_usage_hardware :
1333++ mir_buffer_usage_software;
1334++
1335++ mir_surface_spec_set_buffer_usage(spec, buffer_usage);
1336++ mir_surface_spec_set_name(spec, "MirSurface");
1337++
1338++ this->hidden->surface = mir_surface_create_sync(spec);
1339++
1340++ mir_surface_spec_release(spec);
1341++
1342++ if (!mir_surface_is_valid(this->hidden->surface))
1343++ {
1344++ const char* error = mir_surface_get_error_message(this->hidden->surface);
1345++ SDL_SetError("Failed to created a mir surface: %s", error);
1346++ mir_surface_release_sync(this->hidden->surface);
1347++ return NULL;
1348++ }
1349++
1350++ mir_surface_set_event_handler(this->hidden->surface, Mir_HandleSurfaceEvent, NULL);
1351++
1352++ if (flags & SDL_OPENGL)
1353++ {
1354++ current->flags |= SDL_OPENGL;
1355++
1356++ if (Mir_GL_CreateESurface(this) < 0)
1357++ {
1358++ SDL_SetError("Could not Create EGL Surface");
1359++ return NULL;
1360++ }
1361++
1362++ if (Mir_GL_CreateContext(this) < 0)
1363++ {
1364++ SDL_SetError("Could not Create GL Context");
1365++ return NULL;
1366++ }
1367++ }
1368++ else
1369++ {
1370++ if ((current->w != width || current->h != height))
1371++ {
1372++ current->pixels = NULL;
1373++ current->w = width;
1374++ current->h = height;
1375++ current->pitch = SDL_CalculatePitch(current);
1376++
1377++ current->pixels = SDL_calloc(1, current->h * current->pitch);
1378++ if (!current->pixels)
1379++ {
1380++ SDL_OutOfMemory();
1381++ return NULL;
1382++ }
1383++ this->UpdateRects = Mir_UpdateRects;
1384++ }
1385++ }
1386++
1387++ return current;
1388++}
1389++
1390++static void Mir_ModeListFree(_THIS)
1391++{
1392++ if (this->hidden->modelist)
1393++ {
1394++ int i = 0;
1395++ while (this->hidden->modelist[i] != NULL)
1396++ {
1397++ SDL_free(this->hidden->modelist[i]);
1398++ ++i;
1399++ }
1400++
1401++ SDL_free(this->hidden->modelist);
1402++ this->hidden->modelist = NULL;
1403++ }
1404++}
1405++
1406++static void Mir_ModeListUpdate(_THIS)
1407++{
1408++ Uint32 d, m;
1409++ Uint32 valid_outputs = 0;
1410++
1411++ Mir_ModeListFree(this);
1412++
1413++ MirDisplayConfiguration* display_config =
1414++ mir_connection_create_display_config(this->hidden->connection);
1415++
1416++ for (d = 0; d < display_config->num_outputs; d++)
1417++ {
1418++ MirDisplayOutput const* out = display_config->outputs + d;
1419++ if (out->used && out->connected)
1420++ valid_outputs += out->num_modes;
1421++ }
1422++
1423++ this->hidden->modelist = SDL_calloc(valid_outputs + 1, sizeof(SDL_Rect*));
1424++
1425++ valid_outputs = 0;
1426++
1427++ for (d = 0; d < display_config->num_outputs; ++d)
1428++ {
1429++ MirDisplayOutput const* out = display_config->outputs + d;
1430++ if (out->used && out->connected)
1431++ {
1432++ for (m = 0; m < out->num_modes; ++m)
1433++ {
1434++ SDL_Rect* sdl_output = SDL_calloc(1, sizeof(SDL_Rect));
1435++ sdl_output->x = out->position_x;
1436++ sdl_output->y = out->position_y;
1437++ sdl_output->w = out->modes[m].horizontal_resolution;
1438++ sdl_output->h = out->modes[m].vertical_resolution;
1439++ this->hidden->modelist[valid_outputs] = sdl_output;
1440++
1441++ ++valid_outputs;
1442++ }
1443++ }
1444++ }
1445++
1446++ this->hidden->modelist[valid_outputs] = NULL;
1447++
1448++ mir_display_config_destroy(display_config);
1449++}
1450++
1451++static void Mir_DisplayConfigChanged(MirConnection *connection, void* data)
1452++{
1453++ Mir_ModeListUpdate(data);
1454++}
1455++
1456++int Mir_VideoInit(_THIS, SDL_PixelFormat *vformat)
1457++{
1458++ this->hidden->connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);
1459++
1460++ if (!mir_connection_is_valid(this->hidden->connection))
1461++ {
1462++ SDL_SetError("Failed to connect to the Mir Server: %s",
1463++ mir_connection_get_error_message(this->hidden->connection));
1464++ mir_connection_release(this->hidden->connection);
1465++ return -1;
1466++ }
1467++
1468++ MirPixelFormat formats[mir_pixel_formats];
1469++ this->hidden->alpha_pixel_format = mir_pixel_format_invalid;
1470++ this->hidden->opaque_pixel_format = mir_pixel_format_invalid;
1471++ Uint32 n_formats, f;
1472++
1473++ mir_connection_get_available_surface_formats (this->hidden->connection, formats,
1474++ mir_pixel_formats, &n_formats);
1475++
1476++ for (f = 0; f < n_formats; ++f)
1477++ {
1478++ if (formats[f] == mir_pixel_format_xbgr_8888 ||
1479++ formats[f] == mir_pixel_format_xrgb_8888)
1480++ {
1481++ this->hidden->opaque_pixel_format = formats[f];
1482++ break;
1483++ }
1484++ }
1485++
1486++ if (this->hidden->opaque_pixel_format == mir_pixel_format_invalid)
1487++ {
1488++ SDL_SetError("No valid opaque pixel format found");
1489++ mir_connection_release(this->hidden->connection);
1490++ return -1;
1491++ }
1492++
1493++ MirPixelFormat alpha_format = mir_pixel_format_invalid;
1494++
1495++ switch (this->hidden->opaque_pixel_format)
1496++ {
1497++ case mir_pixel_format_xrgb_8888:
1498++ alpha_format = mir_pixel_format_argb_8888;
1499++ break;
1500++ case mir_pixel_format_xbgr_8888:
1501++ alpha_format = mir_pixel_format_abgr_8888;
1502++ break;
1503++ default:
1504++ break;
1505++ }
1506++
1507++ for (f = 0; f < n_formats; ++f)
1508++ {
1509++ if (formats[f] == alpha_format)
1510++ {
1511++ this->hidden->alpha_pixel_format = alpha_format;
1512++ break;
1513++ }
1514++ }
1515++
1516++ if (this->hidden->alpha_pixel_format == mir_pixel_format_invalid)
1517++ {
1518++ SDL_SetError("No valid alpha pixel format found");
1519++ mir_connection_release(this->hidden->connection);
1520++ return -1;
1521++ }
1522++
1523++ vformat->BytesPerPixel = MIR_BYTES_PER_PIXEL(this->hidden->alpha_pixel_format);
1524++ vformat->BitsPerPixel = vformat->BytesPerPixel * 8;
1525++ vformat->Amask = 0;
1526++
1527++ switch (this->hidden->alpha_pixel_format)
1528++ {
1529++ case mir_pixel_format_abgr_8888:
1530++ vformat->Bmask = 0x00FF0000;
1531++ vformat->Gmask = 0x0000FF00;
1532++ vformat->Rmask = 0x000000FF;
1533++ break;
1534++ case mir_pixel_format_argb_8888:
1535++ vformat->Rmask = 0x00FF0000;
1536++ vformat->Gmask = 0x0000FF00;
1537++ vformat->Bmask = 0x000000FF;
1538++ break;
1539++ default:
1540++ break;
1541++ }
1542++
1543++ if (vformat->BytesPerPixel == 4)
1544++ vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask));
1545++
1546++ Mir_ModeListUpdate(this);
1547++ mir_connection_set_display_config_change_callback(this->hidden->connection,
1548++ Mir_DisplayConfigChanged, this);
1549++
1550++ this->info.wm_available = 1;
1551++
1552++ return 0;
1553++}
1554++
1555++// FIXME Make sure we clean everything up, Also:
1556++// we get a crash (call of virtual function) when releasing the connection :(
1557++void Mir_VideoQuit(_THIS)
1558++{
1559++ if (this->hidden->surface)
1560++ {
1561++ mir_surface_release_sync(this->hidden->surface);
1562++ this->hidden->surface = NULL;
1563++ }
1564++
1565++#if SDL_VIDEO_OPENGL
1566++ if (this->gl_config.driver_loaded != 0)
1567++ {
1568++ Mir_GL_DeleteContext(this);
1569++ Mir_GL_UnloadLibrary(this);
1570++ }
1571++#endif // SDL_VIDEO_OPENGL
1572++
1573++ if (mir_connection_is_valid(this->hidden->connection))
1574++ {
1575++ mir_connection_set_display_config_change_callback(this->hidden->connection,
1576++ NULL, NULL);
1577++ }
1578++
1579++ if (this->hidden->connection)
1580++ {
1581++ mir_connection_release(this->hidden->connection);
1582++ this->hidden->connection = NULL;
1583++ }
1584++
1585++ Mir_ModeListFree(this);
1586++}
1587+--- /dev/null
1588++++ b/src/video/mir/SDL_mirvideo.h
1589+@@ -0,0 +1,44 @@
1590++/*
1591++ SDL - Simple DirectMedia Layer
1592++ Copyright (C) 2013 Canonical Ltd
1593++
1594++ This library is free software; you can redistribute it and/or
1595++ modify it under the terms of the GNU Lesser General Public
1596++ License as published by the Free Software Foundation; either
1597++ version 2.1 of the License, or (at your option) any later version.
1598++
1599++ This library is distributed in the hope that it will be useful,
1600++ but WITHOUT ANY WARRANTY; without even the implied warranty of
1601++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1602++ Lesser General Public License for more details.
1603++
1604++ You should have received a copy of the GNU Lesser General Public
1605++ License along with this library; if not, write to the Free Software
1606++ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1607++
1608++ Brandon Schaefer
1609++ brandon.schaefer@canonical.com
1610++*/
1611++
1612++#include "SDL_config.h"
1613++
1614++#ifndef _SDL_mirvideo_h
1615++#define _SDL_mirvideo_h
1616++
1617++#include "../SDL_sysvideo.h"
1618++
1619++#include <mir_toolkit/mir_client_library.h>
1620++
1621++#define _THIS SDL_VideoDevice *this
1622++
1623++struct SDL_PrivateVideoData {
1624++ MirConnection* connection;
1625++ MirSurface* surface;
1626++ MirPixelFormat alpha_pixel_format;
1627++ MirPixelFormat opaque_pixel_format;
1628++
1629++ SDL_bool mode_changed;
1630++ SDL_Rect** modelist;
1631++};
1632++
1633++#endif //_SDL_mirvideo_h
1634
1635=== modified file 'debian/patches/series'
1636--- debian/patches/series 2014-07-01 23:03:57 +0000
1637+++ debian/patches/series 2016-05-12 22:16:09 +0000
1638@@ -4,3 +4,4 @@
1639 fix_window_resizing.diff
1640 fix_joystick_misc_axes.diff
1641 sdl-check-for-SDL_VIDEO_X11_BACKINGSTORE.patch
1642+mir_support.patch

Subscribers

People subscribed via source and target branches