mirror of https://github.com/PCSX2/pcsx2.git
GL/Context: Load wayland-egl dynamically
Gets rid of the dependency on libwayland-egl, allowing us to always use the system version. Solves missing symbol issues by including it in the AppImage.
This commit is contained in:
parent
af4c047c41
commit
8620febeb3
|
@ -126,9 +126,6 @@ else()
|
|||
check_lib(XCB xcb xcb/xcb.h)
|
||||
check_lib(XRANDR xrandr)
|
||||
endif()
|
||||
if(WAYLAND_API)
|
||||
find_package(Wayland REQUIRED)
|
||||
endif()
|
||||
|
||||
if(Linux)
|
||||
check_lib(AIO aio libaio.h)
|
||||
|
@ -169,9 +166,9 @@ else()
|
|||
## Use pcsx2 package to find module
|
||||
find_package(HarfBuzz)
|
||||
endif()
|
||||
endif()
|
||||
if(WAYLAND_API)
|
||||
find_package(Wayland REQUIRED)
|
||||
if(WAYLAND_API)
|
||||
find_package(Wayland REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
endif(WIN32)
|
||||
|
||||
|
|
|
@ -243,7 +243,6 @@ if(USE_OPENGL)
|
|||
GL/ContextEGLWayland.cpp
|
||||
GL/ContextEGLWayland.h
|
||||
)
|
||||
target_link_libraries(common PRIVATE ${WAYLAND_EGL_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -14,27 +14,34 @@
|
|||
*/
|
||||
|
||||
#include "common/PrecompiledHeader.h"
|
||||
#include "common/Console.h"
|
||||
|
||||
#include "ContextEGLWayland.h"
|
||||
#include <wayland-egl.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
namespace GL
|
||||
{
|
||||
static const char* WAYLAND_EGL_MODNAME = "libwayland-egl.so.1";
|
||||
|
||||
ContextEGLWayland::ContextEGLWayland(const WindowInfo& wi)
|
||||
: ContextEGL(wi)
|
||||
{
|
||||
}
|
||||
|
||||
ContextEGLWayland::~ContextEGLWayland()
|
||||
{
|
||||
if (m_wl_window)
|
||||
wl_egl_window_destroy(m_wl_window);
|
||||
m_wl_egl_window_destroy(m_wl_window);
|
||||
if (m_wl_module)
|
||||
dlclose(m_wl_module);
|
||||
}
|
||||
|
||||
std::unique_ptr<Context> ContextEGLWayland::Create(const WindowInfo& wi, const Version* versions_to_try,
|
||||
size_t num_versions_to_try)
|
||||
{
|
||||
std::unique_ptr<ContextEGLWayland> context = std::make_unique<ContextEGLWayland>(wi);
|
||||
if (!context->Initialize(versions_to_try, num_versions_to_try))
|
||||
if (!context->LoadModule() || !context->Initialize(versions_to_try, num_versions_to_try))
|
||||
return nullptr;
|
||||
|
||||
return context;
|
||||
|
@ -45,7 +52,7 @@ namespace GL
|
|||
std::unique_ptr<ContextEGLWayland> context = std::make_unique<ContextEGLWayland>(wi);
|
||||
context->m_display = m_display;
|
||||
|
||||
if (!context->CreateContextAndSurface(m_version, m_context, false))
|
||||
if (!context->LoadModule() || !context->CreateContextAndSurface(m_version, m_context, false))
|
||||
return nullptr;
|
||||
|
||||
return context;
|
||||
|
@ -54,7 +61,7 @@ namespace GL
|
|||
void ContextEGLWayland::ResizeSurface(u32 new_surface_width, u32 new_surface_height)
|
||||
{
|
||||
if (m_wl_window)
|
||||
wl_egl_window_resize(m_wl_window, new_surface_width, new_surface_height, 0, 0);
|
||||
m_wl_egl_window_resize(m_wl_window, new_surface_width, new_surface_height, 0, 0);
|
||||
|
||||
ContextEGL::ResizeSurface(new_surface_width, new_surface_height);
|
||||
}
|
||||
|
@ -63,15 +70,36 @@ namespace GL
|
|||
{
|
||||
if (m_wl_window)
|
||||
{
|
||||
wl_egl_window_destroy(m_wl_window);
|
||||
m_wl_egl_window_destroy(m_wl_window);
|
||||
m_wl_window = nullptr;
|
||||
}
|
||||
|
||||
m_wl_window =
|
||||
wl_egl_window_create(static_cast<wl_surface*>(m_wi.window_handle), m_wi.surface_width, m_wi.surface_height);
|
||||
m_wl_egl_window_create(static_cast<wl_surface*>(m_wi.window_handle), m_wi.surface_width, m_wi.surface_height);
|
||||
if (!m_wl_window)
|
||||
return {};
|
||||
|
||||
return reinterpret_cast<EGLNativeWindowType>(m_wl_window);
|
||||
}
|
||||
|
||||
bool ContextEGLWayland::LoadModule()
|
||||
{
|
||||
m_wl_module = dlopen(WAYLAND_EGL_MODNAME, RTLD_NOW | RTLD_GLOBAL);
|
||||
if (!m_wl_module)
|
||||
{
|
||||
Console.Error("Failed to load %s.", WAYLAND_EGL_MODNAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_wl_egl_window_create = reinterpret_cast<decltype(m_wl_egl_window_create)>(dlsym(m_wl_module, "wl_egl_window_create"));
|
||||
m_wl_egl_window_destroy = reinterpret_cast<decltype(m_wl_egl_window_destroy)>(dlsym(m_wl_module, "wl_egl_window_destroy"));
|
||||
m_wl_egl_window_resize = reinterpret_cast<decltype(m_wl_egl_window_resize)>(dlsym(m_wl_module, "wl_egl_window_resize"));
|
||||
if (!m_wl_egl_window_create || !m_wl_egl_window_destroy || !m_wl_egl_window_resize)
|
||||
{
|
||||
Console.Error("Failed to load one or more functions from %s.", WAYLAND_EGL_MODNAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace GL
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
#include "common/GL/ContextEGL.h"
|
||||
|
||||
#include <wayland-egl.h>
|
||||
struct wl_egl_window;
|
||||
struct wl_surface;
|
||||
|
||||
namespace GL
|
||||
{
|
||||
|
@ -37,7 +38,13 @@ namespace GL
|
|||
EGLNativeWindowType GetNativeWindow(EGLConfig config) override;
|
||||
|
||||
private:
|
||||
wl_egl_window* m_wl_window = nullptr;
|
||||
};
|
||||
bool LoadModule();
|
||||
|
||||
wl_egl_window* m_wl_window = nullptr;
|
||||
|
||||
void* m_wl_module = nullptr;
|
||||
wl_egl_window* (*m_wl_egl_window_create)(struct wl_surface* surface, int width, int height);
|
||||
void (*m_wl_egl_window_destroy)(struct wl_egl_window* egl_window);
|
||||
void (*m_wl_egl_window_resize)(struct wl_egl_window* egl_window, int width, int height, int dx, int dy);
|
||||
};
|
||||
} // namespace GL
|
||||
|
|
Loading…
Reference in New Issue