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"
26 #include "../SDL_sysvideo.h"
28 #include "SDL_syswm.h"
29 #include "SDL_video.h"
30 #include "SDL_loadso.h"
32 #include "SDL_tizenwindow.h"
33 #include "SDL_tizenvideo.h"
34 #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 return SDL_SetError("Could not retrieve Vulkan function " #NAME); \
46 Tizen_vulkan_GetInstanceExtensions(_THIS, const char* driver, unsigned int* count, char** names)
48 uint32_t instance_extension_count = 0;
49 uint32_t enabled_extension_count = 0;
52 if (strcmp(driver, "tizen")) {
53 SDL_SetError("Unsupported video driver '%s'", driver);
57 if (!names) *count = 0;
59 err = _this->vk_data->vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL);
61 SDL_SetError("Fail to get Instance extension");
65 if (instance_extension_count > 0) {
67 VkExtensionProperties *instance_extensions =
68 malloc(sizeof(VkExtensionProperties) * instance_extension_count);
69 err = _this->vk_data->vkEnumerateInstanceExtensionProperties(
70 NULL, &instance_extension_count, instance_extensions);
71 for (i = 0; i < instance_extension_count; i++) {
72 if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
73 if (names && (*count > 0)) names[enabled_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
74 else enabled_extension_count++;
77 if (!strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,instance_extensions[i].extensionName)) {
78 if (names && (*count > 0)) names[enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
79 else enabled_extension_count++;
82 free(instance_extensions);
86 *count = enabled_extension_count;
92 Tizen_vulkan_CreateSurface(_THIS, SDL_Window* window, SDL_vulkanInstance instance, SDL_vulkanSurface* surface)
95 SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
96 SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata;
98 if (!SDL_GetWindowWMInfo(window, &wminfo))
101 switch (wminfo.subsystem)
103 case SDL_SYSWM_TIZEN:
105 VkWaylandSurfaceCreateInfoKHR createInfo;
107 createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
108 createInfo.pNext = NULL;
109 createInfo.flags = 0;
110 createInfo.display = video_data->display;
111 createInfo.surface = wmdata->surface;
113 ret = _this->vk_data->vkCreateWaylandSurfaceKHR((VkInstance)instance, &createInfo, NULL, (VkSurfaceKHR*)surface);
114 if (ret != VK_SUCCESS) {
115 SDL_SetError("fail to vkCreateWaylandSurfaceKHR : %i", (int)ret);
122 SDL_SetError("Unsupported subsystem %i", (int)wminfo.subsystem);
129 Tizen_vulkan_LoadLibrary(_THIS, const char *vk_path)
131 void *vk_dll_handle = NULL;
134 if (_this->vk_config.driver_loaded) {
138 _this->vk_data = (struct SDL_vulkan_Data *) SDL_calloc(1, sizeof(SDL_vulkan_Data));
139 if (!_this->vk_data) {
140 return SDL_OutOfMemory();
144 vk_dll_handle = SDL_LoadObject(vk_path);
147 if (!vk_dll_handle) {
148 path = SDL_getenv("SDL_VIDEO_VULKAN_DRIVER");
151 path = DEFAULT_VULKAN;
154 vk_dll_handle = SDL_LoadObject(path);
157 _this->vk_data->vk_dll_handle = vk_dll_handle;
159 if (vk_dll_handle == NULL) {
160 return SDL_SetError("Could not initialize Vulkan library");
163 LOAD_FUNC(vkEnumerateInstanceExtensionProperties);
164 LOAD_FUNC(vkCreateWaylandSurfaceKHR);
166 _this->vk_config.driver_loaded = 1;