[SDL Tizen] Add vulkan feature to SDL. 25/82125/4
authorWonsik, Jung <sidein@samsung.com>
Mon, 1 Aug 2016 01:26:49 +0000 (10:26 +0900)
committerWonsik, Jung <sidein@samsung.com>
Tue, 9 Aug 2016 01:56:45 +0000 (10:56 +0900)
Add vulkan feature as for tizen, wayland and x11.
Tizen backend is tested and work fine.
But, wayland and x11 does not test yet.
These backend will be implemented and tested.

Change-Id: I42b7f0659ad4923f0e342f56db7e9687f68f0383

27 files changed:
CMakeLists.txt
cmake/sdlchecks.cmake
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
include/SDL_syswm.h
include/SDL_video.h
packaging/SDL2.spec
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/tizen/SDL_tizenopengles.c
src/video/tizen/SDL_tizenopengles.h
src/video/tizen/SDL_tizenvideo.c
src/video/tizen/SDL_tizenvideo.h
src/video/tizen/SDL_tizenvulkan.c [new file with mode: 0644]
src/video/tizen/SDL_tizenvulkan.h [new file with mode: 0644]
src/video/tizen/SDL_tizenwindow.c
src/video/tizen/SDL_tizenwindow.h
src/video/wayland/SDL_waylandvideo.c
src/video/wayland/SDL_waylandvulkan.c [new file with mode: 0644]
src/video/wayland/SDL_waylandvulkan.h [new file with mode: 0644]
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11vulkan.c [new file with mode: 0644]
src/video/x11/SDL_x11vulkan.h [new file with mode: 0644]

