2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
22 #include "../../SDL_internal.h"
24 #include "../SDL_sysvideo.h"
26 #include "SDL_syswm.h"
27 #include "SDL_video.h"
28 #include "SDL_loadso.h"
30 #include "SDL_tizenwindow.h"
31 #include "SDL_tizenvideo.h"
32 #include "SDL_tizenvulkan.h"
36 #define DEFAULT_VULKAN "libvulkan.so"
38 #define LOAD_FUNC(NAME) \
39 _this->vk_data->NAME = SDL_LoadFunction(_this->vk_data->vk_dll_handle, #NAME); \
40 if (!_this->vk_data->NAME) \
42 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Could not retrieve Vulkan function " #NAME); \
47 Tizen_vulkan_GetInstanceExtensions(_THIS, const char* driver, unsigned int* count, char** names)
49 uint32_t instance_extension_count = 0;
50 uint32_t enabled_extension_count = 0;
53 if (strcmp(driver, "tizen")) {
54 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Unsupported video driver '%s'", driver);
58 if (!names) *count = 0;
60 err = _this->vk_data->vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL);
62 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Fail to get Instance extension");
66 if (instance_extension_count > 0) {
68 VkExtensionProperties *instance_extensions =
69 malloc(sizeof(VkExtensionProperties) * instance_extension_count);
70 err = _this->vk_data->vkEnumerateInstanceExtensionProperties(
71 NULL, &instance_extension_count, instance_extensions);
72 for (i = 0; i < instance_extension_count; i++) {
73 if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
74 if (names && (*count > 0)) names[enabled_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
75 else enabled_extension_count++;
78 if (!strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
79 if (names && (*count > 0)) names[enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
80 else enabled_extension_count++;
83 free(instance_extensions);
87 *count = enabled_extension_count;
93 Tizen_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
96 SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
97 SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata;
99 if (!SDL_GetWindowWMInfo(window, &wminfo))
102 switch (wminfo.subsystem)
104 case SDL_SYSWM_TIZEN:
106 VkWaylandSurfaceCreateInfoKHR createInfo;
108 createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
109 createInfo.pNext = NULL;
110 createInfo.flags = 0;
111 createInfo.display = video_data->display;
112 createInfo.surface = wmdata->surface;
114 ret = _this->vk_data->vkCreateWaylandSurfaceKHR((VkInstance)instance, &createInfo, NULL, (VkSurfaceKHR*)surface);
115 if (ret != VK_SUCCESS) {
116 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "fail to vkCreateWaylandSurfaceKHR : %i", (int)ret);
123 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Unsupported subsystem %i", (int)wminfo.subsystem);
130 Tizen_vulkan_LoadLibrary(_THIS, const char *vk_path)
132 void *vk_dll_handle = NULL;
135 if (_this->vk_config.driver_loaded) {
139 _this->vk_data = (struct SDL_vulkan_Data *) SDL_calloc(1, sizeof(SDL_vulkan_Data));
140 if (!_this->vk_data) {
141 return SDL_OutOfMemory();
145 vk_dll_handle = SDL_LoadObject(vk_path);
148 if (!vk_dll_handle) {
149 path = SDL_getenv("SDL_VIDEO_VULKAN_DRIVER");
152 path = DEFAULT_VULKAN;
155 vk_dll_handle = SDL_LoadObject(path);
158 _this->vk_data->vk_dll_handle = vk_dll_handle;
160 if (vk_dll_handle == NULL) {
161 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Could not initialize Vulkan library");
165 LOAD_FUNC(vkEnumerateInstanceExtensionProperties);
166 LOAD_FUNC(vkCreateWaylandSurfaceKHR);
168 _this->vk_config.driver_loaded = 1;