Skip to content

Commit ec23776

Browse files
mcourteauxalesambits
authored andcommitted
Properly support Wayland under EGL and Vulkan. (bkaradzic#3358)
1 parent 3b39dac commit ec23776

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

examples/common/entry/entry_glfw.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,8 @@ namespace entry
4646
{
4747
# if BX_PLATFORM_LINUX
4848
# if ENTRY_CONFIG_USE_WAYLAND
49-
wl_egl_window *win_impl = (wl_egl_window*)glfwGetWindowUserPointer(_window);
50-
if(!win_impl)
51-
{
52-
int width, height;
53-
glfwGetWindowSize(_window, &width, &height);
54-
struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(_window);
55-
if(!surface)
56-
return nullptr;
57-
win_impl = wl_egl_window_create(surface, width, height);
58-
glfwSetWindowUserPointer(_window, (void*)(uintptr_t)win_impl);
59-
}
60-
return (void*)(uintptr_t)win_impl;
49+
struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(_window);
50+
return (void*)surface;
6151
# else
6252
return (void*)(uintptr_t)glfwGetX11Window(_window);
6353
# endif

examples/common/entry/entry_sdl.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,7 @@ namespace entry
5151
# if BX_PLATFORM_LINUX
5252
# if ENTRY_CONFIG_USE_WAYLAND
5353
if (wmi.subsystem == SDL_SYSWM_WAYLAND)
54-
{
55-
wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(_window, "wl_egl_window");
56-
if(!win_impl)
57-
{
58-
int width, height;
59-
SDL_GetWindowSize(_window, &width, &height);
60-
struct wl_surface* surface = wmi.info.wl.surface;
61-
if(!surface)
62-
return nullptr;
63-
win_impl = wl_egl_window_create(surface, width, height);
64-
SDL_SetWindowData(_window, "wl_egl_window", win_impl);
65-
}
66-
return (void*)(uintptr_t)win_impl;
67-
}
54+
return (void*)wmi.info.wl.surface;
6855
else
6956
# endif // ENTRY_CONFIG_USE_WAYLAND
7057
return (void*)wmi.info.x11.window;

examples/common/example-glue.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
290290
}
291291
}
292292
}
293+
#else
294+
ImGui::Text("Renderer: %s", bgfx::getRendererName(bgfx::getRendererType()));
293295
#endif // 0
294296

295297
const bgfx::Stats* stats = bgfx::getStats();

src/glcontext_egl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
# define EGL_CHECK(_call) _call
2828
#endif // BGFX_CONFIG_DEBUG
2929

30+
#if defined(WL_EGL_PLATFORM)
31+
# include <wayland-egl.h>
32+
#endif
33+
3034
namespace bgfx { namespace gl
3135
{
3236
#ifndef EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
@@ -329,6 +333,14 @@ EGL_IMPORT
329333
vc_dispmanx_update_submit_sync(dispmanUpdate);
330334
# endif // BX_PLATFORM_ANDROID
331335

336+
# if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
337+
if (g_platformData.type == NativeWindowHandleType::Wayland) {
338+
// A wl_surface needs to be first wrapped in a wl_egl_window
339+
// before it can be used to create the EGLSurface.
340+
m_egl_window = wl_egl_window_create((wl_surface*)nwh, _width, _height);
341+
nwh = m_egl_window;
342+
}
343+
# endif
332344
if (headless)
333345
{
334346
EGLint pbAttribs[] =
@@ -430,6 +442,11 @@ EGL_IMPORT
430442
EGL_CHECK(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) );
431443
EGL_CHECK(eglDestroyContext(m_display, m_context) );
432444
EGL_CHECK(eglDestroySurface(m_display, m_surface) );
445+
# if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
446+
if (m_egl_window) {
447+
wl_egl_window_destroy(m_egl_window);
448+
}
449+
# endif
433450
EGL_CHECK(eglTerminate(m_display) );
434451
m_context = NULL;
435452
}
@@ -461,6 +478,10 @@ EGL_IMPORT
461478
}
462479
# elif BX_PLATFORM_EMSCRIPTEN
463480
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(HTML5_TARGET_CANVAS_SELECTOR, _width, _height) );
481+
# elif BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
482+
if (NULL != m_egl_window) {
483+
wl_egl_window_resize(m_egl_window, _width, _height, 0, 0);
484+
}
464485
# else
465486
BX_UNUSED(_width, _height);
466487
# endif // BX_PLATFORM_*

src/glcontext_egl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <EGL/egl.h>
1212
#include <EGL/eglext.h>
1313

14+
1415
// EGL pulls X11 crap...
1516
#if defined(None)
1617
# undef None
@@ -35,6 +36,9 @@ namespace bgfx { namespace gl
3536
, m_context(NULL)
3637
, m_display(NULL)
3738
, m_surface(NULL)
39+
#if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
40+
, m_egl_window(NULL)
41+
#endif
3842
, m_msaaContext(false)
3943
{
4044
}
@@ -62,6 +66,9 @@ namespace bgfx { namespace gl
6266
EGLContext m_context;
6367
EGLDisplay m_display;
6468
EGLSurface m_surface;
69+
#if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
70+
struct wl_egl_window *m_egl_window;
71+
#endif
6572
// true when MSAA is handled by the context instead of using MSAA FBO
6673
bool m_msaaContext;
6774
};

src/renderer_vk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6940,7 +6940,7 @@ VK_DESTROY
69406940
sci.pNext = NULL;
69416941
sci.flags = 0;
69426942
sci.display = (wl_display*)g_platformData.ndt;
6943-
sci.surface = (wl_surface*)((wl_egl_window*)m_nwh)->surface;
6943+
sci.surface = (wl_surface*)m_nwh;
69446944
result = vkCreateWaylandSurfaceKHR(instance, &sci, allocatorCb, &m_surface);
69456945
}
69466946
else

0 commit comments

Comments
 (0)