Wayland support
authorGabriel Jacobo <gabomdq@gmail.com>
Sat, 14 Dec 2013 20:18:43 -0300
changeset 80624fc5f66d63cc
parent 8061 a5f8137ccf01
child 8063 405d84eedad8
Wayland support

Based on the original port to Wayland by: Joel Teichroeb, Benjamin Franzke, Scott Moreau, et al.

Additional changes in this commit, done by me:

* Wayland uses the common EGL framework
* EGL can now create a desktop OpenGL context
* testgl2 loads GL functions dynamically, no need to link to libGL anymore
* Assorted fixes to the Wayland backend

Tested on the Weston Compositor (v1.0.5) that ships with Ubuntu 13.10,
running Weston under X. Tests ran: testrendercopyex (all backends), testgl2, testgles2,testintersections
CMakeLists.txt
WhatsNew.txt
cmake/sdlchecks.cmake
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_syswm.h
src/render/opengl/SDL_glfuncs.h
src/video/SDL_egl.c
src/video/SDL_egl_c.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/wayland/SDL_waylandevents.c
src/video/wayland/SDL_waylandevents_c.h
src/video/wayland/SDL_waylandmouse.c
src/video/wayland/SDL_waylandmouse.h
src/video/wayland/SDL_waylandopengles.c
src/video/wayland/SDL_waylandopengles.h
src/video/wayland/SDL_waylandvideo.c
src/video/wayland/SDL_waylandvideo.h
src/video/wayland/SDL_waylandwindow.c
src/video/wayland/SDL_waylandwindow.h
test/Makefile.in
test/testgl2.c
     1.1 --- a/CMakeLists.txt	Fri Dec 13 09:48:12 2013 -0300
     1.2 +++ b/CMakeLists.txt	Sat Dec 14 20:18:43 2013 -0300
     1.3 @@ -218,6 +218,7 @@
     1.4  set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
     1.5  set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
     1.6  set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
     1.7 +set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
     1.8  dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
     1.9  set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
    1.10  foreach(_SUB ${SDL_X11_OPTIONS})
    1.11 @@ -641,6 +642,7 @@
    1.12      CheckDirectFB()
    1.13      CheckOpenGLX11()
    1.14      CheckOpenGLESX11()
    1.15 +    CheckWayland()
    1.16    endif(SDL_VIDEO)
    1.17  
    1.18    if(LINUX)
     2.1 --- a/WhatsNew.txt	Fri Dec 13 09:48:12 2013 -0300
     2.2 +++ b/WhatsNew.txt	Sat Dec 14 20:18:43 2013 -0300
     2.3 @@ -7,7 +7,10 @@
     2.4  General:
     2.5  * Added an API to load a database of Game Controller mappings from a file:    
     2.6      SDL_GameControllerAddMappingsFromFile
     2.7 -    
     2.8 +* EGL can now create/manage OpenGL and OpenGL ES 1.x/2.x contexts, and share
     2.9 +  them using SDL_GL_SHARE_WITH_CURRENT_CONTEXT
    2.10 +* Added testgles2. testgl2 does not need to link with libGL anymore.
    2.11 +  
    2.12  Windows:
    2.13  * Support for OpenGL ES 2.x contexts using either WGL or EGL (natively via
    2.14    the driver or emulated through ANGLE)
    2.15 @@ -20,7 +23,7 @@
    2.16  
    2.17  Linux:
    2.18  * Fixed fullscreen and focused behavior when receiving NotifyGrab events
    2.19 -
    2.20 +* Wayland support
    2.21  
    2.22  ---------------------------------------------------------------------------
    2.23  2.0.1:
     3.1 --- a/cmake/sdlchecks.cmake	Fri Dec 13 09:48:12 2013 -0300
     3.2 +++ b/cmake/sdlchecks.cmake	Sat Dec 14 20:18:43 2013 -0300
     3.3 @@ -506,6 +506,29 @@
     3.4  endmacro(CheckX11)
     3.5  
     3.6  # Requires:
     3.7 +# - EGL
     3.8 +macro(CheckWayland)
     3.9 +  if(VIDEO_WAYLAND)
    3.10 +    pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
    3.11 +    if(WAYLAND_FOUND)
    3.12 +      link_directories(
    3.13 +          ${WAYLAND_LIBRARY_DIRS}
    3.14 +      )
    3.15 +      include_directories(
    3.16 +          ${WAYLAND_INCLUDE_DIRS}
    3.17 +      )
    3.18 +      set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
    3.19 +      set(HAVE_VIDEO_WAYLAND TRUE)
    3.20 +      set(HAVE_SDL_VIDEO TRUE)
    3.21 +
    3.22 +      file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
    3.23 +      set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
    3.24 +      set(SDL_VIDEO_DRIVER_WAYLAND 1)
    3.25 +    endif(WAYLAND_FOUND)
    3.26 +  endif(VIDEO_WAYLAND)
    3.27 +endmacro(CheckWayland)
    3.28 +
    3.29 +# Requires:
    3.30  # - n/a
    3.31  #
    3.32  macro(CheckCOCOA)
     4.1 --- a/configure	Fri Dec 13 09:48:12 2013 -0300
     4.2 +++ b/configure	Sat Dec 14 20:18:43 2013 -0300
     4.3 @@ -817,6 +817,7 @@
     4.4  enable_sndio_shared
     4.5  enable_diskaudio
     4.6  enable_dummyaudio
     4.7 +enable_video_wayland
     4.8  enable_video_x11
     4.9  with_x
    4.10  enable_x11_shared
    4.11 @@ -1532,6 +1533,7 @@
    4.12    --enable-sndio-shared   dynamically load sndio audio support [[default=yes]]
    4.13    --enable-diskaudio      support the disk writer audio driver [[default=yes]]
    4.14    --enable-dummyaudio     support the dummy audio driver [[default=yes]]
    4.15 +  --enable-video-wayland  use Wayland video driver [[default=yes]]
    4.16    --enable-video-x11      use X11 video driver [[default=yes]]
    4.17    --enable-x11-shared     dynamically load X11 support [[default=maybe]]
    4.18    --enable-video-x11-xcursor
    4.19 @@ -18633,6 +18635,82 @@
    4.20      fi
    4.21  }
    4.22  
    4.23 +CheckWayland()
    4.24 +{
    4.25 +    # Check whether --enable-video-wayland was given.
    4.26 +if test "${enable_video_wayland+set}" = set; then :
    4.27 +  enableval=$enable_video_wayland;
    4.28 +else
    4.29 +  enable_video_wayland=yes
    4.30 +fi
    4.31 +
    4.32 +
    4.33 +    if test x$enable_video = xyes -a x$enable_video_wayland = xyes; then
    4.34 +        # Extract the first word of "pkg-config", so it can be a program name with args.
    4.35 +set dummy pkg-config; ac_word=$2
    4.36 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
    4.37 +$as_echo_n "checking for $ac_word... " >&6; }
    4.38 +if ${ac_cv_path_PKG_CONFIG+:} false; then :
    4.39 +  $as_echo_n "(cached) " >&6
    4.40 +else
    4.41 +  case $PKG_CONFIG in
    4.42 +  [\\/]* | ?:[\\/]*)
    4.43 +  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
    4.44 +  ;;
    4.45 +  *)
    4.46 +  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
    4.47 +for as_dir in $PATH
    4.48 +do
    4.49 +  IFS=$as_save_IFS
    4.50 +  test -z "$as_dir" && as_dir=.
    4.51 +    for ac_exec_ext in '' $ac_executable_extensions; do
    4.52 +  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    4.53 +    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
    4.54 +    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    4.55 +    break 2
    4.56 +  fi
    4.57 +done
    4.58 +  done
    4.59 +IFS=$as_save_IFS
    4.60 +
    4.61 +  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
    4.62 +  ;;
    4.63 +esac
    4.64 +fi
    4.65 +PKG_CONFIG=$ac_cv_path_PKG_CONFIG
    4.66 +if test -n "$PKG_CONFIG"; then
    4.67 +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
    4.68 +$as_echo "$PKG_CONFIG" >&6; }
    4.69 +else
    4.70 +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
    4.71 +$as_echo "no" >&6; }
    4.72 +fi
    4.73 +
    4.74 +
    4.75 +        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Wayland support" >&5
    4.76 +$as_echo_n "checking for Wayland support... " >&6; }
    4.77 +        video_wayland=no
    4.78 +        if test x$PKG_CONFIG != xno; then
    4.79 +            if $PKG_CONFIG --exists wayland-client wayland-egl wayland-cursor egl xkbcommon ; then
    4.80 +                WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor egl xkbcommon`
    4.81 +                WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor egl xkbcommon`
    4.82 +                video_wayland=yes
    4.83 +            fi
    4.84 +        fi
    4.85 +        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_wayland" >&5
    4.86 +$as_echo "$video_wayland" >&6; }
    4.87 +
    4.88 +        if test x$video_wayland = xyes; then
    4.89 +
    4.90 +$as_echo "#define SDL_VIDEO_DRIVER_WAYLAND 1" >>confdefs.h
    4.91 +
    4.92 +            SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
    4.93 +            EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS"
    4.94 +                        EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS"
    4.95 +            have_video=yes
    4.96 +        fi
    4.97 +    fi
    4.98 +}
    4.99  
   4.100  CheckX11()
   4.101  {
   4.102 @@ -22220,6 +22298,7 @@
   4.103          CheckNAS
   4.104          CheckSNDIO
   4.105          CheckX11
   4.106 +        CheckWayland
   4.107          CheckDirectFB
   4.108          CheckFusionSound
   4.109          CheckOpenGLX11
     5.1 --- a/configure.in	Fri Dec 13 09:48:12 2013 -0300
     5.2 +++ b/configure.in	Sat Dec 14 20:18:43 2013 -0300
     5.3 @@ -1115,6 +1115,36 @@
     5.4      fi
     5.5  }
     5.6  
     5.7 +dnl Check for Wayland
     5.8 +CheckWayland()
     5.9 +{
    5.10 +    AC_ARG_ENABLE(video-wayland,
    5.11 +AC_HELP_STRING([--enable-video-wayland], [use Wayland video driver [[default=yes]]]),
    5.12 +                  ,enable_video_wayland=yes)
    5.13 +
    5.14 +    if test x$enable_video = xyes -a x$enable_video_wayland = xyes; then
    5.15 +        AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
    5.16 +        AC_MSG_CHECKING(for Wayland support)
    5.17 +        video_wayland=no
    5.18 +        if test x$PKG_CONFIG != xno; then
    5.19 +            if $PKG_CONFIG --exists wayland-client wayland-egl wayland-cursor egl xkbcommon ; then
    5.20 +                WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor egl xkbcommon`
    5.21 +                WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor egl xkbcommon`
    5.22 +                video_wayland=yes
    5.23 +            fi
    5.24 +        fi
    5.25 +        AC_MSG_RESULT($video_wayland)
    5.26 +
    5.27 +        if test x$video_wayland = xyes; then
    5.28 +            AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND, 1, [ ])
    5.29 +            SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
    5.30 +            EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS"
    5.31 +            dnl FIXME do dynamic loading code here.
    5.32 +            EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS"
    5.33 +            have_video=yes
    5.34 +        fi
    5.35 +    fi
    5.36 +}
    5.37  
    5.38  dnl Find the X11 include and library directories
    5.39  CheckX11()
    5.40 @@ -2449,6 +2479,7 @@
    5.41          CheckNAS
    5.42          CheckSNDIO
    5.43          CheckX11
    5.44 +        CheckWayland
    5.45          CheckDirectFB
    5.46          CheckFusionSound
    5.47          CheckOpenGLX11
     6.1 --- a/include/SDL_config.h.cmake	Fri Dec 13 09:48:12 2013 -0300
     6.2 +++ b/include/SDL_config.h.cmake	Sat Dec 14 20:18:43 2013 -0300
     6.3 @@ -259,6 +259,7 @@
     6.4  #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@
     6.5  #cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
     6.6  #cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
     6.7 +#cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
     6.8  #cmakedefine SDL_VIDEO_DRIVER_X11 @SDL_VIDEO_DRIVER_X11@
     6.9  #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@
    6.10  #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT @SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT@
     7.1 --- a/include/SDL_config.h.in	Fri Dec 13 09:48:12 2013 -0300
     7.2 +++ b/include/SDL_config.h.in	Sat Dec 14 20:18:43 2013 -0300
     7.3 @@ -260,6 +260,7 @@
     7.4  #undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
     7.5  #undef SDL_VIDEO_DRIVER_DUMMY
     7.6  #undef SDL_VIDEO_DRIVER_WINDOWS
     7.7 +#undef SDL_VIDEO_DRIVER_WAYLAND
     7.8  #undef SDL_VIDEO_DRIVER_X11
     7.9  #undef SDL_VIDEO_DRIVER_RPI
    7.10  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
     8.1 --- a/include/SDL_syswm.h	Fri Dec 13 09:48:12 2013 -0300
     8.2 +++ b/include/SDL_syswm.h	Sat Dec 14 20:18:43 2013 -0300
     8.3 @@ -101,6 +101,7 @@
     8.4      SDL_SYSWM_UNKNOWN,
     8.5      SDL_SYSWM_WINDOWS,
     8.6      SDL_SYSWM_X11,
     8.7 +    SDL_SYSWM_WAYLAND,
     8.8      SDL_SYSWM_DIRECTFB,
     8.9      SDL_SYSWM_COCOA,
    8.10      SDL_SYSWM_UIKIT,
    8.11 @@ -175,6 +176,14 @@
    8.12              Window window;              /**< The X11 window */
    8.13          } x11;
    8.14  #endif
    8.15 +#if defined(SDL_VIDEO_DRIVER_WAYLAND)
    8.16 +        struct
    8.17 +        {
    8.18 +            struct wl_display *display;            /**< Wayland display */
    8.19 +            struct wl_surface *surface;            /**< Wayland surface */
    8.20 +            struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
    8.21 +        } wl;
    8.22 +#endif
    8.23  #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
    8.24          struct
    8.25          {
     9.1 --- a/src/render/opengl/SDL_glfuncs.h	Fri Dec 13 09:48:12 2013 -0300
     9.2 +++ b/src/render/opengl/SDL_glfuncs.h	Sat Dec 14 20:18:43 2013 -0300
     9.3 @@ -30,7 +30,7 @@
     9.4  SDL_PROC_UNUSED(void, glColor3d, (GLdouble, GLdouble, GLdouble))
     9.5  SDL_PROC_UNUSED(void, glColor3dv, (const GLdouble *))
     9.6  SDL_PROC_UNUSED(void, glColor3f, (GLfloat, GLfloat, GLfloat))
     9.7 -SDL_PROC_UNUSED(void, glColor3fv, (const GLfloat *))
     9.8 +SDL_PROC(void, glColor3fv, (const GLfloat *))
     9.9  SDL_PROC_UNUSED(void, glColor3i, (GLint, GLint, GLint))
    9.10  SDL_PROC_UNUSED(void, glColor3iv, (const GLint *))
    9.11  SDL_PROC_UNUSED(void, glColor3s, (GLshort, GLshort, GLshort))
    9.12 @@ -85,7 +85,7 @@
    9.13  SDL_PROC_UNUSED(void, glCullFace, (GLenum mode))
    9.14  SDL_PROC_UNUSED(void, glDeleteLists, (GLuint list, GLsizei range))
    9.15  SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint * textures))
    9.16 -SDL_PROC_UNUSED(void, glDepthFunc, (GLenum func))
    9.17 +SDL_PROC(void, glDepthFunc, (GLenum func))
    9.18  SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
    9.19  SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar))
    9.20  SDL_PROC(void, glDisable, (GLenum cap))
    9.21 @@ -334,13 +334,13 @@
    9.22  SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode))
    9.23  SDL_PROC(void, glRotated,
    9.24                  (GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
    9.25 -SDL_PROC_UNUSED(void, glRotatef,
    9.26 +SDL_PROC(void, glRotatef,
    9.27                  (GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
    9.28  SDL_PROC_UNUSED(void, glScaled, (GLdouble x, GLdouble y, GLdouble z))
    9.29  SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z))
    9.30  SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height))
    9.31  SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint * buffer))
    9.32 -SDL_PROC_UNUSED(void, glShadeModel, (GLenum mode))
    9.33 +SDL_PROC(void, glShadeModel, (GLenum mode))
    9.34  SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask))
    9.35  SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask))
    9.36  SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass))
    9.37 @@ -432,7 +432,7 @@
    9.38  SDL_PROC_UNUSED(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z))
    9.39  SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble * v))
    9.40  SDL_PROC_UNUSED(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z))
    9.41 -SDL_PROC_UNUSED(void, glVertex3fv, (const GLfloat * v))
    9.42 +SDL_PROC(void, glVertex3fv, (const GLfloat * v))
    9.43  SDL_PROC_UNUSED(void, glVertex3i, (GLint x, GLint y, GLint z))
    9.44  SDL_PROC_UNUSED(void, glVertex3iv, (const GLint * v))
    9.45  SDL_PROC_UNUSED(void, glVertex3s, (GLshort x, GLshort y, GLshort z))
    10.1 --- a/src/video/SDL_egl.c	Fri Dec 13 09:48:12 2013 -0300
    10.2 +++ b/src/video/SDL_egl.c	Sat Dec 14 20:18:43 2013 -0300
    10.3 @@ -50,6 +50,7 @@
    10.4  
    10.5  #else
    10.6  /* Desktop Linux */
    10.7 +#define DEFAULT_OGL "libGL.so.1"
    10.8  #define DEFAULT_EGL "libEGL.so.1"
    10.9  #define DEFAULT_OGL_ES2 "libGLESv2.so.2"
   10.10  #define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
   10.11 @@ -149,23 +150,31 @@
   10.12      }
   10.13  
   10.14      if (egl_dll_handle == NULL) {
   10.15 -        if (_this->gl_config.major_version > 1) {
   10.16 -            path = DEFAULT_OGL_ES2;
   10.17 +        if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
   10.18 +            if (_this->gl_config.major_version > 1) {
   10.19 +                path = DEFAULT_OGL_ES2;
   10.20 +                egl_dll_handle = SDL_LoadObject(path);
   10.21 +            }
   10.22 +            else {
   10.23 +                path = DEFAULT_OGL_ES;
   10.24 +                egl_dll_handle = SDL_LoadObject(path);
   10.25 +                if (egl_dll_handle == NULL) {
   10.26 +                    path = DEFAULT_OGL_ES_PVR;
   10.27 +                    egl_dll_handle = SDL_LoadObject(path);
   10.28 +                }
   10.29 +            }
   10.30 +        }
   10.31 +#ifdef DEFAULT_OGL         
   10.32 +        else {
   10.33 +            path = DEFAULT_OGL;
   10.34              egl_dll_handle = SDL_LoadObject(path);
   10.35          }
   10.36 -        else {
   10.37 -            path = DEFAULT_OGL_ES;
   10.38 -            egl_dll_handle = SDL_LoadObject(path);
   10.39 -            if (egl_dll_handle == NULL) {
   10.40 -                path = DEFAULT_OGL_ES_PVR;
   10.41 -                egl_dll_handle = SDL_LoadObject(path);
   10.42 -            }
   10.43 -        }
   10.44 +#endif        
   10.45      }
   10.46      _this->egl_data->egl_dll_handle = egl_dll_handle;
   10.47  
   10.48      if (egl_dll_handle == NULL) {
   10.49 -        return SDL_SetError("Could not initialize OpenGL ES library");
   10.50 +        return SDL_SetError("Could not initialize OpenGL / GLES library");
   10.51      }
   10.52  
   10.53      /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
   10.54 @@ -205,6 +214,7 @@
   10.55      LOAD_FUNC(eglSwapInterval);
   10.56      LOAD_FUNC(eglWaitNative);
   10.57      LOAD_FUNC(eglWaitGL);
   10.58 +    LOAD_FUNC(eglBindAPI);
   10.59      
   10.60      _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
   10.61      if (!_this->egl_data->egl_display) {
   10.62 @@ -281,14 +291,21 @@
   10.63      }
   10.64      
   10.65      attribs[i++] = EGL_RENDERABLE_TYPE;
   10.66 -    if (_this->gl_config.major_version == 2) {
   10.67 -        attribs[i++] = EGL_OPENGL_ES2_BIT;
   10.68 -    } else {
   10.69 -        attribs[i++] = EGL_OPENGL_ES_BIT;
   10.70 +    if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
   10.71 +        if (_this->gl_config.major_version == 2) {
   10.72 +            attribs[i++] = EGL_OPENGL_ES2_BIT;
   10.73 +        } else {
   10.74 +            attribs[i++] = EGL_OPENGL_ES_BIT;
   10.75 +        }
   10.76 +        _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
   10.77 +    }
   10.78 +    else {
   10.79 +        attribs[i++] = EGL_OPENGL_BIT;
   10.80 +        _this->egl_data->eglBindAPI(EGL_OPENGL_API);
   10.81      }
   10.82      
   10.83      attribs[i++] = EGL_NONE;
   10.84 -    
   10.85 +   
   10.86      if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
   10.87          attribs,
   10.88          configs, SDL_arraysize(configs),
   10.89 @@ -347,18 +364,27 @@
   10.90          return NULL;
   10.91      }
   10.92      
   10.93 -    if (_this->gl_config.major_version) {
   10.94 -        context_attrib_list[1] = _this->gl_config.major_version;
   10.95 -    }
   10.96 -    
   10.97      if (_this->gl_config.share_with_current_context) {
   10.98          share_context = (EGLContext)SDL_GL_GetCurrentContext();
   10.99      }
  10.100 +    
  10.101 +    /* Bind the API */
  10.102 +    if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
  10.103 +        _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
  10.104 +        if (_this->gl_config.major_version) {
  10.105 +            context_attrib_list[1] = _this->gl_config.major_version;
  10.106 +        }
  10.107  
  10.108 -    egl_context =
  10.109 -    _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
  10.110 -                                      _this->egl_data->egl_config,
  10.111 -                                      share_context, context_attrib_list);
  10.112 +        egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
  10.113 +                                          _this->egl_data->egl_config,
  10.114 +                                          share_context, context_attrib_list);
  10.115 +    }
  10.116 +    else {
  10.117 +        _this->egl_data->eglBindAPI(EGL_OPENGL_API);
  10.118 +        egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
  10.119 +                                          _this->egl_data->egl_config,
  10.120 +                                          share_context, NULL);
  10.121 +    }
  10.122      
  10.123      if (egl_context == EGL_NO_CONTEXT) {
  10.124          SDL_SetError("Could not create EGL context");
    11.1 --- a/src/video/SDL_egl_c.h	Fri Dec 13 09:48:12 2013 -0300
    11.2 +++ b/src/video/SDL_egl_c.h	Sat Dec 14 20:18:43 2013 -0300
    11.3 @@ -76,6 +76,9 @@
    11.4      EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint  engine);
    11.5  
    11.6      EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
    11.7 +    
    11.8 +    EGLBoolean(EGLAPIENTRY *eglBindAPI)(EGLenum);
    11.9 +
   11.10  } SDL_EGL_VideoData;
   11.11  
   11.12  /* OpenGLES functions */
    12.1 --- a/src/video/SDL_sysvideo.h	Fri Dec 13 09:48:12 2013 -0300
    12.2 +++ b/src/video/SDL_sysvideo.h	Sat Dec 14 20:18:43 2013 -0300
    12.3 @@ -369,6 +369,9 @@
    12.4  #if SDL_VIDEO_DRIVER_DUMMY
    12.5  extern VideoBootStrap DUMMY_bootstrap;
    12.6  #endif
    12.7 +#if SDL_VIDEO_DRIVER_WAYLAND
    12.8 +extern VideoBootStrap Wayland_bootstrap;
    12.9 +#endif
   12.10  
   12.11  extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   12.12  extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
    13.1 --- a/src/video/SDL_video.c	Fri Dec 13 09:48:12 2013 -0300
    13.2 +++ b/src/video/SDL_video.c	Sat Dec 14 20:18:43 2013 -0300
    13.3 @@ -86,6 +86,9 @@
    13.4  #if SDL_VIDEO_DRIVER_DUMMY
    13.5      &DUMMY_bootstrap,
    13.6  #endif
    13.7 +#if SDL_VIDEO_DRIVER_WAYLAND
    13.8 +    &Wayland_bootstrap,
    13.9 +#endif
   13.10      NULL
   13.11  };
   13.12  
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/video/wayland/SDL_waylandevents.c	Sat Dec 14 20:18:43 2013 -0300
    14.3 @@ -0,0 +1,381 @@
    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 +#include "SDL_config.h"
   14.26 +
   14.27 +#include "SDL_stdinc.h"
   14.28 +#include "SDL_assert.h"
   14.29 +
   14.30 +#include "../../events/SDL_sysevents.h"
   14.31 +#include "../../events/SDL_events_c.h"
   14.32 +#include "../../events/scancodes_xfree86.h"
   14.33 +
   14.34 +#include "SDL_waylandvideo.h"
   14.35 +#include "SDL_waylandevents_c.h"
   14.36 +#include "SDL_waylandwindow.h"
   14.37 +
   14.38 +#include <linux/input.h>
   14.39 +#include <sys/select.h>
   14.40 +#include <sys/mman.h>
   14.41 +#include <poll.h>
   14.42 +#include <errno.h>
   14.43 +#include <unistd.h>
   14.44 +#include <xkbcommon/xkbcommon.h>
   14.45 +
   14.46 +struct SDL_WaylandInput {
   14.47 +    SDL_VideoData *display;
   14.48 +    struct wl_seat *seat;
   14.49 +    struct wl_pointer *pointer;
   14.50 +    struct wl_keyboard *keyboard;
   14.51 +    SDL_WindowData *pointer_focus;
   14.52 +    SDL_WindowData *keyboard_focus;
   14.53 +
   14.54 +    struct {
   14.55 +        struct xkb_keymap *keymap;
   14.56 +        struct xkb_state *state;
   14.57 +    } xkb;
   14.58 +};
   14.59 +
   14.60 +void
   14.61 +Wayland_PumpEvents(_THIS)
   14.62 +{
   14.63 +    SDL_VideoData *d = _this->driverdata;
   14.64 +    struct pollfd pfd[1];
   14.65 +
   14.66 +    pfd[0].fd = wl_display_get_fd(d->display);
   14.67 +    pfd[0].events = POLLIN;
   14.68 +    poll(pfd, 1, 0);
   14.69 +
   14.70 +    if (pfd[0].revents & POLLIN)
   14.71 +        wl_display_dispatch(d->display);
   14.72 +    else
   14.73 +        wl_display_dispatch_pending(d->display);
   14.74 +}
   14.75 +
   14.76 +static void
   14.77 +pointer_handle_enter(void *data, struct wl_pointer *pointer,
   14.78 +                     uint32_t serial, struct wl_surface *surface,
   14.79 +                     wl_fixed_t sx_w, wl_fixed_t sy_w)
   14.80 +{
   14.81 +    struct SDL_WaylandInput *input = data;
   14.82 +    SDL_WindowData *window;
   14.83 +
   14.84 +    if (!surface) {
   14.85 +        /* enter event for a window we've just destroyed */
   14.86 +        return;
   14.87 +    }
   14.88 +
   14.89 +    input->pointer_focus = wl_surface_get_user_data(surface);
   14.90 +    window = input->pointer_focus;
   14.91 +    SDL_SetMouseFocus(window->sdlwindow);
   14.92 +}
   14.93 +
   14.94 +static void
   14.95 +pointer_handle_leave(void *data, struct wl_pointer *pointer,
   14.96 +                     uint32_t serial, struct wl_surface *surface)
   14.97 +{
   14.98 +    struct SDL_WaylandInput *input = data;
   14.99 +
  14.100 +    SDL_SetMouseFocus(NULL);
  14.101 +    input->pointer_focus = NULL;
  14.102 +}
  14.103 +
  14.104 +static void
  14.105 +pointer_handle_motion(void *data, struct wl_pointer *pointer,
  14.106 +                      uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
  14.107 +{
  14.108 +    struct SDL_WaylandInput *input = data;
  14.109 +    SDL_WindowData *window = input->pointer_focus;
  14.110 +    int sx = wl_fixed_to_int(sx_w);
  14.111 +    int sy = wl_fixed_to_int(sy_w);
  14.112 +
  14.113 +    SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy);
  14.114 +}
  14.115 +
  14.116 +static void
  14.117 +pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
  14.118 +                      uint32_t time, uint32_t button, uint32_t state_w)
  14.119 +{
  14.120 +    struct SDL_WaylandInput *input = data;
  14.121 +    SDL_WindowData *window = input->pointer_focus;
  14.122 +    enum wl_pointer_button_state state = state_w;
  14.123 +    uint32_t sdl_button;
  14.124 +
  14.125 +    switch (button) {
  14.126 +    case BTN_LEFT:
  14.127 +        sdl_button = SDL_BUTTON_LEFT;
  14.128 +        break;
  14.129 +    case BTN_MIDDLE:
  14.130 +        sdl_button = SDL_BUTTON_MIDDLE;
  14.131 +        break;
  14.132 +    case BTN_RIGHT:
  14.133 +        sdl_button = SDL_BUTTON_RIGHT;
  14.134 +        break;
  14.135 +    case BTN_SIDE:
  14.136 +        sdl_button = SDL_BUTTON_X1;
  14.137 +        break;
  14.138 +    case BTN_EXTRA:
  14.139 +        sdl_button = SDL_BUTTON_X2;
  14.140 +        break;
  14.141 +    default:
  14.142 +        return;
  14.143 +    }
  14.144 +
  14.145 +    SDL_SendMouseButton(window->sdlwindow, 0,
  14.146 +                        state ? SDL_PRESSED : SDL_RELEASED, sdl_button);
  14.147 +}
  14.148 +
  14.149 +static void
  14.150 +pointer_handle_axis(void *data, struct wl_pointer *pointer,
  14.151 +                    uint32_t time, uint32_t axis, wl_fixed_t value)
  14.152 +{
  14.153 +    struct SDL_WaylandInput *input = data;
  14.154 +    SDL_WindowData *window = input->pointer_focus;
  14.155 +    enum wl_pointer_axis a = axis;
  14.156 +    int x, y;
  14.157 +
  14.158 +    switch (a) {
  14.159 +    case WL_POINTER_AXIS_VERTICAL_SCROLL:
  14.160 +        x = 0;
  14.161 +        y = wl_fixed_to_int(value);
  14.162 +        break;
  14.163 +    case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
  14.164 +        x = wl_fixed_to_int(value);
  14.165 +        y = 0;
  14.166 +        break;
  14.167 +    default:
  14.168 +        return;
  14.169 +    }
  14.170 +
  14.171 +    SDL_SendMouseWheel(window->sdlwindow, 0, x, y);
  14.172 +}
  14.173 +
  14.174 +static const struct wl_pointer_listener pointer_listener = {
  14.175 +    pointer_handle_enter,
  14.176 +    pointer_handle_leave,
  14.177 +    pointer_handle_motion,
  14.178 +    pointer_handle_button,
  14.179 +    pointer_handle_axis,
  14.180 +};
  14.181 +
  14.182 +static void
  14.183 +keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
  14.184 +                       uint32_t format, int fd, uint32_t size)
  14.185 +{
  14.186 +    struct SDL_WaylandInput *input = data;
  14.187 +    char *map_str;
  14.188 +
  14.189 +    if (!data) {
  14.190 +        close(fd);
  14.191 +        return;
  14.192 +    }
  14.193 +
  14.194 +    if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
  14.195 +        close(fd);
  14.196 +        return;
  14.197 +    }
  14.198 +
  14.199 +    map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
  14.200 +    if (map_str == MAP_FAILED) {
  14.201 +        close(fd);
  14.202 +        return;
  14.203 +    }
  14.204 +
  14.205 +    input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context,
  14.206 +                                                map_str,
  14.207 +                                                XKB_KEYMAP_FORMAT_TEXT_V1,
  14.208 +                                                0);
  14.209 +    munmap(map_str, size);
  14.210 +    close(fd);
  14.211 +
  14.212 +    if (!input->xkb.keymap) {
  14.213 +        fprintf(stderr, "failed to compile keymap\n");
  14.214 +        return;
  14.215 +    }
  14.216 +
  14.217 +    input->xkb.state = xkb_state_new(input->xkb.keymap);
  14.218 +    if (!input->xkb.state) {
  14.219 +        fprintf(stderr, "failed to create XKB state\n");
  14.220 +        xkb_map_unref(input->xkb.keymap);
  14.221 +        input->xkb.keymap = NULL;
  14.222 +        return;
  14.223 +    }
  14.224 +}
  14.225 +
  14.226 +static void
  14.227 +keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
  14.228 +                      uint32_t serial, struct wl_surface *surface,
  14.229 +                      struct wl_array *keys)
  14.230 +{
  14.231 +    struct SDL_WaylandInput *input = data;
  14.232 +    SDL_WindowData *window = wl_surface_get_user_data(surface);
  14.233 +
  14.234 +    input->keyboard_focus = window;
  14.235 +    window->keyboard_device = input;
  14.236 +    SDL_SetKeyboardFocus(window->sdlwindow);
  14.237 +}
  14.238 +
  14.239 +static void
  14.240 +keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
  14.241 +                      uint32_t serial, struct wl_surface *surface)
  14.242 +{
  14.243 +    SDL_SetKeyboardFocus(NULL);
  14.244 +}
  14.245 +
  14.246 +static void
  14.247 +keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
  14.248 +                    uint32_t serial, uint32_t time, uint32_t key,
  14.249 +                    uint32_t state_w)
  14.250 +{
  14.251 +    struct SDL_WaylandInput *input = data;
  14.252 +    SDL_WindowData *window = input->keyboard_focus;
  14.253 +    enum wl_keyboard_key_state state = state_w;
  14.254 +    const xkb_keysym_t *syms;
  14.255 +    uint32_t scancode;
  14.256 +    char text[8];
  14.257 +    int size;
  14.258 +
  14.259 +    if (key < SDL_arraysize(xfree86_scancode_table2)) {
  14.260 +        scancode = xfree86_scancode_table2[key];
  14.261 +
  14.262 +        // TODO when do we get WL_KEYBOARD_KEY_STATE_REPEAT?
  14.263 +        if (scancode != SDL_SCANCODE_UNKNOWN)
  14.264 +            SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ?
  14.265 +                                SDL_PRESSED : SDL_RELEASED, scancode);
  14.266 +    }
  14.267 +
  14.268 +    if (!window || window->keyboard_device != input || !input->xkb.state)
  14.269 +        return;
  14.270 +
  14.271 +    // TODO can this happen?
  14.272 +    if (xkb_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
  14.273 +        return;
  14.274 +
  14.275 +    if (state) {
  14.276 +        size = xkb_keysym_to_utf8(syms[0], text, sizeof text);
  14.277 +
  14.278 +        if (size > 0) {
  14.279 +            text[size] = 0;
  14.280 +            SDL_SendKeyboardText(text);
  14.281 +        }
  14.282 +    }
  14.283 +}
  14.284 +
  14.285 +static void
  14.286 +keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
  14.287 +                          uint32_t serial, uint32_t mods_depressed,
  14.288 +                          uint32_t mods_latched, uint32_t mods_locked,
  14.289 +                          uint32_t group)
  14.290 +{
  14.291 +    struct SDL_WaylandInput *input = data;
  14.292 +
  14.293 +    xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
  14.294 +                          mods_locked, 0, 0, group);
  14.295 +}
  14.296 +
  14.297 +static const struct wl_keyboard_listener keyboard_listener = {
  14.298 +    keyboard_handle_keymap,
  14.299 +    keyboard_handle_enter,
  14.300 +    keyboard_handle_leave,
  14.301 +    keyboard_handle_key,
  14.302 +    keyboard_handle_modifiers,
  14.303 +};
  14.304 +
  14.305 +static void
  14.306 +seat_handle_capabilities(void *data, struct wl_seat *seat,
  14.307 +                         enum wl_seat_capability caps)
  14.308 +{
  14.309 +    struct SDL_WaylandInput *input = data;
  14.310 +
  14.311 +    if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
  14.312 +        input->pointer = wl_seat_get_pointer(seat);
  14.313 +        input->display->pointer = input->pointer;
  14.314 +        wl_pointer_set_user_data(input->pointer, input);
  14.315 +        wl_pointer_add_listener(input->pointer, &pointer_listener,
  14.316 +                                input);
  14.317 +    } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
  14.318 +        wl_pointer_destroy(input->pointer);
  14.319 +        input->pointer = NULL;
  14.320 +    }
  14.321 +
  14.322 +    if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
  14.323 +        input->keyboard = wl_seat_get_keyboard(seat);
  14.324 +        wl_keyboard_set_user_data(input->keyboard, input);
  14.325 +        wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
  14.326 +                                 input);
  14.327 +    } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
  14.328 +        wl_keyboard_destroy(input->keyboard);
  14.329 +        input->keyboard = NULL;
  14.330 +    }
  14.331 +}
  14.332 +
  14.333 +static const struct wl_seat_listener seat_listener = {
  14.334 +    seat_handle_capabilities,
  14.335 +};
  14.336 +
  14.337 +void
  14.338 +Wayland_display_add_input(SDL_VideoData *d, uint32_t id)
  14.339 +{
  14.340 +    struct SDL_WaylandInput *input;
  14.341 +
  14.342 +    input = malloc(sizeof *input);
  14.343 +    if (input == NULL)
  14.344 +        return;
  14.345 +
  14.346 +    memset(input, 0, sizeof *input);
  14.347 +    input->display = d;
  14.348 +    input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
  14.349 +
  14.350 +    d->input = input;
  14.351 +
  14.352 +    wl_seat_add_listener(input->seat, &seat_listener, input);
  14.353 +    wl_seat_set_user_data(input->seat, input);
  14.354 +
  14.355 +    wayland_schedule_write(d);
  14.356 +}
  14.357 +
  14.358 +void Wayland_display_destroy_input(SDL_VideoData *d)
  14.359 +{
  14.360 +    struct SDL_WaylandInput *input = d->input;
  14.361 +
  14.362 +    if (!input)
  14.363 +        return;
  14.364 +
  14.365 +    if (input->keyboard)
  14.366 +        wl_keyboard_destroy(input->keyboard);
  14.367 +
  14.368 +    if (input->pointer)
  14.369 +        wl_pointer_destroy(input->pointer);
  14.370 +
  14.371 +    if (input->seat)
  14.372 +        wl_seat_destroy(input->seat);
  14.373 +
  14.374 +    if (input->xkb.state)
  14.375 +        xkb_state_unref(input->xkb.state);
  14.376 +
  14.377 +    if (input->xkb.keymap)
  14.378 +        xkb_map_unref(input->xkb.keymap);
  14.379 +
  14.380 +    free(input);
  14.381 +    d->input = NULL;
  14.382 +}
  14.383 +
  14.384 +/* vi: set ts=4 sw=4 expandtab: */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/video/wayland/SDL_waylandevents_c.h	Sat Dec 14 20:18:43 2013 -0300
    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 +#include "SDL_config.h"
   15.26 +
   15.27 +#ifndef _SDL_waylandevents_h
   15.28 +#define _SDL_waylandevents_h
   15.29 +
   15.30 +#include "SDL_waylandvideo.h"
   15.31 +#include "SDL_waylandwindow.h"
   15.32 +
   15.33 +extern void Wayland_PumpEvents(_THIS);
   15.34 +
   15.35 +extern void Wayland_display_add_input(SDL_VideoData *d, uint32_t id);
   15.36 +extern void Wayland_display_destroy_input(SDL_VideoData *d);
   15.37 +
   15.38 +#endif /* _SDL_waylandevents_h */
   15.39 +
   15.40 +/* vi: set ts=4 sw=4 expandtab: */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/video/wayland/SDL_waylandmouse.c	Sat Dec 14 20:18:43 2013 -0300
    16.3 @@ -0,0 +1,407 @@
    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 +#ifndef _GNU_SOURCE
   16.26 +#define _GNU_SOURCE
   16.27 +#endif
   16.28 +
   16.29 +#include <errno.h>
   16.30 +#include <sys/types.h>
   16.31 +#include <sys/mman.h>
   16.32 +#include <fcntl.h>
   16.33 +#include <unistd.h>
   16.34 +#include <stdlib.h>
   16.35 +#include <limits.h>
   16.36 +
   16.37 +#include "../SDL_sysvideo.h"
   16.38 +
   16.39 +#include "SDL_config.h"
   16.40 +#include "SDL_mouse.h"
   16.41 +#include "../../events/SDL_mouse_c.h"
   16.42 +#include "SDL_waylandvideo.h"
   16.43 +#include "SDL_waylandevents_c.h"
   16.44 +
   16.45 +#include "SDL_assert.h"
   16.46 +
   16.47 +#if SDL_VIDEO_DRIVER_WAYLAND
   16.48 +
   16.49 +typedef struct {
   16.50 +    struct wl_buffer   *buffer;
   16.51 +    struct wl_surface  *surface;
   16.52 +
   16.53 +    int                hot_x, hot_y;
   16.54 +
   16.55 +    /* Either a preloaded cursor, or one we created ourselves */
   16.56 +    struct wl_cursor   *cursor;
   16.57 +    void               *shm_data;
   16.58 +} Wayland_CursorData;
   16.59 +
   16.60 +static int
   16.61 +wayland_create_tmp_file(off_t size)
   16.62 +{
   16.63 +    static const char template[] = "/sdl-shared-XXXXXX";
   16.64 +    char *xdg_path;
   16.65 +    char tmp_path[PATH_MAX];
   16.66 +    int fd;
   16.67 +
   16.68 +    xdg_path = SDL_getenv("XDG_RUNTIME_DIR");
   16.69 +    if (!xdg_path) {
   16.70 +        errno = ENOENT;
   16.71 +        return -1;
   16.72 +    }
   16.73 +
   16.74 +    SDL_strlcpy(tmp_path, xdg_path, PATH_MAX);
   16.75 +    SDL_strlcat(tmp_path, template, PATH_MAX);
   16.76 +
   16.77 +    fd = mkostemp(tmp_path, O_CLOEXEC);
   16.78 +    if (fd < 0)
   16.79 +        return -1;
   16.80 +
   16.81 +    if (ftruncate(fd, size) < 0) {
   16.82 +        close(fd);
   16.83 +        return -1;
   16.84 +    }
   16.85 +
   16.86 +    return fd;
   16.87 +}
   16.88 +
   16.89 +static void
   16.90 +mouse_buffer_release(void *data, struct wl_buffer *buffer)
   16.91 +{
   16.92 +}
   16.93 +
   16.94 +static const struct wl_buffer_listener mouse_buffer_listener = {
   16.95 +    mouse_buffer_release
   16.96 +};
   16.97 +
   16.98 +static int
   16.99 +create_buffer_from_shm(Wayland_CursorData *d,
  16.100 +                       int width,
  16.101 +                       int height,
  16.102 +                       uint32_t format)
  16.103 +{
  16.104 +    SDL_VideoDevice *vd = SDL_GetVideoDevice();
  16.105 +    SDL_VideoData *data = (SDL_VideoData *) vd->driverdata;
  16.106 +
  16.107 +    int stride = width * 4;
  16.108 +    int size = stride * height;
  16.109 +
  16.110 +    int shm_fd;
  16.111 +
  16.112 +    shm_fd = wayland_create_tmp_file(size);
  16.113 +    if (shm_fd < 0)
  16.114 +    {
  16.115 +        fprintf(stderr, "creating mouse cursor buffer failed!\n");
  16.116 +        return -1;
  16.117 +    }
  16.118 +
  16.119 +    d->shm_data = mmap(NULL,
  16.120 +                       size,
  16.121 +                       PROT_READ | PROT_WRITE,
  16.122 +                       MAP_SHARED,
  16.123 +                       shm_fd,
  16.124 +                       0);
  16.125 +    if (data == MAP_FAILED) {
  16.126 +        d->shm_data = NULL;
  16.127 +        fprintf (stderr, "mmap () failed\n");
  16.128 +        close (shm_fd);
  16.129 +    }
  16.130 +
  16.131 +    struct wl_shm_pool *shm_pool = wl_shm_create_pool(data->shm,
  16.132 +                                                      shm_fd,
  16.133 +                                                      size);
  16.134 +    d->buffer = wl_shm_pool_create_buffer(shm_pool,
  16.135 +                                          0,
  16.136 +                                          width,
  16.137 +                                          height,
  16.138 +                                          stride,
  16.139 +                                          format);
  16.140 +    wl_buffer_add_listener(d->buffer,
  16.141 +                           &mouse_buffer_listener,
  16.142 +                           d);
  16.143 +
  16.144 +    wl_shm_pool_destroy (shm_pool);
  16.145 +    close (shm_fd);
  16.146 +
  16.147 +    return 0;
  16.148 +}
  16.149 +
  16.150 +static SDL_Cursor *
  16.151 +Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
  16.152 +{
  16.153 +    SDL_Cursor *cursor;
  16.154 +
  16.155 +    cursor = calloc(1, sizeof (*cursor));
  16.156 +    if (cursor) {
  16.157 +        SDL_VideoDevice *vd = SDL_GetVideoDevice ();
  16.158 +        SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata;
  16.159 +        Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
  16.160 +        cursor->driverdata = (void *) data;
  16.161 +
  16.162 +        /* Assume ARGB8888 */
  16.163 +        SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
  16.164 +        SDL_assert(surface->pitch == surface->w * 4);
  16.165 +
  16.166 +        /* Allocate shared memory buffer for this cursor */
  16.167 +        if (create_buffer_from_shm (data,
  16.168 +                                    surface->w,
  16.169 +                                    surface->h,
  16.170 +                                    WL_SHM_FORMAT_XRGB8888) < 0)
  16.171 +        {
  16.172 +            free (cursor->driverdata);
  16.173 +            free (cursor);
  16.174 +            return NULL;
  16.175 +        }
  16.176 +
  16.177 +        SDL_memcpy(data->shm_data,
  16.178 +                   surface->pixels,
  16.179 +                   surface->h * surface->pitch);
  16.180 +
  16.181 +        data->surface = wl_compositor_create_surface(wd->compositor);
  16.182 +        wl_surface_attach(data->surface,
  16.183 +                          data->buffer,
  16.184 +                          0,
  16.185 +                          0);
  16.186 +        wl_surface_damage(data->surface,
  16.187 +                          0,
  16.188 +                          0,
  16.189 +                          surface->w,
  16.190 +                          surface->h);
  16.191 +        wl_surface_commit(data->surface);
  16.192 +
  16.193 +        data->hot_x = hot_x;
  16.194 +        data->hot_y = hot_y;
  16.195 +    }
  16.196 +
  16.197 +    return cursor;
  16.198 +}
  16.199 +
  16.200 +static SDL_Cursor *
  16.201 +CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor)
  16.202 +{
  16.203 +    SDL_Cursor *cursor;
  16.204 +
  16.205 +    cursor = calloc(1, sizeof (*cursor));
  16.206 +    if (cursor) {
  16.207 +        Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
  16.208 +        cursor->driverdata = (void *) data;
  16.209 +
  16.210 +        /* The wl_buffer here will be destroyed from wl_cursor_theme_destroy
  16.211 +         * if we are fetching this from a wl_cursor_theme, so don't store a
  16.212 +         * reference to it here */
  16.213 +        data->buffer = NULL;
  16.214 +        data->surface = wl_compositor_create_surface(d->compositor);
  16.215 +        wl_surface_attach(data->surface,
  16.216 +                          wl_cursor_image_get_buffer(wlcursor->images[0]),
  16.217 +                          0,
  16.218 +                          0);
  16.219 +        wl_surface_damage(data->surface,
  16.220 +                          0,
  16.221 +                          0,
  16.222 +                          wlcursor->images[0]->width,
  16.223 +                          wlcursor->images[0]->height);
  16.224 +        wl_surface_commit(data->surface);
  16.225 +        data->hot_x = wlcursor->images[0]->hotspot_x;
  16.226 +        data->hot_y = wlcursor->images[0]->hotspot_y;
  16.227 +        data->cursor= wlcursor;
  16.228 +    } else {
  16.229 +        SDL_OutOfMemory ();
  16.230 +    }
  16.231 +
  16.232 +    return cursor;
  16.233 +}
  16.234 +
  16.235 +static SDL_Cursor *
  16.236 +Wayland_CreateDefaultCursor()
  16.237 +{
  16.238 +    SDL_VideoDevice *device = SDL_GetVideoDevice();
  16.239 +    SDL_VideoData *data = device->driverdata;
  16.240 +
  16.241 +    return CreateCursorFromWlCursor (data,
  16.242 +                                     wl_cursor_theme_get_cursor(data->cursor_theme,
  16.243 +                                                                "left_ptr"));
  16.244 +}
  16.245 +
  16.246 +static SDL_Cursor *
  16.247 +Wayland_CreateSystemCursor(SDL_SystemCursor id)
  16.248 +{
  16.249 +    SDL_VideoDevice *vd = SDL_GetVideoDevice();
  16.250 +    SDL_VideoData *d = vd->driverdata;
  16.251 +
  16.252 +    struct wl_cursor *cursor = NULL;
  16.253 +
  16.254 +    switch(id)
  16.255 +    {
  16.256 +    default:
  16.257 +        SDL_assert(0);
  16.258 +        return NULL;
  16.259 +    case SDL_SYSTEM_CURSOR_ARROW:
  16.260 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
  16.261 +        break;
  16.262 +    case SDL_SYSTEM_CURSOR_IBEAM:
  16.263 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
  16.264 +        break;
  16.265 +    case SDL_SYSTEM_CURSOR_WAIT:
  16.266 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "wait");
  16.267 +        break;
  16.268 +    case SDL_SYSTEM_CURSOR_CROSSHAIR:
  16.269 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.270 +        break;
  16.271 +    case SDL_SYSTEM_CURSOR_WAITARROW:
  16.272 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "wait");
  16.273 +        break;
  16.274 +    case SDL_SYSTEM_CURSOR_SIZENWSE:
  16.275 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.276 +        break;
  16.277 +    case SDL_SYSTEM_CURSOR_SIZENESW:
  16.278 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.279 +        break;
  16.280 +    case SDL_SYSTEM_CURSOR_SIZEWE:
  16.281 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.282 +        break;
  16.283 +    case SDL_SYSTEM_CURSOR_SIZENS:
  16.284 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.285 +        break;
  16.286 +    case SDL_SYSTEM_CURSOR_SIZEALL:
  16.287 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.288 +        break;
  16.289 +    case SDL_SYSTEM_CURSOR_NO:
  16.290 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
  16.291 +        break;
  16.292 +    case SDL_SYSTEM_CURSOR_HAND:
  16.293 +        cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
  16.294 +        break;
  16.295 +    }
  16.296 +
  16.297 +    SDL_Cursor *sdl_cursor = CreateCursorFromWlCursor (d, cursor);
  16.298 +
  16.299 +    return sdl_cursor;
  16.300 +}
  16.301 +
  16.302 +static void
  16.303 +Wayland_FreeCursor(SDL_Cursor *cursor)
  16.304 +{
  16.305 +    if (!cursor)
  16.306 +        return;
  16.307 +
  16.308 +    Wayland_CursorData *d = cursor->driverdata;
  16.309 +
  16.310 +    /* Probably not a cursor we own */
  16.311 +    if (!d)
  16.312 +        return;
  16.313 +
  16.314 +    if (d->buffer)
  16.315 +        wl_buffer_destroy(d->buffer);
  16.316 +
  16.317 +    if (d->surface)
  16.318 +        wl_surface_destroy(d->surface);
  16.319 +
  16.320 +    /* Not sure what's meant to happen to shm_data */
  16.321 +    free (cursor->driverdata);
  16.322 +    SDL_free(cursor);
  16.323 +}
  16.324 +
  16.325 +static int
  16.326 +Wayland_ShowCursor(SDL_Cursor *cursor)
  16.327 +{
  16.328 +    SDL_VideoDevice *vd = SDL_GetVideoDevice();
  16.329 +    SDL_VideoData *d = vd->driverdata;
  16.330 +
  16.331 +    struct wl_pointer *pointer = d->pointer;
  16.332 +
  16.333 +    if (!pointer)
  16.334 +        return -1;
  16.335 +
  16.336 +    if (cursor)
  16.337 +    {
  16.338 +        Wayland_CursorData *data = cursor->driverdata;
  16.339 +
  16.340 +        wl_pointer_set_cursor (pointer, 0,
  16.341 +                               data->surface,
  16.342 +                               data->hot_x,
  16.343 +                               data->hot_y);
  16.344 +    }
  16.345 +    else
  16.346 +    {
  16.347 +        wl_pointer_set_cursor (pointer, 0,
  16.348 +                               NULL,
  16.349 +                               0,
  16.350 +                               0);
  16.351 +    }
  16.352 +    
  16.353 +    return 0;
  16.354 +}
  16.355 +
  16.356 +static void
  16.357 +Wayland_WarpMouse(SDL_Window *window, int x, int y)
  16.358 +{
  16.359 +    SDL_Unsupported();
  16.360 +    return;
  16.361 +}
  16.362 +
  16.363 +static int
  16.364 +Wayland_SetRelativeMouseMode(SDL_bool enabled)
  16.365 +{
  16.366 +    SDL_Unsupported();
  16.367 +    return -1;
  16.368 +}
  16.369 +
  16.370 +void
  16.371 +Wayland_InitMouse(void)
  16.372 +{
  16.373 +    SDL_Mouse *mouse = SDL_GetMouse();
  16.374 +
  16.375 +    mouse->CreateCursor = Wayland_CreateCursor;
  16.376 +    mouse->CreateSystemCursor = Wayland_CreateSystemCursor;
  16.377 +    mouse->ShowCursor = Wayland_ShowCursor;
  16.378 +    mouse->FreeCursor = Wayland_FreeCursor;
  16.379 +    mouse->WarpMouse = Wayland_WarpMouse;
  16.380 +    mouse->SetRelativeMouseMode = Wayland_SetRelativeMouseMode;
  16.381 +
  16.382 +    SDL_SetDefaultCursor(Wayland_CreateDefaultCursor());
  16.383 +}
  16.384 +
  16.385 +void
  16.386 +Wayland_FiniMouse(void)
  16.387 +{
  16.388 +    /* This effectively assumes that nobody else
  16.389 +     * touches SDL_Mouse which is effectively
  16.390 +     * a singleton */
  16.391 +
  16.392 +    SDL_Mouse *mouse = SDL_GetMouse();
  16.393 +
  16.394 +    /* Free the current cursor if not the same pointer as
  16.395 +     * the default cursor */
  16.396 +    if (mouse->def_cursor != mouse->cur_cursor)
  16.397 +        Wayland_FreeCursor (mouse->cur_cursor);
  16.398 +
  16.399 +    Wayland_FreeCursor (mouse->def_cursor);
  16.400 +    mouse->def_cursor = NULL;
  16.401 +    mouse->cur_cursor = NULL;
  16.402 +
  16.403 +    mouse->CreateCursor =  NULL;
  16.404 +    mouse->CreateSystemCursor = NULL;
  16.405 +    mouse->ShowCursor = NULL;
  16.406 +    mouse->FreeCursor = NULL;
  16.407 +    mouse->WarpMouse = NULL;
  16.408 +    mouse->SetRelativeMouseMode = NULL;
  16.409 +}
  16.410 +#endif
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/wayland/SDL_waylandmouse.h	Sat Dec 14 20:18:43 2013 -0300
    17.3 @@ -0,0 +1,31 @@
    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 +#include "SDL_config.h"
   17.26 +#include "SDL_mouse.h"
   17.27 +#include "SDL_waylandvideo.h"
   17.28 +
   17.29 +#if SDL_VIDEO_DRIVER_WAYLAND
   17.30 +
   17.31 +extern void Wayland_InitMouse(void);
   17.32 +extern void Wayland_FiniMouse(void);
   17.33 +
   17.34 +#endif
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/video/wayland/SDL_waylandopengles.c	Sat Dec 14 20:18:43 2013 -0300
    18.3 @@ -0,0 +1,90 @@
    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 +#include "SDL_config.h"
   18.25 +
   18.26 +#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
   18.27 +
   18.28 +#include "SDL_waylandvideo.h"
   18.29 +#include "SDL_waylandopengles.h"
   18.30 +#include "SDL_waylandwindow.h"
   18.31 +#include "SDL_waylandevents_c.h"
   18.32 +
   18.33 +/* EGL implementation of SDL OpenGL ES support */
   18.34 +
   18.35 +int
   18.36 +Wayland_GLES_LoadLibrary(_THIS, const char *path) {
   18.37 +    int ret;
   18.38 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   18.39 +    
   18.40 +    ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display);
   18.41 +
   18.42 +    Wayland_PumpEvents(_this);
   18.43 +    wayland_schedule_write(data);
   18.44 +    
   18.45 +    return ret;
   18.46 +}
   18.47 +
   18.48 +
   18.49 +SDL_GLContext
   18.50 +Wayland_GLES_CreateContext(_THIS, SDL_Window * window)
   18.51 +{
   18.52 +    SDL_GLContext context;
   18.53 +    context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
   18.54 +    wayland_schedule_write(_this->driverdata);
   18.55 +    
   18.56 +    return context;
   18.57 +}
   18.58 +
   18.59 +void
   18.60 +Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
   18.61 +{
   18.62 +    SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
   18.63 +    wayland_schedule_write(_this->driverdata);
   18.64 +}
   18.65 +
   18.66 +
   18.67 +int
   18.68 +Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   18.69 +{
   18.70 +    int ret;
   18.71 +    
   18.72 +    if (window && context) {
   18.73 +        ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
   18.74 +    }
   18.75 +    else {
   18.76 +        ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
   18.77 +    }
   18.78 +    
   18.79 +    wayland_schedule_write(_this->driverdata);
   18.80 +    
   18.81 +    return ret;
   18.82 +}
   18.83 +
   18.84 +void 
   18.85 +Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context)
   18.86 +{
   18.87 +    SDL_EGL_DeleteContext(_this, context);
   18.88 +    wayland_schedule_write(_this->driverdata);
   18.89 +}
   18.90 +
   18.91 +#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
   18.92 +
   18.93 +/* vi: set ts=4 sw=4 expandtab: */
   18.94 \ No newline at end of file
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/wayland/SDL_waylandopengles.h	Sat Dec 14 20:18:43 2013 -0300
    19.3 @@ -0,0 +1,46 @@
    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 +#include "SDL_config.h"
   19.25 +
   19.26 +#ifndef _SDL_waylandopengles_h
   19.27 +#define _SDL_waylandopengles_h
   19.28 +
   19.29 +#include "../SDL_sysvideo.h"
   19.30 +#include "../SDL_egl_c.h"
   19.31 +
   19.32 +typedef struct SDL_PrivateGLESData
   19.33 +{
   19.34 +} SDL_PrivateGLESData;
   19.35 +
   19.36 +/* OpenGLES functions */
   19.37 +#define Wayland_GLES_GetAttribute SDL_EGL_GetAttribute
   19.38 +#define Wayland_GLES_GetProcAddress SDL_EGL_GetProcAddress
   19.39 +#define Wayland_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
   19.40 +#define Wayland_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
   19.41 +#define Wayland_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
   19.42 +
   19.43 +extern int Wayland_GLES_LoadLibrary(_THIS, const char *path);
   19.44 +extern SDL_GLContext Wayland_GLES_CreateContext(_THIS, SDL_Window * window);
   19.45 +extern void Wayland_GLES_SwapWindow(_THIS, SDL_Window * window);
   19.46 +extern int Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
   19.47 +extern void Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context);
   19.48 +
   19.49 +#endif /* _SDL_waylandopengles_h */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Sat Dec 14 20:18:43 2013 -0300
    20.3 @@ -0,0 +1,365 @@
    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 +#include "SDL_config.h"
   20.26 +
   20.27 +#include "SDL_video.h"
   20.28 +#include "SDL_mouse.h"
   20.29 +#include "../../events/SDL_events_c.h"
   20.30 +
   20.31 +#include "SDL_waylandvideo.h"
   20.32 +#include "SDL_waylandevents_c.h"
   20.33 +#include "SDL_waylandwindow.h"
   20.34 +#include "SDL_waylandopengles.h"
   20.35 +#include "SDL_waylandmouse.h"
   20.36 +
   20.37 +#include <fcntl.h>
   20.38 +#include <xkbcommon/xkbcommon.h>
   20.39 +
   20.40 +#define WAYLANDVID_DRIVER_NAME "wayland"
   20.41 +
   20.42 +struct wayland_mode {
   20.43 +    SDL_DisplayMode mode;
   20.44 +    struct wl_list link;
   20.45 +};
   20.46 +
   20.47 +/* Initialization/Query functions */
   20.48 +static int
   20.49 +Wayland_VideoInit(_THIS);
   20.50 +
   20.51 +static void
   20.52 +Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display);
   20.53 +static int
   20.54 +Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
   20.55 +
   20.56 +static void
   20.57 +Wayland_VideoQuit(_THIS);
   20.58 +
   20.59 +/* Wayland driver bootstrap functions */
   20.60 +static int
   20.61 +Wayland_Available(void)
   20.62 +{
   20.63 +    struct wl_display *display = NULL;
   20.64 +
   20.65 +    display = wl_display_connect(NULL);
   20.66 +    if (display != NULL) {
   20.67 +        wl_display_disconnect(display);
   20.68 +    }
   20.69 +
   20.70 +    return (display != NULL);
   20.71 +}
   20.72 +
   20.73 +static void
   20.74 +Wayland_DeleteDevice(SDL_VideoDevice *device)
   20.75 +{
   20.76 +    SDL_free(device);
   20.77 +}
   20.78 +
   20.79 +static SDL_VideoDevice *
   20.80 +Wayland_CreateDevice(int devindex)
   20.81 +{
   20.82 +    SDL_VideoDevice *device;
   20.83 +
   20.84 +    /* Initialize all variables that we clean on shutdown */
   20.85 +    device = SDL_calloc(1, sizeof(SDL_VideoDevice));
   20.86 +    if (!device) {
   20.87 +        SDL_OutOfMemory();
   20.88 +        return NULL;
   20.89 +    }
   20.90 +
   20.91 +    /* Set the function pointers */
   20.92 +    device->VideoInit = Wayland_VideoInit;
   20.93 +    device->VideoQuit = Wayland_VideoQuit;
   20.94 +    device->SetDisplayMode = Wayland_SetDisplayMode;
   20.95 +    device->GetDisplayModes = Wayland_GetDisplayModes;
   20.96 +    device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
   20.97 +
   20.98 +    device->PumpEvents = Wayland_PumpEvents;
   20.99 +
  20.100 +    device->GL_SwapWindow = Wayland_GLES_SwapWindow;
  20.101 +    device->GL_GetSwapInterval = Wayland_GLES_GetSwapInterval;
  20.102 +    device->GL_SetSwapInterval = Wayland_GLES_SetSwapInterval;
  20.103 +    device->GL_MakeCurrent = Wayland_GLES_MakeCurrent;
  20.104 +    device->GL_CreateContext = Wayland_GLES_CreateContext;
  20.105 +    device->GL_LoadLibrary = Wayland_GLES_LoadLibrary;
  20.106 +    device->GL_UnloadLibrary = Wayland_GLES_UnloadLibrary;
  20.107 +    device->GL_GetProcAddress = Wayland_GLES_GetProcAddress;
  20.108 +    device->GL_DeleteContext = Wayland_GLES_DeleteContext;
  20.109 +
  20.110 +    device->CreateWindow = Wayland_CreateWindow;
  20.111 +    device->ShowWindow = Wayland_ShowWindow;
  20.112 +    device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
  20.113 +    device->SetWindowSize = Wayland_SetWindowSize;
  20.114 +    device->DestroyWindow = Wayland_DestroyWindow;
  20.115 +
  20.116 +    device->free = Wayland_DeleteDevice;
  20.117 +
  20.118 +    return device;
  20.119 +}
  20.120 +
  20.121 +VideoBootStrap Wayland_bootstrap = {
  20.122 +    WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
  20.123 +    Wayland_Available, Wayland_CreateDevice
  20.124 +};
  20.125 +
  20.126 +static void
  20.127 +wayland_add_mode(SDL_VideoData *d, SDL_DisplayMode m)
  20.128 +{
  20.129 +    struct wayland_mode *mode;
  20.130 +
  20.131 +    /* Check for duplicate mode */
  20.132 +    wl_list_for_each(mode, &d->modes_list, link)
  20.133 +        if (mode->mode.w == m.w && mode->mode.h == m.h &&
  20.134 +	    mode->mode.refresh_rate == m.refresh_rate)
  20.135 +	    return;
  20.136 +
  20.137 +    /* Add new mode to the list */
  20.138 +    mode = SDL_calloc(1, sizeof *mode);
  20.139 +
  20.140 +    if (!mode)
  20.141 +	return;
  20.142 +
  20.143 +    mode->mode = m;
  20.144 +    wl_list_insert(&d->modes_list, &mode->link);
  20.145 +}
  20.146 +
  20.147 +static void
  20.148 +display_handle_geometry(void *data,
  20.149 +                        struct wl_output *output,
  20.150 +                        int x, int y,
  20.151 +                        int physical_width,
  20.152 +                        int physical_height,
  20.153 +                        int subpixel,
  20.154 +                        const char *make,
  20.155 +                        const char *model,
  20.156 +                        int transform)
  20.157 +
  20.158 +{
  20.159 +    SDL_VideoData *d = data;
  20.160 +
  20.161 +    d->screen_allocation.x = x;
  20.162 +    d->screen_allocation.y = y;
  20.163 +}
  20.164 +
  20.165 +static void
  20.166 +display_handle_mode(void *data,
  20.167 +                    struct wl_output *wl_output,
  20.168 +                    uint32_t flags,
  20.169 +                    int width,
  20.170 +                    int height,
  20.171 +                    int refresh)
  20.172 +{
  20.173 +    SDL_VideoData *d = data;
  20.174 +    SDL_DisplayMode mode;
  20.175 +
  20.176 +    SDL_zero(mode);
  20.177 +    mode.w = width;
  20.178 +    mode.h = height;
  20.179 +    mode.refresh_rate = refresh / 1000;
  20.180 +
  20.181 +    wayland_add_mode(d, mode);
  20.182 +
  20.183 +    if (flags & WL_OUTPUT_MODE_CURRENT) {
  20.184 +        d->screen_allocation.width = width;
  20.185 +        d->screen_allocation.height = height;
  20.186 +    }
  20.187 +}
  20.188 +
  20.189 +static const struct wl_output_listener output_listener = {
  20.190 +    display_handle_geometry,
  20.191 +    display_handle_mode
  20.192 +};
  20.193 +
  20.194 +static void
  20.195 +shm_handle_format(void *data,
  20.196 +                  struct wl_shm *shm,
  20.197 +                  uint32_t format)
  20.198 +{
  20.199 +    SDL_VideoData *d = data;
  20.200 +
  20.201 +    d->shm_formats |= (1 << format);
  20.202 +}
  20.203 +
  20.204 +static const struct wl_shm_listener shm_listener = {
  20.205 +    shm_handle_format
  20.206 +};
  20.207 +
  20.208 +static void
  20.209 +display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
  20.210 +					const char *interface, uint32_t version)
  20.211 +{
  20.212 +    SDL_VideoData *d = data;
  20.213 +
  20.214 +    if (strcmp(interface, "wl_compositor") == 0) {
  20.215 +        d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
  20.216 +    } else if (strcmp(interface, "wl_output") == 0) {
  20.217 +        d->output = wl_registry_bind(d->registry, id, &wl_output_interface, 1);
  20.218 +        wl_output_add_listener(d->output, &output_listener, d);
  20.219 +    } else if (strcmp(interface, "wl_seat") == 0) {
  20.220 +        Wayland_display_add_input(d, id);
  20.221 +    } else if (strcmp(interface, "wl_shell") == 0) {
  20.222 +        d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
  20.223 +    } else if (strcmp(interface, "wl_shm") == 0) {
  20.224 +        d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
  20.225 +        d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm);
  20.226 +        d->default_cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
  20.227 +        wl_shm_add_listener(d->shm, &shm_listener, d);
  20.228 +    }
  20.229 +}
  20.230 +
  20.231 +static const struct wl_registry_listener registry_listener = {
  20.232 +	display_handle_global
  20.233 +};
  20.234 +
  20.235 +int
  20.236 +Wayland_VideoInit(_THIS)
  20.237 +{
  20.238 +    SDL_VideoData *data;
  20.239 +
  20.240 +    data = malloc(sizeof *data);
  20.241 +    if (data == NULL)
  20.242 +        return 0;
  20.243 +    memset(data, 0, sizeof *data);
  20.244 +
  20.245 +    _this->driverdata = data;
  20.246 +
  20.247 +    wl_list_init(&data->modes_list);
  20.248 +    
  20.249 +    data->display = wl_display_connect(NULL);
  20.250 +    if (data->display == NULL) {
  20.251 +        SDL_SetError("Failed to connect to a Wayland display");
  20.252 +        return 0;
  20.253 +    }
  20.254 +
  20.255 +    data->registry = wl_display_get_registry(data->display);
  20.256 +    wl_registry_add_listener(data->registry, &registry_listener, data);
  20.257 +
  20.258 +    while (data->screen_allocation.width == 0)
  20.259 +        wl_display_dispatch(data->display);
  20.260 +
  20.261 +    data->xkb_context = xkb_context_new(0);
  20.262 +    if (!data->xkb_context) {
  20.263 +        SDL_SetError("Failed to create XKB context");
  20.264 +        return 0;
  20.265 +    }
  20.266 +
  20.267 +    SDL_VideoDisplay display;
  20.268 +    SDL_DisplayMode mode;
  20.269 +
  20.270 +    /* Use a fake 32-bpp desktop mode */
  20.271 +    mode.format = SDL_PIXELFORMAT_RGB888;
  20.272 +    mode.w = data->screen_allocation.width;
  20.273 +    mode.h = data->screen_allocation.height;
  20.274 +    mode.refresh_rate = 0;
  20.275 +    mode.driverdata = NULL;
  20.276 +    wayland_add_mode(data, mode);
  20.277 +    SDL_zero(display);
  20.278 +    display.desktop_mode = mode;
  20.279 +    display.current_mode = mode;
  20.280 +    display.driverdata = NULL;
  20.281 +    SDL_AddVideoDisplay(&display);
  20.282 +
  20.283 +    Wayland_InitMouse ();
  20.284 +
  20.285 +    wayland_schedule_write(data);
  20.286 +
  20.287 +    return 0;
  20.288 +}
  20.289 +
  20.290 +static void
  20.291 +Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
  20.292 +{
  20.293 +    SDL_VideoData *data = _this->driverdata;
  20.294 +    SDL_DisplayMode mode;
  20.295 +    struct wayland_mode *m;
  20.296 +
  20.297 +    Wayland_PumpEvents(_this);
  20.298 +
  20.299 +    wl_list_for_each(m, &data->modes_list, link) {
  20.300 +        m->mode.format = SDL_PIXELFORMAT_RGB888;
  20.301 +        SDL_AddDisplayMode(sdl_display, &m->mode);
  20.302 +        m->mode.format = SDL_PIXELFORMAT_RGBA8888;
  20.303 +        SDL_AddDisplayMode(sdl_display, &m->mode);
  20.304 +    }
  20.305 +
  20.306 +    mode.w = data->screen_allocation.width;
  20.307 +    mode.h = data->screen_allocation.height;
  20.308 +    mode.refresh_rate = 0;
  20.309 +    mode.driverdata = NULL;
  20.310 +
  20.311 +    mode.format = SDL_PIXELFORMAT_RGB888;
  20.312 +    SDL_AddDisplayMode(sdl_display, &mode);
  20.313 +    mode.format = SDL_PIXELFORMAT_RGBA8888;
  20.314 +    SDL_AddDisplayMode(sdl_display, &mode);
  20.315 +}
  20.316 +
  20.317 +static int
  20.318 +Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
  20.319 +{
  20.320 +    return 0;
  20.321 +}
  20.322 +
  20.323 +void
  20.324 +Wayland_VideoQuit(_THIS)
  20.325 +{
  20.326 +    SDL_VideoData *data = _this->driverdata;
  20.327 +    struct wayland_mode *t, *m;
  20.328 +
  20.329 +    Wayland_FiniMouse ();
  20.330 +
  20.331 +    if (data->output)
  20.332 +        wl_output_destroy(data->output);
  20.333 +
  20.334 +    Wayland_display_destroy_input(data);
  20.335 +
  20.336 +    if (data->xkb_context) {
  20.337 +        xkb_context_unref(data->xkb_context);
  20.338 +        data->xkb_context = NULL;
  20.339 +    }
  20.340 +
  20.341 +    if (data->shm)
  20.342 +        wl_shm_destroy(data->shm);
  20.343 +
  20.344 +    if (data->cursor_theme)
  20.345 +        wl_cursor_theme_destroy(data->cursor_theme);
  20.346 +
  20.347 +    if (data->shell)
  20.348 +        wl_shell_destroy(data->shell);
  20.349 +
  20.350 +    if (data->compositor)
  20.351 +        wl_compositor_destroy(data->compositor);
  20.352 +
  20.353 +    if (data->display) {
  20.354 +        wl_display_flush(data->display);
  20.355 +        wl_display_disconnect(data->display);
  20.356 +    }
  20.357 +    
  20.358 +    wl_list_for_each_safe(m, t, &data->modes_list, link) {
  20.359 +        wl_list_remove(&m->link);
  20.360 +        free(m);
  20.361 +    }
  20.362 +
  20.363 +
  20.364 +    free(data);
  20.365 +    _this->driverdata = NULL;
  20.366 +}
  20.367 +
  20.368 +/* vi: set ts=4 sw=4 expandtab: */
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/wayland/SDL_waylandvideo.h	Sat Dec 14 20:18:43 2013 -0300
    21.3 @@ -0,0 +1,71 @@
    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 +#include "SDL_config.h"
   21.26 +
   21.27 +#ifndef _SDL_waylandvideo_h
   21.28 +#define _SDL_waylandvideo_h
   21.29 +
   21.30 +#include <wayland-client.h>
   21.31 +#include <wayland-cursor.h>
   21.32 +#include <wayland-egl.h>
   21.33 +
   21.34 +#include <EGL/egl.h>
   21.35 +
   21.36 +struct xkb_context;
   21.37 +struct SDL_WaylandInput;
   21.38 +
   21.39 +typedef struct {
   21.40 +    struct wl_display *display;
   21.41 +    struct wl_registry *registry;
   21.42 +    struct wl_compositor *compositor;
   21.43 +    struct wl_output *output;
   21.44 +    struct wl_shm *shm;
   21.45 +    struct wl_cursor_theme *cursor_theme;
   21.46 +    struct wl_cursor *default_cursor;
   21.47 +    struct wl_pointer *pointer;
   21.48 +    struct wl_shell *shell;
   21.49 +
   21.50 +    struct {
   21.51 +        int32_t x, y, width, height;
   21.52 +    } screen_allocation;
   21.53 +
   21.54 +    struct wl_list modes_list;
   21.55 +
   21.56 +    EGLDisplay edpy;
   21.57 +    EGLContext context;
   21.58 +    EGLConfig econf;
   21.59 +
   21.60 +    struct xkb_context *xkb_context;
   21.61 +    struct SDL_WaylandInput *input;
   21.62 +
   21.63 +    uint32_t shm_formats;
   21.64 +} SDL_VideoData;
   21.65 +
   21.66 +static inline void
   21.67 +wayland_schedule_write(SDL_VideoData *data)
   21.68 +{
   21.69 +    wl_display_flush(data->display);
   21.70 +}
   21.71 +
   21.72 +#endif /* _SDL_nullvideo_h */
   21.73 +
   21.74 +/* vi: set ts=4 sw=4 expandtab: */
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Sat Dec 14 20:18:43 2013 -0300
    22.3 @@ -0,0 +1,192 @@
    22.4 +/*
    22.5 +  Simple DirectMedia Layer
    22.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    22.7 +
    22.8 +  This software is provided 'as-is', without any express or implied
    22.9 +  warranty.  In no event will the authors be held liable for any damages
   22.10 +  arising from the use of this software.
   22.11 +
   22.12 +  Permission is granted to anyone to use this software for any purpose,
   22.13 +  including commercial applications, and to alter it and redistribute it
   22.14 +  freely, subject to the following restrictions:
   22.15 +
   22.16 +  1. The origin of this software must not be misrepresented; you must not
   22.17 +     claim that you wrote the original software. If you use this software
   22.18 +     in a product, an acknowledgment in the product documentation would be
   22.19 +     appreciated but is not required.
   22.20 +  2. Altered source versions must be plainly marked as such, and must not be
   22.21 +     misrepresented as being the original software.
   22.22 +  3. This notice may not be removed or altered from any source distribution.
   22.23 +*/
   22.24 +
   22.25 +#include "SDL_config.h"
   22.26 +
   22.27 +#include "../SDL_sysvideo.h"
   22.28 +#include "../../events/SDL_windowevents_c.h"
   22.29 +#include "../SDL_egl_c.h"
   22.30 +#include "SDL_waylandwindow.h"
   22.31 +#include "SDL_waylandvideo.h"
   22.32 +
   22.33 +static void
   22.34 +handle_ping(void *data, struct wl_shell_surface *shell_surface,
   22.35 +            uint32_t serial)
   22.36 +{
   22.37 +    wl_shell_surface_pong(shell_surface, serial);
   22.38 +}
   22.39 +
   22.40 +static void
   22.41 +handle_configure(void *data, struct wl_shell_surface *shell_surface,
   22.42 +                 uint32_t edges, int32_t width, int32_t height)
   22.43 +{
   22.44 +}
   22.45 +
   22.46 +static void
   22.47 +handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
   22.48 +{
   22.49 +}
   22.50 +
   22.51 +static const struct wl_shell_surface_listener shell_surface_listener = {
   22.52 +    handle_ping,
   22.53 +    handle_configure,
   22.54 +    handle_popup_done
   22.55 +};
   22.56 +
   22.57 +SDL_bool
   22.58 +Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
   22.59 +{
   22.60 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   22.61 +
   22.62 +    info->info.wl.display = data->waylandData->display;
   22.63 +    info->info.wl.surface = data->surface;
   22.64 +    info->info.wl.shell_surface = data->shell_surface;
   22.65 +    info->subsystem = SDL_SYSWM_WAYLAND;
   22.66 +
   22.67 +    return SDL_TRUE;
   22.68 +}
   22.69 +
   22.70 +void Wayland_ShowWindow(_THIS, SDL_Window *window)
   22.71 +{
   22.72 +    SDL_WindowData *wind = window->driverdata;
   22.73 +
   22.74 +    if (window->flags & SDL_WINDOW_FULLSCREEN)
   22.75 +        wl_shell_surface_set_fullscreen(wind->shell_surface,
   22.76 +                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
   22.77 +                                        0, NULL);
   22.78 +    else
   22.79 +        wl_shell_surface_set_toplevel(wind->shell_surface);
   22.80 +
   22.81 +    wayland_schedule_write(_this->driverdata);
   22.82 +}
   22.83 +
   22.84 +void
   22.85 +Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
   22.86 +                            SDL_VideoDisplay * _display, SDL_bool fullscreen)
   22.87 +{
   22.88 +    SDL_WindowData *wind = window->driverdata;
   22.89 +
   22.90 +    if (fullscreen)
   22.91 +        wl_shell_surface_set_fullscreen(wind->shell_surface,
   22.92 +                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
   22.93 +                                        0, NULL);
   22.94 +    else
   22.95 +        wl_shell_surface_set_toplevel(wind->shell_surface);
   22.96 +
   22.97 +    wayland_schedule_write(_this->driverdata);
   22.98 +}
   22.99 +
  22.100 +int Wayland_CreateWindow(_THIS, SDL_Window *window)
  22.101 +{
  22.102 +    SDL_WindowData *data;
  22.103 +    SDL_VideoData *c;
  22.104 +    struct wl_region *region;
  22.105 +
  22.106 +    data = calloc(1, sizeof *data);
  22.107 +    if (data == NULL)
  22.108 +        return 0;
  22.109 +
  22.110 +    c = _this->driverdata;
  22.111 +    window->driverdata = data;
  22.112 +
  22.113 +    if (!(window->flags & SDL_WINDOW_OPENGL)) {
  22.114 +        SDL_GL_LoadLibrary(NULL);
  22.115 +        window->flags |= SDL_WINDOW_OPENGL;
  22.116 +    }
  22.117 +
  22.118 +    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
  22.119 +        window->x = 0;
  22.120 +    }
  22.121 +    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
  22.122 +        window->y = 0;
  22.123 +    }
  22.124 +
  22.125 +    data->waylandData = c;
  22.126 +    data->sdlwindow = window;
  22.127 +
  22.128 +    data->surface =
  22.129 +        wl_compositor_create_surface(c->compositor);
  22.130 +    wl_surface_set_user_data(data->surface, data);
  22.131 +    data->shell_surface = wl_shell_get_shell_surface(c->shell,
  22.132 +                                                     data->surface);
  22.133 +    data->egl_window = wl_egl_window_create(data->surface,
  22.134 +                                            window->w, window->h);
  22.135 +
  22.136 +    /* Create the GLES window surface */
  22.137 +    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
  22.138 +    
  22.139 +    if (data->egl_surface == EGL_NO_SURFACE) {
  22.140 +        SDL_SetError("failed to create a window surface");
  22.141 +        return -1;
  22.142 +    }
  22.143 +
  22.144 +    if (data->shell_surface) {
  22.145 +        wl_shell_surface_set_user_data(data->shell_surface, data);
  22.146 +        wl_shell_surface_add_listener(data->shell_surface,
  22.147 +                                      &shell_surface_listener, data);
  22.148 +    }
  22.149 +
  22.150 +    region = wl_compositor_create_region(c->compositor);
  22.151 +    wl_region_add(region, 0, 0, window->w, window->h);
  22.152 +    wl_surface_set_opaque_region(data->surface, region);
  22.153 +    wl_region_destroy(region);
  22.154 +
  22.155 +    wayland_schedule_write(c);
  22.156 +
  22.157 +    return 0;
  22.158 +}
  22.159 +
  22.160 +void Wayland_SetWindowSize(_THIS, SDL_Window * window)
  22.161 +{
  22.162 +    SDL_VideoData *data = _this->driverdata;
  22.163 +    SDL_WindowData *wind = window->driverdata;
  22.164 +    struct wl_region *region;
  22.165 +
  22.166 +    wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
  22.167 +
  22.168 +    region = wl_compositor_create_region(data->compositor);
  22.169 +    wl_region_add(region, 0, 0, window->w, window->h);
  22.170 +    wl_surface_set_opaque_region(wind->surface, region);
  22.171 +    wl_region_destroy(region);
  22.172 +}
  22.173 +
  22.174 +void Wayland_DestroyWindow(_THIS, SDL_Window *window)
  22.175 +{
  22.176 +    SDL_VideoData *data = _this->driverdata;
  22.177 +    SDL_WindowData *wind = window->driverdata;
  22.178 +
  22.179 +    window->driverdata = NULL;
  22.180 +
  22.181 +    if (data) {
  22.182 +        SDL_EGL_DestroySurface(_this, wind->egl_surface);
  22.183 +        wl_egl_window_destroy(wind->egl_window);
  22.184 +
  22.185 +        if (wind->shell_surface)
  22.186 +            wl_shell_surface_destroy(wind->shell_surface);
  22.187 +
  22.188 +        wl_surface_destroy(wind->surface);
  22.189 +
  22.190 +        SDL_free(wind);
  22.191 +        wayland_schedule_write(data);
  22.192 +    }
  22.193 +}
  22.194 +
  22.195 +/* vi: set ts=4 sw=4 expandtab: */
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/video/wayland/SDL_waylandwindow.h	Sat Dec 14 20:18:43 2013 -0300
    23.3 @@ -0,0 +1,58 @@
    23.4 +/*
    23.5 +  Simple DirectMedia Layer
    23.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    23.7 +
    23.8 +  This software is provided 'as-is', without any express or implied
    23.9 +  warranty.  In no event will the authors be held liable for any damages
   23.10 +  arising from the use of this software.
   23.11 +
   23.12 +  Permission is granted to anyone to use this software for any purpose,
   23.13 +  including commercial applications, and to alter it and redistribute it
   23.14 +  freely, subject to the following restrictions:
   23.15 +
   23.16 +  1. The origin of this software must not be misrepresented; you must not
   23.17 +     claim that you wrote the original software. If you use this software
   23.18 +     in a product, an acknowledgment in the product documentation would be
   23.19 +     appreciated but is not required.
   23.20 +  2. Altered source versions must be plainly marked as such, and must not be
   23.21 +     misrepresented as being the original software.
   23.22 +  3. This notice may not be removed or altered from any source distribution.
   23.23 +*/
   23.24 +
   23.25 +#include "SDL_config.h"
   23.26 +
   23.27 +#ifndef _SDL_waylandwindow_h
   23.28 +#define _SDL_waylandwindow_h
   23.29 +
   23.30 +#include "../SDL_sysvideo.h"
   23.31 +#include "SDL_syswm.h"
   23.32 +
   23.33 +#include "SDL_waylandvideo.h"
   23.34 +
   23.35 +struct SDL_WaylandInput;
   23.36 +
   23.37 +typedef struct {
   23.38 +    SDL_Window *sdlwindow;
   23.39 +    SDL_VideoData *waylandData;
   23.40 +    struct wl_surface *surface;
   23.41 +    struct wl_shell_surface *shell_surface;
   23.42 +    struct wl_egl_window *egl_window;
   23.43 +    struct SDL_WaylandInput *keyboard_device;
   23.44 +
   23.45 +    EGLSurface egl_surface;
   23.46 +} SDL_WindowData;
   23.47 +
   23.48 +extern void Wayland_ShowWindow(_THIS, SDL_Window *window);
   23.49 +extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
   23.50 +                                        SDL_VideoDisplay * _display,
   23.51 +                                        SDL_bool fullscreen);
   23.52 +extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
   23.53 +extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
   23.54 +extern void Wayland_DestroyWindow(_THIS, SDL_Window *window);
   23.55 +
   23.56 +extern SDL_bool
   23.57 +Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
   23.58 +
   23.59 +#endif /* _SDL_waylandwindow_h */
   23.60 +
   23.61 +/* vi: set ts=4 sw=4 expandtab: */
    24.1 --- a/test/Makefile.in	Fri Dec 13 09:48:12 2013 -0300
    24.2 +++ b/test/Makefile.in	Sat Dec 14 20:18:43 2013 -0300
    24.3 @@ -128,13 +128,13 @@
    24.4  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
    24.5   
    24.6  testgl2$(EXE): $(srcdir)/testgl2.c
    24.7 -	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
    24.8 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
    24.9  
   24.10  testgles$(EXE): $(srcdir)/testgles.c
   24.11  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLESLIB@ @MATHLIB@
   24.12  
   24.13  testgles2$(EXE): $(srcdir)/testgles2.c
   24.14 -	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLES2LIB@ @MATHLIB@
   24.15 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
   24.16  
   24.17  testhaptic$(EXE): $(srcdir)/testhaptic.c
   24.18  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    25.1 --- a/test/testgl2.c	Fri Dec 13 09:48:12 2013 -0300
    25.2 +++ b/test/testgl2.c	Sat Dec 14 20:18:43 2013 -0300
    25.3 @@ -24,11 +24,48 @@
    25.4  
    25.5  #include "SDL_opengl.h"
    25.6  
    25.7 +typedef struct GL_Context
    25.8 +{
    25.9 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
   25.10 +#include "../src/render/opengl/SDL_glfuncs.h"
   25.11 +#undef SDL_PROC
   25.12 +} GL_Context;
   25.13 +
   25.14 +
   25.15  /* Undefine this if you want a flat cube instead of a rainbow cube */
   25.16  #define SHADED_CUBE
   25.17  
   25.18  static SDLTest_CommonState *state;
   25.19  static SDL_GLContext context;
   25.20 +static GL_Context ctx;
   25.21 +
   25.22 +static int LoadContext(GL_Context * data)
   25.23 +{
   25.24 +#if SDL_VIDEO_DRIVER_UIKIT
   25.25 +#define __SDL_NOGETPROCADDR__
   25.26 +#elif SDL_VIDEO_DRIVER_ANDROID
   25.27 +#define __SDL_NOGETPROCADDR__
   25.28 +#elif SDL_VIDEO_DRIVER_PANDORA
   25.29 +#define __SDL_NOGETPROCADDR__
   25.30 +#endif
   25.31 +
   25.32 +#if defined __SDL_NOGETPROCADDR__
   25.33 +#define SDL_PROC(ret,func,params) data->func=func;
   25.34 +#else
   25.35 +#define SDL_PROC(ret,func,params) \
   25.36 +    do { \
   25.37 +        data->func = SDL_GL_GetProcAddress(#func); \
   25.38 +        if ( ! data->func ) { \
   25.39 +            return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
   25.40 +        } \
   25.41 +    } while ( 0 );
   25.42 +#endif /* _SDL_NOGETPROCADDR_ */
   25.43 +
   25.44 +#include "../src/render/opengl/SDL_glfuncs.h"
   25.45 +#undef SDL_PROC
   25.46 +    return 0;
   25.47 +}
   25.48 +
   25.49  
   25.50  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
   25.51  static void
   25.52 @@ -67,107 +104,107 @@
   25.53      };
   25.54  
   25.55      /* Do our drawing, too. */
   25.56 -    glClearColor(0.0, 0.0, 0.0, 1.0);
   25.57 -    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   25.58 +    ctx.glClearColor(0.0, 0.0, 0.0, 1.0);
   25.59 +    ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   25.60  
   25.61 -    glBegin(GL_QUADS);
   25.62 +    ctx.glBegin(GL_QUADS);
   25.63  
   25.64  #ifdef SHADED_CUBE
   25.65 -    glColor3fv(color[0]);
   25.66 -    glVertex3fv(cube[0]);
   25.67 -    glColor3fv(color[1]);
   25.68 -    glVertex3fv(cube[1]);
   25.69 -    glColor3fv(color[2]);
   25.70 -    glVertex3fv(cube[2]);
   25.71 -    glColor3fv(color[3]);
   25.72 -    glVertex3fv(cube[3]);
   25.73 +    ctx.glColor3fv(color[0]);
   25.74 +    ctx.glVertex3fv(cube[0]);
   25.75 +    ctx.glColor3fv(color[1]);
   25.76 +    ctx.glVertex3fv(cube[1]);
   25.77 +    ctx.glColor3fv(color[2]);
   25.78 +    ctx.glVertex3fv(cube[2]);
   25.79 +    ctx.glColor3fv(color[3]);
   25.80 +    ctx.glVertex3fv(cube[3]);
   25.81  
   25.82 -    glColor3fv(color[3]);
   25.83 -    glVertex3fv(cube[3]);
   25.84 -    glColor3fv(color[4]);
   25.85 -    glVertex3fv(cube[4]);
   25.86 -    glColor3fv(color[7]);
   25.87 -    glVertex3fv(cube[7]);
   25.88 -    glColor3fv(color[2]);
   25.89 -    glVertex3fv(cube[2]);
   25.90 +    ctx.glColor3fv(color[3]);
   25.91 +    ctx.glVertex3fv(cube[3]);
   25.92 +    ctx.glColor3fv(color[4]);
   25.93 +    ctx.glVertex3fv(cube[4]);
   25.94 +    ctx.glColor3fv(color[7]);
   25.95 +    ctx.glVertex3fv(cube[7]);
   25.96 +    ctx.glColor3fv(color[2]);
   25.97 +    ctx.glVertex3fv(cube[2]);
   25.98  
   25.99 -    glColor3fv(color[0]);
  25.100 -    glVertex3fv(cube[0]);
  25.101 -    glColor3fv(color[5]);
  25.102 -    glVertex3fv(cube[5]);
  25.103 -    glColor3fv(color[6]);
  25.104 -    glVertex3fv(cube[6]);
  25.105 -    glColor3fv(color[1]);
  25.106 -    glVertex3fv(cube[1]);
  25.107 +    ctx.glColor3fv(color[0]);
  25.108 +    ctx.glVertex3fv(cube[0]);
  25.109 +    ctx.glColor3fv(color[5]);
  25.110 +    ctx.glVertex3fv(cube[5]);
  25.111 +    ctx.glColor3fv(color[6]);
  25.112 +    ctx.glVertex3fv(cube[6]);
  25.113 +    ctx.glColor3fv(color[1]);
  25.114 +    ctx.glVertex3fv(cube[1]);
  25.115  
  25.116 -    glColor3fv(color[5]);
  25.117 -    glVertex3fv(cube[5]);
  25.118 -    glColor3fv(color[4]);
  25.119 -    glVertex3fv(cube[4]);
  25.120 -    glColor3fv(color[7]);
  25.121 -    glVertex3fv(cube[7]);
  25.122 -    glColor3fv(color[6]);
  25.123 -    glVertex3fv(cube[6]);
  25.124 +    ctx.glColor3fv(color[5]);
  25.125 +    ctx.glVertex3fv(cube[5]);
  25.126 +    ctx.glColor3fv(color[4]);
  25.127 +    ctx.glVertex3fv(cube[4]);
  25.128 +    ctx.glColor3fv(color[7]);
  25.129 +    ctx.glVertex3fv(cube[7]);
  25.130 +    ctx.glColor3fv(color[6]);
  25.131 +    ctx.glVertex3fv(cube[6]);
  25.132  
  25.133 -    glColor3fv(color[5]);
  25.134 -    glVertex3fv(cube[5]);
  25.135 -    glColor3fv(color[0]);
  25.136 -    glVertex3fv(cube[0]);
  25.137 -    glColor3fv(color[3]);
  25.138 -    glVertex3fv(cube[3]);
  25.139 -    glColor3fv(color[4]);
  25.140 -    glVertex3fv(cube[4]);
  25.141 +    ctx.glColor3fv(color[5]);
  25.142 +    ctx.glVertex3fv(cube[5]);
  25.143 +    ctx.glColor3fv(color[0]);
  25.144 +    ctx.glVertex3fv(cube[0]);
  25.145 +    ctx.glColor3fv(color[3]);
  25.146 +    ctx.glVertex3fv(cube[3]);
  25.147 +    ctx.glColor3fv(color[4]);
  25.148 +    ctx.glVertex3fv(cube[4]);
  25.149  
  25.150 -    glColor3fv(color[6]);
  25.151 -    glVertex3fv(cube[6]);
  25.152 -    glColor3fv(color[1]);
  25.153 -    glVertex3fv(cube[1]);
  25.154 -    glColor3fv(color[2]);
  25.155 -    glVertex3fv(cube[2]);
  25.156 -    glColor3fv(color[7]);
  25.157 -    glVertex3fv(cube[7]);
  25.158 +    ctx.glColor3fv(color[6]);
  25.159 +    ctx.glVertex3fv(cube[6]);
  25.160 +    ctx.glColor3fv(color[1]);
  25.161 +    ctx.glVertex3fv(cube[1]);
  25.162 +    ctx.glColor3fv(color[2]);
  25.163 +    ctx.glVertex3fv(cube[2]);
  25.164 +    ctx.glColor3fv(color[7]);
  25.165 +    ctx.glVertex3fv(cube[7]);
  25.166  #else /* flat cube */
  25.167 -    glColor3f(1.0, 0.0, 0.0);
  25.168 -    glVertex3fv(cube[0]);
  25.169 -    glVertex3fv(cube[1]);
  25.170 -    glVertex3fv(cube[2]);
  25.171 -    glVertex3fv(cube[3]);
  25.172 +    ctx.glColor3f(1.0, 0.0, 0.0);
  25.173 +    ctx.glVertex3fv(cube[0]);
  25.174 +    ctx.glVertex3fv(cube[1]);
  25.175 +    ctx.glVertex3fv(cube[2]);
  25.176 +    ctx.glVertex3fv(cube[3]);
  25.177  
  25.178 -    glColor3f(0.0, 1.0, 0.0);
  25.179 -    glVertex3fv(cube[3]);
  25.180 -    glVertex3fv(cube[4]);
  25.181 -    glVertex3fv(cube[7]);
  25.182 -    glVertex3fv(cube[2]);
  25.183 +    ctx.glColor3f(0.0, 1.0, 0.0);
  25.184 +    ctx.glVertex3fv(cube[3]);
  25.185 +    ctx.glVertex3fv(cube[4]);
  25.186 +    ctx.glVertex3fv(cube[7]);
  25.187 +    ctx.glVertex3fv(cube[2]);
  25.188  
  25.189 -    glColor3f(0.0, 0.0, 1.0);
  25.190 -    glVertex3fv(cube[0]);
  25.191 -    glVertex3fv(cube[5]);
  25.192 -    glVertex3fv(cube[6]);
  25.193 -    glVertex3fv(cube[1]);
  25.194 +    ctx.glColor3f(0.0, 0.0, 1.0);
  25.195 +    ctx.glVertex3fv(cube[0]);
  25.196 +    ctx.glVertex3fv(cube[5]);
  25.197 +    ctx.glVertex3fv(cube[6]);
  25.198 +    ctx.glVertex3fv(cube[1]);
  25.199  
  25.200 -    glColor3f(0.0, 1.0, 1.0);
  25.201 -    glVertex3fv(cube[5]);
  25.202 -    glVertex3fv(cube[4]);
  25.203 -    glVertex3fv(cube[7]);
  25.204 -    glVertex3fv(cube[6]);
  25.205 +    ctx.glColor3f(0.0, 1.0, 1.0);
  25.206 +    ctx.glVertex3fv(cube[5]);
  25.207 +    ctx.glVertex3fv(cube[4]);
  25.208 +    ctx.glVertex3fv(cube[7]);
  25.209 +    ctx.glVertex3fv(cube[6]);
  25.210  
  25.211 -    glColor3f(1.0, 1.0, 0.0);
  25.212 -    glVertex3fv(cube[5]);
  25.213 -    glVertex3fv(cube[0]);
  25.214 -    glVertex3fv(cube[3]);
  25.215 -    glVertex3fv(cube[4]);
  25.216 +    ctx.glColor3f(1.0, 1.0, 0.0);
  25.217 +    ctx.glVertex3fv(cube[5]);
  25.218 +    ctx.glVertex3fv(cube[0]);
  25.219 +    ctx.glVertex3fv(cube[3]);
  25.220 +    ctx.glVertex3fv(cube[4]);
  25.221  
  25.222 -    glColor3f(1.0, 0.0, 1.0);
  25.223 -    glVertex3fv(cube[6]);
  25.224 -    glVertex3fv(cube[1]);
  25.225 -    glVertex3fv(cube[2]);
  25.226 -    glVertex3fv(cube[7]);
  25.227 +    ctx.glColor3f(1.0, 0.0, 1.0);
  25.228 +    ctx.glVertex3fv(cube[6]);
  25.229 +    ctx.glVertex3fv(cube[1]);
  25.230 +    ctx.glVertex3fv(cube[2]);
  25.231 +    ctx.glVertex3fv(cube[7]);
  25.232  #endif /* SHADED_CUBE */
  25.233  
  25.234 -    glEnd();
  25.235 +    ctx.glEnd();
  25.236  
  25.237 -    glMatrixMode(GL_MODELVIEW);
  25.238 -    glRotatef(5.0, 1.0, 1.0, 1.0);
  25.239 +    ctx.glMatrixMode(GL_MODELVIEW);
  25.240 +    ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
  25.241  }
  25.242  
  25.243  int
  25.244 @@ -242,6 +279,13 @@
  25.245          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
  25.246          quit(2);
  25.247      }
  25.248 +    
  25.249 +    /* Important: call this *after* creating the context */
  25.250 +    if (LoadContext(&ctx) < 0) {
  25.251 +        SDL_Log("Could not load GL functions\n");
  25.252 +        quit(2);
  25.253 +        return 0;
  25.254 +    }
  25.255  
  25.256      if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
  25.257          /* try late-swap-tearing first. If not supported, try normal vsync. */
  25.258 @@ -260,10 +304,10 @@
  25.259      SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
  25.260      SDL_Log("Draw Size     : %d,%d\n", dw, dh);
  25.261      SDL_Log("\n");
  25.262 -    SDL_Log("Vendor        : %s\n", glGetString(GL_VENDOR));
  25.263 -    SDL_Log("Renderer      : %s\n", glGetString(GL_RENDERER));
  25.264 -    SDL_Log("Version       : %s\n", glGetString(GL_VERSION));
  25.265 -    SDL_Log("Extensions    : %s\n", glGetString(GL_EXTENSIONS));
  25.266 +    SDL_Log("Vendor        : %s\n", ctx.glGetString(GL_VENDOR));
  25.267 +    SDL_Log("Renderer      : %s\n", ctx.glGetString(GL_RENDERER));
  25.268 +    SDL_Log("Version       : %s\n", ctx.glGetString(GL_VERSION));
  25.269 +    SDL_Log("Extensions    : %s\n", ctx.glGetString(GL_EXTENSIONS));
  25.270      SDL_Log("\n");
  25.271  
  25.272      status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
  25.273 @@ -319,14 +363,14 @@
  25.274      }
  25.275  
  25.276      /* Set rendering settings */
  25.277 -    glMatrixMode(GL_PROJECTION);
  25.278 -    glLoadIdentity();
  25.279 -    glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
  25.280 -    glMatrixMode(GL_MODELVIEW);
  25.281 -    glLoadIdentity();
  25.282 -    glEnable(GL_DEPTH_TEST);
  25.283 -    glDepthFunc(GL_LESS);
  25.284 -    glShadeModel(GL_SMOOTH);
  25.285 +    ctx.glMatrixMode(GL_PROJECTION);
  25.286 +    ctx.glLoadIdentity();
  25.287 +    ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
  25.288 +    ctx.glMatrixMode(GL_MODELVIEW);
  25.289 +    ctx.glLoadIdentity();
  25.290 +    ctx.glEnable(GL_DEPTH_TEST);
  25.291 +    ctx.glDepthFunc(GL_LESS);
  25.292 +    ctx.glShadeModel(GL_SMOOTH);
  25.293      
  25.294      /* Main render loop */
  25.295      frames = 0;
  25.296 @@ -344,7 +388,7 @@
  25.297                  continue;
  25.298              SDL_GL_MakeCurrent(state->windows[i], context);
  25.299              SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
  25.300 -            glViewport(0, 0, w, h);
  25.301 +            ctx.glViewport(0, 0, w, h);
  25.302              Render();
  25.303              SDL_GL_SwapWindow(state->windows[i]);
  25.304          }