SDL  2.0
SDL_waylandvulkan.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 /*
23  * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
24  * SDL_x11vulkan.c.
25  */
26 
27 #include "../../SDL_internal.h"
28 
29 #if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WAYLAND
30 
31 #include "SDL_waylandvideo.h"
32 #include "SDL_waylandwindow.h"
33 
34 #include "SDL_loadso.h"
35 #include "SDL_waylandvulkan.h"
36 #include "SDL_syswm.h"
37 
38 #if defined(__OpenBSD__)
39 #define DEFAULT_VULKAN "libvulkan.so"
40 #else
41 #define DEFAULT_VULKAN "libvulkan.so.1"
42 #endif
43 
44 int Wayland_Vulkan_LoadLibrary(_THIS, const char *path)
45 {
46  VkExtensionProperties *extensions = NULL;
47  Uint32 i, extensionCount = 0;
48  SDL_bool hasSurfaceExtension = SDL_FALSE;
49  SDL_bool hasWaylandSurfaceExtension = SDL_FALSE;
52  return SDL_SetError("Vulkan already loaded");
53 
54  /* Load the Vulkan loader library */
55  if(!path)
56  path = SDL_getenv("SDL_VULKAN_LIBRARY");
57  if(!path)
58  path = DEFAULT_VULKAN;
61  return -1;
65  _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
67  goto fail;
71  VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
73  goto fail;
74  extensions = SDL_Vulkan_CreateInstanceExtensionsList(
77  &extensionCount);
78  if(!extensions)
79  goto fail;
80  for(i = 0; i < extensionCount; i++)
81  {
82  if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
83  hasSurfaceExtension = SDL_TRUE;
84  else if(SDL_strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
85  hasWaylandSurfaceExtension = SDL_TRUE;
86  }
87  SDL_free(extensions);
88  if(!hasSurfaceExtension)
89  {
90  SDL_SetError("Installed Vulkan doesn't implement the "
91  VK_KHR_SURFACE_EXTENSION_NAME " extension");
92  goto fail;
93  }
94  else if(!hasWaylandSurfaceExtension)
95  {
96  SDL_SetError("Installed Vulkan doesn't implement the "
98  goto fail;
99  }
100  return 0;
101 
102 fail:
105  return -1;
106 }
107 
108 void Wayland_Vulkan_UnloadLibrary(_THIS)
109 {
111  {
114  }
115 }
116 
117 SDL_bool Wayland_Vulkan_GetInstanceExtensions(_THIS,
119  unsigned *count,
120  const char **names)
121 {
122  static const char *const extensionsForWayland[] = {
124  };
126  {
127  SDL_SetError("Vulkan is not loaded");
128  return SDL_FALSE;
129  }
130  return SDL_Vulkan_GetInstanceExtensions_Helper(
131  count, names, SDL_arraysize(extensionsForWayland),
132  extensionsForWayland);
133 }
134 
135 void Wayland_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
136 {
138  if (window->driverdata) {
139  data = (SDL_WindowData *) window->driverdata;
140 
141  if (w) {
142  *w = window->w * data->scale_factor;
143  }
144 
145  if (h) {
146  *h = window->h * data->scale_factor;
147  }
148  }
149 }
150 
151 SDL_bool Wayland_Vulkan_CreateSurface(_THIS,
153  VkInstance instance,
154  VkSurfaceKHR *surface)
155 {
156  SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata;
161  instance,
162  "vkCreateWaylandSurfaceKHR");
165 
167  {
168  SDL_SetError("Vulkan is not loaded");
169  return SDL_FALSE;
170  }
171 
173  {
175  " extension is not enabled in the Vulkan instance.");
176  return SDL_FALSE;
177  }
178  SDL_zero(createInfo);
180  createInfo.pNext = NULL;
181  createInfo.flags = 0;
182  createInfo.display = windowData->waylandData->display;
183  createInfo.surface = windowData->surface;
184  result = vkCreateWaylandSurfaceKHR(instance, &createInfo,
185  NULL, surface);
186  if(result != VK_SUCCESS)
187  {
188  SDL_SetError("vkCreateWaylandSurfaceKHR failed: %s",
189  SDL_Vulkan_GetResultString(result));
190  return SDL_FALSE;
191  }
192  return SDL_TRUE;
193 }
194 
195 #endif
196 
197 /* vim: set ts=4 sw=4 expandtab: */
#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
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint64EXT * result
GLuint GLuint * names
GLsizei const GLchar *const * path
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
#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
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
struct wl_display * display
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
SDL_Surface * surface
SDL_VideoData * waylandData
The type used to identify a window.
Definition: SDL_sysvideo.h:75
VkWaylandSurfaceCreateFlagsKHR flags
struct wl_display * display
struct wl_surface * surface
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_WAYLAND_SURFACE_CREATE_INFO_KHR
Definition: vulkan_core.h:330
VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
#define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
VkResult(VKAPI_PTR * PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)