Fix API/ABI breakage in Mir 0.13/0.14.
authorbschaefer
Sun, 21 Feb 2016 15:19:35 -0800
changeset 1008925fda20d0173
parent 10088 33bee97dbcbb
child 10090 cd34aa8b624c
Fix API/ABI breakage in Mir 0.13/0.14.
configure.in
src/video/mir/SDL_mirdyn.c
src/video/mir/SDL_mirdyn.h
src/video/mir/SDL_mirevents.c
src/video/mir/SDL_mirevents.h
src/video/mir/SDL_mirframebuffer.c
src/video/mir/SDL_mirmouse.c
src/video/mir/SDL_mirsym.h
src/video/mir/SDL_mirvideo.c
src/video/mir/SDL_mirvideo.h
src/video/mir/SDL_mirwindow.c
src/video/mir/SDL_mirwindow.h
     1.1 --- a/configure.in	Sun Feb 21 17:21:29 2016 -0500
     1.2 +++ b/configure.in	Sun Feb 21 15:19:35 2016 -0800
     1.3 @@ -1284,12 +1284,12 @@
     1.4                  MIR_LIBS=`$PKG_CONFIG --libs mirclient egl xkbcommon`
     1.5                  save_CFLAGS="$CFLAGS"
     1.6                  CFLAGS="$save_CFLAGS $MIR_CFLAGS"
     1.7 -                
     1.8 -                dnl This will disable Mir on Ubuntu < 14.04
     1.9 +
    1.10 +                dnl This will disable Mir on Ubuntu < 15.04 (Mir should be 0.14 at this point)
    1.11                  AC_TRY_COMPILE([
    1.12                  #include <mir_toolkit/mir_client_library.h>
    1.13                  ],[
    1.14 -                    MirMotionToolType tool = mir_motion_tool_type_mouse;
    1.15 +                    MirPointerButton button = mir_pointer_button_primary;
    1.16                  ],[
    1.17                  video_mir=yes
    1.18                  ])
     2.1 --- a/src/video/mir/SDL_mirdyn.c	Sun Feb 21 17:21:29 2016 -0500
     2.2 +++ b/src/video/mir/SDL_mirdyn.c	Sun Feb 21 15:19:35 2016 -0800
     2.3 @@ -84,6 +84,7 @@
     2.4  /* Define all the function pointers and wrappers... */
     2.5  #define SDL_MIR_MODULE(modname) int SDL_MIR_HAVE_##modname = 0;
     2.6  #define SDL_MIR_SYM(rc,fn,params) SDL_DYNMIRFN_##fn MIR_##fn = NULL;
     2.7 +#define SDL_MIR_SYM_CONST(type,name) SDL_DYMMIRCONST_##name MIR_##name = NULL;
     2.8  #include "SDL_mirsym.h"
     2.9  
    2.10  static int mir_load_refcount = 0;
    2.11 @@ -101,6 +102,7 @@
    2.12              /* set all the function pointers to NULL. */
    2.13  #define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 0;
    2.14  #define SDL_MIR_SYM(rc,fn,params) MIR_##fn = NULL;
    2.15 +#define SDL_MIR_SYM_CONST(type,name) MIR_##name = NULL;
    2.16  #include "SDL_mirsym.h"
    2.17  
    2.18  
    2.19 @@ -138,6 +140,7 @@
    2.20  
    2.21  #define SDL_MIR_MODULE(modname) thismod = &SDL_MIR_HAVE_##modname;
    2.22  #define SDL_MIR_SYM(rc,fn,params) MIR_##fn = (SDL_DYNMIRFN_##fn) MIR_GetSym(#fn,thismod);
    2.23 +#define SDL_MIR_SYM_CONST(type,name) MIR_##name = *(SDL_DYMMIRCONST_##name*) MIR_GetSym(#name,thismod);
    2.24  #include "SDL_mirsym.h"
    2.25  
    2.26          if ((SDL_MIR_HAVE_MIR_CLIENT) && (SDL_MIR_HAVE_XKBCOMMON)) {
    2.27 @@ -153,6 +156,7 @@
    2.28  
    2.29  #define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 1; /* default yes */
    2.30  #define SDL_MIR_SYM(rc,fn,params) MIR_##fn = fn;
    2.31 +#define SDL_MIR_SYM_CONST(type,name) MIR_##name = name;
    2.32  #include "SDL_mirsym.h"
    2.33  
    2.34  #endif
     3.1 --- a/src/video/mir/SDL_mirdyn.h	Sun Feb 21 17:21:29 2016 -0500
     3.2 +++ b/src/video/mir/SDL_mirdyn.h	Sun Feb 21 15:19:35 2016 -0800
     3.3 @@ -39,6 +39,9 @@
     3.4  #define SDL_MIR_SYM(rc,fn,params) \
     3.5      typedef rc (*SDL_DYNMIRFN_##fn) params; \
     3.6      extern SDL_DYNMIRFN_##fn MIR_##fn;
     3.7 +#define SDL_MIR_SYM_CONST(type, name) \
     3.8 +    typedef type SDL_DYMMIRCONST_##name; \
     3.9 +    extern SDL_DYMMIRCONST_##name MIR_##name;
    3.10  #include "SDL_mirsym.h"
    3.11  
    3.12  #ifdef __cplusplus
     4.1 --- a/src/video/mir/SDL_mirevents.c	Sun Feb 21 17:21:29 2016 -0500
     4.2 +++ b/src/video/mir/SDL_mirevents.c	Sun Feb 21 15:19:35 2016 -0800
     4.3 @@ -58,7 +58,7 @@
     4.4  {
     4.5      SDL_Window* keyboard_window = SDL_GetKeyboardFocus();
     4.6  
     4.7 -    if (keyboard_window != sdl_window)
     4.8 +    if (sdl_window && keyboard_window != sdl_window)
     4.9          SDL_SetKeyboardFocus(sdl_window);
    4.10  }
    4.11  
    4.12 @@ -68,51 +68,68 @@
    4.13     a single key press produces a character.
    4.14  */
    4.15  static void
    4.16 -HandleKeyEvent(MirKeyEvent const ev, SDL_Window* window)
    4.17 +HandleKeyEvent(MirKeyboardEvent const* key_event, SDL_Window* window)
    4.18  {
    4.19 -    uint32_t scancode = SDL_SCANCODE_UNKNOWN;
    4.20 -    Uint8 key_state = ev.action == mir_key_action_up ? SDL_RELEASED : SDL_PRESSED;
    4.21 +    xkb_keysym_t key_code;
    4.22 +    Uint8 key_state;
    4.23 +    int event_scancode;
    4.24 +    uint32_t sdl_scancode = SDL_SCANCODE_UNKNOWN;
    4.25 +
    4.26 +    MirKeyboardAction action = MIR_mir_keyboard_event_action(key_event);
    4.27 +
    4.28 +    key_state      = SDL_PRESSED;
    4.29 +    key_code       = MIR_mir_keyboard_event_key_code(key_event);
    4.30 +    event_scancode = MIR_mir_keyboard_event_scan_code(key_event);
    4.31 +
    4.32 +    if (action == mir_keyboard_action_up)
    4.33 +        key_state = SDL_RELEASED;
    4.34  
    4.35      CheckKeyboardFocus(window);
    4.36  
    4.37 -    if (ev.scan_code < SDL_arraysize(xfree86_scancode_table2))
    4.38 -        scancode = xfree86_scancode_table2[ev.scan_code];
    4.39 +    if (event_scancode < SDL_arraysize(xfree86_scancode_table2))
    4.40 +        sdl_scancode = xfree86_scancode_table2[event_scancode];
    4.41  
    4.42 -    if (scancode != SDL_SCANCODE_UNKNOWN)
    4.43 -        SDL_SendKeyboardKey(key_state, scancode);
    4.44 +    if (sdl_scancode != SDL_SCANCODE_UNKNOWN)
    4.45 +        SDL_SendKeyboardKey(key_state, sdl_scancode);
    4.46  
    4.47      if (key_state == SDL_PRESSED)
    4.48 -        HandleKeyText(ev.key_code);
    4.49 +        HandleKeyText(key_code);
    4.50  }
    4.51  
    4.52  static void
    4.53 -HandleMouseButton(SDL_Window* sdl_window, Uint8 state, MirMotionButton button_state)
    4.54 +HandleMouseButton(SDL_Window* sdl_window, Uint8 state, MirPointerEvent const* pointer)
    4.55  {
    4.56 -    static uint32_t last_sdl_button;
    4.57 -    uint32_t sdl_button;
    4.58 +    uint32_t sdl_button           = SDL_BUTTON_LEFT;
    4.59 +    MirPointerButton button_state = mir_pointer_button_primary;
    4.60 +
    4.61 +    static uint32_t old_button_states = 0;
    4.62 +    uint32_t new_button_states = MIR_mir_pointer_event_buttons(pointer);
    4.63 +
    4.64 +    // XOR on our old button states vs our new states to get the newley pressed/released button
    4.65 +    button_state = new_button_states ^ old_button_states;
    4.66  
    4.67      switch (button_state) {
    4.68 -        case mir_motion_button_primary:
    4.69 +        case mir_pointer_button_primary:
    4.70              sdl_button = SDL_BUTTON_LEFT;
    4.71              break;
    4.72 -        case mir_motion_button_secondary:
    4.73 +        case mir_pointer_button_secondary:
    4.74              sdl_button = SDL_BUTTON_RIGHT;
    4.75              break;
    4.76 -        case mir_motion_button_tertiary:
    4.77 +        case mir_pointer_button_tertiary:
    4.78              sdl_button = SDL_BUTTON_MIDDLE;
    4.79              break;
    4.80 -        case mir_motion_button_forward:
    4.81 +        case mir_pointer_button_forward:
    4.82              sdl_button = SDL_BUTTON_X1;
    4.83              break;
    4.84 -        case mir_motion_button_back:
    4.85 +        case mir_pointer_button_back:
    4.86              sdl_button = SDL_BUTTON_X2;
    4.87              break;
    4.88          default:
    4.89 -            sdl_button = last_sdl_button;
    4.90              break;
    4.91      }
    4.92  
    4.93 -    last_sdl_button = sdl_button;
    4.94 +    old_button_states = new_button_states;
    4.95 +
    4.96      SDL_SendMouseButton(sdl_window, 0, state, sdl_button);
    4.97  }
    4.98  
    4.99 @@ -148,34 +165,91 @@
   4.100  }
   4.101  
   4.102  static void
   4.103 -HandleTouchEvent(MirMotionEvent const motion, int cord_index, SDL_Window* sdl_window)
   4.104 +HandleTouchEvent(MirTouchEvent const* touch, int device_id, SDL_Window* sdl_window)
   4.105  {
   4.106 -    int device_id = motion.device_id;
   4.107 -    int id = motion.pointer_coordinates[cord_index].id;
   4.108 +    int i, point_count;
   4.109 +    point_count = MIR_mir_touch_event_point_count(touch);
   4.110  
   4.111 -    int width  = sdl_window->w;
   4.112 -    int height = sdl_window->h;
   4.113 -    float x   = motion.pointer_coordinates[cord_index].x;
   4.114 -    float y   = motion.pointer_coordinates[cord_index].y;
   4.115 +    AddTouchDevice(device_id);
   4.116  
   4.117 -    float n_x = x / width;
   4.118 -    float n_y = y / height;
   4.119 -    float pressure = motion.pointer_coordinates[cord_index].pressure;
   4.120 +    for (i = 0; i < point_count; i++) {
   4.121 +        int id = MIR_mir_touch_event_id(touch, i);
   4.122  
   4.123 -    AddTouchDevice(motion.device_id);
   4.124 +        int width  = sdl_window->w;
   4.125 +        int height = sdl_window->h;
   4.126  
   4.127 -    switch (motion.action) {
   4.128 -        case mir_motion_action_down:
   4.129 -        case mir_motion_action_pointer_down:
   4.130 -            HandleTouchPress(device_id, id, SDL_TRUE, n_x, n_y, pressure);
   4.131 +        float x = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_x);
   4.132 +        float y = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_y);
   4.133 +
   4.134 +        float n_x = x / width;
   4.135 +        float n_y = y / height;
   4.136 +
   4.137 +        float pressure = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_pressure);
   4.138 +
   4.139 +        switch (MIR_mir_touch_event_action(touch, i)) {
   4.140 +            case mir_touch_action_up:
   4.141 +                HandleTouchPress(device_id, id, SDL_FALSE, n_x, n_y, pressure);
   4.142 +                break;
   4.143 +            case mir_touch_action_down:
   4.144 +                HandleTouchPress(device_id, id, SDL_TRUE, n_x, n_y, pressure);
   4.145 +                break;
   4.146 +            case mir_touch_action_change:
   4.147 +                HandleTouchMotion(device_id, id, n_x, n_y, pressure);
   4.148 +                break;
   4.149 +        }
   4.150 +    }
   4.151 +}
   4.152 +
   4.153 +static void
   4.154 +HandleMouseEvent(MirPointerEvent const* pointer, SDL_Window* sdl_window)
   4.155 +{
   4.156 +    SDL_SetMouseFocus(sdl_window);
   4.157 +
   4.158 +    switch (MIR_mir_pointer_event_action(pointer)) {
   4.159 +        case mir_pointer_action_button_down:
   4.160 +            HandleMouseButton(sdl_window, SDL_PRESSED, pointer);
   4.161              break;
   4.162 -        case mir_motion_action_up:
   4.163 -        case mir_motion_action_pointer_up:
   4.164 -            HandleTouchPress(device_id, id, SDL_FALSE, n_x, n_y, pressure);
   4.165 +        case mir_pointer_action_button_up:
   4.166 +            HandleMouseButton(sdl_window, SDL_RELEASED, pointer);
   4.167              break;
   4.168 -        case mir_motion_action_hover_move:
   4.169 -        case mir_motion_action_move:
   4.170 -            HandleTouchMotion(device_id, id, n_x, n_y, pressure);
   4.171 +        case mir_pointer_action_motion: {
   4.172 +            int x, y;
   4.173 +            int hscroll, vscroll;
   4.174 +            SDL_Mouse* mouse = SDL_GetMouse();
   4.175 +            x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x);
   4.176 +            y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y);
   4.177 +            hscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_hscroll);
   4.178 +            vscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_vscroll);
   4.179 +
   4.180 +            if (mouse && (mouse->x != x || mouse->y != y))
   4.181 +                HandleMouseMotion(sdl_window, x, y);
   4.182 +            if (vscroll != 0 || hscroll != 0)
   4.183 +                HandleMouseScroll(sdl_window, hscroll, vscroll);
   4.184 +        }
   4.185 +            break;
   4.186 +        case mir_pointer_action_leave:
   4.187 +            SDL_SetMouseFocus(NULL);
   4.188 +            break;
   4.189 +        case mir_pointer_action_enter:
   4.190 +        default:
   4.191 +            break;
   4.192 +    }
   4.193 +}
   4.194 +
   4.195 +static void
   4.196 +MIR_HandleInput(MirInputEvent const* input_event, SDL_Window* window)
   4.197 +{
   4.198 +    switch (MIR_mir_input_event_get_type(input_event)) {
   4.199 +        case (mir_input_event_type_key):
   4.200 +            HandleKeyEvent(MIR_mir_input_event_get_keyboard_event(input_event), window);
   4.201 +            break;
   4.202 +        case (mir_input_event_type_pointer):
   4.203 +            HandleMouseEvent(MIR_mir_input_event_get_pointer_event(input_event), window);
   4.204 +            break;
   4.205 +        case (mir_input_event_type_touch):
   4.206 +            HandleTouchEvent(MIR_mir_input_event_get_touch_event(input_event),
   4.207 +                             MIR_mir_input_event_get_device_id(input_event),
   4.208 +                             window);
   4.209              break;
   4.210          default:
   4.211              break;
   4.212 @@ -183,69 +257,35 @@
   4.213  }
   4.214  
   4.215  static void
   4.216 -HandleMouseEvent(MirMotionEvent const motion, int cord_index, SDL_Window* sdl_window)
   4.217 +MIR_HandleResize(MirResizeEvent const* resize_event, SDL_Window* window)
   4.218  {
   4.219 -    SDL_SetMouseFocus(sdl_window);
   4.220 +    int new_w = MIR_mir_resize_event_get_width (resize_event);
   4.221 +    int new_h = MIR_mir_resize_event_get_height(resize_event);
   4.222  
   4.223 -    switch (motion.action) {
   4.224 -        case mir_motion_action_down:
   4.225 -        case mir_motion_action_pointer_down:
   4.226 -            HandleMouseButton(sdl_window, SDL_PRESSED, motion.button_state);
   4.227 -            break;
   4.228 -        case mir_motion_action_up:
   4.229 -        case mir_motion_action_pointer_up:
   4.230 -            HandleMouseButton(sdl_window, SDL_RELEASED, motion.button_state);
   4.231 -            break;
   4.232 -        case mir_motion_action_hover_move:
   4.233 -        case mir_motion_action_move:
   4.234 -            HandleMouseMotion(sdl_window,
   4.235 -                              motion.pointer_coordinates[cord_index].x,
   4.236 -                              motion.pointer_coordinates[cord_index].y);
   4.237 -            break;
   4.238 -        case mir_motion_action_outside:
   4.239 -            SDL_SetMouseFocus(NULL);
   4.240 -            break;
   4.241 -        case mir_motion_action_scroll:
   4.242 -            HandleMouseScroll(sdl_window,
   4.243 -                              motion.pointer_coordinates[cord_index].hscroll,
   4.244 -                              motion.pointer_coordinates[cord_index].vscroll);
   4.245 -            break;
   4.246 -        case mir_motion_action_cancel:
   4.247 -        case mir_motion_action_hover_enter:
   4.248 -        case mir_motion_action_hover_exit:
   4.249 -            break;
   4.250 -        default:
   4.251 -            break;
   4.252 -    }
   4.253 -}
   4.254 +    int old_w = window->w;
   4.255 +    int old_h = window->h;
   4.256  
   4.257 -static void
   4.258 -HandleMotionEvent(MirMotionEvent const motion, SDL_Window* sdl_window)
   4.259 -{
   4.260 -    int cord_index;
   4.261 -    for (cord_index = 0; cord_index < motion.pointer_count; cord_index++) {
   4.262 -        if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_finger) {
   4.263 -            HandleTouchEvent(motion, cord_index, sdl_window);
   4.264 -        }
   4.265 -        else {
   4.266 -            HandleMouseEvent(motion, cord_index, sdl_window);
   4.267 -        }
   4.268 -    }
   4.269 +    if (new_w != old_w || new_h != old_h)
   4.270 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, new_w, new_h);
   4.271  }
   4.272  
   4.273  void
   4.274 -MIR_HandleInput(MirSurface* surface, MirEvent const* ev, void* context)
   4.275 +MIR_HandleEvent(MirSurface* surface, MirEvent const* ev, void* context)
   4.276  {
   4.277 -    SDL_Window* window = (SDL_Window*)context;
   4.278 -    switch (ev->type) {
   4.279 -        case (mir_event_type_key):
   4.280 -            HandleKeyEvent(ev->key, window);
   4.281 -            break;
   4.282 -        case (mir_event_type_motion):
   4.283 -            HandleMotionEvent(ev->motion, window);
   4.284 -            break;
   4.285 -        default:
   4.286 -            break;
   4.287 +    MirEventType event_type = MIR_mir_event_get_type(ev);
   4.288 +    SDL_Window* window      = (SDL_Window*)context;
   4.289 +
   4.290 +    if (window) {
   4.291 +        switch (event_type) {
   4.292 +            case (mir_event_type_input):
   4.293 +                MIR_HandleInput(MIR_mir_event_get_input_event(ev), window);
   4.294 +                break;
   4.295 +            case (mir_event_type_resize):
   4.296 +                MIR_HandleResize(MIR_mir_event_get_resize_event(ev), window);
   4.297 +                break;
   4.298 +            default:
   4.299 +                break;
   4.300 +        }
   4.301      }
   4.302  }
   4.303  
     5.1 --- a/src/video/mir/SDL_mirevents.h	Sun Feb 21 17:21:29 2016 -0500
     5.2 +++ b/src/video/mir/SDL_mirevents.h	Sun Feb 21 15:19:35 2016 -0800
     5.3 @@ -29,7 +29,7 @@
     5.4  #include <mir_toolkit/mir_client_library.h>
     5.5  
     5.6  extern void
     5.7 -MIR_HandleInput(MirSurface* surface, MirEvent const* ev, void* context);
     5.8 +MIR_HandleEvent(MirSurface* surface, MirEvent const* ev, void* context);
     5.9  
    5.10  #endif /* _SDL_mirevents_h */
    5.11  
     6.1 --- a/src/video/mir/SDL_mirframebuffer.c	Sun Feb 21 17:21:29 2016 -0500
     6.2 +++ b/src/video/mir/SDL_mirframebuffer.c	Sun Feb 21 15:19:35 2016 -0800
     6.3 @@ -39,7 +39,11 @@
     6.4      SDL_PIXELFORMAT_BGR888,   /* mir_pixel_format_xbgr_8888 */
     6.5      SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
     6.6      SDL_PIXELFORMAT_RGB888,   /* mir_pixel_format_xrgb_8888 */
     6.7 -    SDL_PIXELFORMAT_BGR24     /* mir_pixel_format_bgr_888   */
     6.8 +    SDL_PIXELFORMAT_BGR24,    /* mir_pixel_format_bgr_888   */
     6.9 +    SDL_PIXELFORMAT_RGB24,    /* mir_pixel_format_rgb_888   */
    6.10 +    SDL_PIXELFORMAT_RGB565,   /* mir_pixel_format_rgb_565   */
    6.11 +    SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
    6.12 +    SDL_PIXELFORMAT_RGBA4444  /* mir_pixel_format_rgba_4444 */
    6.13  };
    6.14  
    6.15  Uint32
    6.16 @@ -53,19 +57,13 @@
    6.17                              void** pixels, int* pitch)
    6.18  {
    6.19      MIR_Data* mir_data = _this->driverdata;
    6.20 -    MIR_Window* mir_window;
    6.21 -    MirSurfaceParameters surfaceparm;
    6.22  
    6.23      mir_data->software = SDL_TRUE;
    6.24  
    6.25      if (MIR_CreateWindow(_this, window) < 0)
    6.26          return SDL_SetError("Failed to created a mir window.");
    6.27  
    6.28 -    mir_window = window->driverdata;
    6.29 -
    6.30 -    MIR_mir_surface_get_parameters(mir_window->surface, &surfaceparm);
    6.31 -
    6.32 -    *format = MIR_GetSDLPixelFormat(surfaceparm.pixel_format);
    6.33 +    *format = MIR_GetSDLPixelFormat(mir_data->pixel_format);
    6.34      if (*format == SDL_PIXELFORMAT_UNKNOWN)
    6.35          return SDL_SetError("Unknown pixel format");
    6.36  
    6.37 @@ -75,12 +73,6 @@
    6.38      if (*pixels == NULL)
    6.39          return SDL_OutOfMemory();
    6.40  
    6.41 -    mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
    6.42 -    if (!MIR_mir_surface_is_valid(mir_window->surface)) {
    6.43 -        const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
    6.44 -        return SDL_SetError("Failed to created a mir surface: %s", error);
    6.45 -    }
    6.46 -
    6.47      return 0;
    6.48  }
    6.49  
    6.50 @@ -91,12 +83,14 @@
    6.51      MIR_Window* mir_window = window->driverdata;
    6.52  
    6.53      MirGraphicsRegion region;
    6.54 +    MirBufferStream* bs;
    6.55      int i, j, x, y, w, h, start;
    6.56      int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
    6.57      char* s_dest;
    6.58      char* pixels;
    6.59  
    6.60 -    MIR_mir_surface_get_graphics_region(mir_window->surface, &region);
    6.61 +    bs = MIR_mir_surface_get_buffer_stream(mir_window->surface);
    6.62 +    MIR_mir_buffer_stream_get_graphics_region(bs, &region);
    6.63  
    6.64      s_dest = region.vaddr;
    6.65      pixels = (char*)window->surface->pixels;
    6.66 @@ -144,7 +138,7 @@
    6.67          }
    6.68      }
    6.69  
    6.70 -    MIR_mir_surface_swap_buffers_sync(mir_window->surface);
    6.71 +    MIR_mir_buffer_stream_swap_buffers_sync(bs);
    6.72  
    6.73      return 0;
    6.74  }
     7.1 --- a/src/video/mir/SDL_mirmouse.c	Sun Feb 21 17:21:29 2016 -0500
     7.2 +++ b/src/video/mir/SDL_mirmouse.c	Sun Feb 21 15:19:35 2016 -0800
     7.3 @@ -27,13 +27,22 @@
     7.4  
     7.5  #if SDL_VIDEO_DRIVER_MIR
     7.6  
     7.7 -#include "SDL_mirmouse.h"
     7.8 -
     7.9  #include "../../events/SDL_mouse_c.h"
    7.10 +#include "../SDL_sysvideo.h"
    7.11  #include "SDL_assert.h"
    7.12  
    7.13  #include "SDL_mirdyn.h"
    7.14  
    7.15 +#include "SDL_mirvideo.h"
    7.16 +#include "SDL_mirmouse.h"
    7.17 +#include "SDL_mirwindow.h"
    7.18 +
    7.19 +typedef struct
    7.20 +{
    7.21 +    MirCursorConfiguration* conf;
    7.22 +    MirBufferStream*        stream;
    7.23 +} MIR_Cursor;
    7.24 +
    7.25  static SDL_Cursor*
    7.26  MIR_CreateDefaultCursor()
    7.27  {
    7.28 @@ -41,6 +50,16 @@
    7.29  
    7.30      cursor = SDL_calloc(1, sizeof(SDL_Cursor));
    7.31      if (cursor) {
    7.32 +
    7.33 +        MIR_Cursor* mir_cursor = SDL_calloc(1, sizeof(MIR_Cursor));
    7.34 +        if (mir_cursor) {
    7.35 +            mir_cursor->conf   = NULL;
    7.36 +            mir_cursor->stream = NULL;
    7.37 +            cursor->driverdata = mir_cursor;
    7.38 +        }
    7.39 +        else {
    7.40 +            SDL_OutOfMemory();
    7.41 +        }
    7.42      }
    7.43      else {
    7.44          SDL_OutOfMemory();
    7.45 @@ -49,58 +68,160 @@
    7.46      return cursor;
    7.47  }
    7.48  
    7.49 +static void
    7.50 +CopySurfacePixelsToMirStream(SDL_Surface* surface, MirBufferStream* stream)
    7.51 +{
    7.52 +    char* dest, *pixels;
    7.53 +    int i, s_w, s_h, r_stride, p_stride, bytes_per_pixel, bytes_per_row;
    7.54 +
    7.55 +    MirGraphicsRegion region;
    7.56 +    MIR_mir_buffer_stream_get_graphics_region(stream, &region);
    7.57 +
    7.58 +    s_w = surface->w;
    7.59 +    s_h = surface->h;
    7.60 +
    7.61 +    bytes_per_pixel = surface->format->BytesPerPixel;
    7.62 +    bytes_per_row   = bytes_per_pixel * s_w;
    7.63 +
    7.64 +    dest = region.vaddr;
    7.65 +    pixels = (char*)surface->pixels;
    7.66 +
    7.67 +    r_stride = region.stride;
    7.68 +    p_stride = surface->pitch;
    7.69 +
    7.70 +    for (i = 0; i < s_h; i++)
    7.71 +    {
    7.72 +        memcpy(dest, pixels, bytes_per_row);
    7.73 +        dest   += r_stride;
    7.74 +        pixels += p_stride;
    7.75 +    }
    7.76 +}
    7.77 +
    7.78  static SDL_Cursor*
    7.79 -MIR_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
    7.80 +MIR_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
    7.81  {
    7.82 -    return MIR_CreateDefaultCursor();
    7.83 +    MirCursorConfiguration* conf;
    7.84 +    MirBufferStream*        stream;
    7.85 +
    7.86 +    int s_w = surface->w;
    7.87 +    int s_h = surface->h;
    7.88 +
    7.89 +    MIR_Data* mir_data     = (MIR_Data*)SDL_GetVideoDevice()->driverdata;
    7.90 +    SDL_Cursor* cursor     = MIR_CreateDefaultCursor();
    7.91 +    MIR_Cursor* mir_cursor = (MIR_Cursor*)cursor->driverdata;
    7.92 +
    7.93 +    stream = MIR_mir_connection_create_buffer_stream_sync(mir_data->connection,
    7.94 +                                                          s_w, s_h, mir_data->pixel_format,
    7.95 +                                                          mir_buffer_usage_software);
    7.96 +
    7.97 +    conf = MIR_mir_cursor_configuration_from_buffer_stream(stream, hot_x, hot_y);
    7.98 +
    7.99 +    CopySurfacePixelsToMirStream(surface, stream);
   7.100 +    MIR_mir_buffer_stream_swap_buffers_sync(stream);
   7.101 +
   7.102 +    mir_cursor->conf   = conf;
   7.103 +    mir_cursor->stream = stream;
   7.104 +
   7.105 +    return cursor;
   7.106  }
   7.107  
   7.108  static SDL_Cursor*
   7.109  MIR_CreateSystemCursor(SDL_SystemCursor id)
   7.110  {
   7.111 +    char const* cursor_name = NULL;
   7.112 +    MirCursorConfiguration* conf;
   7.113 +    SDL_Cursor* cursor = MIR_CreateDefaultCursor();
   7.114 +
   7.115      switch(id) {
   7.116          case SDL_SYSTEM_CURSOR_ARROW:
   7.117 +            cursor_name = MIR_mir_arrow_cursor_name;
   7.118              break;
   7.119          case SDL_SYSTEM_CURSOR_IBEAM:
   7.120 +            cursor_name = MIR_mir_caret_cursor_name;
   7.121              break;
   7.122          case SDL_SYSTEM_CURSOR_WAIT:
   7.123 +            cursor_name = MIR_mir_busy_cursor_name;
   7.124              break;
   7.125          case SDL_SYSTEM_CURSOR_CROSSHAIR:
   7.126 +            /* Unsupported */
   7.127 +            cursor_name = MIR_mir_arrow_cursor_name;
   7.128              break;
   7.129          case SDL_SYSTEM_CURSOR_WAITARROW:
   7.130 +            cursor_name = MIR_mir_busy_cursor_name;
   7.131              break;
   7.132          case SDL_SYSTEM_CURSOR_SIZENWSE:
   7.133 +            cursor_name = MIR_mir_omnidirectional_resize_cursor_name;
   7.134              break;
   7.135          case SDL_SYSTEM_CURSOR_SIZENESW:
   7.136 +            cursor_name = MIR_mir_omnidirectional_resize_cursor_name;
   7.137              break;
   7.138          case SDL_SYSTEM_CURSOR_SIZEWE:
   7.139 +            cursor_name = MIR_mir_horizontal_resize_cursor_name;
   7.140              break;
   7.141          case SDL_SYSTEM_CURSOR_SIZENS:
   7.142 +            cursor_name = MIR_mir_vertical_resize_cursor_name;
   7.143              break;
   7.144          case SDL_SYSTEM_CURSOR_SIZEALL:
   7.145 +            cursor_name = MIR_mir_omnidirectional_resize_cursor_name;
   7.146              break;
   7.147          case SDL_SYSTEM_CURSOR_NO:
   7.148 +            /* Unsupported */
   7.149 +            cursor_name = MIR_mir_closed_hand_cursor_name;
   7.150              break;
   7.151          case SDL_SYSTEM_CURSOR_HAND:
   7.152 +            cursor_name = MIR_mir_open_hand_cursor_name;
   7.153              break;
   7.154          default:
   7.155              SDL_assert(0);
   7.156              return NULL;
   7.157      }
   7.158  
   7.159 -    return MIR_CreateDefaultCursor();
   7.160 +    conf = MIR_mir_cursor_configuration_from_name(cursor_name);
   7.161 +
   7.162 +    cursor->driverdata = conf;
   7.163 +
   7.164 +    return cursor;
   7.165  }
   7.166  
   7.167  static void
   7.168  MIR_FreeCursor(SDL_Cursor* cursor)
   7.169  {
   7.170 -    if (cursor)
   7.171 -      SDL_free(cursor);
   7.172 +    if (cursor) {
   7.173 +
   7.174 +        if (cursor->driverdata) {
   7.175 +            MIR_Cursor* mir_cursor = (MIR_Cursor*)cursor->driverdata;
   7.176 +
   7.177 +            if (mir_cursor->conf)
   7.178 +                MIR_mir_cursor_configuration_destroy(mir_cursor->conf);
   7.179 +            if (mir_cursor->stream)
   7.180 +                MIR_mir_buffer_stream_release_sync(mir_cursor->stream);
   7.181 +
   7.182 +            SDL_free(mir_cursor);
   7.183 +        }
   7.184 +
   7.185 +        SDL_free(cursor);
   7.186 +    }
   7.187  }
   7.188  
   7.189  static int
   7.190  MIR_ShowCursor(SDL_Cursor* cursor)
   7.191  {
   7.192 +    MIR_Data* mir_data      = (MIR_Data*)SDL_GetVideoDevice()->driverdata;
   7.193 +    MIR_Window* mir_window  = mir_data->current_window;
   7.194 +
   7.195 +    if (cursor && cursor->driverdata) {
   7.196 +        if (mir_window && MIR_mir_surface_is_valid(mir_window->surface)) {
   7.197 +            MIR_Cursor* mir_cursor = (MIR_Cursor*)cursor->driverdata;
   7.198 +
   7.199 +            if (mir_cursor->conf) {
   7.200 +                MIR_mir_wait_for(MIR_mir_surface_configure_cursor(mir_window->surface, mir_cursor->conf));
   7.201 +            }
   7.202 +        }
   7.203 +    }
   7.204 +    else if(mir_window && MIR_mir_surface_is_valid(mir_window->surface)) {
   7.205 +        MIR_mir_wait_for(MIR_mir_surface_configure_cursor(mir_window->surface, NULL));
   7.206 +    }
   7.207 +    
   7.208      return 0;
   7.209  }
   7.210  
     8.1 --- a/src/video/mir/SDL_mirsym.h	Sun Feb 21 17:21:29 2016 -0500
     8.2 +++ b/src/video/mir/SDL_mirsym.h	Sun Feb 21 15:19:35 2016 -0800
     8.3 @@ -29,31 +29,87 @@
     8.4  #define SDL_MIR_SYM(rc,fn,params)
     8.5  #endif
     8.6  
     8.7 +#ifndef SDL_MIR_SYM_CONST
     8.8 +#define SDL_MIR_SYM_CONST(type, name)
     8.9 +#endif
    8.10 +
    8.11  SDL_MIR_MODULE(MIR_CLIENT)
    8.12  SDL_MIR_SYM(MirDisplayConfiguration*,mir_connection_create_display_config,(MirConnection *connection))
    8.13 -SDL_MIR_SYM(MirSurface *,mir_connection_create_surface_sync,(MirConnection *connection, MirSurfaceParameters const *params))
    8.14 +SDL_MIR_SYM(MirSurface *,mir_surface_create_sync,(MirSurfaceSpec* spec))
    8.15 +SDL_MIR_SYM(MirEGLNativeWindowType,mir_buffer_stream_get_egl_native_window,(MirBufferStream *surface))
    8.16 +SDL_MIR_SYM(void,mir_buffer_stream_get_graphics_region,(MirBufferStream *stream, MirGraphicsRegion *graphics_region))
    8.17 +SDL_MIR_SYM(void,mir_buffer_stream_swap_buffers_sync,(MirBufferStream *stream))
    8.18 +SDL_MIR_SYM(void,mir_surface_set_event_handler,(MirSurface *surface, mir_surface_event_callback callback, void* context))
    8.19 +SDL_MIR_SYM(MirSurfaceSpec*,mir_connection_create_spec_for_normal_surface,(MirConnection *connection, int width, int height, MirPixelFormat format))
    8.20 +SDL_MIR_SYM(MirSurfaceSpec*,mir_connection_create_spec_for_changes,(MirConnection *connection))
    8.21 +SDL_MIR_SYM(void,mir_surface_spec_set_buffer_usage,(MirSurfaceSpec *spec, MirBufferUsage usage))
    8.22 +SDL_MIR_SYM(void,mir_surface_spec_set_name,(MirSurfaceSpec *spec, char const *name))
    8.23 +SDL_MIR_SYM(void,mir_surface_spec_release,(MirSurfaceSpec *spec))
    8.24 +SDL_MIR_SYM(void,mir_surface_spec_set_width,(MirSurfaceSpec *spec, unsigned width))
    8.25 +SDL_MIR_SYM(void,mir_surface_spec_set_height,(MirSurfaceSpec *spec, unsigned height))
    8.26 +SDL_MIR_SYM(void,mir_surface_spec_set_min_width,(MirSurfaceSpec *spec, unsigned min_width))
    8.27 +SDL_MIR_SYM(void,mir_surface_spec_set_min_height,(MirSurfaceSpec *spec, unsigned min_height))
    8.28 +SDL_MIR_SYM(void,mir_surface_spec_set_max_width,(MirSurfaceSpec *spec, unsigned max_width))
    8.29 +SDL_MIR_SYM(void,mir_surface_spec_set_max_height,(MirSurfaceSpec *spec, unsigned max_height))
    8.30 +SDL_MIR_SYM(void,mir_surface_spec_set_type,(MirSurfaceSpec *spec, MirSurfaceType type))
    8.31 +SDL_MIR_SYM(void,mir_surface_spec_set_state,(MirSurfaceSpec *spec, MirSurfaceState state))
    8.32 +SDL_MIR_SYM(void,mir_surface_apply_spec,(MirSurface *surface, MirSurfaceSpec *spec))
    8.33 +SDL_MIR_SYM(void,mir_surface_get_parameters,(MirSurface *surface, MirSurfaceParameters *params))
    8.34 +SDL_MIR_SYM(MirBufferStream*,mir_surface_get_buffer_stream,(MirSurface *surface))
    8.35 +SDL_MIR_SYM(MirCursorConfiguration*,mir_cursor_configuration_from_buffer_stream,(MirBufferStream* stream, int hot_x, int hot_y))
    8.36 +SDL_MIR_SYM(MirBufferStream*,mir_connection_create_buffer_stream_sync,(MirConnection *connection, int w, int h, MirPixelFormat format, MirBufferUsage usage))
    8.37 +SDL_MIR_SYM(MirKeyboardAction,mir_keyboard_event_action,(MirKeyboardEvent const *event))
    8.38 +SDL_MIR_SYM(xkb_keysym_t,mir_keyboard_event_key_code,(MirKeyboardEvent const *event))
    8.39 +SDL_MIR_SYM(int,mir_keyboard_event_scan_code,(MirKeyboardEvent const *event))
    8.40 +SDL_MIR_SYM(bool,mir_pointer_event_button_state,(MirPointerEvent const *event, MirPointerButton button))
    8.41 +SDL_MIR_SYM(MirPointerButtons,mir_pointer_event_buttons,(MirPointerEvent const *event))
    8.42 +SDL_MIR_SYM(MirInputDeviceId,mir_input_event_get_device_id,(MirInputEvent const* ev))
    8.43 +SDL_MIR_SYM(MirTouchId,mir_touch_event_id,(MirTouchEvent const *event, size_t touch_index))
    8.44 +SDL_MIR_SYM(float,mir_touch_event_axis_value,(MirTouchEvent const *event, size_t touch_index, MirTouchAxis axis))
    8.45 +SDL_MIR_SYM(MirTouchAction,mir_touch_event_action,(MirTouchEvent const *event, size_t touch_index))
    8.46 +SDL_MIR_SYM(MirPointerAction,mir_pointer_event_action,(MirPointerEvent const *event))
    8.47 +SDL_MIR_SYM(float,mir_pointer_event_axis_value,(MirPointerEvent const *event, MirPointerAxis))
    8.48 +SDL_MIR_SYM(MirEventType,mir_event_get_type,(MirEvent const *event))
    8.49 +SDL_MIR_SYM(MirInputEventType,mir_input_event_get_type,(MirInputEvent const *event))
    8.50 +SDL_MIR_SYM(MirInputEvent const*,mir_event_get_input_event,(MirEvent const *event))
    8.51 +SDL_MIR_SYM(MirResizeEvent const*,mir_event_get_resize_event,(MirEvent const *event))
    8.52 +SDL_MIR_SYM(MirKeyboardEvent const*,mir_input_event_get_keyboard_event,(MirInputEvent const *event))
    8.53 +SDL_MIR_SYM(MirPointerEvent const*,mir_input_event_get_pointer_event,(MirInputEvent const *event))
    8.54 +SDL_MIR_SYM(MirTouchEvent const*,mir_input_event_get_touch_event,(MirInputEvent const *event))
    8.55 +SDL_MIR_SYM(unsigned int,mir_touch_event_point_count,(MirTouchEvent const *event))
    8.56  SDL_MIR_SYM(void,mir_connection_get_available_surface_formats,(MirConnection* connection, MirPixelFormat* formats, unsigned const int format_size, unsigned int *num_valid_formats))
    8.57  SDL_MIR_SYM(MirEGLNativeDisplayType,mir_connection_get_egl_native_display,(MirConnection *connection))
    8.58 -SDL_MIR_SYM(MirBool,mir_connection_is_valid,(MirConnection *connection))
    8.59 +SDL_MIR_SYM(bool,mir_connection_is_valid,(MirConnection *connection))
    8.60  SDL_MIR_SYM(void,mir_connection_release,(MirConnection *connection))
    8.61 +SDL_MIR_SYM(MirPixelFormat,mir_connection_get_egl_pixel_format,(MirConnection* connection, void* egldisplay, void* eglconfig))
    8.62  SDL_MIR_SYM(MirConnection *,mir_connect_sync,(char const *server, char const *app_name))
    8.63  SDL_MIR_SYM(void,mir_display_config_destroy,(MirDisplayConfiguration* display_configuration))
    8.64 -SDL_MIR_SYM(MirEGLNativeWindowType,mir_surface_get_egl_native_window,(MirSurface *surface))
    8.65  SDL_MIR_SYM(char const *,mir_surface_get_error_message,(MirSurface *surface))
    8.66 -SDL_MIR_SYM(void,mir_surface_get_graphics_region,(MirSurface *surface, MirGraphicsRegion *graphics_region))
    8.67 -SDL_MIR_SYM(void,mir_surface_get_parameters,(MirSurface *surface, MirSurfaceParameters *parameters))
    8.68 -SDL_MIR_SYM(MirBool,mir_surface_is_valid,(MirSurface *surface))
    8.69 +SDL_MIR_SYM(bool,mir_surface_is_valid,(MirSurface *surface))
    8.70  SDL_MIR_SYM(void,mir_surface_release_sync,(MirSurface *surface))
    8.71 -SDL_MIR_SYM(void,mir_surface_set_event_handler,(MirSurface *surface, MirEventDelegate const *event_handler))
    8.72 -SDL_MIR_SYM(MirWaitHandle*,mir_surface_set_type,(MirSurface *surface, MirSurfaceType type))
    8.73 -SDL_MIR_SYM(MirWaitHandle*,mir_surface_set_state,(MirSurface *surface, MirSurfaceState state))
    8.74 -SDL_MIR_SYM(void,mir_surface_swap_buffers_sync,(MirSurface *surface))
    8.75 +SDL_MIR_SYM(void,mir_buffer_stream_release_sync,(MirBufferStream *stream))
    8.76 +SDL_MIR_SYM(MirCursorConfiguration*,mir_cursor_configuration_from_name,(char const* cursor_name))
    8.77 +SDL_MIR_SYM(MirWaitHandle*,mir_surface_configure_cursor,(MirSurface* surface, MirCursorConfiguration const* conf))
    8.78 +SDL_MIR_SYM(void,mir_cursor_configuration_destroy,(MirCursorConfiguration* conf))
    8.79 +SDL_MIR_SYM(void,mir_wait_for,(MirWaitHandle* handle))
    8.80 +SDL_MIR_SYM(int,mir_resize_event_get_width,(MirResizeEvent const* resize_event))
    8.81 +SDL_MIR_SYM(int,mir_resize_event_get_height,(MirResizeEvent const* resize_event))
    8.82 +
    8.83 +SDL_MIR_SYM_CONST(char const*,mir_omnidirectional_resize_cursor_name)
    8.84 +SDL_MIR_SYM_CONST(char const*,mir_busy_cursor_name)
    8.85 +SDL_MIR_SYM_CONST(char const*,mir_arrow_cursor_name)
    8.86 +SDL_MIR_SYM_CONST(char const*,mir_caret_cursor_name)
    8.87 +SDL_MIR_SYM_CONST(char const*,mir_vertical_resize_cursor_name)
    8.88 +SDL_MIR_SYM_CONST(char const*,mir_horizontal_resize_cursor_name)
    8.89 +SDL_MIR_SYM_CONST(char const*,mir_open_hand_cursor_name)
    8.90 +SDL_MIR_SYM_CONST(char const*,mir_closed_hand_cursor_name)
    8.91  
    8.92  SDL_MIR_MODULE(XKBCOMMON)
    8.93  SDL_MIR_SYM(int,xkb_keysym_to_utf8,(xkb_keysym_t keysym, char *buffer, size_t size))
    8.94  
    8.95  #undef SDL_MIR_MODULE
    8.96  #undef SDL_MIR_SYM
    8.97 +#undef SDL_MIR_SYM_CONST
    8.98  
    8.99  /* *INDENT-ON* */
   8.100  
     9.1 --- a/src/video/mir/SDL_mirvideo.c	Sun Feb 21 17:21:29 2016 -0500
     9.2 +++ b/src/video/mir/SDL_mirvideo.c	Sun Feb 21 15:19:35 2016 -0800
     9.3 @@ -27,13 +27,13 @@
     9.4  
     9.5  #if SDL_VIDEO_DRIVER_MIR
     9.6  
     9.7 +#include "SDL_mirwindow.h"
     9.8  #include "SDL_video.h"
     9.9  
    9.10  #include "SDL_mirframebuffer.h"
    9.11  #include "SDL_mirmouse.h"
    9.12  #include "SDL_miropengl.h"
    9.13  #include "SDL_mirvideo.h"
    9.14 -#include "SDL_mirwindow.h"
    9.15  
    9.16  #include "SDL_mirdyn.h"
    9.17  
    9.18 @@ -146,29 +146,29 @@
    9.19      device->GL_GetProcAddress  = MIR_GL_GetProcAddress;
    9.20  
    9.21      /* mirwindow */
    9.22 -    device->CreateWindow        = MIR_CreateWindow;
    9.23 -    device->DestroyWindow       = MIR_DestroyWindow;
    9.24 -    device->GetWindowWMInfo     = MIR_GetWindowWMInfo;
    9.25 -    device->SetWindowFullscreen = MIR_SetWindowFullscreen;
    9.26 -    device->MaximizeWindow      = MIR_MaximizeWindow;
    9.27 -    device->MinimizeWindow      = MIR_MinimizeWindow;
    9.28 -    device->RestoreWindow       = MIR_RestoreWindow;
    9.29 +    device->CreateWindow         = MIR_CreateWindow;
    9.30 +    device->DestroyWindow        = MIR_DestroyWindow;
    9.31 +    device->GetWindowWMInfo      = MIR_GetWindowWMInfo;
    9.32 +    device->SetWindowFullscreen  = MIR_SetWindowFullscreen;
    9.33 +    device->MaximizeWindow       = MIR_MaximizeWindow;
    9.34 +    device->MinimizeWindow       = MIR_MinimizeWindow;
    9.35 +    device->RestoreWindow        = MIR_RestoreWindow;
    9.36 +    device->ShowWindow           = MIR_RestoreWindow;
    9.37 +    device->HideWindow           = MIR_HideWindow;
    9.38 +    device->SetWindowSize        = MIR_SetWindowSize;
    9.39 +    device->SetWindowMinimumSize = MIR_SetWindowMinimumSize;
    9.40 +    device->SetWindowMaximumSize = MIR_SetWindowMaximumSize;
    9.41 +    device->SetWindowTitle       = MIR_SetWindowTitle;
    9.42  
    9.43      device->CreateWindowFrom     = NULL;
    9.44 -    device->SetWindowTitle       = NULL;
    9.45      device->SetWindowIcon        = NULL;
    9.46 -    device->SetWindowPosition    = NULL;
    9.47 -    device->SetWindowSize        = NULL;
    9.48 -    device->SetWindowMinimumSize = NULL;
    9.49 -    device->SetWindowMaximumSize = NULL;
    9.50 -    device->ShowWindow           = NULL;
    9.51 -    device->HideWindow           = NULL;
    9.52      device->RaiseWindow          = NULL;
    9.53      device->SetWindowBordered    = NULL;
    9.54      device->SetWindowGammaRamp   = NULL;
    9.55      device->GetWindowGammaRamp   = NULL;
    9.56      device->SetWindowGrab        = NULL;
    9.57      device->OnWindowEnter        = NULL;
    9.58 +    device->SetWindowPosition    = NULL;
    9.59  
    9.60      /* mirframebuffer */
    9.61      device->CreateWindowFramebuffer  = MIR_CreateWindowFramebuffer;
    9.62 @@ -272,8 +272,10 @@
    9.63  {
    9.64      MIR_Data* mir_data = _this->driverdata;
    9.65  
    9.66 -    mir_data->connection = MIR_mir_connect_sync(NULL, __PRETTY_FUNCTION__);
    9.67 -    mir_data->software = SDL_FALSE;
    9.68 +    mir_data->connection     = MIR_mir_connect_sync(NULL, __PRETTY_FUNCTION__);
    9.69 +    mir_data->current_window = NULL;
    9.70 +    mir_data->software       = SDL_FALSE;
    9.71 +    mir_data->pixel_format   = mir_pixel_format_invalid;
    9.72  
    9.73      if (!MIR_mir_connection_is_valid(mir_data->connection))
    9.74          return SDL_SetError("Failed to connect to the Mir Server");
    10.1 --- a/src/video/mir/SDL_mirvideo.h	Sun Feb 21 17:21:29 2016 -0500
    10.2 +++ b/src/video/mir/SDL_mirvideo.h	Sun Feb 21 15:19:35 2016 -0800
    10.3 @@ -29,11 +29,14 @@
    10.4  #include <EGL/egl.h>
    10.5  #include <mir_toolkit/mir_client_library.h>
    10.6  
    10.7 +typedef struct MIR_Window MIR_Window;
    10.8 +
    10.9  typedef struct
   10.10  {
   10.11      MirConnection* connection;
   10.12 -    SDL_bool software;
   10.13 -    
   10.14 +    MIR_Window*    current_window;
   10.15 +    SDL_bool       software;
   10.16 +    MirPixelFormat pixel_format;
   10.17  } MIR_Data;
   10.18  
   10.19  #endif /* _SDL_mirvideo_h_ */
    11.1 --- a/src/video/mir/SDL_mirwindow.c	Sun Feb 21 17:21:29 2016 -0500
    11.2 +++ b/src/video/mir/SDL_mirwindow.c	Sun Feb 21 15:19:35 2016 -0800
    11.3 @@ -46,52 +46,15 @@
    11.4      return 0;
    11.5  }
    11.6  
    11.7 -MirPixelFormat
    11.8 -FindValidPixelFormat(MIR_Data* mir_data)
    11.9 -{
   11.10 -    unsigned int pf_size = 32;
   11.11 -    unsigned int valid_formats;
   11.12 -    unsigned int f;
   11.13 -
   11.14 -    MirPixelFormat formats[pf_size];
   11.15 -    MIR_mir_connection_get_available_surface_formats(mir_data->connection, formats,
   11.16 -                                                 pf_size, &valid_formats);
   11.17 -
   11.18 -    for (f = 0; f < valid_formats; f++) {
   11.19 -        MirPixelFormat cur_pf = formats[f];
   11.20 -
   11.21 -        if (cur_pf == mir_pixel_format_abgr_8888 ||
   11.22 -            cur_pf == mir_pixel_format_xbgr_8888 ||
   11.23 -            cur_pf == mir_pixel_format_argb_8888 ||
   11.24 -            cur_pf == mir_pixel_format_xrgb_8888) {
   11.25 -
   11.26 -            return cur_pf;
   11.27 -        }
   11.28 -    }
   11.29 -
   11.30 -    return mir_pixel_format_invalid;
   11.31 -}
   11.32 -
   11.33  int
   11.34  MIR_CreateWindow(_THIS, SDL_Window* window)
   11.35  {
   11.36      MIR_Window* mir_window;
   11.37      MIR_Data* mir_data;
   11.38 +    MirPixelFormat pixel_format;
   11.39 +    MirBufferUsage buffer_usage;
   11.40  
   11.41 -    MirSurfaceParameters surfaceparm =
   11.42 -    {
   11.43 -        .name = "MirSurface",
   11.44 -        .width = window->w,
   11.45 -        .height = window->h,
   11.46 -        .pixel_format = mir_pixel_format_invalid,
   11.47 -        .buffer_usage = mir_buffer_usage_hardware,
   11.48 -        .output_id = mir_display_output_id_invalid
   11.49 -    };
   11.50 -
   11.51 -    MirEventDelegate delegate = {
   11.52 -        MIR_HandleInput,
   11.53 -        window
   11.54 -    };
   11.55 +    MirSurfaceSpec* spec;
   11.56  
   11.57      mir_window = SDL_calloc(1, sizeof(MIR_Window));
   11.58      if (!mir_window)
   11.59 @@ -100,9 +63,6 @@
   11.60      mir_data = _this->driverdata;
   11.61      window->driverdata = mir_window;
   11.62  
   11.63 -    if (mir_data->software)
   11.64 -        surfaceparm.buffer_usage = mir_buffer_usage_software;
   11.65 -
   11.66      if (window->x == SDL_WINDOWPOS_UNDEFINED)
   11.67          window->x = 0;
   11.68  
   11.69 @@ -112,12 +72,32 @@
   11.70      mir_window->mir_data = mir_data;
   11.71      mir_window->sdl_window = window;
   11.72  
   11.73 -    surfaceparm.pixel_format = FindValidPixelFormat(mir_data);
   11.74 -    if (surfaceparm.pixel_format == mir_pixel_format_invalid) {
   11.75 +    pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
   11.76 +                                                           _this->egl_data->egl_display,
   11.77 +                                                           _this->egl_data->egl_config);
   11.78 +
   11.79 +    mir_data->pixel_format = pixel_format;
   11.80 +    if (pixel_format == mir_pixel_format_invalid) {
   11.81          return SDL_SetError("Failed to find a valid pixel format.");
   11.82      }
   11.83  
   11.84 -    mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
   11.85 +    buffer_usage = mir_buffer_usage_hardware;
   11.86 +    if (mir_data->software)
   11.87 +        buffer_usage = mir_buffer_usage_software;
   11.88 +
   11.89 +    spec = MIR_mir_connection_create_spec_for_normal_surface(mir_data->connection,
   11.90 +                                                             window->w,
   11.91 +                                                             window->h,
   11.92 +                                                             pixel_format);
   11.93 +
   11.94 +    MIR_mir_surface_spec_set_buffer_usage(spec, buffer_usage);
   11.95 +    MIR_mir_surface_spec_set_name(spec, "Mir surface");
   11.96 +
   11.97 +    mir_window->surface = MIR_mir_surface_create_sync(spec);
   11.98 +    MIR_mir_surface_set_event_handler(mir_window->surface, MIR_HandleEvent, window);
   11.99 +
  11.100 +    MIR_mir_surface_spec_release(spec);
  11.101 +
  11.102      if (!MIR_mir_surface_is_valid(mir_window->surface)) {
  11.103          const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
  11.104          return SDL_SetError("Failed to created a mir surface: %s", error);
  11.105 @@ -125,7 +105,8 @@
  11.106  
  11.107      if (window->flags & SDL_WINDOW_OPENGL) {
  11.108          EGLNativeWindowType egl_native_window =
  11.109 -                        (EGLNativeWindowType)MIR_mir_surface_get_egl_native_window(mir_window->surface);
  11.110 +                        (EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
  11.111 +                                                       MIR_mir_surface_get_buffer_stream(mir_window->surface));
  11.112  
  11.113          mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);
  11.114  
  11.115 @@ -138,7 +119,7 @@
  11.116          mir_window->egl_surface = EGL_NO_SURFACE;
  11.117      }
  11.118  
  11.119 -    MIR_mir_surface_set_event_handler(mir_window->surface, &delegate);
  11.120 +    mir_data->current_window = mir_window;
  11.121  
  11.122      return 0;
  11.123  }
  11.124 @@ -146,13 +127,15 @@
  11.125  void
  11.126  MIR_DestroyWindow(_THIS, SDL_Window* window)
  11.127  {
  11.128 -    MIR_Data* mir_data = _this->driverdata;
  11.129 +    MIR_Data* mir_data     = _this->driverdata;
  11.130      MIR_Window* mir_window = window->driverdata;
  11.131  
  11.132      if (mir_data) {
  11.133          SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
  11.134          MIR_mir_surface_release_sync(mir_window->surface);
  11.135  
  11.136 +        mir_data->current_window = NULL;
  11.137 +
  11.138          SDL_free(mir_window);
  11.139      }
  11.140      window->driverdata = NULL;
  11.141 @@ -180,49 +163,166 @@
  11.142                          SDL_VideoDisplay* display,
  11.143                          SDL_bool fullscreen)
  11.144  {
  11.145 +    MIR_Data*   mir_data   = _this->driverdata;
  11.146      MIR_Window* mir_window = window->driverdata;
  11.147 +    MirSurfaceSpec* spec;
  11.148 +    MirSurfaceState state;
  11.149  
  11.150      if (IsSurfaceValid(mir_window) < 0)
  11.151          return;
  11.152  
  11.153      if (fullscreen) {
  11.154 -        MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_fullscreen);
  11.155 +        state = mir_surface_state_fullscreen;
  11.156      } else {
  11.157 -        MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_restored);
  11.158 +        state = mir_surface_state_restored;
  11.159      }
  11.160 +
  11.161 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.162 +    MIR_mir_surface_spec_set_state(spec, state);
  11.163 +
  11.164 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.165 +    MIR_mir_surface_spec_release(spec);
  11.166  }
  11.167  
  11.168  void
  11.169  MIR_MaximizeWindow(_THIS, SDL_Window* window)
  11.170  {
  11.171 +    MIR_Data*   mir_data   = _this->driverdata;
  11.172      MIR_Window* mir_window = window->driverdata;
  11.173 +    MirSurfaceSpec* spec;
  11.174  
  11.175      if (IsSurfaceValid(mir_window) < 0)
  11.176          return;
  11.177  
  11.178 -    MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_maximized);
  11.179 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.180 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_maximized);
  11.181 +
  11.182 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.183 +    MIR_mir_surface_spec_release(spec);
  11.184  }
  11.185  
  11.186  void
  11.187  MIR_MinimizeWindow(_THIS, SDL_Window* window)
  11.188  {
  11.189 +    MIR_Data*   mir_data   = _this->driverdata;
  11.190      MIR_Window* mir_window = window->driverdata;
  11.191 +    MirSurfaceSpec* spec;
  11.192  
  11.193      if (IsSurfaceValid(mir_window) < 0)
  11.194          return;
  11.195  
  11.196 -    MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_minimized);
  11.197 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.198 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_minimized);
  11.199 +
  11.200 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.201 +    MIR_mir_surface_spec_release(spec);
  11.202  }
  11.203  
  11.204  void
  11.205  MIR_RestoreWindow(_THIS, SDL_Window * window)
  11.206  {
  11.207 +    MIR_Data*   mir_data   = _this->driverdata;
  11.208      MIR_Window* mir_window = window->driverdata;
  11.209 +    MirSurfaceSpec* spec;
  11.210  
  11.211      if (IsSurfaceValid(mir_window) < 0)
  11.212          return;
  11.213  
  11.214 -    MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_restored);
  11.215 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.216 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_restored);
  11.217 +
  11.218 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.219 +    MIR_mir_surface_spec_release(spec);
  11.220 +}
  11.221 +
  11.222 +void
  11.223 +MIR_HideWindow(_THIS, SDL_Window* window)
  11.224 +{
  11.225 +    MIR_Data*   mir_data   = _this->driverdata;
  11.226 +    MIR_Window* mir_window = window->driverdata;
  11.227 +    MirSurfaceSpec* spec;
  11.228 +
  11.229 +    if (IsSurfaceValid(mir_window) < 0)
  11.230 +        return;
  11.231 +
  11.232 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.233 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_hidden);
  11.234 +
  11.235 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.236 +    MIR_mir_surface_spec_release(spec);
  11.237 +}
  11.238 +
  11.239 +void
  11.240 +MIR_SetWindowSize(_THIS, SDL_Window* window)
  11.241 +{
  11.242 +    MIR_Data*   mir_data   = _this->driverdata;
  11.243 +    MIR_Window* mir_window = window->driverdata;
  11.244 +    MirSurfaceSpec* spec;
  11.245 +
  11.246 +    if (IsSurfaceValid(mir_window) < 0)
  11.247 +        return;
  11.248 +
  11.249 +    /* You cannot set the x/y of a mir window! So only update w/h */
  11.250 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.251 +    MIR_mir_surface_spec_set_width (spec, window->w);
  11.252 +    MIR_mir_surface_spec_set_height(spec, window->h);
  11.253 +
  11.254 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.255 +    MIR_mir_surface_spec_release(spec);
  11.256 +}
  11.257 +
  11.258 +void
  11.259 +MIR_SetWindowMinimumSize(_THIS, SDL_Window* window)
  11.260 +{
  11.261 +    MIR_Data*   mir_data   = _this->driverdata;
  11.262 +    MIR_Window* mir_window = window->driverdata;
  11.263 +    MirSurfaceSpec* spec;
  11.264 +
  11.265 +    if (IsSurfaceValid(mir_window) < 0)
  11.266 +        return;
  11.267 +
  11.268 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.269 +    MIR_mir_surface_spec_set_min_width (spec, window->min_w);
  11.270 +    MIR_mir_surface_spec_set_min_height(spec, window->min_h);
  11.271 +
  11.272 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.273 +    MIR_mir_surface_spec_release(spec);
  11.274 +}
  11.275 +
  11.276 +void
  11.277 +MIR_SetWindowMaximumSize(_THIS, SDL_Window* window)
  11.278 +{
  11.279 +    MIR_Data*   mir_data   = _this->driverdata;
  11.280 +    MIR_Window* mir_window = window->driverdata;
  11.281 +    MirSurfaceSpec* spec;
  11.282 +
  11.283 +    if (IsSurfaceValid(mir_window) < 0)
  11.284 +        return;
  11.285 +
  11.286 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.287 +    MIR_mir_surface_spec_set_max_width (spec, window->max_w);
  11.288 +    MIR_mir_surface_spec_set_max_height(spec, window->max_h);
  11.289 +
  11.290 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.291 +    MIR_mir_surface_spec_release(spec);
  11.292 +}
  11.293 +
  11.294 +void
  11.295 +MIR_SetWindowTitle(_THIS, SDL_Window* window)
  11.296 +{
  11.297 +    MIR_Data*   mir_data   = _this->driverdata;
  11.298 +    MIR_Window* mir_window = window->driverdata;
  11.299 +    char const* title = window->title ? window->title : "";
  11.300 +    MirSurfaceSpec* spec;
  11.301 +
  11.302 +    if (IsSurfaceValid(mir_window) < 0)
  11.303 +        return;
  11.304 +
  11.305 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
  11.306 +    MIR_mir_surface_spec_set_name(spec, title);
  11.307 +
  11.308 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
  11.309 +    MIR_mir_surface_spec_release(spec);
  11.310  }
  11.311  
  11.312  #endif /* SDL_VIDEO_DRIVER_MIR */
    12.1 --- a/src/video/mir/SDL_mirwindow.h	Sun Feb 21 17:21:29 2016 -0500
    12.2 +++ b/src/video/mir/SDL_mirwindow.h	Sun Feb 21 15:19:35 2016 -0800
    12.3 @@ -31,13 +31,13 @@
    12.4  
    12.5  #include "SDL_mirvideo.h"
    12.6  
    12.7 -typedef struct {
    12.8 +struct MIR_Window {
    12.9      SDL_Window* sdl_window;
   12.10 -    MIR_Data* mir_data;
   12.11 +    MIR_Data*   mir_data;
   12.12  
   12.13      MirSurface* surface;
   12.14 -    EGLSurface egl_surface;
   12.15 -} MIR_Window;
   12.16 +    EGLSurface  egl_surface;
   12.17 +};
   12.18  
   12.19  
   12.20  extern int
   12.21 @@ -60,10 +60,25 @@
   12.22  extern void
   12.23  MIR_RestoreWindow(_THIS, SDL_Window* window);
   12.24  
   12.25 +extern void
   12.26 +MIR_HideWindow(_THIS, SDL_Window* window);
   12.27 +
   12.28  extern SDL_bool
   12.29  MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info);
   12.30  
   12.31 -#endif /* _SDL_mirwindow_h */
   12.32 +extern void
   12.33 +MIR_SetWindowSize(_THIS, SDL_Window* window);
   12.34 +
   12.35 +extern void
   12.36 +MIR_SetWindowMinimumSize(_THIS, SDL_Window* window);
   12.37 +
   12.38 +extern void
   12.39 +MIR_SetWindowMaximumSize(_THIS, SDL_Window* window);
   12.40 +
   12.41 +extern void
   12.42 +MIR_SetWindowTitle(_THIS, SDL_Window* window);
   12.43 +
   12.44 +#endif /* _SDL_mirwindow */
   12.45  
   12.46  /* vi: set ts=4 sw=4 expandtab: */
   12.47