index 7f70d8c..0218ba4 100755 (executable)
@@ -258,6 +258,7 @@ dep_option(FUSIONSOUND_SHARED  "Dynamically load fusionsound audio support" ON "
 set_option(VIDEO_DUMMY         "Use dummy video driver" ON)
 set_option(VIDEO_OPENGL        "Include OpenGL support" ON)
 set_option(VIDEO_OPENGLES      "Include OpenGL ES support" ON)
+set_option(VIDEO_VULKAN        "Include vulkan support" ON)
 set_option(PTHREADS            "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
 dep_option(PTHREADS_SEM        "Use pthread semaphores" ON "PTHREADS" OFF)
 set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ${SDL_DLOPEN_ENABLED_BY_DEFAULT})
@@ -1289,6 +1290,15 @@ elseif(HAIKU)
   endif()
 
   CheckPTHREAD()
+elseif(TIZEN)
+  if(SDL_VIDEO)
+    if(VIDEO_VULKAN)
+      set(SDL_VIDEO_VULKAN 1)
+      set(HAVE_VIDEO_VULKAN TRUE)
+      set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include")
+      list(APPEND SDL_LIBS "-lvulkan")
+    endif()
+  endif()
 endif()
 
 # Dummies
index 478913c..f232c65 100644 (file)
@@ -594,7 +594,7 @@ endmacro()
 
 macro(CheckTizen)
   if(VIDEO_TIZEN)
-    pkg_check_modules(TIZEN wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-appfw-application dlog)
+    pkg_check_modules(TIZEN wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-appfw-application dlog ecore-imf)
     if(TIZEN_FOUND)
       link_directories(
           ${TIZEN_LIBRARY_DIRS}
@@ -616,7 +616,6 @@ macro(CheckTizen)
           FindLibraryAndSONAME(wayland-egl)
           FindLibraryAndSONAME(ecore)
           FindLibraryAndSONAME(ecore-wayland)
-          FindLibraryAndSONAME(evas)
           FindLibraryAndSONAME(eina)
           FindLibraryAndSONAME(capi-appfw-application)
           FindLibraryAndSONAME(capi-system-system-settings)
@@ -771,6 +770,21 @@ macro(CheckOpenGLESX11)
   endif()
 endmacro()
 
+macro(CheckVulkan)
+  if(VIDEO_VULKAN)
+    check_c_source_compiles("
+       #include <vulkan/vulkan.h>
+      int main (int argc, char** argv) {}" HAVE_VIDEO_VULKAN)
+    if(HAVE_VIDEO_VULKAN)
+        set(SDL_VIDEO_VULKAN 1)
+        set(VULKAN_LDFLAGS "-lvulkan")
+        list(APPEND EXTRA_LDFLAGS ${VULKAN_LDFLAGS})
+        list(APPEND SDL_LIBS ${VULKAN_LDFLAGS})
+    endif()
+
+  endif()
+endmacro()
+
 # Requires:
 # - nada
 # Optional:
index cb0268d..ac20884 100755 (executable)
--- a/configure
+++ b/configure
@@ -845,6 +845,7 @@ enable_video_opengl
 enable_video_opengles
 enable_video_opengles1
 enable_video_opengles2
+enable_video_vulkan
 enable_libudev
 enable_dbus
 enable_ibus
@@ -1584,6 +1585,7 @@ Optional Features:
                           include OpenGL ES 1.1 support [[default=yes]]
   --enable-video-opengles2
                           include OpenGL ES 2.0 support [[default=yes]]
+  --enable-video-vulkan   include Vulkan support [[default=yes]]
   --enable-libudev        enable libudev support [[default=yes]]
   --enable-dbus           enable D-Bus support [[default=yes]]
   --enable-ibus           enable IBus support [[default=yes]]
@@ -18941,12 +18943,13 @@ $as_echo_n "checking for Tizen support... " >&6; }
         if  test x$PKG_CONFIG != xno && \
             test x$video_opengl_egl = xyes && \
             test x$video_opengles_v2 = xyes; then
-            if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf; then
-                TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
-                TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
+            if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf; then
+                TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
+                TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
                 video_tizen=yes
             fi
         fi
+
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_tizen" >&5
 $as_echo "$video_tizen" >&6; }
 
@@ -21220,6 +21223,14 @@ else
   enable_video_opengles2=yes
 fi
 
+# Check whether --enable-video-vulkan was given.
+if test "${enable_video_vulkan+set}" = set; then :
+  enableval=$enable_video_vulkan;
+else
+  enable_video_vulkan=yes
+fi
+
+
 
 CheckOpenGLESX11()
 {
@@ -21537,6 +21548,44 @@ $as_echo "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
     fi
 }
 
+CheckVulkanTizen()
+{
+    if test x$enable_video = xyes -a x$enable_video_vulkan = xyes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Vulkan support" >&5
+$as_echo_n "checking for Vulkan support... " >&6; }
+        video_vulkan=no
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+         #include <vulkan/vulkan.h>
+
+int
+main ()
+{
+
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+        video_vulkan=yes
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_vulkan" >&5
+$as_echo "$video_vulkan" >&6; }
+        if test x$video_vulkan = xyes; then
+
+$as_echo "#define SDL_VIDEO_VULKAN 1" >>confdefs.h
+
+            SUMMARY_video="${SUMMARY_video} vulkan"
+            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvulkan"
+        fi
+    fi
+}
+
 CheckInputEvents()
 {
             { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Linux 2.4 unified input interface" >&5
@@ -23090,6 +23139,7 @@ case "$host" in
         CheckFusionSound
         CheckOpenGLX11
         CheckOpenGLESX11
+        CheckVulkanTizen
         CheckMir
         CheckWayland
         CheckTizen
index 6fcb3cd..5ad20f9 100644 (file)
@@ -1269,12 +1269,13 @@ CheckTizen()
         if  test x$PKG_CONFIG != xno && \
             test x$video_opengl_egl = xyes && \
             test x$video_opengles_v2 = xyes; then
-            if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf; then
-                TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
-                TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland evas eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
+            if $PKG_CONFIG --exists wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf; then
+                TIZEN_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
+                TIZEN_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl ecore ecore-wayland eina capi-appfw-application capi-system-system-settings ecore-input dlog ecore-imf`
                 video_tizen=yes
             fi
         fi
+
         AC_MSG_RESULT($video_tizen)
 
         if test x$video_tizen = xyes; then
@@ -2029,6 +2030,10 @@ AC_HELP_STRING([--enable-video-opengles1], [include OpenGL ES 1.1 support [[defa
 AC_ARG_ENABLE(video-opengles2,
 AC_HELP_STRING([--enable-video-opengles2], [include OpenGL ES 2.0 support [[default=yes]]]),
               , enable_video_opengles2=yes)
+AC_ARG_ENABLE(video-vulkan,
+AC_HELP_STRING([--enable-video-vulkan], [include Vulkan support [[default=yes]]]),
+              , enable_video_vulkan=yes)
+
 
 dnl Find OpenGL ES
 CheckOpenGLESX11()
@@ -2195,6 +2200,27 @@ CheckEmscriptenGLES()
     fi
 }
 
+dnl Check for Tizen Vulkan
+CheckVulkanTizen()
+{
+    if test x$enable_video = xyes -a x$enable_video_vulkan = xyes; then
+        AC_MSG_CHECKING(for Vulkan support)
+        video_vulkan=no
+        AC_TRY_COMPILE([
+         #include <vulkan/vulkan.h>
+        ],[
+        ],[
+        video_vulkan=yes
+        ])
+        AC_MSG_RESULT($video_vulkan)
+        if test x$video_vulkan = xyes; then
+            AC_DEFINE(SDL_VIDEO_VULKAN, 1, [ ])
+            SUMMARY_video="${SUMMARY_video} vulkan"
+            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvulkan"
+        fi
+    fi
+}
+
 dnl See if we can use the new unified event interface in Linux 2.4
 CheckInputEvents()
 {
@@ -2937,6 +2963,7 @@ case "$host" in
         CheckFusionSound
         CheckOpenGLX11
         CheckOpenGLESX11
+        CheckVulkanTizen
         CheckMir
         CheckWayland
         CheckTizen
index 0df88b5..87a471d 100644 (file)
 #cmakedefine SDL_VIDEO_OPENGL_EGL @SDL_VIDEO_OPENGL_EGL@
 #cmakedefine SDL_VIDEO_OPENGL_OSMESA @SDL_VIDEO_OPENGL_OSMESA@
 #cmakedefine SDL_VIDEO_OPENGL_OSMESA_DYNAMIC @SDL_VIDEO_OPENGL_OSMESA_DYNAMIC@
+#cmakedefine SDL_VIDEO_VULKAN @SDL_VIDEO_VULKAN@
 
 /* Enable system power support */
 #cmakedefine SDL_POWER_ANDROID @SDL_POWER_ANDROID@
index 490edef..07f3879 100644 (file)
 #undef SDL_ASSEMBLY_ROUTINES
 #undef SDL_ALTIVEC_BLITTERS
 
+#undef SDL_VIDEO_VULKAN
 #endif /* _SDL_config_h */
index 30c818c..ed731ef 100644 (file)
@@ -236,7 +236,7 @@ struct SDL_SysWMinfo
             GLuint resolveFramebuffer; /* The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
         } uikit;
 #endif
-#if defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_TIZEN)
+#if defined(SDL_VIDEO_DRIVER_WAYLAND)
         struct
         {
             struct wl_display *display;            /**< Wayland display */
@@ -259,6 +259,18 @@ struct SDL_SysWMinfo
             EGLSurface surface;
         } android;
 #endif
+#if defined(SDL_VIDEO_DRIVER_TIZEN)
+        struct
+        {
+//            struct wl_display *display;              /**< Wayland display */
+//            struct wl_surface *surface;              /**< Wayland surface */
+//            struct wl_shell_surface *shell_surface;  /**< Wayland shell_surface (window manager handle) */
+
+            /* For GLES */
+            void*  egl_display;                      /**< EGLDispaly when OPENGLES is enabled */
+            void*  egl_surface;                      /**< EGLSurface when OPENGLES is enabled for this wl_surface */
+        } tizen;
+#endif
 
         /* Can't have an empty union */
         int dummy;
index 52dbbc7..9de22f5 100644 (file)
@@ -109,7 +109,8 @@ typedef enum
     SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
     SDL_WINDOW_FOREIGN = 0x00000800,            /**< window not created by SDL */
     SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000,      /**< window should be created in high-DPI mode if supported */
-    SDL_WINDOW_MOUSE_CAPTURE = 0x00004000       /**< window has mouse captured (unrelated to INPUT_GRABBED) */
+    SDL_WINDOW_MOUSE_CAPTURE = 0x00004000,      /**< window has mouse captured (unrelated to INPUT_GRABBED) */
+    SDL_WINDOW_VULKAN = 0x10000000              /**< window usable with Vulkan */
 } SDL_WindowFlags;
 
 /**
@@ -217,6 +218,16 @@ typedef enum
 } SDL_GLcontextReleaseFlag;
 
 
+/**
+ *  \brief An opaque handle to an Vulkan instance.
+ */
+typedef void *SDL_vulkanInstance;
+
+/**
+ *  \brief An opaque handle to an Vulkan instance.
+ */
+typedef void *SDL_vulkanSurface;
+
 /* Function prototypes */
 
 /**
@@ -1091,6 +1102,15 @@ extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
 
 /* @} *//* OpenGL support functions */
 
+/**
+ *  \name Vulkan support functions
+ */
+/* @{ */
+
+extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetInstanceExtensions(SDL_Window* window, unsigned* count, char** names);
+extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface);
+
+/* @} *//* Vulkan support functions */
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
index 24007f8..39e55fa 100644 (file)
@@ -41,9 +41,10 @@ BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  binutils-devel
 BuildRequires:  which
 BuildRequires:  autoconf
+#BuildRequires:  Vulkan-LoaderAndValidationLayers
+#BuildRequires:  Vulkan-LoaderAndValidationLayers-devel
 
 BuildRequires:  pkgconfig(ecore)
-BuildRequires:  pkgconfig(evas)
 BuildRequires:  pkgconfig(ecore-wayland)
 BuildRequires:  pkgconfig(capi-appfw-application)
 BuildRequires:  pkgconfig(capi-system-system-settings)
@@ -74,7 +75,7 @@ to develop SDL applications.
 
 %build
 %ifos linux
-CFLAGS="$RPM_OPT_FLAGS -D__TIZEN__" ./configure --prefix=%{prefix} --disable-video-directfb --enable-video-wayland
+CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{prefix} --disable-video-directfb --enable-video-tizen
 %else
 %configure
 %endif
index 9fadf11..28804d6 100644 (file)
 #define SDL_GameControllerFromInstanceID SDL_GameControllerFromInstanceID_REAL
 #define SDL_JoystickFromInstanceID SDL_JoystickFromInstanceID_REAL
 #define SDL_tizen_app_init SDL_tizen_app_init_REAL
+#define SDL_Vulkan_GetInstanceExtensions SDL_Vulkan_GetInstanceExtensions_REAL
+#define SDL_Vulkan_CreateSurface SDL_Vulkan_CreateSurface_REAL
index 1efd814..fb5bb7f 100644 (file)
@@ -634,3 +634,5 @@ SDL_DYNAPI_PROC(SDL_Joystick*,SDL_JoystickFromInstanceID,(SDL_JoystickID a),(a),
 #ifdef __TIZEN__
 SDL_DYNAPI_PROC(int,SDL_tizen_app_init,(int a, char *b[]),(a,b),return)
 #endif
+SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_GetInstanceExtensions,(SDL_Window* a, unsigned int* b, char** c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_CreateSurface,(SDL_Window* a, SDL_vulkanInstance b, SDL_vulkanSurface* c),(a,b,c),return)
index e92412f..28b2b9f 100644 (file)
@@ -343,6 +343,9 @@ struct SDL_VideoDevice
     /* * * */
     /* The function used to dispose of this structure */
     void (*free) (_THIS);
+
+    SDL_bool (*vulkan_GetInstanceExtensions) (const char* driver, unsigned int* count, char** names);
+    SDL_bool (*vulkan_CreateSurface) (_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface);
 };
 
 typedef struct VideoBootStrap
index 049a95c..b791f27 100644 (file)
@@ -1294,7 +1294,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
 }
 
 #define CREATE_FLAGS \
-    (SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI)
+    (SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_VULKAN)
 
 static void
 SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
@@ -1362,6 +1362,20 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
         }
     }
 
+#if (SDL_VIDEO_VULKAN)
+    if (flags & SDL_WINDOW_VULKAN) {
+        if (!_this->vulkan_GetInstanceExtensions) {
+            SDL_SetError("No Vulkan support in video driver");
+            return NULL;
+        }
+    }
+
+    if ((flags & SDL_WINDOW_OPENGL) && (flags & SDL_WINDOW_VULKAN)) {
+        SDL_SetError("Don't use both OPENGL and VULKAN");
+        return NULL;
+    }
+#endif
+
     /* Unless the user has specified the high-DPI disabling hint, respect the
      * SDL_WINDOW_ALLOW_HIGHDPI flag.
      */
@@ -1398,6 +1412,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
             window->y = bounds.y + (bounds.h - h) / 2;
         }
     }
+
     window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
     window->last_fullscreen_flags = window->flags;
     window->brightness = 1.0f;
@@ -3666,4 +3681,42 @@ float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
                                   SDL_sqrt((double)den2));
 }
 
+SDL_bool
+SDL_Vulkan_GetInstanceExtensions(SDL_Window* window, unsigned int* count, char** names)
+{
+    if (!count) {
+        SDL_SetError("count ptr is null");
+        return SDL_FALSE;
+    }
+
+    if (!(window->flags & SDL_WINDOW_VULKAN)) {
+        SDL_SetError("Not setup with SDL_WINDOW_VULKAN flags");
+        return SDL_FALSE;
+    }
+
+    const char *driver = SDL_GetCurrentVideoDriver();
+    if (!driver) {
+        SDL_SetError("Current video driveer is NULL");
+        return SDL_FALSE;
+    }
+
+    return _this->vulkan_GetInstanceExtensions(driver, count, names);
+}
+
+SDL_bool
+SDL_Vulkan_CreateSurface(SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
+{
+    if (!window) {
+        SDL_SetError("'window' is null");
+        return SDL_FALSE;
+    }
+
+    if (instance == 0) {
+        SDL_SetError("'instance' is null");
+        return SDL_FALSE;
+    }
+
+    return _this->vulkan_CreateSurface(_this, window, instance, surface);
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
index 86cf548..337eeae 100644 (file)
@@ -21,7 +21,7 @@
 */
 #include "../../SDL_internal.h"
 
-#if SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL
+#if SDL_VIDEO_OPENGL_EGL
 
 #include "SDL_tizenvideo.h"
 #include "SDL_tizenopengles.h"
@@ -36,7 +36,6 @@ Tizen_GLES_LoadLibrary(_THIS, const char *path)
     int ret;
 
     ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)ecore_wl_display_get());
-
     return ret;
 }
 
@@ -45,8 +44,8 @@ SDL_GLContext
 Tizen_GLES_CreateContext(_THIS, SDL_Window *window)
 {
     SDL_GLContext context;
-    context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
 
+    context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
     return context;
 }
 
index 97efd16..c9610f7 100644 (file)
@@ -27,6 +27,8 @@
 #include "../SDL_sysvideo.h"
 #include "../SDL_egl_c.h"
 
+#if SDL_VIDEO_OPENGL_EGL
+
 typedef struct SDL_PrivateGLESData {
 } SDL_PrivateGLESData;
 
@@ -42,5 +44,6 @@ extern SDL_GLContext Tizen_GLES_CreateContext(_THIS, SDL_Window *window);
 extern void Tizen_GLES_SwapWindow(_THIS, SDL_Window *window);
 extern int Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context);
 extern void Tizen_GLES_DeleteContext(_THIS, SDL_GLContext context);
+#endif
 
 #endif /* _SDL_tizenopengles_h */
index b62dcbb..df11641 100644 (file)
@@ -37,6 +37,7 @@
 #include "SDL_tizenmouse.h"
 #include "SDL_tizentouch.h"
 #include "SDL_tizenkeyboard.h"
+#include "SDL_tizenvulkan.h"
 
 
 #define TIZENVID_DRIVER_NAME "tizen"
@@ -54,7 +55,7 @@ static void
 Tizen_VideoQuit(_THIS);
 
 static void
-__tizen_add_display(SDL_VideoData *d, uint32_t id)
+_tizen_add_display(SDL_VideoData *d, uint32_t id)
 {
     SDL_VideoDisplay display;
     SDL_DisplayMode mode;
@@ -108,7 +109,7 @@ Tizen_CreateDevice(int devindex)
     device->free                                       = Tizen_DeleteDevice;
 
     device->PumpEvents = Tizen_PumpEvents;
-
+#if SDL_VIDEO_OPENGL_EGL
     device->GL_SwapWindow = Tizen_GLES_SwapWindow;
     device->GL_GetSwapInterval = Tizen_GLES_GetSwapInterval;
     device->GL_SetSwapInterval = Tizen_GLES_SetSwapInterval;
@@ -118,7 +119,7 @@ Tizen_CreateDevice(int devindex)
     device->GL_UnloadLibrary = Tizen_GLES_UnloadLibrary;
     device->GL_GetProcAddress = Tizen_GLES_GetProcAddress;
     device->GL_DeleteContext = Tizen_GLES_DeleteContext;
-
+#endif
     device->CreateWindow = Tizen_CreateWindow;
     device->ShowWindow = Tizen_ShowWindow;
     device->SetWindowFullscreen = Tizen_SetWindowFullscreen;
@@ -138,6 +139,11 @@ Tizen_CreateDevice(int devindex)
     //device->HideScreenKeyboard = Tizen_HideScreenKeyboard;
     device->IsScreenKeyboardShown = Tizen_IsScreenKeyboardShown;
 
+#if SDL_VIDEO_VULKAN
+    device->vulkan_GetInstanceExtensions = Tizen_vulkan_GetInstanceExtensions;
+    device->vulkan_CreateSurface = Tizen_vulkan_CreateSurface;
+#endif
+
     return device;
 }
 
@@ -158,7 +164,8 @@ Tizen_VideoInit(_THIS)
     _this->driverdata = data;
 
     ecore_wl_init(NULL);
-    __tizen_add_display(data, 0);
+    _tizen_add_display(data, 0);
+    data->display = ecore_wl_display_get();
 
     Tizen_InitWindow(_this);
     Tizen_InitMouse();
@@ -168,7 +175,7 @@ Tizen_VideoInit(_THIS)
 static void
 Tizen_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
 {
-
+    SDL_Unsupported();
 }
 
 static int
index 0501cc3..b7b5b9e 100644 (file)
@@ -29,6 +29,8 @@
 #include <Ecore_Wayland.h>
 
 typedef struct {
+    struct wl_display *display;
+
     EGLDisplay edpy;
     EGLContext context;
     EGLConfig econf;
diff --git a/src/video/tizen/SDL_tizenvulkan.c b/src/video/tizen/SDL_tizenvulkan.c
new file mode 100644 (file)
index 0000000..13b3c5e
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+  Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN
+#include <SDL_syswm.h>
+#include "../SDL_sysvideo.h"
+#include "SDL_video.h"
+#include "SDL_tizenwindow.h"
+#include "SDL_tizenvideo.h"
+#include "SDL_tizenvideo.h"
+#include "SDL_tizenvulkan.h"
+
+SDL_bool
+Tizen_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char** names)
+{
+    uint32_t instance_extension_count = 0;
+    uint32_t enabled_extension_count = 0;
+    VkBool32 surfaceExtFound = 0;
+    VkBool32 platformSurfaceExtFound = 0;
+    VkResult err;
+
+    if (strcmp(driver, "tizen")) {
+        SDL_SetError("Unsupported video driver '%s'", driver);
+        return SDL_FALSE;
+    }
+
+    err = vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL);
+    if (err < 0) {
+        SDL_SetError("Fail to get Instance extension");
+        return SDL_FALSE;
+    }
+
+    if (instance_extension_count > 0) {
+        uint32_t i;
+        VkExtensionProperties *instance_extensions =
+            malloc(sizeof(VkExtensionProperties) * instance_extension_count);
+        err = vkEnumerateInstanceExtensionProperties(
+            NULL, &instance_extension_count, instance_extensions);
+        for (i = 0; i < instance_extension_count; i++) {
+            if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
+                names[enabled_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
+            }
+
+            if (!strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
+                names[enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
+            }
+
+            if (enabled_extension_count > 64) {
+                SDL_SetError("Insufficient capacity for extension names");
+                free(instance_extensions);
+                return SDL_FALSE;
+            }
+        }
+        free(instance_extensions);
+    }
+    *count = enabled_extension_count;
+    return SDL_TRUE;
+}
+
+SDL_bool
+Tizen_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
+{
+    SDL_SysWMinfo wminfo;
+    SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
+    SDL_VideoData  *video_data  = (SDL_VideoData *)_this->driverdata;
+
+    if (!SDL_GetWindowWMInfo(window, &wminfo))
+        return SDL_FALSE;
+
+    switch (wminfo.subsystem)
+    {
+    case SDL_SYSWM_TIZEN:
+        {
+            VkWaylandSurfaceCreateInfoKHR createInfo;
+            VkResult ret;
+            createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
+            createInfo.pNext = NULL;
+            createInfo.flags = 0;
+            createInfo.display = video_data->display;
+            createInfo.surface = wmdata->surface;
+
+            ret = vkCreateWaylandSurfaceKHR((VkInstance)instance, &createInfo, NULL, (VkSurfaceKHR*)surface);
+            if (ret != VK_SUCCESS) {
+                SDL_SetError("fail to vkCreateWaylandSurfaceKHR : %i", (int)ret);
+                return SDL_FALSE;
+            }
+            return SDL_TRUE;
+        }
+    default:
+        (void)surface;
+        SDL_SetError("Unsupported subsystem %i", (int)wminfo.subsystem);
+        return SDL_FALSE;
+    }
+}
+
+#endif
diff --git a/src/video/tizen/SDL_tizenvulkan.h b/src/video/tizen/SDL_tizenvulkan.h
new file mode 100644 (file)
index 0000000..0fe118b
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+  Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef _SDL_tizenvulkan_h
+#define _SDL_tizenvulkan_h
+
+#if SDL_VIDEO_VULKAN
+#define VK_USE_PLATFORM_WAYLAND_KHR
+#include <vulkan/vulkan.h>
+#include "../SDL_sysvideo.h"
+
+extern SDL_bool Tizen_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char** names);
+extern SDL_bool Tizen_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface);
+#endif
+#endif /* _SDL_tizenvulkan_h */
index c6298ee..a8cfa48 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "../../SDL_internal.h"
 
-#if SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL
+#if SDL_VIDEO_DRIVER_TIZEN
 
 #include "../SDL_sysvideo.h"
 #include "../../events/SDL_windowevents_c.h"
 SDL_bool
 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
 {
+    SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
+    SDL_VideoData  *video_data  = (SDL_VideoData *)_this->driverdata;
+
+//    info->info.tizen.display = video_data->display;
+//    info->info.tizen.surface = wmdata->surface;
+//    info->info.tizen.shell_surface = NULL;
+    info->info.tizen.egl_display = NULL;
+    info->info.tizen.egl_surface = NULL;
+#if SDL_VIDEO_OPENGL_EGL
+    if (_this->egl_data)
+    {
+       info->info.tizen.egl_display = (void*)_this->egl_data->egl_display;
+    }
+    info->info.tizen.egl_surface = (void*)wmdata->egl_surface;
+#endif
+    info->subsystem = SDL_SYSWM_TIZEN;
     return SDL_TRUE;
 }
 
@@ -72,15 +88,16 @@ Tizen_CreateWindow(_THIS, SDL_Window *window)
     SDL_WindowData *wind;
 
     wind = calloc(1, sizeof * wind);
-    if (wind == NULL)
+    if (!wind)
         return SDL_OutOfMemory();
 
     window->driverdata = wind;
 
-    if (!(window->flags & SDL_WINDOW_OPENGL)) {
+#if SDL_VIDEO_OPENGL_EGL
+    if (window->flags & SDL_WINDOW_OPENGL) {
         SDL_GL_LoadLibrary(NULL);
-        window->flags |= SDL_WINDOW_OPENGL;
     }
+#endif
 
     if (window->x == SDL_WINDOWPOS_UNDEFINED) {
         window->x = 0;
@@ -92,15 +109,18 @@ Tizen_CreateWindow(_THIS, SDL_Window *window)
     wind->window = ecore_wl_window_new(NULL,
                                        window->x, window->y, window->w, window->h,
                                        ECORE_WL_WINDOW_BUFFER_TYPE_SHM);
-    ecore_wl_window_surface_create(wind->window);
-
-    wind->egl_window = wl_egl_window_create(ecore_wl_window_surface_get(wind->window), window->w, window->h);
-
-    /* Create the GLES window surface */
-    wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
-    if (wind->egl_surface == EGL_NO_SURFACE) {
-        return SDL_SetError("failed to create a window surface");
+    wind->surface = ecore_wl_window_surface_create(wind->window);
+#if SDL_VIDEO_OPENGL_EGL
+    if (window->flags & SDL_WINDOW_OPENGL) {
+        wind->egl_window = wl_egl_window_create(ecore_wl_window_surface_get(wind->window), window->w, window->h);
+
+        /* Create the GLES window surface */
+        wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
+        if (wind->egl_surface == EGL_NO_SURFACE) {
+            return SDL_SetError("failed to create a window surface");
+        }
     }
+#endif
 
     wind->id = ecore_wl_window_id_get(wind->window);
     eina_hash_add(data->windows, &wind->id, window);
@@ -117,8 +137,11 @@ void
 Tizen_SetWindowSize(_THIS, SDL_Window *window)
 {
     SDL_WindowData *wind = window->driverdata;
-
-    wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+#if SDL_VIDEO_OPENGL_EGL
+    if (window->flags & SDL_WINDOW_OPENGL) {
+        wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+    }
+#endif
 }
 
 void
@@ -129,11 +152,13 @@ Tizen_DestroyWindow(_THIS, SDL_Window *window)
 
     if (data) {
         eina_hash_del(data->windows, &wind->id, window);
-
+#if SDL_VIDEO_OPENGL_EGL
+    if (window->flags & SDL_WINDOW_OPENGL) {
         SDL_EGL_DestroySurface(_this, wind->egl_surface);
         wl_egl_window_destroy(wind->egl_window);
+    }
+#endif
         ecore_wl_window_free(wind->window);
-
         SDL_free(wind);
     }
 
@@ -183,7 +208,6 @@ Tizen_InitWindow(_THIS)
                         __tizen_cb_event_keyup_change,  NULL);
     ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
                         __tizen_cb_event_keydown_change,       NULL);
-
     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
                         __tizen_cb_event_mousedown_change,     _this);
     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
@@ -201,6 +225,6 @@ Tizen_DeinitWindow(_THIS)
 
     eina_hash_free(data->windows);
 }
-#endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
+#endif /* SDL_VIDEO_DRIVER_TIZEN */
 
 /* vi: set ts=4 sw=4 expandtab: */
index b60ddee..489137b 100644 (file)
@@ -35,6 +35,8 @@ typedef struct {
     uint32_t id;
 
     Ecore_Wl_Window *window;
+    struct wl_surface *surface;
+    struct wl_shell_surface *shell_surface;
     struct wl_egl_window *egl_window;
     EGLSurface egl_surface;
 } SDL_WindowData;
index 92357f9..bcdbbb6 100644 (file)
@@ -34,6 +34,7 @@
 #include "SDL_waylandopengles.h"
 #include "SDL_waylandmouse.h"
 #include "SDL_waylandtouch.h"
+#include "SDL_waylandvulkan.h"
 
 #include <fcntl.h>
 #include <xkbcommon/xkbcommon.h>
@@ -125,6 +126,10 @@ Wayland_CreateDevice(int devindex)
 
     device->free = Wayland_DeleteDevice;
 
+#if SDL_VIDEO_VULKAN
+    device->vulkan_GetInstanceExtensions = Wayland_vulkan_GetInstanceExtensions;
+    device->vulkan_CreateSurface = Wayland_vulkan_CreateSurface;
+#endif
     return device;
 }
 
diff --git a/src/video/wayland/SDL_waylandvulkan.c b/src/video/wayland/SDL_waylandvulkan.c
new file mode 100644 (file)
index 0000000..3efd7ab
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN
+#include <SDL_syswm.h>
+#include "SDL_video.h"
+#include "../SDL_sysvideo.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandvulkan.h"
+
+SDL_bool
+Wayland_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char** names)
+{
+    uint32_t instance_extension_count = 0;
+    uint32_t enabled_extension_count = 0;
+    VkBool32 surfaceExtFound = 0;
+    VkBool32 platformSurfaceExtFound = 0;
+    VkResult err;
+
+    if (strcmp(driver, "wayland")) {
+        SDL_SetError("Unsupported video driver '%s'", driver);
+        return SDL_FALSE;
+    }
+
+    err = vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL);
+    if (err < 0) {
+        SDL_SetError("Fail to get Instance extension");
+        return SDL_FALSE;
+    }
+
+    if (instance_extension_count > 0) {
+        uint32_t i;
+        VkExtensionProperties *instance_extensions =
+            malloc(sizeof(VkExtensionProperties) * instance_extension_count);
+        err = vkEnumerateInstanceExtensionProperties(
+            NULL, &instance_extension_count, instance_extensions);
+        for (i = 0; i < instance_extension_count; i++) {
+            if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
+                names[enabled_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
+            }
+
+            if (!strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
+                names[enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
+            }
+
+            if (enabled_extension_count > 64) {
+                SDL_SetError("Insufficient capacity for extension names");
+                free(instance_extensions);
+                return SDL_FALSE;
+            }
+        }
+        free(instance_extensions);
+    }
+    *count = enabled_extension_count;
+    return SDL_TRUE;
+}
+
+SDL_bool
+Wayland_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
+{
+    SDL_SysWMinfo wminfo;
+    SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
+    SDL_VideoData  *video_data  = (SDL_VideoData *)_this->driverdata;
+    if (!SDL_GetWindowWMInfo(window, &wminfo))
+        return SDL_FALSE;
+
+    switch (wminfo.subsystem)
+    {
+    case SDL_SYSWM_WAYLAND:
+        {
+            VkWaylandSurfaceCreateInfoKHR createInfo;
+            VkResult ret;
+            createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
+            createInfo.pNext = NULL;
+            createInfo.flags = 0;
+            createInfo.display = video_data->display;
+            createInfo.surface = wmdata->surface;
+
+            ret = vkCreateWaylandSurfaceKHR((VkInstance)instance, &createInfo, NULL, (VkSurfaceKHR*)surface);
+            if (ret != VK_SUCCESS) {
+                SDL_SetError("fail to vkCreateWaylandSurfaceKHR : %i", (int)ret);
+                return SDL_FALSE;
+            }
+            return SDL_TRUE;
+        }
+    default:
+        (void)surface;
+        SDL_SetError("Unsupported subsystem %i", (int)wminfo.subsystem);
+        return SDL_FALSE;
+    }
+}
+
+#endif
diff --git a/src/video/wayland/SDL_waylandvulkan.h b/src/video/wayland/SDL_waylandvulkan.h
new file mode 100644 (file)
index 0000000..f972d70
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef _SDL_waylandvulkan_h
+#define _SDL_waylandvulkan_h
+
+#if SDL_VIDEO_VULKAN
+#define VK_USE_PLATFORM_WAYLAND_KHR
+#include <vulkan/vulkan.h>
+#include "../SDL_sysvideo.h"
+
+extern SDL_bool Wayland_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char** names);
+extern SDL_bool Wayland_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface);
+
+#endif
+#endif /* _SDL_waylandvulkan_h */
index 01f8ae6..b3a1c4e 100644 (file)
@@ -281,6 +281,11 @@ X11_CreateDevice(int devindex)
     
     device->free = X11_DeleteDevice;
 
+#if SDL_VIDEO_VULKAN
+    device->vulkan_GetInstanceExtensions = X11_vulkan_GetInstanceExtensions;
+    device->vulkan_CreateSurface = X11_vulkan_CreateSurface;
+#endif
+
     return device;
 }
 
diff --git a/src/video/x11/SDL_x11vulkan.c b/src/video/x11/SDL_x11vulkan.c
new file mode 100644 (file)
index 0000000..b4e7ac4
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_VULKAN
+
+#define VK_USE_PLATFORM_XCB_KHR
+#include <X11/Xlib-xcb.h>
+
+#include <vulkan/vulkan.h>
+#include <SDL_syswm.h>
+#include "SDL_x11video.h"
+#include "SDL_x11vulkan.h"
+
+SDL_bool
+X11_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char** names)
+{
+    uint32_t instance_extension_count = 0;
+    uint32_t enabled_extension_count = 0;
+    VkBool32 surfaceExtFound = 0;
+    VkBool32 platformSurfaceExtFound = 0;
+    VkResult err;
+
+    if (strcmp(driver, "x11")) {
+        SDL_SetError("Unsupported video driver '%s'", driver);
+        return SDL_FALSE;
+    }
+
+    err = vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL);
+    if (err < 0) {
+        SDL_SetError("Fail to get Instance extension");
+        return SDL_FALSE;
+    }
+
+    if (instance_extension_count > 0) {
+        uint32_t i;
+        VkExtensionProperties *instance_extensions =
+            malloc(sizeof(VkExtensionProperties) * instance_extension_count);
+        err = vkEnumerateInstanceExtensionProperties(
+            NULL, &instance_extension_count, instance_extensions);
+        for (i = 0; i < instance_extension_count; i++) {
+            if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
+                names[enabled_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
+            }
+
+            if (!strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
+                names[enabled_extension_count++] = VK_KHR_XCB_SURFACE_EXTENSION_NAME;
+            }
+
+            if (enabled_extension_count > 64) {
+                SDL_SetError("Insufficient capacity for extension names");
+                free(instance_extensions);
+                return SDL_FALSE;
+            }
+        }
+        free(instance_extensions);
+    }
+    *count = enabled_extension_count;
+    return SDL_TRUE;
+}
+
+SDL_bool
+X11_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
+{
+    SDL_SysWMinfo wminfo;
+    if (!SDL_GetWindowWMInfo(window, &wminfo))
+        return SDL_FALSE;
+
+    switch (wminfo.subsystem)
+    {
+    case SDL_SYSWM_X11:
+        {
+            VkXcbSurfaceCreateInfoKHR createInfo;
+            VkResult ret;
+            createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
+            createInfo.pNext = NULL;
+            createInfo.flags = 0;
+            createInfo.connection = XGetXCBConnection(wminfo.info.x11.display);
+            createInfo.window = wminfo.info.x11.window;
+
+            ret = vkCreateXcbSurfaceKHR((VkInstance)instance, &createInfo, NULL, (VkSurfaceKHR*)surface);
+            if (ret != VK_SUCCESS) {
+                SDL_SetError("fail to vkCreateXcbSurfaceKHR : %i", (int)ret);
+                return SDL_FALSE;
+            }
+            return SDL_TRUE;
+        }
+    default:
+        (void)surface;
+        SDL_SetError("Unsupported subsystem %i", (int)wminfo.subsystem);
+        return SDL_FALSE;
+    }
+}
+
+#endif
diff --git a/src/video/x11/SDL_x11vulkan.h b/src/video/x11/SDL_x11vulkan.h
new file mode 100644 (file)
index 0000000..0b65aa3
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef _SDL_x11vulkan_h
+#define _SDL_x11vulkan_h
+
+#if SDL_VIDEO_VULKAN
+extern SDL_bool X11_vulkan_GetInstanceExtensions(const char* driver, unsigned int* count, char** names);
+extern SDL_bool X11_vulkan_CreateSurface(_THIS, SDL_Window* window,SDL_vulkanInstance instance, SDL_vulkanSurface* surface);
+#endif
+
+#endif /* _SDL_x11vulkan_h */