SDL  2.0
SDL_DirectFB_vulkan.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #include "../../SDL_internal.h"
23 
24 #if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_DIRECTFB
25 
26 #include "SDL_DirectFB_window.h"
27 
28 #include "SDL_loadso.h"
29 #include "SDL_DirectFB_vulkan.h"
30 
31 int DirectFB_Vulkan_LoadLibrary(_THIS, const char *path)
32 {
33  VkExtensionProperties *extensions = NULL;
34  Uint32 i, extensionCount = 0;
35  SDL_bool hasSurfaceExtension = SDL_FALSE;
36  SDL_bool hasDirectFBSurfaceExtension = SDL_FALSE;
39  return SDL_SetError("Vulkan already loaded");
40 
41  /* Load the Vulkan loader library */
42  if(!path)
43  path = SDL_getenv("SDL_VULKAN_LIBRARY");
44  if(!path)
45  path = "libvulkan.so.1";
48  return -1;
52  _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
54  goto fail;
58  VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
60  goto fail;
61  extensions = SDL_Vulkan_CreateInstanceExtensionsList(
64  &extensionCount);
65  if(!extensions)
66  goto fail;
67  for(i = 0; i < extensionCount; i++)
68  {
69  if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
70  hasSurfaceExtension = SDL_TRUE;
71  else if(SDL_strcmp(VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
72  hasDirectFBSurfaceExtension = SDL_TRUE;
73  }
74  SDL_free(extensions);
75  if(!hasSurfaceExtension)
76  {
77  SDL_SetError("Installed Vulkan doesn't implement the "
78  VK_KHR_SURFACE_EXTENSION_NAME " extension");
79  goto fail;
80  }
81  else if(!hasDirectFBSurfaceExtension)
82  {
83  SDL_SetError("Installed Vulkan doesn't implement the "
85  goto fail;
86  }
87  return 0;
88 
89 fail:
92  return -1;
93 }
94 
95 void DirectFB_Vulkan_UnloadLibrary(_THIS)
96 {
98  {
101  }
102 }
103 
104 SDL_bool DirectFB_Vulkan_GetInstanceExtensions(_THIS,
106  unsigned *count,
107  const char **names)
108 {
109  static const char *const extensionsForDirectFB[] = {
111  };
113  {
114  SDL_SetError("Vulkan is not loaded");
115  return SDL_FALSE;
116  }
117  return SDL_Vulkan_GetInstanceExtensions_Helper(
118  count, names, SDL_arraysize(extensionsForDirectFB),
119  extensionsForDirectFB);
120 }
121 
122 SDL_bool DirectFB_Vulkan_CreateSurface(_THIS,
124  VkInstance instance,
125  VkSurfaceKHR *surface)
126 {
133  instance,
134  "vkCreateDirectFBSurfaceEXT");
137 
139  {
140  SDL_SetError("Vulkan is not loaded");
141  return SDL_FALSE;
142  }
143 
145  {
147  " extension is not enabled in the Vulkan instance.");
148  return SDL_FALSE;
149  }
150  SDL_zero(createInfo);
152  createInfo.pNext = NULL;
153  createInfo.flags = 0;
154  createInfo.dfb = devdata->dfb;
155  createInfo.surface = windata->surface;
156  result = vkCreateDirectFBSurfaceEXT(instance, &createInfo,
157  NULL, surface);
158  if(result != VK_SUCCESS)
159  {
160  SDL_SetError("vkCreateDirectFBSurfaceEXT failed: %s",
161  SDL_Vulkan_GetResultString(result));
162  return SDL_FALSE;
163  }
164  return SDL_TRUE;
165 }
166 
167 #endif
168 
169 /* vim: set ts=4 sw=4 expandtab: */
#define SDL_DFB_DEVICEDATA(dev)
#define SDL_DFB_WINDOWDATA(win)
#define _THIS
#define SDL_SetError
#define SDL_LoadObject
#define SDL_UnloadObject
#define SDL_getenv
#define SDL_strlcpy
#define SDL_free
#define SDL_strcmp
void * SDL_LoadFunction(void *handle, const char *name)
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
GLuint64EXT * result
GLuint GLuint * names
GLsizei const GLchar *const * path
#define SDL_zero(x)
Definition: SDL_stdinc.h:426
SDL_bool
Definition: SDL_stdinc.h:168
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
uint32_t Uint32
Definition: SDL_stdinc.h:209
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:163
EGLSurface surface
Definition: eglext.h:248
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
struct SDL_VideoDevice::@441 vulkan_config
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr
Definition: SDL_sysvideo.h:387
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties
Definition: SDL_sysvideo.h:388
char loader_path[256]
Definition: SDL_sysvideo.h:390
void * loader_handle
Definition: SDL_sysvideo.h:391
The type used to identify a window.
Definition: SDL_sysvideo.h:75
VkDirectFBSurfaceCreateFlagsEXT flags
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *pName)
#define VK_KHR_SURFACE_EXTENSION_NAME
Definition: vulkan_core.h:5654
VkResult
Definition: vulkan_core.h:103
@ VK_SUCCESS
Definition: vulkan_core.h:104
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
Definition: vulkan_core.h:3121
#define VK_NULL_HANDLE
Definition: vulkan_core.h:55
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:3117
@ VK_STRUCTURE_TYPE_DIRECTFB_SURFACE_CREATE_INFO_EXT
Definition: vulkan_core.h:617
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
VkResult(VKAPI_PTR * PFN_vkCreateDirectFBSurfaceEXT)(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
#define VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME