fix SDL_Vulkan API 96/99796/2
authorDaeKwang Ryu <dkdk.ryu@samsung.com>
Wed, 23 Nov 2016 07:57:11 +0000 (16:57 +0900)
committerDaeKwang Ryu <dkdk.ryu@samsung.com>
Fri, 25 Nov 2016 05:15:59 +0000 (14:15 +0900)
1. call SDL_Vulkan_GetInstanceExtensions twice
   to get vulkan instance extension names
2. check window magic
3. null check in SDL API layer, not porting layer

Change-Id: Iefb5f7c7da564a1b8489700ff363ead7179e9380

src/video/SDL_video.c
src/video/tizen/SDL_tizenvulkan.c

index afc1905..74ce080 100755 (executable)
@@ -3772,16 +3772,18 @@ float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
 SDL_bool
 SDL_Vulkan_GetInstanceExtensions(SDL_Window* window, unsigned int* count, char** names)
 {
-    if (!count) {
-        SDL_SetError("count ptr is null");
-        return SDL_FALSE;
-    }
+    CHECK_WINDOW_MAGIC(window, SDL_FALSE);
 
     if (!(window->flags & SDL_WINDOW_VULKAN)) {
         SDL_SetError("Not setup with SDL_WINDOW_VULKAN flags");
         return SDL_FALSE;
     }
 
+    if (!count) {
+        SDL_SetError("count pointer is NULL");
+        return SDL_FALSE;
+    }
+
     const char *driver = SDL_GetCurrentVideoDriver();
     if (!driver) {
         SDL_SetError("Current video driveer is NULL");
@@ -3794,16 +3796,18 @@ SDL_Vulkan_GetInstanceExtensions(SDL_Window* window, unsigned int* count, char**
 SDL_bool
 SDL_Vulkan_CreateSurface(SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
 {
-    if (!window) {
-        SDL_SetError("'window' is null");
-        return SDL_FALSE;
-    }
+    CHECK_WINDOW_MAGIC(window, SDL_FALSE);
 
-    if (instance == 0) {
+    if (!instance) {
         SDL_SetError("'instance' is null");
         return SDL_FALSE;
     }
 
+    if (!surface) {
+       SDL_SetError("'surface' is null");
+       return SDL_FALSE;
+    }
+
     return _this->vulkan_CreateSurface(_this, window, instance, surface);
 }
 
index b7a1ecc..77dfeaa 100755 (executable)
@@ -74,6 +74,8 @@ Tizen_vulkan_GetInstanceExtensions(_THIS, const char* driver, unsigned int* coun
         return SDL_FALSE;
     }
 
+    if (!names) *count = 0;
+
     err = _this->vk_data->vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL);
     if (err < 0) {
         SDL_SetError("Fail to get Instance extension");
@@ -88,22 +90,21 @@ Tizen_vulkan_GetInstanceExtensions(_THIS, const char* driver, unsigned int* coun
             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 (names && (*count > 0)) names[enabled_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
+                else enabled_extension_count++;
             }
 
             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;
+                if (names && (*count > 0)) names[enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
+                else enabled_extension_count++;
             }
         }
         free(instance_extensions);
     }
-    *count = enabled_extension_count;
+
+    if (*count == 0)
+        *count = enabled_extension_count;
+
     return SDL_TRUE;
 }