Skip to content

Commit 1d19b02

Browse files
committed
feat(linux): add wayland support
1 parent 26bb7fd commit 1d19b02

13 files changed

Lines changed: 112 additions & 14 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project (Anvil)
33

44
option(ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT "Includes 32-/64-bit Windows window system support (Windows builds only)" ON)
55
option(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT "Includes XCB window system support (Linux builds only)" ON)
6+
option(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT "Includes Wayland window system support (Linux builds only)" ON)
67
option(ANVIL_LINK_EXAMPLES "Build examples showing how to use Anvil" OFF)
78
option(ANVIL_LINK_STATICALLY_WITH_VULKAN_LIB "Link statically with Vulkan loader. If disabled, Anvil will load the func ptrs from ANVIL_VULKAN_DYNAMIC_DLL_DEPENDENCY at VK instance creation time" ON)
89
option(ANVIL_LINK_WITH_GLSLANG "Links with glslang, instead of spawning a new process whenever GLSL->SPIR-V conversion is required" ON)

include/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818

1919
/* Defined if XCB window system support is to be included in Anvil */
2020
#define ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT
21+
22+
/* Defined if Wayland window system support is to be included in Anvil */
23+
#define ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT

include/config.h.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
#cmakedefine ANVIL_INCLUDE_WIN3264_WINDOW_SYSTEM_SUPPORT
1818

1919
/* Defined if XCB window system support is to be included in Anvil */
20-
#cmakedefine ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT
20+
#cmakedefine ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT
21+
22+
/* Defined if Wayland window system support is to be included in Anvil */
23+
#cmakedefine ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT

include/misc/extensions.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ namespace Anvil
280280
#if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT)
281281
ValueType khr_xcb_surface;
282282
#endif
283+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
284+
ValueType khr_wayland_surface;
285+
#endif
283286
#endif
284287

285288
std::map<std::string, ValueType> values_by_extension_names;
@@ -321,6 +324,9 @@ namespace Anvil
321324
#if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT)
322325
{ExtensionData(VK_KHR_XCB_SURFACE_EXTENSION_NAME, &khr_xcb_surface)},
323326
#endif
327+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
328+
{ExtensionData(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, &khr_wayland_surface)},
329+
#endif
324330
#endif
325331
};
326332

@@ -473,6 +479,9 @@ namespace Anvil
473479
#if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT)
474480
virtual bool khr_xcb_surface() const = 0;
475481
#endif
482+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
483+
virtual bool khr_wayland_surface() const = 0;
484+
#endif
476485
#endif
477486

478487
virtual bool by_name(const std::string& in_name) const = 0;
@@ -1230,6 +1239,14 @@ namespace Anvil
12301239
return m_instance_extensions_ptr->khr_xcb_surface;
12311240
}
12321241
#endif
1242+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
1243+
ValueType khr_wayland_surface() const final
1244+
{
1245+
anvil_assert(!m_expose_device_extensions);
1246+
1247+
return m_instance_extensions_ptr->khr_wayland_surface;
1248+
}
1249+
#endif
12331250
#endif
12341251

12351252
/* Private variables */

include/misc/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
#if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT)
5757
#define VK_USE_PLATFORM_XCB_KHR
5858
#endif
59+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
60+
#define VK_USE_PLATFORM_WAYLAND_KHR
61+
#endif
5962
#endif
6063

6164
#ifdef _WIN32

include/misc/types_struct.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,14 @@ namespace Anvil
11811181
ExtensionKHRXcbSurfaceEntrypoints();
11821182
} ExtensionKHRXcbSurfaceEntrypoints;
11831183
#endif
1184+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
1185+
typedef struct ExtensionKHRWaylandSurfaceEntrypoints
1186+
{
1187+
PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR;
1188+
1189+
ExtensionKHRWaylandSurfaceEntrypoints();
1190+
} ExtensionKHRWaylandSurfaceEntrypoints;
1191+
#endif
11841192
#endif
11851193

11861194
typedef struct ExtensionKHRDeviceGroupCreationEntrypoints

include/misc/window_generic.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ namespace Anvil
4141

4242
Count,
4343
};
44-
static Anvil::WindowUniquePtr create(Type type, void *windowHandle, uint32_t width, uint32_t height, bool visible);
44+
union Handle {
45+
void *win32Window;
46+
void *waylandWindow;
47+
uint32_t xcbWindow;
48+
};
49+
using Connection = void*;
50+
using Display = void*;
51+
static Anvil::WindowUniquePtr create(Type type, Handle handle, Display display, Connection connection, uint32_t width, uint32_t height, bool visible);
4552

4653
virtual ~WindowGeneric() { /* Stub */ }
4754

@@ -54,14 +61,15 @@ namespace Anvil
5461
return WINDOW_PLATFORM_GENERIC;
5562
}
5663

