use egl to get wayland display

pull/1414/head
Etaash Mathamsetty 2 months ago committed by flightlessmango
parent e8817f8ba3
commit 606fa2794d

@ -10,9 +10,12 @@
#include "mesa/util/os_time.h"
#include "blacklist.h"
#include "gl_hud.h"
#include "wayland_hook.h"
using namespace MangoHud::GL;
#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
EXPORT_C_(void *) eglGetProcAddress(const char* procName);
static void* get_egl_proc_address(const char* name) {
@ -82,15 +85,61 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
return res;
}
EXPORT_C_(void*) eglGetPlatformDisplay( unsigned int platform, void* native_display, const intptr_t* attrib_list);
EXPORT_C_(void*) eglGetPlatformDisplay( unsigned int platform, void* native_display, const intptr_t* attrib_list)
{
static void* (*pfn_eglGetPlatformDisplay)(unsigned int, void*, const intptr_t*) = nullptr;
if (!pfn_eglGetPlatformDisplay)
pfn_eglGetPlatformDisplay = reinterpret_cast<decltype(pfn_eglGetPlatformDisplay)>(get_egl_proc_address("eglGetPlatformDisplay"));
if(platform == EGL_PLATFORM_WAYLAND_KHR)
{
wl_display_ptr = (struct wl_display*)native_display;
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
init_wayland_data();
}
return pfn_eglGetPlatformDisplay(platform, native_display, attrib_list);
}
EXPORT_C_(void*) eglGetDisplay( void* native_display );
EXPORT_C_(void*) eglGetDisplay( void* native_display )
{
static void* (*pfn_eglGetDisplay)(void*) = nullptr;
if (!pfn_eglGetDisplay)
pfn_eglGetDisplay = reinterpret_cast<decltype(pfn_eglGetDisplay)>(get_egl_proc_address("eglGetDisplay"));
try
{
void** display_ptr = (void**)native_display;
wl_interface* iface = (wl_interface*)*display_ptr;
if(strcmp(iface->name, wl_display_interface.name) == 0)
{
wl_display_ptr = (struct wl_display*)native_display;
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
init_wayland_data();
}
}
catch(const std::exception& e)
{
}
return pfn_eglGetDisplay(native_display);
}
struct func_ptr {
const char *name;
void *ptr;
};
static std::array<const func_ptr, 2> name_to_funcptr_map = {{
static std::array<const func_ptr, 4> name_to_funcptr_map = {{
#define ADD_HOOK(fn) { #fn, (void *) fn }
ADD_HOOK(eglGetProcAddress),
ADD_HOOK(eglSwapBuffers),
ADD_HOOK(eglGetPlatformDisplay),
ADD_HOOK(eglGetDisplay)
#undef ADD_HOOK
}};

@ -8,7 +8,5 @@
dlsym;
mangohud_find_glx_ptr;
mangohud_find_egl_ptr;
wl_display_connect;
wl_display_connect_to_fd;
local: *;
};

@ -156,7 +156,6 @@ if is_unixy
pre_args += '-DHAVE_WAYLAND'
vklayer_files += files(
'wayland_hook.cpp',
'wayland_keybinds.cpp'
)
endif

@ -1,66 +0,0 @@
#include <cstdint>
#include <array>
#include <dlfcn.h>
#include <cstdio>
#include "real_dlsym.h"
#include "wayland_hook.h"
#include "hud_elements.h"
EXPORT_C_(struct wl_display*) wl_display_connect(const char *name);
EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd);
typedef struct wl_display* (*pwl_display_connect)(const char *name);
typedef struct wl_display* (*pwl_display_connect_to_fd)(int fd);
pwl_display_connect wl_display_connect_ptr = nullptr;
pwl_display_connect_to_fd wl_display_connect_to_fd_ptr = nullptr;
void* wl_handle = nullptr;
struct wl_display* wl_display_ptr = nullptr;
EXPORT_C_(struct wl_display*) wl_display_connect(const char *name)
{
struct wl_display *ret = nullptr;
if (!wl_handle) {
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
}
if (wl_handle) {
wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect");
wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd");
ret = wl_display_connect_ptr(name);
if (!wl_display_ptr) {
wl_display_ptr = ret;
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
init_wayland_data();
}
}
return ret;
}
EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd)
{
struct wl_display *ret = nullptr;
if (!wl_handle) {
wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY);
}
if (wl_handle) {
wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd");
wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect");
ret = wl_display_connect_to_fd_ptr(fd);
if (!wl_display_ptr) {
wl_display_ptr = ret;
HUDElements.display_server = HUDElements.display_servers::WAYLAND;
init_wayland_data();
}
}
return ret;
}

@ -11,6 +11,8 @@
#include "timing.hpp"
#include "keybinds.h"
void* wl_handle;
struct wl_display* wl_display_ptr;
struct wl_seat* seat = nullptr;
struct wl_keyboard* keyboard = nullptr;
struct xkb_context *context_xkb = nullptr;

Loading…
Cancel
Save