Added Mir video target (thanks, Brandon!).
authorRyan C. Gordon <icculus@icculus.org>
Sun, 02 Feb 2014 23:41:46 -0500
changeset 81533e43c73ac79b
parent 8152 8f8e4958651c
child 8154 ea6b25de67b6
Added Mir video target (thanks, Brandon!).
CMakeLists.txt
cmake/sdlchecks.cmake
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_syswm.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/mir/SDL_mirevents.c
src/video/mir/SDL_mirevents.h
src/video/mir/SDL_mirframebuffer.c
src/video/mir/SDL_mirframebuffer.h
src/video/mir/SDL_mirmouse.c
src/video/mir/SDL_mirmouse.h
src/video/mir/SDL_miropengl.c
src/video/mir/SDL_miropengl.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/CMakeLists.txt	Sun Feb 02 21:38:16 2014 -0500
     1.2 +++ b/CMakeLists.txt	Sun Feb 02 23:41:46 2014 -0500
     1.3 @@ -231,6 +231,7 @@
     1.4  set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
     1.5  set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
     1.6  set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
     1.7 +set_option(VIDEO_MIR           "Use Mir video driver" ${UNIX_SYS})
     1.8  set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
     1.9  set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
    1.10  dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
    1.11 @@ -654,6 +655,7 @@
    1.12  
    1.13    if(SDL_VIDEO)
    1.14      CheckX11()
    1.15 +    CheckMir()
    1.16      CheckDirectFB()
    1.17      CheckOpenGLX11()
    1.18      CheckOpenGLESX11()
     2.1 --- a/cmake/sdlchecks.cmake	Sun Feb 02 21:38:16 2014 -0500
     2.2 +++ b/cmake/sdlchecks.cmake	Sun Feb 02 23:41:46 2014 -0500
     2.3 @@ -505,6 +505,27 @@
     2.4    endif(VIDEO_X11)
     2.5  endmacro(CheckX11)
     2.6  
     2.7 +macro(CheckMir)
     2.8 +    if(VIDEO_MIR)
     2.9 +        find_library(MIR_LIB mirclient mircommon egl)
    2.10 +        pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
    2.11 +        pkg_check_modules(EGL egl)
    2.12 +        pkg_check_modules(XKB xkbcommon)
    2.13 +
    2.14 +        if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
    2.15 +            set(HAVE_VIDEO_MIR TRUE)
    2.16 +            set(HAVE_SDL_VIDEO TRUE)
    2.17 +
    2.18 +            file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
    2.19 +            set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
    2.20 +            set(SDL_VIDEO_DRIVER_MIR 1)
    2.21 +
    2.22 +            list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
    2.23 +            list(APPEND EXTRA_LDFLAGS ${MIR_TOOLKIT_LDFLAGS} ${EGL_LDLAGS} ${XKB_LDLAGS})
    2.24 +        endif (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
    2.25 +    endif(VIDEO_MIR)
    2.26 +endmacro(CheckMir)
    2.27 +
    2.28  # Requires:
    2.29  # - EGL
    2.30  macro(CheckWayland)
     3.1 --- a/configure	Sun Feb 02 21:38:16 2014 -0500
     3.2 +++ b/configure	Sun Feb 02 23:41:46 2014 -0500
     3.3 @@ -817,6 +817,7 @@
     3.4  enable_sndio_shared
     3.5  enable_diskaudio
     3.6  enable_dummyaudio
     3.7 +enable_video_mir
     3.8  enable_video_wayland
     3.9  enable_video_wayland_qt_touch
    3.10  enable_wayland_shared
    3.11 @@ -1534,6 +1535,7 @@
    3.12    --enable-sndio-shared   dynamically load sndio audio support [[default=yes]]
    3.13    --enable-diskaudio      support the disk writer audio driver [[default=yes]]
    3.14    --enable-dummyaudio     support the dummy audio driver [[default=yes]]
    3.15 +  --enable-video-mir      use Mir video driver [[default=yes]]
    3.16    --enable-video-wayland  use Wayland video driver [[default=yes]]
    3.17    --enable-video-wayland-qt-touch
    3.18                            QtWayland server support for Wayland video driver
    3.19 @@ -18627,6 +18629,103 @@
    3.20      fi
    3.21  }
    3.22  
    3.23 +CheckMir()
    3.24 +{
    3.25 +    # Check whether --enable-video-mir was given.
    3.26 +if test "${enable_video_mir+set}" = set; then :
    3.27 +  enableval=$enable_video_mir;
    3.28 +else
    3.29 +  enable_video_mir=yes
    3.30 +fi
    3.31 +
    3.32 +
    3.33 +    if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
    3.34 +        # Extract the first word of "pkg-config", so it can be a program name with args.
    3.35 +set dummy pkg-config; ac_word=$2
    3.36 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
    3.37 +$as_echo_n "checking for $ac_word... " >&6; }
    3.38 +if ${ac_cv_path_PKG_CONFIG+:} false; then :
    3.39 +  $as_echo_n "(cached) " >&6
    3.40 +else
    3.41 +  case $PKG_CONFIG in
    3.42 +  [\\/]* | ?:[\\/]*)
    3.43 +  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
    3.44 +  ;;
    3.45 +  *)
    3.46 +  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
    3.47 +for as_dir in $PATH
    3.48 +do
    3.49 +  IFS=$as_save_IFS
    3.50 +  test -z "$as_dir" && as_dir=.
    3.51 +    for ac_exec_ext in '' $ac_executable_extensions; do
    3.52 +  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    3.53 +    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
    3.54 +    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    3.55 +    break 2
    3.56 +  fi
    3.57 +done
    3.58 +  done
    3.59 +IFS=$as_save_IFS
    3.60 +
    3.61 +  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
    3.62 +  ;;
    3.63 +esac
    3.64 +fi
    3.65 +PKG_CONFIG=$ac_cv_path_PKG_CONFIG
    3.66 +if test -n "$PKG_CONFIG"; then
    3.67 +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
    3.68 +$as_echo "$PKG_CONFIG" >&6; }
    3.69 +else
    3.70 +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
    3.71 +$as_echo "no" >&6; }
    3.72 +fi
    3.73 +
    3.74 +
    3.75 +
    3.76 +        if test x$PKG_CONFIG != xno; then
    3.77 +            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Mir support" >&5
    3.78 +$as_echo_n "checking for Mir support... " >&6; }
    3.79 +            video_mir=no
    3.80 +            tmp_CFLAGS="$CFLAGS"
    3.81 +            CFLAGS="$EXTRA_CFLAGS `$PKG_CONFIG --cflags egl mirclient xkbcommon`"
    3.82 +
    3.83 +            cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    3.84 +/* end confdefs.h.  */
    3.85 +
    3.86 +             #include <EGL/egl.h>
    3.87 +             #include <xkbcommon/xkbcommon.h>
    3.88 +             #include <mir_toolkit/mir_client_library.h>
    3.89 +
    3.90 +int
    3.91 +main ()
    3.92 +{
    3.93 +
    3.94 +
    3.95 +  ;
    3.96 +  return 0;
    3.97 +}
    3.98 +_ACEOF
    3.99 +if ac_fn_c_try_compile "$LINENO"; then :
   3.100 +
   3.101 +            video_mir=yes
   3.102 +
   3.103 +fi
   3.104 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   3.105 +            CFLAGS="$tmp_CFLAGS"
   3.106 +            { $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_mir" >&5
   3.107 +$as_echo "$video_mir" >&6; }
   3.108 +
   3.109 +            if test x$video_mir = xyes; then
   3.110 +                  $as_echo "#define SDL_VIDEO_DRIVER_MIR 1" >>confdefs.h
   3.111 +
   3.112 +                  SOURCES="$SOURCES $srcdir/src/video/mir/*.c"
   3.113 +                  EXTRA_CFLAGS="$EXTRA_CFLAGS `$PKG_CONFIG --cflags egl mirclient xkbcommon`"
   3.114 +                  EXTRA_LDFLAGS="$EXTRA_LDFLAGS `$PKG_CONFIG --libs egl mirclient xkbcommon`"
   3.115 +                  have_video=yes
   3.116 +            fi
   3.117 +        fi
   3.118 +    fi
   3.119 +}
   3.120  
   3.121  CheckWarnAll()
   3.122  {
   3.123 @@ -22451,6 +22550,7 @@
   3.124          CheckSNDIO
   3.125          CheckX11
   3.126          CheckWayland
   3.127 +        CheckMir
   3.128          CheckDirectFB
   3.129          CheckFusionSound
   3.130          CheckOpenGLX11
     4.1 --- a/configure.in	Sun Feb 02 21:38:16 2014 -0500
     4.2 +++ b/configure.in	Sun Feb 02 23:41:46 2014 -0500
     4.3 @@ -1124,6 +1124,42 @@
     4.4      fi
     4.5  }
     4.6  
     4.7 +CheckMir()
     4.8 +{
     4.9 +    AC_ARG_ENABLE(video-mir,
    4.10 +    AC_HELP_STRING([--enable-video-mir], [use Mir video driver [[default=yes]]]),
    4.11 +                   , enable_video_mir=yes)
    4.12 +
    4.13 +    if test x$enable_video = xyes -a x$enable_video_mir = xyes; then
    4.14 +        AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
    4.15 +
    4.16 +        if test x$PKG_CONFIG != xno; then
    4.17 +            AC_MSG_CHECKING(for Mir support)
    4.18 +            video_mir=no
    4.19 +            tmp_CFLAGS="$CFLAGS"
    4.20 +            CFLAGS="$EXTRA_CFLAGS `$PKG_CONFIG --cflags egl mirclient xkbcommon`"
    4.21 +
    4.22 +            AC_TRY_COMPILE([
    4.23 +             #include <EGL/egl.h>
    4.24 +             #include <xkbcommon/xkbcommon.h>
    4.25 +             #include <mir_toolkit/mir_client_library.h>
    4.26 +            ],[
    4.27 +            ],[
    4.28 +            video_mir=yes
    4.29 +            ])
    4.30 +            CFLAGS="$tmp_CFLAGS"
    4.31 +            AC_MSG_RESULT($video_mir)
    4.32 +
    4.33 +            if test x$video_mir = xyes; then
    4.34 +                  AC_DEFINE(SDL_VIDEO_DRIVER_MIR)
    4.35 +                  SOURCES="$SOURCES $srcdir/src/video/mir/*.c"
    4.36 +                  EXTRA_CFLAGS="$EXTRA_CFLAGS `$PKG_CONFIG --cflags egl mirclient xkbcommon`"
    4.37 +                  EXTRA_LDFLAGS="$EXTRA_LDFLAGS `$PKG_CONFIG --libs egl mirclient xkbcommon`"
    4.38 +                  have_video=yes
    4.39 +            fi
    4.40 +        fi
    4.41 +    fi
    4.42 +}
    4.43  
    4.44  dnl See if GCC's -Wall is supported.
    4.45  CheckWarnAll()
    4.46 @@ -2612,6 +2648,7 @@
    4.47          CheckSNDIO
    4.48          CheckX11
    4.49          CheckWayland
    4.50 +        CheckMir
    4.51          CheckDirectFB
    4.52          CheckFusionSound
    4.53          CheckOpenGLX11
     5.1 --- a/include/SDL_config.h.cmake	Sun Feb 02 21:38:16 2014 -0500
     5.2 +++ b/include/SDL_config.h.cmake	Sun Feb 02 23:41:46 2014 -0500
     5.3 @@ -259,6 +259,7 @@
     5.4  #cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
     5.5  #cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
     5.6  #cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
     5.7 +#cmakedefine SDL_VIDEO_DRIVER_MIR @SDL_VIDEO_DRIVER_MIR@
     5.8  #cmakedefine SDL_VIDEO_DRIVER_X11 @SDL_VIDEO_DRIVER_X11@
     5.9  #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@
    5.10  #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT @SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT@
     6.1 --- a/include/SDL_config.h.in	Sun Feb 02 21:38:16 2014 -0500
     6.2 +++ b/include/SDL_config.h.in	Sun Feb 02 23:41:46 2014 -0500
     6.3 @@ -267,6 +267,7 @@
     6.4  #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL
     6.5  #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR
     6.6  #undef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON
     6.7 +#undef SDL_VIDEO_DRIVER_MIR
     6.8  #undef SDL_VIDEO_DRIVER_X11
     6.9  #undef SDL_VIDEO_DRIVER_RPI
    6.10  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
     7.1 --- a/include/SDL_syswm.h	Sun Feb 02 21:38:16 2014 -0500
     7.2 +++ b/include/SDL_syswm.h	Sun Feb 02 23:41:46 2014 -0500
     7.3 @@ -105,6 +105,7 @@
     7.4      SDL_SYSWM_COCOA,
     7.5      SDL_SYSWM_UIKIT,
     7.6      SDL_SYSWM_WAYLAND,
     7.7 +    SDL_SYSWM_MIR,
     7.8  } SDL_SYSWM_TYPE;
     7.9  
    7.10  /**
     8.1 --- a/src/video/SDL_sysvideo.h	Sun Feb 02 21:38:16 2014 -0500
     8.2 +++ b/src/video/SDL_sysvideo.h	Sun Feb 02 23:41:46 2014 -0500
     8.3 @@ -345,6 +345,9 @@
     8.4  #if SDL_VIDEO_DRIVER_X11
     8.5  extern VideoBootStrap X11_bootstrap;
     8.6  #endif
     8.7 +#if SDL_VIDEO_DRIVER_MIR
     8.8 +extern VideoBootStrap MIR_bootstrap;
     8.9 +#endif
    8.10  #if SDL_VIDEO_DRIVER_DIRECTFB
    8.11  extern VideoBootStrap DirectFB_bootstrap;
    8.12  #endif
     9.1 --- a/src/video/SDL_video.c	Sun Feb 02 21:38:16 2014 -0500
     9.2 +++ b/src/video/SDL_video.c	Sun Feb 02 23:41:46 2014 -0500
     9.3 @@ -59,6 +59,9 @@
     9.4  #if SDL_VIDEO_DRIVER_X11
     9.5      &X11_bootstrap,
     9.6  #endif
     9.7 +#if SDL_VIDEO_DRIVER_MIR
     9.8 +    &MIR_bootstrap,
     9.9 +#endif
    9.10  #if SDL_VIDEO_DRIVER_DIRECTFB
    9.11      &DirectFB_bootstrap,
    9.12  #endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/mir/SDL_mirevents.c	Sun Feb 02 23:41:46 2014 -0500
    10.3 @@ -0,0 +1,246 @@
    10.4 +/*
    10.5 +  Simple DirectMedia Layer
    10.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    10.7 +
    10.8 +  This software is provided 'as-is', without any express or implied
    10.9 +  warranty.  In no event will the authors be held liable for any damages
   10.10 +  arising from the use of this software.
   10.11 +
   10.12 +  Permission is granted to anyone to use this software for any purpose,
   10.13 +  including commercial applications, and to alter it and redistribute it
   10.14 +  freely, subject to the following restrictions:
   10.15 +
   10.16 +  1. The origin of this software must not be misrepresented; you must not
   10.17 +     claim that you wrote the original software. If you use this software
   10.18 +     in a product, an acknowledgment in the product documentation would be
   10.19 +     appreciated but is not required.
   10.20 +  2. Altered source versions must be plainly marked as such, and must not be
   10.21 +     misrepresented as being the original software.
   10.22 +  3. This notice may not be removed or altered from any source distribution.
   10.23 +*/
   10.24 +
   10.25 +/*
   10.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   10.27 +*/
   10.28 +
   10.29 +#include "SDL_config.h"
   10.30 +
   10.31 +#include "../../events/SDL_events_c.h"
   10.32 +#include "../../events/SDL_keyboard_c.h"
   10.33 +#include "../../events/SDL_touch_c.h"
   10.34 +#include "../../events/scancodes_xfree86.h"
   10.35 +
   10.36 +#include "SDL_mirevents.h"
   10.37 +#include "SDL_mirwindow.h"
   10.38 +
   10.39 +#include <xkbcommon/xkbcommon.h>
   10.40 +
   10.41 +static void
   10.42 +HandleKeyText(int32_t key_code)
   10.43 +{
   10.44 +    char text[8];
   10.45 +    int size = 0;
   10.46 +
   10.47 +    size = xkb_keysym_to_utf8(key_code, text, sizeof text);
   10.48 +
   10.49 +    if (size > 0) {
   10.50 +        text[size] = '\0';
   10.51 +        SDL_SendKeyboardText(text);
   10.52 +    }
   10.53 +}
   10.54 +
   10.55 +static void
   10.56 +CheckKeyboardFocus(SDL_Window* sdl_window)
   10.57 +{
   10.58 +    SDL_Window* keyboard_window = SDL_GetKeyboardFocus();
   10.59 +
   10.60 +    if (keyboard_window != sdl_window)
   10.61 +        SDL_SetKeyboardFocus(sdl_window);
   10.62 +}
   10.63 +
   10.64 +
   10.65 +/* FIXME
   10.66 +   Mir still needs to implement its IM API, for now we assume
   10.67 +   a single key press produces a character.
   10.68 +*/
   10.69 +static void
   10.70 +HandleKeyEvent(MirKeyEvent const ev, SDL_Window* window)
   10.71 +{
   10.72 +    uint32_t scancode = SDL_SCANCODE_UNKNOWN;
   10.73 +    Uint8 key_state = ev.action == mir_key_action_up ? SDL_RELEASED : SDL_PRESSED;
   10.74 +
   10.75 +    CheckKeyboardFocus(window);
   10.76 +
   10.77 +    if (ev.scan_code < SDL_arraysize(xfree86_scancode_table2))
   10.78 +        scancode = xfree86_scancode_table2[ev.scan_code];
   10.79 +
   10.80 +    if (scancode != SDL_SCANCODE_UNKNOWN)
   10.81 +        SDL_SendKeyboardKey(key_state, scancode);
   10.82 +
   10.83 +    if (key_state == SDL_PRESSED)
   10.84 +        HandleKeyText(ev.key_code);
   10.85 +}
   10.86 +
   10.87 +static void
   10.88 +HandleMouseButton(SDL_Window* sdl_window, Uint8 state, MirMotionButton button_state)
   10.89 +{
   10.90 +    static uint32_t last_sdl_button;
   10.91 +    uint32_t sdl_button;
   10.92 +
   10.93 +    switch (button_state) {
   10.94 +        case mir_motion_button_primary:
   10.95 +            sdl_button = SDL_BUTTON_LEFT;
   10.96 +            break;
   10.97 +        case mir_motion_button_secondary:
   10.98 +            sdl_button = SDL_BUTTON_RIGHT;
   10.99 +            break;
  10.100 +        case mir_motion_button_tertiary:
  10.101 +            sdl_button = SDL_BUTTON_MIDDLE;
  10.102 +            break;
  10.103 +        case mir_motion_button_forward:
  10.104 +            sdl_button = SDL_BUTTON_X1;
  10.105 +            break;
  10.106 +        case mir_motion_button_back:
  10.107 +            sdl_button = SDL_BUTTON_X2;
  10.108 +            break;
  10.109 +        default:
  10.110 +            sdl_button = last_sdl_button;
  10.111 +            break;
  10.112 +    }
  10.113 +
  10.114 +    last_sdl_button = sdl_button;
  10.115 +    SDL_SendMouseButton(sdl_window, 0, state, sdl_button);
  10.116 +}
  10.117 +
  10.118 +static void
  10.119 +HandleTouchPress(int device_id, int source_id, SDL_bool down, float x, float y, float pressure)
  10.120 +{
  10.121 +    SDL_SendTouch(device_id, source_id, down, x, y, pressure);
  10.122 +}
  10.123 +
  10.124 +static void
  10.125 +HandleTouchMotion(int device_id, int source_id, float x, float y, float pressure)
  10.126 +{
  10.127 +    SDL_SendTouchMotion(device_id, source_id, x, y, pressure);
  10.128 +}
  10.129 +
  10.130 +static void
  10.131 +HandleMouseMotion(SDL_Window* sdl_window, int x, int y)
  10.132 +{
  10.133 +    SDL_SendMouseMotion(sdl_window, 0, 0, x, y);
  10.134 +}
  10.135 +
  10.136 +static void
  10.137 +HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll)
  10.138 +{
  10.139 +    SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll);
  10.140 +}
  10.141 +
  10.142 +static void
  10.143 +AddTouchDevice(int device_id)
  10.144 +{
  10.145 +    if (SDL_AddTouch(device_id, "") < 0)
  10.146 +        SDL_SetError("Error: can't add touch %s, %d", __FILE__, __LINE__);
  10.147 +}
  10.148 +
  10.149 +static void
  10.150 +HandleTouchEvent(MirMotionEvent const motion, int cord_index, SDL_Window* sdl_window)
  10.151 +{
  10.152 +    int device_id = motion.device_id;
  10.153 +    int id = motion.pointer_coordinates[cord_index].id;
  10.154 +
  10.155 +    int width  = sdl_window->w;
  10.156 +    int height = sdl_window->h;
  10.157 +    float x   = motion.pointer_coordinates[cord_index].x;
  10.158 +    float y   = motion.pointer_coordinates[cord_index].y;
  10.159 +
  10.160 +    float n_x = x / width;
  10.161 +    float n_y = y / height;
  10.162 +    float pressure = motion.pointer_coordinates[cord_index].pressure;
  10.163 +
  10.164 +    AddTouchDevice(motion.device_id);
  10.165 +
  10.166 +    switch (motion.action) {
  10.167 +        case mir_motion_action_down:
  10.168 +        case mir_motion_action_pointer_down:
  10.169 +            HandleTouchPress(device_id, id, SDL_TRUE, n_x, n_y, pressure);
  10.170 +            break;
  10.171 +        case mir_motion_action_up:
  10.172 +        case mir_motion_action_pointer_up:
  10.173 +            HandleTouchPress(device_id, id, SDL_FALSE, n_x, n_y, pressure);
  10.174 +            break;
  10.175 +        case mir_motion_action_hover_move:
  10.176 +        case mir_motion_action_move:
  10.177 +            HandleTouchMotion(device_id, id, n_x, n_y, pressure);
  10.178 +            break;
  10.179 +        default:
  10.180 +            break;
  10.181 +    }
  10.182 +}
  10.183 +
  10.184 +static void
  10.185 +HandleMouseEvent(MirMotionEvent const motion, int cord_index, SDL_Window* sdl_window)
  10.186 +{
  10.187 +    SDL_SetMouseFocus(sdl_window);
  10.188 +
  10.189 +    switch (motion.action) {
  10.190 +        case mir_motion_action_down:
  10.191 +        case mir_motion_action_pointer_down:
  10.192 +            HandleMouseButton(sdl_window, SDL_PRESSED, motion.button_state);
  10.193 +            break;
  10.194 +        case mir_motion_action_up:
  10.195 +        case mir_motion_action_pointer_up:
  10.196 +            HandleMouseButton(sdl_window, SDL_RELEASED, motion.button_state);
  10.197 +            break;
  10.198 +        case mir_motion_action_hover_move:
  10.199 +        case mir_motion_action_move:
  10.200 +            HandleMouseMotion(sdl_window,
  10.201 +                              motion.pointer_coordinates[cord_index].x,
  10.202 +                              motion.pointer_coordinates[cord_index].y);
  10.203 +            break;
  10.204 +        case mir_motion_action_outside:
  10.205 +            SDL_SetMouseFocus(NULL);
  10.206 +            break;
  10.207 +        case mir_motion_action_scroll:
  10.208 +            HandleMouseScroll(sdl_window,
  10.209 +                              motion.pointer_coordinates[cord_index].hscroll,
  10.210 +                              motion.pointer_coordinates[cord_index].vscroll);
  10.211 +            break;
  10.212 +        case mir_motion_action_cancel:
  10.213 +        case mir_motion_action_hover_enter:
  10.214 +        case mir_motion_action_hover_exit:
  10.215 +            break;
  10.216 +        default:
  10.217 +            break;
  10.218 +    }
  10.219 +}
  10.220 +
  10.221 +static void
  10.222 +HandleMotionEvent(MirMotionEvent const motion, SDL_Window* sdl_window)
  10.223 +{
  10.224 +    int cord_index;
  10.225 +    for (cord_index = 0; cord_index < motion.pointer_count; cord_index++) {
  10.226 +        if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_mouse) {
  10.227 +            HandleMouseEvent(motion, cord_index, sdl_window);
  10.228 +        }
  10.229 +        else if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_finger) {
  10.230 +            HandleTouchEvent(motion, cord_index, sdl_window);
  10.231 +        }
  10.232 +    }
  10.233 +}
  10.234 +
  10.235 +void
  10.236 +MIR_HandleInput(MirSurface* surface, MirEvent const* ev, void* context)
  10.237 +{
  10.238 +    SDL_Window* window = (SDL_Window*)context;
  10.239 +    switch (ev->type) {
  10.240 +        case (mir_event_type_key):
  10.241 +            HandleKeyEvent(ev->key, window);
  10.242 +            break;
  10.243 +        case (mir_event_type_motion):
  10.244 +            HandleMotionEvent(ev->motion, window);
  10.245 +            break;
  10.246 +        default:
  10.247 +            break;
  10.248 +    }
  10.249 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/mir/SDL_mirevents.h	Sun Feb 02 23:41:46 2014 -0500
    11.3 @@ -0,0 +1,36 @@
    11.4 +/*
    11.5 +  Simple DirectMedia Layer
    11.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    11.7 +
    11.8 +  This software is provided 'as-is', without any express or implied
    11.9 +  warranty.  In no event will the authors be held liable for any damages
   11.10 +  arising from the use of this software.
   11.11 +
   11.12 +  Permission is granted to anyone to use this software for any purpose,
   11.13 +  including commercial applications, and to alter it and redistribute it
   11.14 +  freely, subject to the following restrictions:
   11.15 +
   11.16 +  1. The origin of this software must not be misrepresented; you must not
   11.17 +     claim that you wrote the original software. If you use this software
   11.18 +     in a product, an acknowledgment in the product documentation would be
   11.19 +     appreciated but is not required.
   11.20 +  2. Altered source versions must be plainly marked as such, and must not be
   11.21 +     misrepresented as being the original software.
   11.22 +  3. This notice may not be removed or altered from any source distribution.
   11.23 +*/
   11.24 +
   11.25 +/*
   11.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   11.27 +*/
   11.28 +
   11.29 +#include "SDL_config.h"
   11.30 +
   11.31 +#ifndef _SDL_mirevents_h
   11.32 +#define _SDL_mirevents_h
   11.33 +
   11.34 +#include <mir_toolkit/mir_client_library.h>
   11.35 +
   11.36 +extern void
   11.37 +MIR_HandleInput(MirSurface* surface, MirEvent const* ev, void* context);
   11.38 +
   11.39 +#endif /* _SDL_mirevents_h */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/mir/SDL_mirframebuffer.c	Sun Feb 02 23:41:46 2014 -0500
    12.3 @@ -0,0 +1,146 @@
    12.4 +/*
    12.5 +  Simple DirectMedia Layer
    12.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    12.7 +
    12.8 +  This software is provided 'as-is', without any express or implied
    12.9 +  warranty.  In no event will the authors be held liable for any damages
   12.10 +  arising from the use of this software.
   12.11 +
   12.12 +  Permission is granted to anyone to use this software for any purpose,
   12.13 +  including commercial applications, and to alter it and redistribute it
   12.14 +  freely, subject to the following restrictions:
   12.15 +
   12.16 +  1. The origin of this software must not be misrepresented; you must not
   12.17 +     claim that you wrote the original software. If you use this software
   12.18 +     in a product, an acknowledgment in the product documentation would be
   12.19 +     appreciated but is not required.
   12.20 +  2. Altered source versions must be plainly marked as such, and must not be
   12.21 +     misrepresented as being the original software.
   12.22 +  3. This notice may not be removed or altered from any source distribution.
   12.23 +*/
   12.24 +
   12.25 +/*
   12.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   12.27 +*/
   12.28 +
   12.29 +#include "SDL_config.h"
   12.30 +#include "SDL_mirevents.h"
   12.31 +#include "SDL_mirframebuffer.h"
   12.32 +#include "SDL_mirwindow.h"
   12.33 +
   12.34 +static const Uint32 mir_pixel_format_to_sdl_format[] = {
   12.35 +    SDL_PIXELFORMAT_UNKNOWN,  /* mir_pixel_format_invalid   */
   12.36 +    SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
   12.37 +    SDL_PIXELFORMAT_BGR888,   /* mir_pixel_format_xbgr_8888 */
   12.38 +    SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
   12.39 +    SDL_PIXELFORMAT_RGB888,   /* mir_pixel_format_xrgb_8888 */
   12.40 +    SDL_PIXELFORMAT_BGR24     /* mir_pixel_format_bgr_888   */
   12.41 +};
   12.42 +
   12.43 +Uint32
   12.44 +MIR_GetSDLPixelFormat(MirPixelFormat format)
   12.45 +{
   12.46 +    return mir_pixel_format_to_sdl_format[format];
   12.47 +}
   12.48 +
   12.49 +int
   12.50 +MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
   12.51 +                            void** pixels, int* pitch)
   12.52 +{
   12.53 +    MIR_Data* mir_data = _this->driverdata;
   12.54 +    MIR_Window* mir_window;
   12.55 +    MirSurfaceParameters surfaceparm;
   12.56 +
   12.57 +    if (MIR_CreateWindow(_this, window) < 0)
   12.58 +        return SDL_SetError("Failed to created a mir window.");
   12.59 +
   12.60 +    mir_window = window->driverdata;
   12.61 +
   12.62 +    mir_surface_get_parameters(mir_window->surface, &surfaceparm);
   12.63 +
   12.64 +    *format = MIR_GetSDLPixelFormat(surfaceparm.pixel_format);
   12.65 +    if (*format == SDL_PIXELFORMAT_UNKNOWN)
   12.66 +        return SDL_SetError("Unknown pixel format");
   12.67 +
   12.68 +    *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
   12.69 +
   12.70 +    *pixels = SDL_malloc(window->h*(*pitch));
   12.71 +    if (*pixels == NULL)
   12.72 +        return SDL_OutOfMemory();
   12.73 +
   12.74 +    mir_window->surface = mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
   12.75 +    if (!mir_surface_is_valid(mir_window->surface)) {
   12.76 +        const char* error = mir_surface_get_error_message(mir_window->surface);
   12.77 +        return SDL_SetError("Failed to created a mir surface: %s", error);
   12.78 +    }
   12.79 +
   12.80 +    return 0;
   12.81 +}
   12.82 +
   12.83 +int
   12.84 +MIR_UpdateWindowFramebuffer(_THIS, SDL_Window* window,
   12.85 +                            const SDL_Rect* rects, int numrects)
   12.86 +{
   12.87 +    MIR_Window* mir_window = window->driverdata;
   12.88 +
   12.89 +    MirGraphicsRegion region;
   12.90 +    int i, j, x, y, w, h, start;
   12.91 +    int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
   12.92 +
   12.93 +    mir_surface_get_graphics_region(mir_window->surface, &region);
   12.94 +
   12.95 +    char* s_dest = region.vaddr;
   12.96 +    char* pixels = (char*)window->surface->pixels;
   12.97 +
   12.98 +    s_stride = window->surface->pitch;
   12.99 +    d_stride = region.stride;
  12.100 +    bytes_per_pixel = window->surface->format->BytesPerPixel;
  12.101 +
  12.102 +    for (i = 0; i < numrects; i++) {
  12.103 +        s_dest = region.vaddr;
  12.104 +        pixels = (char*)window->surface->pixels;
  12.105 +
  12.106 +        x = rects[i].x;
  12.107 +        y = rects[i].y;
  12.108 +        w = rects[i].w;
  12.109 +        h = rects[i].h;
  12.110 +
  12.111 +        if (w <= 0 || h <= 0 || (x + w) <= 0 || (y + h) <= 0)
  12.112 +            continue;
  12.113 +
  12.114 +        if (x < 0) {
  12.115 +            x += w;
  12.116 +            w += rects[i].x;
  12.117 +        }
  12.118 +
  12.119 +        if (y < 0) {
  12.120 +            y += h;
  12.121 +            h += rects[i].y;
  12.122 +        }
  12.123 +
  12.124 +        if (x + w > window->w)
  12.125 +            w = window->w - x;
  12.126 +        if (y + h > window->h)
  12.127 +            h = window->h - y;
  12.128 +
  12.129 +        start = y * s_stride + x;
  12.130 +        pixels += start;
  12.131 +        s_dest += start;
  12.132 +
  12.133 +        bytes_per_row =  bytes_per_pixel * w;
  12.134 +        for (j = 0; j < h; j++) {
  12.135 +            memcpy(s_dest, pixels, bytes_per_row);
  12.136 +            pixels += s_stride;
  12.137 +            s_dest += d_stride;
  12.138 +        }
  12.139 +    }
  12.140 +
  12.141 +    mir_surface_swap_buffers_sync(mir_window->surface);
  12.142 +
  12.143 +    return 0;
  12.144 +}
  12.145 +
  12.146 +void
  12.147 +MIR_DestroyWindowFramebuffer(_THIS, SDL_Window* window)
  12.148 +{
  12.149 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/video/mir/SDL_mirframebuffer.h	Sun Feb 02 23:41:46 2014 -0500
    13.3 @@ -0,0 +1,46 @@
    13.4 +/*
    13.5 +  Simple DirectMedia Layer
    13.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    13.7 +
    13.8 +  This software is provided 'as-is', without any express or implied
    13.9 +  warranty.  In no event will the authors be held liable for any damages
   13.10 +  arising from the use of this software.
   13.11 +
   13.12 +  Permission is granted to anyone to use this software for any purpose,
   13.13 +  including commercial applications, and to alter it and redistribute it
   13.14 +  freely, subject to the following restrictions:
   13.15 +
   13.16 +  1. The origin of this software must not be misrepresented; you must not
   13.17 +     claim that you wrote the original software. If you use this software
   13.18 +     in a product, an acknowledgment in the product documentation would be
   13.19 +     appreciated but is not required.
   13.20 +  2. Altered source versions must be plainly marked as such, and must not be
   13.21 +     misrepresented as being the original software.
   13.22 +  3. This notice may not be removed or altered from any source distribution.
   13.23 +*/
   13.24 +
   13.25 +/*
   13.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   13.27 +*/
   13.28 +
   13.29 +#include "SDL_config.h"
   13.30 +
   13.31 +#ifndef _SDL_mirframebuffer_h
   13.32 +#define _SDL_mirframebuffer_h
   13.33 +
   13.34 +#include "../SDL_sysvideo.h"
   13.35 +
   13.36 +#include "SDL_mirvideo.h"
   13.37 +
   13.38 +extern int
   13.39 +MIR_CreateWindowFramebuffer(_THIS, SDL_Window* sdl_window, Uint32* format,
   13.40 +                            void** pixels, int* pitch);
   13.41 +
   13.42 +extern int
   13.43 +MIR_UpdateWindowFramebuffer(_THIS, SDL_Window* sdl_window,
   13.44 +                            const SDL_Rect* rects, int numrects);
   13.45 +
   13.46 +extern void
   13.47 +MIR_DestroyWindowFramebuffer(_THIS, SDL_Window* sdl_window);
   13.48 +
   13.49 +#endif /* _SDL_mirframebuffer_h */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/video/mir/SDL_mirmouse.c	Sun Feb 02 23:41:46 2014 -0500
    14.3 @@ -0,0 +1,145 @@
    14.4 +/*
    14.5 +  Simple DirectMedia Layer
    14.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    14.7 +
    14.8 +  This software is provided 'as-is', without any express or implied
    14.9 +  warranty.  In no event will the authors be held liable for any damages
   14.10 +  arising from the use of this software.
   14.11 +
   14.12 +  Permission is granted to anyone to use this software for any purpose,
   14.13 +  including commercial applications, and to alter it and redistribute it
   14.14 +  freely, subject to the following restrictions:
   14.15 +
   14.16 +  1. The origin of this software must not be misrepresented; you must not
   14.17 +     claim that you wrote the original software. If you use this software
   14.18 +     in a product, an acknowledgment in the product documentation would be
   14.19 +     appreciated but is not required.
   14.20 +  2. Altered source versions must be plainly marked as such, and must not be
   14.21 +     misrepresented as being the original software.
   14.22 +  3. This notice may not be removed or altered from any source distribution.
   14.23 +*/
   14.24 +
   14.25 +/*
   14.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   14.27 +*/
   14.28 +
   14.29 +#include "SDL_config.h"
   14.30 +
   14.31 +#include "SDL_mirmouse.h"
   14.32 +
   14.33 +#include "../../events/SDL_mouse_c.h"
   14.34 +#include "SDL_assert.h"
   14.35 +
   14.36 +static SDL_Cursor*
   14.37 +MIR_CreateDefaultCursor()
   14.38 +{
   14.39 +    SDL_Cursor* cursor;
   14.40 +
   14.41 +    cursor = SDL_calloc(1, sizeof(SDL_Cursor));
   14.42 +    if (cursor) {
   14.43 +    }
   14.44 +    else {
   14.45 +        SDL_OutOfMemory();
   14.46 +    }
   14.47 +
   14.48 +    return cursor;
   14.49 +}
   14.50 +
   14.51 +static SDL_Cursor*
   14.52 +MIR_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
   14.53 +{
   14.54 +    return MIR_CreateDefaultCursor();
   14.55 +}
   14.56 +
   14.57 +static SDL_Cursor*
   14.58 +MIR_CreateSystemCursor(SDL_SystemCursor id)
   14.59 +{
   14.60 +    switch(id) {
   14.61 +        case SDL_SYSTEM_CURSOR_ARROW:
   14.62 +            break;
   14.63 +        case SDL_SYSTEM_CURSOR_IBEAM:
   14.64 +            break;
   14.65 +        case SDL_SYSTEM_CURSOR_WAIT:
   14.66 +            break;
   14.67 +        case SDL_SYSTEM_CURSOR_CROSSHAIR:
   14.68 +            break;
   14.69 +        case SDL_SYSTEM_CURSOR_WAITARROW:
   14.70 +            break;
   14.71 +        case SDL_SYSTEM_CURSOR_SIZENWSE:
   14.72 +            break;
   14.73 +        case SDL_SYSTEM_CURSOR_SIZENESW:
   14.74 +            break;
   14.75 +        case SDL_SYSTEM_CURSOR_SIZEWE:
   14.76 +            break;
   14.77 +        case SDL_SYSTEM_CURSOR_SIZENS:
   14.78 +            break;
   14.79 +        case SDL_SYSTEM_CURSOR_SIZEALL:
   14.80 +            break;
   14.81 +        case SDL_SYSTEM_CURSOR_NO:
   14.82 +            break;
   14.83 +        case SDL_SYSTEM_CURSOR_HAND:
   14.84 +            break;
   14.85 +        default:
   14.86 +            SDL_assert(0);
   14.87 +            return NULL;
   14.88 +    }
   14.89 +
   14.90 +    return MIR_CreateDefaultCursor();
   14.91 +}
   14.92 +
   14.93 +static void
   14.94 +MIR_FreeCursor(SDL_Cursor* cursor)
   14.95 +{
   14.96 +    if (cursor)
   14.97 +      SDL_free(cursor);
   14.98 +}
   14.99 +
  14.100 +static int
  14.101 +MIR_ShowCursor(SDL_Cursor* cursor)
  14.102 +{
  14.103 +    return 0;
  14.104 +}
  14.105 +
  14.106 +static void
  14.107 +MIR_WarpMouse(SDL_Window* window, int x, int y)
  14.108 +{
  14.109 +    SDL_Unsupported();
  14.110 +}
  14.111 +
  14.112 +static int
  14.113 +MIR_SetRelativeMouseMode(SDL_bool enabled)
  14.114 +{
  14.115 +    return SDL_Unsupported();
  14.116 +}
  14.117 +
  14.118 +/* TODO Actually implement the cursor, need to wait for mir support */
  14.119 +void
  14.120 +MIR_InitMouse()
  14.121 +{
  14.122 +    SDL_Mouse* mouse = SDL_GetMouse();
  14.123 +
  14.124 +    mouse->CreateCursor         = MIR_CreateCursor;
  14.125 +    mouse->ShowCursor           = MIR_ShowCursor;
  14.126 +    mouse->FreeCursor           = MIR_FreeCursor;
  14.127 +    mouse->WarpMouse            = MIR_WarpMouse;
  14.128 +    mouse->CreateSystemCursor   = MIR_CreateSystemCursor;
  14.129 +    mouse->SetRelativeMouseMode = MIR_SetRelativeMouseMode;
  14.130 +
  14.131 +    SDL_SetDefaultCursor(MIR_CreateDefaultCursor());
  14.132 +}
  14.133 +
  14.134 +void
  14.135 +MIR_FiniMouse()
  14.136 +{
  14.137 +    SDL_Mouse* mouse = SDL_GetMouse();
  14.138 +
  14.139 +    MIR_FreeCursor(mouse->def_cursor);
  14.140 +    mouse->def_cursor = NULL;
  14.141 +
  14.142 +    mouse->CreateCursor         = NULL;
  14.143 +    mouse->ShowCursor           = NULL;
  14.144 +    mouse->FreeCursor           = NULL;
  14.145 +    mouse->WarpMouse            = NULL;
  14.146 +    mouse->CreateSystemCursor   = NULL;
  14.147 +    mouse->SetRelativeMouseMode = NULL;
  14.148 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/video/mir/SDL_mirmouse.h	Sun Feb 02 23:41:46 2014 -0500
    15.3 @@ -0,0 +1,37 @@
    15.4 +/*
    15.5 +  Simple DirectMedia Layer
    15.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    15.7 +
    15.8 +  This software is provided 'as-is', without any express or implied
    15.9 +  warranty.  In no event will the authors be held liable for any damages
   15.10 +  arising from the use of this software.
   15.11 +
   15.12 +  Permission is granted to anyone to use this software for any purpose,
   15.13 +  including commercial applications, and to alter it and redistribute it
   15.14 +  freely, subject to the following restrictions:
   15.15 +
   15.16 +  1. The origin of this software must not be misrepresented; you must not
   15.17 +     claim that you wrote the original software. If you use this software
   15.18 +     in a product, an acknowledgment in the product documentation would be
   15.19 +     appreciated but is not required.
   15.20 +  2. Altered source versions must be plainly marked as such, and must not be
   15.21 +     misrepresented as being the original software.
   15.22 +  3. This notice may not be removed or altered from any source distribution.
   15.23 +*/
   15.24 +
   15.25 +/*
   15.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   15.27 +*/
   15.28 +
   15.29 +#include "SDL_config.h"
   15.30 +
   15.31 +#ifndef _SDL_mirmouse_h
   15.32 +#define _SDL_mirmouse_h
   15.33 +
   15.34 +extern void
   15.35 +MIR_InitMouse();
   15.36 +
   15.37 +extern void
   15.38 +MIR_FiniMouse();
   15.39 +
   15.40 +#endif /* _SDL_mirmouse_h */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/video/mir/SDL_miropengl.c	Sun Feb 02 23:41:46 2014 -0500
    16.3 @@ -0,0 +1,122 @@
    16.4 +/*
    16.5 +  Simple DirectMedia Layer
    16.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    16.7 +
    16.8 +  This software is provided 'as-is', without any express or implied
    16.9 +  warranty.  In no event will the authors be held liable for any damages
   16.10 +  arising from the use of this software.
   16.11 +
   16.12 +  Permission is granted to anyone to use this software for any purpose,
   16.13 +  including commercial applications, and to alter it and redistribute it
   16.14 +  freely, subject to the following restrictions:
   16.15 +
   16.16 +  1. The origin of this software must not be misrepresented; you must not
   16.17 +     claim that you wrote the original software. If you use this software
   16.18 +     in a product, an acknowledgment in the product documentation would be
   16.19 +     appreciated but is not required.
   16.20 +  2. Altered source versions must be plainly marked as such, and must not be
   16.21 +     misrepresented as being the original software.
   16.22 +  3. This notice may not be removed or altered from any source distribution.
   16.23 +*/
   16.24 +
   16.25 +/*
   16.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   16.27 +*/
   16.28 +
   16.29 +#include "SDL_config.h"
   16.30 +#include "SDL_miropengl.h"
   16.31 +
   16.32 +#include <dlfcn.h>
   16.33 +
   16.34 +#define DEFAULT_OGL_ES2 "libGLESv2.so"
   16.35 +
   16.36 +void* MIR_GLHandle = NULL;
   16.37 +
   16.38 +void
   16.39 +MIR_GL_SwapWindow(_THIS, SDL_Window* window)
   16.40 +{
   16.41 +    MIR_Window* mir_wind = window->driverdata;
   16.42 +
   16.43 +    SDL_EGL_SwapBuffers(_this, mir_wind->egl_surface);
   16.44 +}
   16.45 +
   16.46 +int
   16.47 +MIR_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
   16.48 +{
   16.49 +  if (window) {
   16.50 +      EGLSurface egl_surface = ((MIR_Window*)window->driverdata)->egl_surface;
   16.51 +      return SDL_EGL_MakeCurrent(_this, egl_surface, context);
   16.52 +  }
   16.53 +
   16.54 +  return SDL_EGL_MakeCurrent(_this, NULL, NULL);
   16.55 +}
   16.56 +
   16.57 +SDL_GLContext
   16.58 +MIR_GL_CreateContext(_THIS, SDL_Window* window)
   16.59 +{
   16.60 +    MIR_Window* mir_window = window->driverdata;
   16.61 +
   16.62 +    SDL_GLContext context;
   16.63 +    context = SDL_EGL_CreateContext(_this, mir_window->egl_surface);
   16.64 +
   16.65 +    return context;
   16.66 +}
   16.67 +
   16.68 +int
   16.69 +MIR_GL_LoadLibrary(_THIS, const char* path)
   16.70 +{
   16.71 +    MIR_Data* mir_data = _this->driverdata;
   16.72 +
   16.73 +    SDL_EGL_LoadLibrary(_this, path,
   16.74 +                        mir_connection_get_egl_native_display(mir_data->connection));
   16.75 +
   16.76 +    SDL_EGL_ChooseConfig(_this);
   16.77 +
   16.78 +    return 0;
   16.79 +}
   16.80 +
   16.81 +void
   16.82 +MIR_GL_UnloadLibrary(_THIS)
   16.83 +{
   16.84 +    SDL_EGL_UnloadLibrary(_this);
   16.85 +
   16.86 +    if (MIR_GLHandle) {
   16.87 +        dlclose(MIR_GLHandle);
   16.88 +        MIR_GLHandle = NULL;
   16.89 +    }
   16.90 +}
   16.91 +
   16.92 +void
   16.93 +Ensure_GL_HandleOpen()
   16.94 +{
   16.95 +    if (!MIR_GLHandle) {
   16.96 +        MIR_GLHandle = dlopen(DEFAULT_OGL_ES2, RTLD_GLOBAL);
   16.97 +        if (!MIR_GLHandle) {
   16.98 +            SDL_SetError("Failed to dlopen library.");
   16.99 +        }
  16.100 +    }
  16.101 +}
  16.102 +
  16.103 +void*
  16.104 +MIR_GL_GetProcAddress(_THIS, const char* proc)
  16.105 +{
  16.106 +    void* proc_addr = eglGetProcAddress(proc);
  16.107 +
  16.108 +    /* FIXME when on the phone/tablet eglGetProcAddress returns NULL through libhybris,
  16.109 +       seems to be a problem in android. Also looks like a problem in the android video driver:
  16.110 +       src/video/android/SDL_androidgl.c
  16.111 +
  16.112 +       Workaround, to just get the address ourself
  16.113 +    */
  16.114 +
  16.115 +    if (!proc_addr) {
  16.116 +        Ensure_GL_HandleOpen();
  16.117 +        proc_addr = dlsym(MIR_GLHandle, proc);
  16.118 +    }
  16.119 +
  16.120 +    if (!proc_addr) {
  16.121 +        SDL_SetError("Failed to find proc address!");
  16.122 +    }
  16.123 +
  16.124 +    return proc_addr;
  16.125 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/mir/SDL_miropengl.h	Sun Feb 02 23:41:46 2014 -0500
    17.3 @@ -0,0 +1,57 @@
    17.4 +/*
    17.5 +  Simple DirectMedia Layer
    17.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    17.7 +
    17.8 +  This software is provided 'as-is', without any express or implied
    17.9 +  warranty.  In no event will the authors be held liable for any damages
   17.10 +  arising from the use of this software.
   17.11 +
   17.12 +  Permission is granted to anyone to use this software for any purpose,
   17.13 +  including commercial applications, and to alter it and redistribute it
   17.14 +  freely, subject to the following restrictions:
   17.15 +
   17.16 +  1. The origin of this software must not be misrepresented; you must not
   17.17 +     claim that you wrote the original software. If you use this software
   17.18 +     in a product, an acknowledgment in the product documentation would be
   17.19 +     appreciated but is not required.
   17.20 +  2. Altered source versions must be plainly marked as such, and must not be
   17.21 +     misrepresented as being the original software.
   17.22 +  3. This notice may not be removed or altered from any source distribution.
   17.23 +*/
   17.24 +
   17.25 +/*
   17.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   17.27 +*/
   17.28 +
   17.29 +#include "SDL_config.h"
   17.30 +
   17.31 +#ifndef _SDL_miropengl_h
   17.32 +#define _SDL_miropengl_h
   17.33 +
   17.34 +#include "SDL_mirwindow.h"
   17.35 +
   17.36 +#include "../SDL_egl_c.h"
   17.37 +
   17.38 +#define MIR_GL_DeleteContext   SDL_EGL_DeleteContext
   17.39 +#define MIR_GL_GetSwapInterval SDL_EGL_GetSwapInterval
   17.40 +#define MIR_GL_SetSwapInterval SDL_EGL_SetSwapInterval
   17.41 +
   17.42 +extern void
   17.43 +MIR_GL_SwapWindow(_THIS, SDL_Window* window);
   17.44 +
   17.45 +extern int
   17.46 +MIR_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context);
   17.47 +
   17.48 +extern SDL_GLContext
   17.49 +MIR_GL_CreateContext(_THIS, SDL_Window* window);
   17.50 +
   17.51 +extern int
   17.52 +MIR_GL_LoadLibrary(_THIS, const char* path);
   17.53 +
   17.54 +extern void
   17.55 +MIR_GL_UnloadLibrary(_THIS);
   17.56 +
   17.57 +extern void*
   17.58 +MIR_GL_GetProcAddress(_THIS, const char* proc);
   17.59 +
   17.60 +#endif /* _SDL_miropengl_h */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/video/mir/SDL_mirvideo.c	Sun Feb 02 23:41:46 2014 -0500
    18.3 @@ -0,0 +1,319 @@
    18.4 +/*
    18.5 +  Simple DirectMedia Layer
    18.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    18.7 +
    18.8 +  This software is provided 'as-is', without any express or implied
    18.9 +  warranty.  In no event will the authors be held liable for any damages
   18.10 +  arising from the use of this software.
   18.11 +
   18.12 +  Permission is granted to anyone to use this software for any purpose,
   18.13 +  including commercial applications, and to alter it and redistribute it
   18.14 +  freely, subject to the following restrictions:
   18.15 +
   18.16 +  1. The origin of this software must not be misrepresented; you must not
   18.17 +     claim that you wrote the original software. If you use this software
   18.18 +     in a product, an acknowledgment in the product documentation would be
   18.19 +     appreciated but is not required.
   18.20 +  2. Altered source versions must be plainly marked as such, and must not be
   18.21 +     misrepresented as being the original software.
   18.22 +  3. This notice may not be removed or altered from any source distribution.
   18.23 +*/
   18.24 +
   18.25 +/*
   18.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   18.27 +*/
   18.28 +
   18.29 +#include "SDL_config.h"
   18.30 +#include "SDL_video.h"
   18.31 +
   18.32 +#include "SDL_mirframebuffer.h"
   18.33 +#include "SDL_mirmouse.h"
   18.34 +#include "SDL_miropengl.h"
   18.35 +#include "SDL_mirvideo.h"
   18.36 +#include "SDL_mirwindow.h"
   18.37 +
   18.38 +#define MIR_DRIVER_NAME "mir"
   18.39 +
   18.40 +static int
   18.41 +MIR_VideoInit(_THIS);
   18.42 +
   18.43 +static void
   18.44 +MIR_VideoQuit(_THIS);
   18.45 +
   18.46 +static int
   18.47 +MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect);
   18.48 +
   18.49 +static void
   18.50 +MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display);
   18.51 +
   18.52 +static int
   18.53 +MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode);
   18.54 +
   18.55 +static SDL_WindowShaper*
   18.56 +MIR_CreateShaper(SDL_Window* window)
   18.57 +{
   18.58 +    /* FIXME Im not sure if mir support this atm, will have to come back to this */
   18.59 +    return NULL;
   18.60 +}
   18.61 +
   18.62 +static int
   18.63 +MIR_SetWindowShape(SDL_WindowShaper* shaper, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode)
   18.64 +{
   18.65 +    return SDL_Unsupported();
   18.66 +}
   18.67 +
   18.68 +static int
   18.69 +MIR_ResizeWindowShape(SDL_Window* window)
   18.70 +{
   18.71 +    return SDL_Unsupported();
   18.72 +}
   18.73 +
   18.74 +static int
   18.75 +MIR_Available()
   18.76 +{
   18.77 +    return 1;
   18.78 +}
   18.79 +
   18.80 +static void
   18.81 +MIR_DeleteDevice(SDL_VideoDevice* device)
   18.82 +{
   18.83 +    SDL_free(device);
   18.84 +}
   18.85 +
   18.86 +void
   18.87 +MIR_PumpEvents(_THIS)
   18.88 +{
   18.89 +}
   18.90 +
   18.91 +static SDL_VideoDevice*
   18.92 +MIR_CreateDevice(int device_index)
   18.93 +{
   18.94 +    MIR_Data* mir_data;
   18.95 +    SDL_VideoDevice* device = SDL_calloc(1, sizeof(SDL_VideoDevice));
   18.96 +    if (!device) {
   18.97 +        SDL_OutOfMemory();
   18.98 +        return NULL;
   18.99 +    }
  18.100 +
  18.101 +    mir_data = SDL_calloc(1, sizeof(MIR_Data));
  18.102 +    if (!mir_data) {
  18.103 +        SDL_OutOfMemory();
  18.104 +        SDL_free(device);
  18.105 +        return NULL;
  18.106 +    }
  18.107 +
  18.108 +    device->driverdata = mir_data;
  18.109 +
  18.110 +    /* mirvideo */
  18.111 +    device->VideoInit        = MIR_VideoInit;
  18.112 +    device->VideoQuit        = MIR_VideoQuit;
  18.113 +    device->GetDisplayBounds = MIR_GetDisplayBounds;
  18.114 +    device->GetDisplayModes  = MIR_GetDisplayModes;
  18.115 +    device->SetDisplayMode   = MIR_SetDisplayMode;
  18.116 +    device->free             = MIR_DeleteDevice;
  18.117 +
  18.118 +    /* miropengles */
  18.119 +    device->GL_SwapWindow      = MIR_GL_SwapWindow;
  18.120 +    device->GL_MakeCurrent     = MIR_GL_MakeCurrent;
  18.121 +    device->GL_CreateContext   = MIR_GL_CreateContext;
  18.122 +    device->GL_DeleteContext   = MIR_GL_DeleteContext;
  18.123 +    device->GL_LoadLibrary     = MIR_GL_LoadLibrary;
  18.124 +    device->GL_UnloadLibrary   = MIR_GL_UnloadLibrary;
  18.125 +    device->GL_GetSwapInterval = MIR_GL_GetSwapInterval;
  18.126 +    device->GL_SetSwapInterval = MIR_GL_SetSwapInterval;
  18.127 +    device->GL_GetProcAddress  = MIR_GL_GetProcAddress;
  18.128 +
  18.129 +    /* mirwindow */
  18.130 +    device->CreateWindow        = MIR_CreateWindow;
  18.131 +    device->DestroyWindow       = MIR_DestroyWindow;
  18.132 +    device->GetWindowWMInfo     = MIR_GetWindowWMInfo;
  18.133 +    device->SetWindowFullscreen = MIR_SetWindowFullscreen;
  18.134 +    device->MaximizeWindow      = MIR_MaximizeWindow;
  18.135 +    device->MinimizeWindow      = MIR_MinimizeWindow;
  18.136 +    device->RestoreWindow       = MIR_RestoreWindow;
  18.137 +
  18.138 +    device->CreateWindowFrom     = NULL;
  18.139 +    device->SetWindowTitle       = NULL;
  18.140 +    device->SetWindowIcon        = NULL;
  18.141 +    device->SetWindowPosition    = NULL;
  18.142 +    device->SetWindowSize        = NULL;
  18.143 +    device->SetWindowMinimumSize = NULL;
  18.144 +    device->SetWindowMaximumSize = NULL;
  18.145 +    device->ShowWindow           = NULL;
  18.146 +    device->HideWindow           = NULL;
  18.147 +    device->RaiseWindow          = NULL;
  18.148 +    device->SetWindowBordered    = NULL;
  18.149 +    device->SetWindowGammaRamp   = NULL;
  18.150 +    device->GetWindowGammaRamp   = NULL;
  18.151 +    device->SetWindowGrab        = NULL;
  18.152 +    device->OnWindowEnter        = NULL;
  18.153 +
  18.154 +    /* mirframebuffer */
  18.155 +    device->CreateWindowFramebuffer  = MIR_CreateWindowFramebuffer;
  18.156 +    device->UpdateWindowFramebuffer  = MIR_UpdateWindowFramebuffer;
  18.157 +    device->DestroyWindowFramebuffer = MIR_DestroyWindowFramebuffer;
  18.158 +
  18.159 +    device->shape_driver.CreateShaper      = MIR_CreateShaper;
  18.160 +    device->shape_driver.SetWindowShape    = MIR_SetWindowShape;
  18.161 +    device->shape_driver.ResizeWindowShape = MIR_ResizeWindowShape;
  18.162 +
  18.163 +    device->PumpEvents = MIR_PumpEvents;
  18.164 +
  18.165 +    device->SuspendScreenSaver = NULL;
  18.166 +
  18.167 +    device->StartTextInput   = NULL;
  18.168 +    device->StopTextInput    = NULL;
  18.169 +    device->SetTextInputRect = NULL;
  18.170 +
  18.171 +    device->HasScreenKeyboardSupport = NULL;
  18.172 +    device->ShowScreenKeyboard       = NULL;
  18.173 +    device->HideScreenKeyboard       = NULL;
  18.174 +    device->IsScreenKeyboardShown    = NULL;
  18.175 +
  18.176 +    device->SetClipboardText = NULL;
  18.177 +    device->GetClipboardText = NULL;
  18.178 +    device->HasClipboardText = NULL;
  18.179 +
  18.180 +    device->ShowMessageBox = NULL;
  18.181 +
  18.182 +    return device;
  18.183 +}
  18.184 +
  18.185 +VideoBootStrap MIR_bootstrap = {
  18.186 +    MIR_DRIVER_NAME, "SDL Mir video driver",
  18.187 +    MIR_Available, MIR_CreateDevice
  18.188 +};
  18.189 +
  18.190 +static void
  18.191 +MIR_SetCurrentDisplayMode(MirDisplayOutput const* out, SDL_VideoDisplay* display)
  18.192 +{
  18.193 +    SDL_DisplayMode mode = {
  18.194 +        .format = SDL_PIXELFORMAT_RGB888,
  18.195 +        .w = out->modes[out->current_mode].horizontal_resolution,
  18.196 +        .h = out->modes[out->current_mode].vertical_resolution,
  18.197 +        .refresh_rate = out->modes[out->current_mode].refresh_rate,
  18.198 +        .driverdata = NULL
  18.199 +    };
  18.200 +
  18.201 +    display->desktop_mode = mode;
  18.202 +    display->current_mode = mode;
  18.203 +}
  18.204 +
  18.205 +static void
  18.206 +MIR_AddAllModesFromDisplay(MirDisplayOutput const* out, SDL_VideoDisplay* display)
  18.207 +{
  18.208 +    int n_mode;
  18.209 +    for (n_mode = 0; n_mode < out->num_modes; ++n_mode) {
  18.210 +        SDL_DisplayMode mode = {
  18.211 +            .format = SDL_PIXELFORMAT_RGB888,
  18.212 +            .w = out->modes[n_mode].horizontal_resolution,
  18.213 +            .h = out->modes[n_mode].vertical_resolution,
  18.214 +            .refresh_rate = out->modes[n_mode].refresh_rate,
  18.215 +            .driverdata = NULL
  18.216 +        };
  18.217 +
  18.218 +        SDL_AddDisplayMode(display, &mode);
  18.219 +    }
  18.220 +}
  18.221 +
  18.222 +static void
  18.223 +MIR_InitDisplays(_THIS)
  18.224 +{
  18.225 +    MIR_Data* mir_data = _this->driverdata;
  18.226 +    int d;
  18.227 +
  18.228 +    MirDisplayConfiguration* display_config =
  18.229 +            mir_connection_create_display_config(mir_data->connection);
  18.230 +
  18.231 +    for (d = 0; d < display_config->num_outputs; d++) {
  18.232 +        MirDisplayOutput const* out = display_config->outputs + d;
  18.233 +
  18.234 +        SDL_VideoDisplay display;
  18.235 +        SDL_zero(display);
  18.236 +
  18.237 +        if (out->used &&
  18.238 +            out->connected &&
  18.239 +            out->num_modes &&
  18.240 +            out->current_mode < out->num_modes) {
  18.241 +
  18.242 +            MIR_SetCurrentDisplayMode(out, &display);
  18.243 +            MIR_AddAllModesFromDisplay(out, &display);
  18.244 +
  18.245 +            SDL_AddVideoDisplay(&display);
  18.246 +        }
  18.247 +    }
  18.248 +
  18.249 +    mir_display_config_destroy(display_config);
  18.250 +}
  18.251 +
  18.252 +int
  18.253 +MIR_VideoInit(_THIS)
  18.254 +{
  18.255 +    MIR_Data* mir_data = _this->driverdata;
  18.256 +
  18.257 +    mir_data->connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);
  18.258 +
  18.259 +    if (!mir_connection_is_valid(mir_data->connection))
  18.260 +        return SDL_SetError("Failed to connect to the Mir Server");
  18.261 +
  18.262 +    MIR_InitDisplays(_this);
  18.263 +    MIR_InitMouse();
  18.264 +
  18.265 +    return 0;
  18.266 +}
  18.267 +
  18.268 +void
  18.269 +MIR_VideoQuit(_THIS)
  18.270 +{
  18.271 +    MIR_Data* mir_data = _this->driverdata;
  18.272 +
  18.273 +    MIR_FiniMouse();
  18.274 +
  18.275 +    MIR_GL_DeleteContext(_this, NULL);
  18.276 +    MIR_GL_UnloadLibrary(_this);
  18.277 +
  18.278 +    mir_connection_release(mir_data->connection);
  18.279 +
  18.280 +    SDL_free(mir_data);
  18.281 +    _this->driverdata = NULL;
  18.282 +}
  18.283 +
  18.284 +static int
  18.285 +MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect)
  18.286 +{
  18.287 +    MIR_Data* mir_data = _this->driverdata;
  18.288 +    int d;
  18.289 +
  18.290 +    MirDisplayConfiguration* display_config =
  18.291 +            mir_connection_create_display_config(mir_data->connection);
  18.292 +
  18.293 +    for (d = 0; d < display_config->num_outputs; d++) {
  18.294 +        MirDisplayOutput const* out = display_config->outputs + d;
  18.295 +
  18.296 +        if (out->used &&
  18.297 +            out->connected &&
  18.298 +            out->num_modes &&
  18.299 +            out->current_mode < out->num_modes) {
  18.300 +
  18.301 +            rect->x = out->position_x;
  18.302 +            rect->y = out->position_y;
  18.303 +            rect->w = out->modes->horizontal_resolution;
  18.304 +            rect->h = out->modes->vertical_resolution;
  18.305 +        }
  18.306 +    }
  18.307 +
  18.308 +    mir_display_config_destroy(display_config);
  18.309 +
  18.310 +    return 0;
  18.311 +}
  18.312 +
  18.313 +static void
  18.314 +MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display)
  18.315 +{
  18.316 +}
  18.317 +
  18.318 +static int
  18.319 +MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode)
  18.320 +{
  18.321 +    return 0;
  18.322 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/mir/SDL_mirvideo.h	Sun Feb 02 23:41:46 2014 -0500
    19.3 @@ -0,0 +1,40 @@
    19.4 +/*
    19.5 +  Simple DirectMedia Layer
    19.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    19.7 +
    19.8 +  This software is provided 'as-is', without any express or implied
    19.9 +  warranty.  In no event will the authors be held liable for any damages
   19.10 +  arising from the use of this software.
   19.11 +
   19.12 +  Permission is granted to anyone to use this software for any purpose,
   19.13 +  including commercial applications, and to alter it and redistribute it
   19.14 +  freely, subject to the following restrictions:
   19.15 +
   19.16 +  1. The origin of this software must not be misrepresented; you must not
   19.17 +     claim that you wrote the original software. If you use this software
   19.18 +     in a product, an acknowledgment in the product documentation would be
   19.19 +     appreciated but is not required.
   19.20 +  2. Altered source versions must be plainly marked as such, and must not be
   19.21 +     misrepresented as being the original software.
   19.22 +  3. This notice may not be removed or altered from any source distribution.
   19.23 +*/
   19.24 +
   19.25 +/*
   19.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   19.27 +*/
   19.28 +
   19.29 +#include "SDL_config.h"
   19.30 +
   19.31 +#ifndef _SDL_mirvideo_h_
   19.32 +#define _SDL_mirvideo_h_
   19.33 +
   19.34 +#include <EGL/egl.h>
   19.35 +#include <mir_toolkit/mir_client_library.h>
   19.36 +
   19.37 +typedef struct
   19.38 +{
   19.39 +    MirConnection* connection;
   19.40 +
   19.41 +} MIR_Data;
   19.42 +
   19.43 +#endif /* _SDL_mirvideo_h_ */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/mir/SDL_mirwindow.c	Sun Feb 02 23:41:46 2014 -0500
    20.3 @@ -0,0 +1,216 @@
    20.4 +/*
    20.5 +  Simple DirectMedia Layer
    20.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    20.7 +
    20.8 +  This software is provided 'as-is', without any express or implied
    20.9 +  warranty.  In no event will the authors be held liable for any damages
   20.10 +  arising from the use of this software.
   20.11 +
   20.12 +  Permission is granted to anyone to use this software for any purpose,
   20.13 +  including commercial applications, and to alter it and redistribute it
   20.14 +  freely, subject to the following restrictions:
   20.15 +
   20.16 +  1. The origin of this software must not be misrepresented; you must not
   20.17 +     claim that you wrote the original software. If you use this software
   20.18 +     in a product, an acknowledgment in the product documentation would be
   20.19 +     appreciated but is not required.
   20.20 +  2. Altered source versions must be plainly marked as such, and must not be
   20.21 +     misrepresented as being the original software.
   20.22 +  3. This notice may not be removed or altered from any source distribution.
   20.23 +*/
   20.24 +
   20.25 +/*
   20.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   20.27 +*/
   20.28 +
   20.29 +#include "SDL_config.h"
   20.30 +
   20.31 +#include "../SDL_egl_c.h"
   20.32 +#include "../SDL_sysvideo.h"
   20.33 +
   20.34 +#include "SDL_mirevents.h"
   20.35 +#include "SDL_mirwindow.h"
   20.36 +
   20.37 +int
   20.38 +IsSurfaceValid(MIR_Window* mir_window)
   20.39 +{
   20.40 +    if (!mir_surface_is_valid(mir_window->surface)) {
   20.41 +        const char* error = mir_surface_get_error_message(mir_window->surface);
   20.42 +        return SDL_SetError("Failed to created a mir surface: %s", error);
   20.43 +    }
   20.44 +
   20.45 +    return 0;
   20.46 +}
   20.47 +
   20.48 +MirPixelFormat
   20.49 +FindValidPixelFormat(MIR_Data* mir_data)
   20.50 +{
   20.51 +    unsigned int pf_size = 32;
   20.52 +    unsigned int valid_formats;
   20.53 +    unsigned int f;
   20.54 +
   20.55 +    MirPixelFormat formats[pf_size];
   20.56 +    mir_connection_get_available_surface_formats(mir_data->connection, formats,
   20.57 +                                                 pf_size, &valid_formats);
   20.58 +
   20.59 +    for (f = 0; f < valid_formats; f++) {
   20.60 +        MirPixelFormat cur_pf = formats[f];
   20.61 +
   20.62 +        if (cur_pf == mir_pixel_format_abgr_8888 ||
   20.63 +            cur_pf == mir_pixel_format_xbgr_8888 ||
   20.64 +            cur_pf == mir_pixel_format_argb_8888 ||
   20.65 +            cur_pf == mir_pixel_format_xrgb_8888) {
   20.66 +
   20.67 +            return cur_pf;
   20.68 +        }
   20.69 +    }
   20.70 +
   20.71 +    return mir_pixel_format_invalid;
   20.72 +}
   20.73 +
   20.74 +int
   20.75 +MIR_CreateWindow(_THIS, SDL_Window* window)
   20.76 +{
   20.77 +    MIR_Window* mir_window;
   20.78 +    MIR_Data* mir_data;
   20.79 +
   20.80 +    MirSurfaceParameters surfaceparm =
   20.81 +    {
   20.82 +        .name = "MirSurface",
   20.83 +        .width = window->w,
   20.84 +        .height = window->h,
   20.85 +        .pixel_format = mir_pixel_format_invalid,
   20.86 +        .buffer_usage = mir_buffer_usage_hardware
   20.87 +    };
   20.88 +
   20.89 +    MirEventDelegate delegate = {
   20.90 +        MIR_HandleInput,
   20.91 +        window
   20.92 +    };
   20.93 +
   20.94 +    mir_window = SDL_calloc(1, sizeof(MIR_Window));
   20.95 +    if (!mir_window)
   20.96 +        return SDL_OutOfMemory();
   20.97 +
   20.98 +    mir_data = _this->driverdata;
   20.99 +    window->driverdata = mir_window;
  20.100 +
  20.101 +    if (window->x == SDL_WINDOWPOS_UNDEFINED)
  20.102 +        window->x = 0;
  20.103 +
  20.104 +    if (window->y == SDL_WINDOWPOS_UNDEFINED)
  20.105 +        window->y = 0;
  20.106 +
  20.107 +    mir_window->mir_data = mir_data;
  20.108 +    mir_window->sdl_window = window;
  20.109 +
  20.110 +    surfaceparm.pixel_format = FindValidPixelFormat(mir_data);
  20.111 +    if (surfaceparm.pixel_format == mir_pixel_format_invalid) {
  20.112 +        return SDL_SetError("Failed to find a valid pixel format.");
  20.113 +    }
  20.114 +
  20.115 +    mir_window->surface = mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
  20.116 +    if (!mir_surface_is_valid(mir_window->surface)) {
  20.117 +        const char* error = mir_surface_get_error_message(mir_window->surface);
  20.118 +        return SDL_SetError("Failed to created a mir surface: %s", error);
  20.119 +    }
  20.120 +
  20.121 +    if (window->flags & SDL_WINDOW_OPENGL) {
  20.122 +        EGLNativeWindowType egl_native_window =
  20.123 +                        (EGLNativeWindowType)mir_surface_get_egl_native_window(mir_window->surface);
  20.124 +
  20.125 +        mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);
  20.126 +
  20.127 +        if (mir_window->egl_surface == EGL_NO_SURFACE) {
  20.128 +            return SDL_SetError("Failed to created a window surface %p",
  20.129 +                                _this->egl_data->egl_display);
  20.130 +        }
  20.131 +    }
  20.132 +    else {
  20.133 +        mir_window->egl_surface = EGL_NO_SURFACE;
  20.134 +    }
  20.135 +
  20.136 +    mir_surface_set_event_handler(mir_window->surface, &delegate);
  20.137 +
  20.138 +    return 0;
  20.139 +}
  20.140 +
  20.141 +void
  20.142 +MIR_DestroyWindow(_THIS, SDL_Window* window)
  20.143 +{
  20.144 +    MIR_Data* mir_data = _this->driverdata;
  20.145 +    MIR_Window* mir_window = window->driverdata;
  20.146 +
  20.147 +    window->driverdata = NULL;
  20.148 +
  20.149 +    if (mir_data) {
  20.150 +        SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
  20.151 +        mir_surface_release_sync(mir_window->surface);
  20.152 +
  20.153 +        SDL_free(mir_window);
  20.154 +    }
  20.155 +}
  20.156 +
  20.157 +SDL_bool
  20.158 +MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info)
  20.159 +{
  20.160 +    if (info->version.major == SDL_MAJOR_VERSION &&
  20.161 +        info->version.minor == SDL_MINOR_VERSION) {
  20.162 +
  20.163 +        info->subsystem = SDL_SYSWM_MIR;
  20.164 +        return SDL_TRUE;
  20.165 +    }
  20.166 +
  20.167 +    return SDL_FALSE;
  20.168 +}
  20.169 +
  20.170 +void
  20.171 +MIR_SetWindowFullscreen(_THIS, SDL_Window* window,
  20.172 +                        SDL_VideoDisplay* display,
  20.173 +                        SDL_bool fullscreen)
  20.174 +{
  20.175 +    MIR_Window* mir_window = window->driverdata;
  20.176 +
  20.177 +    if (IsSurfaceValid(mir_window) < 0)
  20.178 +        return;
  20.179 +
  20.180 +    if (fullscreen) {
  20.181 +        mir_surface_set_type(mir_window->surface, mir_surface_state_fullscreen);
  20.182 +    }
  20.183 +    else {
  20.184 +        mir_surface_set_type(mir_window->surface, mir_surface_state_restored);
  20.185 +    }
  20.186 +}
  20.187 +
  20.188 +void
  20.189 +MIR_MaximizeWindow(_THIS, SDL_Window* window)
  20.190 +{
  20.191 +    MIR_Window* mir_window = window->driverdata;
  20.192 +
  20.193 +    if (IsSurfaceValid(mir_window) < 0)
  20.194 +        return;
  20.195 +
  20.196 +    mir_surface_set_type(mir_window->surface, mir_surface_state_maximized);
  20.197 +}
  20.198 +
  20.199 +void
  20.200 +MIR_MinimizeWindow(_THIS, SDL_Window* window)
  20.201 +{
  20.202 +    MIR_Window* mir_window = window->driverdata;
  20.203 +
  20.204 +    if (IsSurfaceValid(mir_window) < 0)
  20.205 +        return;
  20.206 +
  20.207 +    mir_surface_set_type(mir_window->surface, mir_surface_state_minimized);
  20.208 +}
  20.209 +
  20.210 +void
  20.211 +MIR_RestoreWindow(_THIS, SDL_Window * window)
  20.212 +{
  20.213 +    MIR_Window* mir_window = window->driverdata;
  20.214 +
  20.215 +    if (IsSurfaceValid(mir_window) < 0)
  20.216 +        return;
  20.217 +
  20.218 +    mir_surface_set_type(mir_window->surface, mir_surface_state_restored);
  20.219 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/mir/SDL_mirwindow.h	Sun Feb 02 23:41:46 2014 -0500
    21.3 @@ -0,0 +1,69 @@
    21.4 +/*
    21.5 +  Simple DirectMedia Layer
    21.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    21.7 +
    21.8 +  This software is provided 'as-is', without any express or implied
    21.9 +  warranty.  In no event will the authors be held liable for any damages
   21.10 +  arising from the use of this software.
   21.11 +
   21.12 +  Permission is granted to anyone to use this software for any purpose,
   21.13 +  including commercial applications, and to alter it and redistribute it
   21.14 +  freely, subject to the following restrictions:
   21.15 +
   21.16 +  1. The origin of this software must not be misrepresented; you must not
   21.17 +     claim that you wrote the original software. If you use this software
   21.18 +     in a product, an acknowledgment in the product documentation would be
   21.19 +     appreciated but is not required.
   21.20 +  2. Altered source versions must be plainly marked as such, and must not be
   21.21 +     misrepresented as being the original software.
   21.22 +  3. This notice may not be removed or altered from any source distribution.
   21.23 +*/
   21.24 +
   21.25 +/*
   21.26 +  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
   21.27 +*/
   21.28 +
   21.29 +#include "SDL_config.h"
   21.30 +
   21.31 +#ifndef _SDL_mirwindow_h
   21.32 +#define _SDL_mirwindow_h
   21.33 +
   21.34 +#include "../SDL_sysvideo.h"
   21.35 +#include "SDL_syswm.h"
   21.36 +
   21.37 +#include "SDL_mirvideo.h"
   21.38 +
   21.39 +typedef struct {
   21.40 +    SDL_Window* sdl_window;
   21.41 +    MIR_Data* mir_data;
   21.42 +
   21.43 +    MirSurface* surface;
   21.44 +    EGLSurface egl_surface;
   21.45 +
   21.46 +} MIR_Window;
   21.47 +
   21.48 +
   21.49 +extern int
   21.50 +MIR_CreateWindow(_THIS, SDL_Window* window);
   21.51 +
   21.52 +extern void
   21.53 +MIR_DestroyWindow(_THIS, SDL_Window* window);
   21.54 +
   21.55 +extern void
   21.56 +MIR_SetWindowFullscreen(_THIS, SDL_Window* window,
   21.57 +                        SDL_VideoDisplay* display,
   21.58 +                        SDL_bool fullscreen);
   21.59 +
   21.60 +extern void
   21.61 +MIR_MaximizeWindow(_THIS, SDL_Window* window);
   21.62 +
   21.63 +extern void
   21.64 +MIR_MinimizeWindow(_THIS, SDL_Window* window);
   21.65 +
   21.66 +extern void
   21.67 +MIR_RestoreWindow(_THIS, SDL_Window* window);
   21.68 +
   21.69 +extern SDL_bool
   21.70 +MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info);
   21.71 +
   21.72 +#endif /* _SDL_mirwindow */