57-
/* This function should never be called under Windows */
58-
virtual void* get_connection() const
64+
virtual bool is_dummy()
5965
{
60-
anvil_assert_fail();
61-
62-
return nullptr;
66+
return false;
6367
}
68+
69+
/* This function should never be called under Windows */
70+
virtual void* get_connection() const { return m_connection; }
6471
Type get_type() const { return m_type; }
72+
Display get_display() const { return m_display; }
6573

6674
/** Changes the window title.
6775
*
@@ -73,8 +81,10 @@ namespace Anvil
7381
/* Private functions */
7482

7583
WindowGeneric(Type type,
76-
void *windowHandle,
84+
Handle handle,
7785
const std::string &in_title,
86+
Display display,
87+
Connection connection,
7888
unsigned int in_width,
7989
unsigned int in_height,
8090
PresentCallbackFunction in_present_callback_func);
@@ -84,6 +94,8 @@ namespace Anvil
8494

8595
/* Private variables */
8696
Type m_type;
97+
Display m_display;
98+
Connection m_connection;
8799
};
88100
}; /* namespace Anvil */
89101

include/wrappers/instance.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ namespace Anvil
9696
**/
9797
const ExtensionKHRXcbSurfaceEntrypoints& get_extension_khr_xcb_surface_entrypoints() const;
9898
#endif
99+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
100+
/** Returns a container with entry-points to functions introduced by VK_KHR_wayland_surface.
101+
*
102+
* Will fire an assertion failure if the extension is not supported.
103+
**/
104+
const ExtensionKHRWaylandSurfaceEntrypoints& get_extension_khr_wayland_surface_entrypoints() const;
105+
#endif
99106
#endif
100107

101108
/** Returns a container with entry-points to functions introduced by VK_KHR_device_group_creation extension.
@@ -229,6 +236,9 @@ namespace Anvil
229236
#if defined(ANVIL_INCLUDE_XCB_WINDOW_SYSTEM_SUPPORT)
230237
ExtensionKHRXcbSurfaceEntrypoints m_khr_xcb_surface_entrypoints;
231238
#endif
239+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
240+
ExtensionKHRWaylandSurfaceEntrypoints m_khr_wayland_surface_entrypoints;
241+
#endif
232242
#endif
233243

234244
Anvil::APIVersion m_api_version;

src/misc/types_struct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ Anvil::ExtensionKHRSwapchainEntrypoints::ExtensionKHRSwapchainEntrypoints()
546546
vkCreateXcbSurfaceKHR = nullptr;
547547
}
548548
#endif
549+
#if defined(ANVIL_INCLUDE_WAYLAND_WINDOW_SYSTEM_SUPPORT)
550+
Anvil::ExtensionKHRWaylandSurfaceEntrypoints::ExtensionKHRWaylandSurfaceEntrypoints()
551+
{
552+
vkCreateWaylandSurfaceKHR = nullptr;
553+
}
554+
#endif
549555
#endif
550556

551557
Anvil::ExtensionKHRGetMemoryRequirements2Entrypoints::ExtensionKHRGetMemoryRequirements2Entrypoints()

src/misc/window_generic.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
/* See create() for documentation */
2727
Anvil::WindowGeneric::WindowGeneric(Type type,
28-
void *windowHandle,
28+
Handle handle,
2929
const std::string &in_title,
30+
Display display,
31+
Connection connection,
3032
unsigned int in_width,
3133
unsigned int in_height,
3234
Anvil::PresentCallbackFunction in_present_callback_func)
@@ -36,13 +38,15 @@ Anvil::WindowGeneric::WindowGeneric(Type type,
3638
true, /* in_closable */
3739
in_present_callback_func)
3840
{
39-
m_window = reinterpret_cast<WindowHandle>(windowHandle);
41+
m_window = *reinterpret_cast<WindowHandle*>(&handle);
4042
m_window_owned = false;
4143
m_type = type;
44+
m_display = display;
45+
m_connection = connection;
4246
}
4347

4448
/** Please see header for specification */
45-
Anvil::WindowUniquePtr Anvil::WindowGeneric::create(Type type, void *windowHandle, uint32_t width, uint32_t height, bool visible)
49+
Anvil::WindowUniquePtr Anvil::WindowGeneric::create(Type type, Handle handle, Display display, Connection connection, uint32_t width, uint32_t height, bool visible)
4650
{
4751
WindowUniquePtr result_ptr (nullptr,
4852
std::default_delete<Window>() );
@@ -54,8 +58,10 @@ Anvil::WindowUniquePtr Anvil::WindowGeneric::create(Type type, void *windowHandl
5458
/* Go ahead and create the window wrapper instance */
5559
result_ptr.reset(
5660
new Anvil::WindowGeneric(type,
57-
windowHandle,
61+
handle,
5862
"Generic wrapper window instance",
63+
display,
64+
connection,
5965
window_size[0],
6066
window_size[1],
6167
nullptr) /* present_callback_func_ptr */

0 commit comments

Comments
 (0)