Skip to content

Commit e8987c5

Browse files
committed
fix(linux): wayland surface failing to initialize
1 parent 30d8a97 commit e8987c5

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

include/misc/window_generic.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace Anvil
4848
};
4949
using Connection = void*;
5050
using Display = void*;
51-
static Anvil::WindowUniquePtr create(Type type, Handle handle, Display display, Connection connection, uint32_t width, uint32_t height, bool visible);
51+
static Anvil::WindowUniquePtr create(Type type, Handle handle, Display display, Connection connection, uint32_t width, uint32_t height, bool visible, uint32_t fbWidth, uint32_t fbHeight);
5252

5353
virtual ~WindowGeneric() { /* Stub */ }
5454

@@ -70,6 +70,9 @@ namespace Anvil
7070
virtual void* get_connection() const { return m_connection; }
7171
Type get_type() const { return m_type; }
7272
Display get_display() const { return m_display; }
73+
Handle get_generic_handle() const { return m_handle; }
74+
uint32_t get_framebuffer_width() const { return m_fbWidth; }
75+
uint32_t get_framebuffer_height() const { return m_fbHeight; }
7376

7477
/** Changes the window title.
7578
*
@@ -87,6 +90,8 @@ namespace Anvil
8790
Connection connection,
8891
unsigned int in_width,
8992
unsigned int in_height,
93+
uint32_t fbWidth,
94+
uint32_t fbHeight,
9095
PresentCallbackFunction in_present_callback_func);
9196

9297
/** Creates a new system window and prepares it for usage. */
@@ -96,6 +101,9 @@ namespace Anvil
96101
Type m_type;
97102
Display m_display;
98103
Connection m_connection;
104+
Handle m_handle;
105+
uint32_t m_fbWidth;
106+
uint32_t m_fbHeight;
99107
};
100108
}; /* namespace Anvil */
101109

src/misc/window_generic.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,26 @@ Anvil::WindowGeneric::WindowGeneric(Type type,
3131
Connection connection,
3232
unsigned int in_width,
3333
unsigned int in_height,
34+
uint32_t fbWidth,
35+
uint32_t fbHeight,
3436
Anvil::PresentCallbackFunction in_present_callback_func)
3537
:Window(in_title,
3638
in_width,
3739
in_height,
3840
true, /* in_closable */
3941
in_present_callback_func)
4042
{
41-
m_window = *reinterpret_cast<WindowHandle*>(&handle);
4243
m_window_owned = false;
4344
m_type = type;
4445
m_display = display;
4546
m_connection = connection;
47+
m_handle = handle;
48+
m_fbWidth = fbWidth;
49+
m_fbHeight = fbHeight;
4650
}
4751

4852
/** Please see header for specification */
49-
Anvil::WindowUniquePtr Anvil::WindowGeneric::create(Type type, Handle handle, Display display, Connection connection, uint32_t width, uint32_t height, bool visible)
53+
Anvil::WindowUniquePtr Anvil::WindowGeneric::create(Type type, Handle handle, Display display, Connection connection, uint32_t width, uint32_t height, bool visible, uint32_t fbWidth, uint32_t fbHeight)
5054
{
5155
WindowUniquePtr result_ptr (nullptr,
5256
std::default_delete<Window>() );
@@ -64,6 +68,8 @@ Anvil::WindowUniquePtr Anvil::WindowGeneric::create(Type type, Handle handle, Di
6468
connection,
6569
window_size[0],
6670
window_size[1],
71+
fbWidth,
72+
fbHeight,
6773
nullptr) /* present_callback_func_ptr */
6874
);
6975

src/wrappers/rendering_surface.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ bool Anvil::RenderingSurface::init()
413413
VkXcbSurfaceCreateInfoKHR surface_create_info;
414414

415415
surface_create_info.flags = 0;
416-
surface_create_info.window = window_ptr->get_handle();
416+
surface_create_info.window = generic_ptr->get_generic_handle().xcbWindow;
417417
surface_create_info.connection = static_cast<xcb_connection_t *>(window_ptr->get_connection());
418418
surface_create_info.pNext = nullptr;
419419
surface_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
@@ -422,13 +422,15 @@ bool Anvil::RenderingSurface::init()
422422
&m_surface);
423423
}
424424
else if(type == Anvil::WindowGeneric::Type::Wayland) {
425+
auto vkInstance = instance_ptr->get_instance_vk();
426+
auto &entrypoints = instance_ptr->get_extension_khr_wayland_surface_entrypoints();
425427
VkWaylandSurfaceCreateInfoKHR surface_create_info;
426428
surface_create_info.flags = 0;
427429
surface_create_info.display = reinterpret_cast<wl_display *>(window_ptr->get_connection());
428-
surface_create_info.surface = reinterpret_cast<wl_surface *>(window_ptr->get_handle());
430+
surface_create_info.surface = reinterpret_cast<wl_surface *>(generic_ptr->get_generic_handle().waylandWindow);
429431
surface_create_info.pNext = nullptr;
430432
surface_create_info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
431-
result = instance_ptr->get_extension_khr_wayland_surface_entrypoints().vkCreateWaylandSurfaceKHR(instance_ptr->get_instance_vk(), &surface_create_info, nullptr, /* pAllocator */
433+
result = entrypoints.vkCreateWaylandSurfaceKHR(vkInstance, &surface_create_info, nullptr, /* pAllocator */
432434
&m_surface);
433435
}
434436
else
@@ -736,6 +738,28 @@ void Anvil::RenderingSurface::update_surface_extents() const
736738
{
737739
m_height = surface_caps.current_extent.height;
738740
m_width = surface_caps.current_extent.width;
741+
742+
if(m_width == m_height && m_width == std::numeric_limits<uint32_t>::max())
743+
{
744+
// The surface is not limited to a specific size, so we'll just use the window framebuffer size
745+
auto *generic_ptr = dynamic_cast<const Anvil::WindowGeneric *>(window_ptr);
746+
if(generic_ptr != nullptr)
747+
{
748+
m_height = generic_ptr->get_framebuffer_height();
749+
m_width = generic_ptr->get_framebuffer_width();
750+
751+
// Clamp to max extents
752+
if(m_height > surface_caps.max_image_extent.height)
753+
m_height = surface_caps.max_image_extent.height;
754+
if(m_width > surface_caps.max_image_extent.width)
755+
m_width = surface_caps.max_image_extent.width;
756+
}
757+
else
758+
{
759+
m_height = surface_caps.min_image_extent.height;
760+
m_width = surface_caps.min_image_extent.width;
761+
}
762+
}
739763
}
740764
else
741765
{

0 commit comments

Comments
 (0)