mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 20:21:59 -05:00
* fix(fex): x86-64 programs on Wayland render on the GPU * fix(fex): address review on the Wayland and EGL thunks Keep the GLES overlay on the 64-bit EGL thunk only, filter EGL extensions whose entrypoints the guest lacks, accept EGLDeviceEXT displays, make the Wayland display check thread-safe, bound event signature copies, reject a second listener without freeing the first and guard wl_array_add growth. The FEX updater now removes thunk libraries a new build no longer ships, so an older 32-bit Wayland or EGL thunk cannot be enabled by the new config. * fix(fex): check every EGL extension entrypoint and every host device EGL_EXTENSIONS now hides an extension unless the guest exports all of its entrypoints, using a table built from the EGL registry. eglGetDisplay asks the host for its device count before matching EGLDeviceEXT handles. * fix(fex): pick the eglGetDisplay platform the way Mesa does A legacy eglGetDisplay handle now follows EGL_PLATFORM or EGL_DISPLAY first, then Wayland detection, and only then the X11 mapping, so device handles no longer depend on enumerating host devices.
983 lines
38 KiB
Diff
983 lines
38 KiB
Diff
diff --git a/Data/ThunksDB.json b/Data/ThunksDB.json
|
|
index 886379a..7844b27 100644
|
|
--- a/Data/ThunksDB.json
|
|
+++ b/Data/ThunksDB.json
|
|
@@ -49,6 +49,24 @@
|
|
"@PREFIX_LIB@/libwayland-client.so.0.20.0"
|
|
]
|
|
},
|
|
+ "EGL": {
|
|
+ "Library" : "libEGL-guest.so",
|
|
+ "Overlay": [
|
|
+ "@PREFIX_LIB@/libEGL.so",
|
|
+ "@PREFIX_LIB@/libEGL.so.1",
|
|
+ "@PREFIX_LIB@/libEGL.so.1.1.0",
|
|
+ "@PREFIX_LIB@/libGLESv2.so.2",
|
|
+ "@PREFIX_LIB@/libGLESv2.so.2.1.0"
|
|
+ ]
|
|
+ },
|
|
+ "WaylandEGL": {
|
|
+ "Library" : "libwayland-egl-guest.so",
|
|
+ "Overlay": [
|
|
+ "@PREFIX_LIB@/libwayland-egl.so",
|
|
+ "@PREFIX_LIB@/libwayland-egl.so.1",
|
|
+ "@PREFIX_LIB@/libwayland-egl.so.1.0.0"
|
|
+ ]
|
|
+ },
|
|
"cuda": {
|
|
"Library" : "libcuda-guest.so",
|
|
"Overlay": [
|
|
diff --git a/ThunkLibs/GuestLibs/CMakeLists.txt b/ThunkLibs/GuestLibs/CMakeLists.txt
|
|
index bf666d9..72b0832 100644
|
|
--- a/ThunkLibs/GuestLibs/CMakeLists.txt
|
|
+++ b/ThunkLibs/GuestLibs/CMakeLists.txt
|
|
@@ -211,6 +211,21 @@ if (BITNESS EQUAL 64)
|
|
target_include_directories_from_pkgconfig(libasound-guest-deps alsa)
|
|
add_guest_lib(asound "libasound.so.2")
|
|
|
|
+ generate(libwayland-client ${CMAKE_CURRENT_SOURCE_DIR}/../libwayland-client/libwayland-client_interface.cpp)
|
|
+ add_guest_lib(wayland-client "libwayland-client.so.0.20.0")
|
|
+ target_include_directories_from_pkgconfig(libwayland-client-guest-deps wayland-client /usr/include/wayland)
|
|
+
|
|
+ generate(libwayland-egl ${CMAKE_CURRENT_SOURCE_DIR}/../libwayland-egl/libwayland-egl_interface.cpp)
|
|
+ add_guest_lib(wayland-egl "libwayland-egl.so.1")
|
|
+ target_include_directories_from_pkgconfig(libwayland-egl-guest-deps wayland-egl /usr/include/wayland)
|
|
+
|
|
+ generate(libEGL ${CMAKE_CURRENT_SOURCE_DIR}/../libEGL/libEGL_interface.cpp)
|
|
+ target_include_directories_from_pkgconfig(libEGL-guest-deps egl)
|
|
+ add_guest_lib(EGL "libEGL.so.1")
|
|
+ target_link_libraries(EGL-guest PRIVATE GL-guest)
|
|
+ target_link_libraries(EGL-guest PRIVATE PlaceholderX11)
|
|
+ target_include_directories_from_pkgconfig(libEGL-guest-deps "xcb;x11")
|
|
+
|
|
# disabled for now, headers are platform specific
|
|
# find_package(SDL2 REQUIRED)
|
|
# generate(libSDL2)
|
|
@@ -229,10 +244,6 @@ if (BITNESS EQUAL 64)
|
|
add_guest_lib(drm "libdrm.so.2")
|
|
endif()
|
|
|
|
-generate(libwayland-client ${CMAKE_CURRENT_SOURCE_DIR}/../libwayland-client/libwayland-client_interface.cpp)
|
|
-add_guest_lib(wayland-client "libwayland-client.so.0.20.0")
|
|
-target_include_directories_from_pkgconfig(libwayland-client-guest-deps wayland-client /usr/include/wayland)
|
|
-
|
|
generate(libVDSO ${CMAKE_CURRENT_SOURCE_DIR}/../libVDSO/libVDSO_interface.cpp)
|
|
add_guest_lib(VDSO "linux-vdso.so.1")
|
|
# Can't use a stack protector because otherwise cross-compiling fails
|
|
@@ -271,11 +282,6 @@ target_include_directories_from_pkgconfig(libGL-guest-deps gl)
|
|
target_include_directories_from_pkgconfig(libGL-guest-deps "xcb;x11;xrandr;xrender")
|
|
add_guest_lib(GL "libGL.so.1")
|
|
|
|
-generate(libEGL ${CMAKE_CURRENT_SOURCE_DIR}/../libEGL/libEGL_interface.cpp)
|
|
-target_include_directories_from_pkgconfig(libEGL-guest-deps egl)
|
|
-add_guest_lib(EGL "libEGL.so.1")
|
|
-target_link_libraries(EGL-guest PRIVATE GL-guest)
|
|
-
|
|
# libGL must pull in libX11.so, so generate a placeholder libX11.so to link against
|
|
add_library(PlaceholderX11 SHARED ../libX11/libX11_NativeGuest.cpp)
|
|
target_link_options(PlaceholderX11 PRIVATE "LINKER:-soname,libX11.so.6")
|
|
diff --git a/ThunkLibs/HostLibs/CMakeLists.txt b/ThunkLibs/HostLibs/CMakeLists.txt
|
|
index 8d18d0e..c10066f 100644
|
|
--- a/ThunkLibs/HostLibs/CMakeLists.txt
|
|
+++ b/ThunkLibs/HostLibs/CMakeLists.txt
|
|
@@ -167,13 +167,19 @@ foreach(GUEST_BITNESS IN LISTS BITNESS_LIST)
|
|
target_include_directories_from_pkgconfig(libvulkan-${GUEST_BITNESS}-deps "xcb;x11;xrandr;xrender")
|
|
add_host_lib(vulkan ${GUEST_BITNESS})
|
|
|
|
- generate(libwayland-client ${CMAKE_CURRENT_SOURCE_DIR}/../libwayland-client/libwayland-client_interface.cpp ${GUEST_BITNESS})
|
|
- add_host_lib(wayland-client ${GUEST_BITNESS})
|
|
- target_include_directories_from_pkgconfig(libwayland-client-${GUEST_BITNESS}-deps wayland-client /usr/include/wayland)
|
|
-
|
|
- generate(libEGL ${CMAKE_CURRENT_SOURCE_DIR}/../libEGL/libEGL_interface.cpp ${GUEST_BITNESS})
|
|
- target_include_directories_from_pkgconfig(libEGL-${GUEST_BITNESS}-deps egl)
|
|
- add_host_lib(EGL ${GUEST_BITNESS})
|
|
+ if (GUEST_BITNESS EQUAL 64)
|
|
+ generate(libwayland-client ${CMAKE_CURRENT_SOURCE_DIR}/../libwayland-client/libwayland-client_interface.cpp ${GUEST_BITNESS})
|
|
+ add_host_lib(wayland-client ${GUEST_BITNESS})
|
|
+ target_include_directories_from_pkgconfig(libwayland-client-${GUEST_BITNESS}-deps wayland-client /usr/include/wayland)
|
|
+
|
|
+ generate(libwayland-egl ${CMAKE_CURRENT_SOURCE_DIR}/../libwayland-egl/libwayland-egl_interface.cpp ${GUEST_BITNESS})
|
|
+ add_host_lib(wayland-egl ${GUEST_BITNESS})
|
|
+ target_include_directories_from_pkgconfig(libwayland-egl-${GUEST_BITNESS}-deps wayland-egl /usr/include/wayland)
|
|
+
|
|
+ generate(libEGL ${CMAKE_CURRENT_SOURCE_DIR}/../libEGL/libEGL_interface.cpp ${GUEST_BITNESS})
|
|
+ target_include_directories_from_pkgconfig(libEGL-${GUEST_BITNESS}-deps "egl;xcb;x11")
|
|
+ add_host_lib(EGL ${GUEST_BITNESS})
|
|
+ endif()
|
|
|
|
generate(libGL ${CMAKE_CURRENT_SOURCE_DIR}/../libGL/libGL_interface.cpp ${GUEST_BITNESS})
|
|
target_include_directories_from_pkgconfig(libGL-${GUEST_BITNESS}-deps gl)
|
|
diff --git a/ThunkLibs/libEGL/libEGL_Guest.cpp b/ThunkLibs/libEGL/libEGL_Guest.cpp
|
|
index c157f00..196c7e8 100644
|
|
--- a/ThunkLibs/libEGL/libEGL_Guest.cpp
|
|
+++ b/ThunkLibs/libEGL/libEGL_Guest.cpp
|
|
@@ -5,11 +5,22 @@ desc: Depends on glXGetProcAddress thunk
|
|
$end_info$
|
|
*/
|
|
|
|
+#define EGL_EGLEXT_PROTOTYPES 1
|
|
#include <GL/glx.h>
|
|
#include <EGL/egl.h>
|
|
+#include <EGL/eglext.h>
|
|
+#include <X11/Xlib.h>
|
|
|
|
+#ifndef _GNU_SOURCE
|
|
+#define _GNU_SOURCE
|
|
+#endif
|
|
+#include <dlfcn.h>
|
|
#include <stdio.h>
|
|
#include <cstring>
|
|
+#include <mutex>
|
|
+#include <set>
|
|
+#include <string>
|
|
+#include <string_view>
|
|
|
|
#include "common/Guest.h"
|
|
|
|
@@ -17,12 +28,128 @@ $end_info$
|
|
|
|
typedef void voidFunc();
|
|
|
|
+static void* Self() {
|
|
+ static void* self = [] {
|
|
+ Dl_info info {};
|
|
+ return dladdr(reinterpret_cast<void*>(&Self), &info) && info.dli_fname ? dlopen(info.dli_fname, RTLD_LAZY | RTLD_NOLOAD) : nullptr;
|
|
+ }();
|
|
+ return self;
|
|
+}
|
|
+
|
|
+static constexpr std::pair<std::string_view, std::string_view> ExtensionEntrypoints[] = {
|
|
+ {"EGL_ANDROID_blob_cache", "eglSetBlobCacheFuncsANDROID"},
|
|
+ {"EGL_ANDROID_create_native_client_buffer", "eglCreateNativeClientBufferANDROID"},
|
|
+ {"EGL_ANDROID_get_frame_timestamps", "eglGetCompositorTimingSupportedANDROID eglGetCompositorTimingANDROID eglGetNextFrameIdANDROID eglGetFrameTimestampSupportedANDROID eglGetFrameTimestampsANDROID"},
|
|
+ {"EGL_ANDROID_get_native_client_buffer", "eglGetNativeClientBufferANDROID"},
|
|
+ {"EGL_ANDROID_native_fence_sync", "eglDupNativeFenceFDANDROID"},
|
|
+ {"EGL_ANDROID_presentation_time", "eglPresentationTimeANDROID"},
|
|
+ {"EGL_ANGLE_query_surface_pointer", "eglQuerySurfacePointerANGLE"},
|
|
+ {"EGL_ANGLE_sync_control_rate", "eglGetMscRateANGLE"},
|
|
+ {"EGL_EXT_client_sync", "eglClientSignalSyncEXT"},
|
|
+ {"EGL_EXT_compositor", "eglCompositorSetContextListEXT eglCompositorSetContextAttributesEXT eglCompositorSetWindowListEXT eglCompositorSetWindowAttributesEXT eglCompositorBindTexWindowEXT eglCompositorSetSizeEXT eglCompositorSwapPolicyEXT"},
|
|
+ {"EGL_EXT_device_base", "eglQueryDeviceAttribEXT eglQueryDeviceStringEXT eglQueryDevicesEXT eglQueryDisplayAttribEXT"},
|
|
+ {"EGL_EXT_device_enumeration", "eglQueryDevicesEXT"},
|
|
+ {"EGL_EXT_device_persistent_id", "eglQueryDeviceBinaryEXT"},
|
|
+ {"EGL_EXT_device_query", "eglQueryDeviceAttribEXT eglQueryDeviceStringEXT eglQueryDisplayAttribEXT"},
|
|
+ {"EGL_EXT_image_dma_buf_import_modifiers", "eglQueryDmaBufFormatsEXT eglQueryDmaBufModifiersEXT"},
|
|
+ {"EGL_EXT_output_base", "eglGetOutputLayersEXT eglGetOutputPortsEXT eglOutputLayerAttribEXT eglQueryOutputLayerAttribEXT eglQueryOutputLayerStringEXT eglOutputPortAttribEXT eglQueryOutputPortAttribEXT eglQueryOutputPortStringEXT"},
|
|
+ {"EGL_EXT_platform_base", "eglGetPlatformDisplayEXT eglCreatePlatformWindowSurfaceEXT eglCreatePlatformPixmapSurfaceEXT"},
|
|
+ {"EGL_EXT_stream_consumer_egloutput", "eglStreamConsumerOutputEXT"},
|
|
+ {"EGL_EXT_surface_compression", "eglQuerySupportedCompressionRatesEXT"},
|
|
+ {"EGL_EXT_swap_buffers_with_damage", "eglSwapBuffersWithDamageEXT"},
|
|
+ {"EGL_EXT_sync_reuse", "eglUnsignalSyncEXT"},
|
|
+ {"EGL_HI_clientpixmap", "eglCreatePixmapSurfaceHI"},
|
|
+ {"EGL_KHR_cl_event2", "eglCreateSync64KHR"},
|
|
+ {"EGL_KHR_debug", "eglDebugMessageControlKHR eglQueryDebugKHR eglLabelObjectKHR"},
|
|
+ {"EGL_KHR_display_reference", "eglQueryDisplayAttribKHR"},
|
|
+ {"EGL_KHR_fence_sync", "eglCreateSyncKHR eglDestroySyncKHR eglClientWaitSyncKHR eglGetSyncAttribKHR"},
|
|
+ {"EGL_KHR_image", "eglCreateImageKHR eglDestroyImageKHR"},
|
|
+ {"EGL_KHR_image_base", "eglCreateImageKHR eglDestroyImageKHR"},
|
|
+ {"EGL_KHR_lock_surface", "eglLockSurfaceKHR eglUnlockSurfaceKHR"},
|
|
+ {"EGL_KHR_lock_surface3", "eglLockSurfaceKHR eglUnlockSurfaceKHR eglQuerySurface64KHR"},
|
|
+ {"EGL_KHR_partial_update", "eglSetDamageRegionKHR"},
|
|
+ {"EGL_KHR_reusable_sync", "eglCreateSyncKHR eglDestroySyncKHR eglClientWaitSyncKHR eglSignalSyncKHR eglGetSyncAttribKHR"},
|
|
+ {"EGL_KHR_stream", "eglCreateStreamKHR eglDestroyStreamKHR eglStreamAttribKHR eglQueryStreamKHR eglQueryStreamu64KHR"},
|
|
+ {"EGL_KHR_stream_attrib", "eglCreateStreamAttribKHR eglSetStreamAttribKHR eglQueryStreamAttribKHR eglStreamConsumerAcquireAttribKHR eglStreamConsumerReleaseAttribKHR"},
|
|
+ {"EGL_KHR_stream_consumer_gltexture", "eglStreamConsumerGLTextureExternalKHR eglStreamConsumerAcquireKHR eglStreamConsumerReleaseKHR"},
|
|
+ {"EGL_KHR_stream_cross_process_fd", "eglGetStreamFileDescriptorKHR eglCreateStreamFromFileDescriptorKHR"},
|
|
+ {"EGL_KHR_stream_fifo", "eglQueryStreamTimeKHR"},
|
|
+ {"EGL_KHR_stream_producer_eglsurface", "eglCreateStreamProducerSurfaceKHR"},
|
|
+ {"EGL_KHR_swap_buffers_with_damage", "eglSwapBuffersWithDamageKHR"},
|
|
+ {"EGL_KHR_wait_sync", "eglWaitSyncKHR"},
|
|
+ {"EGL_MESA_drm_image", "eglCreateDRMImageMESA eglExportDRMImageMESA"},
|
|
+ {"EGL_MESA_image_dma_buf_export", "eglExportDMABUFImageQueryMESA eglExportDMABUFImageMESA"},
|
|
+ {"EGL_MESA_query_driver", "eglGetDisplayDriverConfig eglGetDisplayDriverName"},
|
|
+ {"EGL_NOK_swap_region", "eglSwapBuffersRegionNOK"},
|
|
+ {"EGL_NOK_swap_region2", "eglSwapBuffersRegion2NOK"},
|
|
+ {"EGL_NV_native_query", "eglQueryNativeDisplayNV eglQueryNativeWindowNV eglQueryNativePixmapNV"},
|
|
+ {"EGL_NV_post_sub_buffer", "eglPostSubBufferNV"},
|
|
+ {"EGL_NV_stream_consumer_eglimage", "eglStreamImageConsumerConnectNV eglQueryStreamConsumerEventNV eglStreamAcquireImageNV eglStreamReleaseImageNV"},
|
|
+ {"EGL_NV_stream_consumer_gltexture_yuv", "eglStreamConsumerGLTextureExternalAttribsNV"},
|
|
+ {"EGL_NV_stream_flush", "eglStreamFlushNV"},
|
|
+ {"EGL_NV_stream_metadata", "eglQueryDisplayAttribNV eglSetStreamMetadataNV eglQueryStreamMetadataNV"},
|
|
+ {"EGL_NV_stream_reset", "eglResetStreamNV"},
|
|
+ {"EGL_NV_stream_sync", "eglCreateStreamSyncNV"},
|
|
+ {"EGL_NV_sync", "eglCreateFenceSyncNV eglDestroySyncNV eglFenceNV eglClientWaitSyncNV eglSignalSyncNV eglGetSyncAttribNV"},
|
|
+ {"EGL_NV_system_time", "eglGetSystemTimeFrequencyNV eglGetSystemTimeNV"},
|
|
+ {"EGL_WL_bind_wayland_display", "eglBindWaylandDisplayWL eglUnbindWaylandDisplayWL eglQueryWaylandBufferWL"},
|
|
+ {"EGL_WL_create_wayland_buffer_from_image", "eglCreateWaylandBufferFromImageWL"},
|
|
+};
|
|
+
|
|
+static bool GuestHasEntrypoints(std::string_view extension) {
|
|
+ for (const auto& [name, entrypoints] : ExtensionEntrypoints) {
|
|
+ if (name != extension) {
|
|
+ continue;
|
|
+ }
|
|
+ std::string_view rest = entrypoints;
|
|
+ while (!rest.empty()) {
|
|
+ auto end = rest.find(' ');
|
|
+ if (!Self() || !dlsym(Self(), std::string {rest.substr(0, end)}.c_str())) {
|
|
+ return false;
|
|
+ }
|
|
+ rest = end == std::string_view::npos ? std::string_view {} : rest.substr(end + 1);
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
|
|
extern "C" {
|
|
voidFunc* eglGetProcAddress(const char* procname) {
|
|
- // TODO: Fix this HACK
|
|
+ if (strncmp(procname, "egl", 3) == 0) {
|
|
+ return Self() ? reinterpret_cast<voidFunc*>(dlsym(Self(), procname)) : nullptr;
|
|
+ }
|
|
return glXGetProcAddress((const GLubyte*)procname);
|
|
}
|
|
+
|
|
+const char* eglQueryString(EGLDisplay display, EGLint name) {
|
|
+ const char* result = fexfn_pack_eglQueryString(display, name);
|
|
+ if (!result || name != EGL_EXTENSIONS) {
|
|
+ return result;
|
|
+ }
|
|
+ std::string filtered;
|
|
+ std::string_view all {result};
|
|
+ while (!all.empty()) {
|
|
+ auto end = all.find(' ');
|
|
+ auto extension = all.substr(0, end);
|
|
+ if (!extension.empty() && GuestHasEntrypoints(extension)) {
|
|
+ if (!filtered.empty()) {
|
|
+ filtered += ' ';
|
|
+ }
|
|
+ filtered += extension;
|
|
+ }
|
|
+ all = end == std::string_view::npos ? std::string_view {} : all.substr(end + 1);
|
|
+ }
|
|
+ static std::mutex mutex;
|
|
+ static std::set<std::string> strings;
|
|
+ std::lock_guard lock(mutex);
|
|
+ return strings.insert(std::move(filtered)).first->c_str();
|
|
+}
|
|
+}
|
|
+
|
|
+static void OnInit() {
|
|
+ fexfn_pack_EGL_SetGuestXSync((uintptr_t)XSync, (uintptr_t)CallbackUnpack<decltype(XSync)>::Unpack);
|
|
+ fexfn_pack_EGL_SetGuestXDisplayString((uintptr_t)XDisplayString, (uintptr_t)CallbackUnpack<decltype(XDisplayString)>::Unpack);
|
|
}
|
|
|
|
-LOAD_LIB(libEGL)
|
|
+LOAD_LIB_INIT(libEGL, OnInit)
|
|
diff --git a/ThunkLibs/libEGL/libEGL_Host.cpp b/ThunkLibs/libEGL/libEGL_Host.cpp
|
|
index ac8a87e..9b154b8 100644
|
|
--- a/ThunkLibs/libEGL/libEGL_Host.cpp
|
|
+++ b/ThunkLibs/libEGL/libEGL_Host.cpp
|
|
@@ -4,14 +4,163 @@ tags: thunklibs|EGL
|
|
$end_info$
|
|
*/
|
|
|
|
+#include <atomic>
|
|
#include <cstdio>
|
|
+#include <cstdlib>
|
|
#include <dlfcn.h>
|
|
+#include <mutex>
|
|
+#include <string_view>
|
|
+#include <unordered_map>
|
|
|
|
+#define EGL_EGLEXT_PROTOTYPES 1
|
|
#include <EGL/egl.h>
|
|
+#include <EGL/eglext.h>
|
|
|
|
#include "common/Host.h"
|
|
-#include <dlfcn.h>
|
|
+#include <X11/Xutil.h>
|
|
+#include "common/X11Manager.h"
|
|
+
|
|
+static X11Manager x11_manager;
|
|
+static std::mutex x11_displays_mutex;
|
|
+static std::unordered_map<EGLDisplay, _XDisplay*> x11_displays;
|
|
+
|
|
+static void* fex_egl_get_proc_address(void* so, const char* name) {
|
|
+ static auto get_proc_address = reinterpret_cast<void* (*)(const char*)>(dlsym(so, "eglGetProcAddress"));
|
|
+ return get_proc_address ? get_proc_address(name) : nullptr;
|
|
+}
|
|
+
|
|
+static void fexfn_impl_libEGL_EGL_SetGuestXSync(uintptr_t GuestTarget, uintptr_t GuestUnpacker) {
|
|
+ MakeHostTrampolineForGuestFunctionAt(GuestTarget, GuestUnpacker, &x11_manager.GuestXSync);
|
|
+}
|
|
+
|
|
+static void fexfn_impl_libEGL_EGL_SetGuestXDisplayString(uintptr_t GuestTarget, uintptr_t GuestUnpacker) {
|
|
+ MakeHostTrampolineForGuestFunctionAt(GuestTarget, GuestUnpacker, &x11_manager.GuestXDisplayString);
|
|
+}
|
|
|
|
#include "thunkgen_host_libEGL.inl"
|
|
|
|
+static bool IsWaylandDisplay(void* native) {
|
|
+ static std::atomic<void*> cached_interface {nullptr};
|
|
+ void* wl_display_interface = cached_interface.load(std::memory_order_acquire);
|
|
+ if (!wl_display_interface) {
|
|
+ if (void* so = dlopen("libwayland-client.so.0", RTLD_LAZY | RTLD_NOLOAD)) {
|
|
+ wl_display_interface = dlsym(so, "wl_display_interface");
|
|
+ dlclose(so);
|
|
+ cached_interface.store(wl_display_interface, std::memory_order_release);
|
|
+ }
|
|
+ }
|
|
+ return wl_display_interface && *reinterpret_cast<void**>(native) == wl_display_interface;
|
|
+}
|
|
+
|
|
+static std::string_view EnvPlatform() {
|
|
+ const char* name = getenv("EGL_PLATFORM");
|
|
+ if (!name || !*name) {
|
|
+ name = getenv("EGL_DISPLAY");
|
|
+ }
|
|
+ return name ? std::string_view {name} : std::string_view {};
|
|
+}
|
|
+
|
|
+static void* HostNativeDisplay(EGLenum platform, void* native, _XDisplay** guest_x11) {
|
|
+ if (!native) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ switch (platform) {
|
|
+ case EGL_PLATFORM_X11_KHR: break;
|
|
+#ifdef EGL_PLATFORM_XCB_EXT
|
|
+ case EGL_PLATFORM_XCB_EXT: return x11_manager.GuestToHostConnection(static_cast<xcb_connection_t*>(native));
|
|
+#endif
|
|
+ case 0:
|
|
+ if (auto env = EnvPlatform(); !env.empty()) {
|
|
+ if (env == "xcb") {
|
|
+ return x11_manager.GuestToHostConnection(static_cast<xcb_connection_t*>(native));
|
|
+ }
|
|
+ if (env != "x11") {
|
|
+ return native;
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+ if (IsWaylandDisplay(native)) {
|
|
+ return native;
|
|
+ }
|
|
+ break;
|
|
+ default: return native;
|
|
+ }
|
|
+ *guest_x11 = static_cast<_XDisplay*>(native);
|
|
+ return x11_manager.GuestToHostDisplay(*guest_x11);
|
|
+}
|
|
+
|
|
+static EGLDisplay TrackDisplay(EGLDisplay display, _XDisplay* guest_x11) {
|
|
+ if (display != EGL_NO_DISPLAY && guest_x11) {
|
|
+ std::lock_guard lock(x11_displays_mutex);
|
|
+ x11_displays[display] = guest_x11;
|
|
+ }
|
|
+ return display;
|
|
+}
|
|
+
|
|
+static void SyncGuestDisplay(EGLDisplay display) {
|
|
+ _XDisplay* guest_x11 = nullptr;
|
|
+ {
|
|
+ std::lock_guard lock(x11_displays_mutex);
|
|
+ if (auto it = x11_displays.find(display); it != x11_displays.end()) {
|
|
+ guest_x11 = it->second;
|
|
+ }
|
|
+ }
|
|
+ if (guest_x11) {
|
|
+ x11_manager.GuestXSync(guest_x11, 0);
|
|
+ }
|
|
+}
|
|
+
|
|
+EGLDisplay fexfn_impl_libEGL_eglGetDisplay(guest_layout<EGLNativeDisplayType> native) {
|
|
+ _XDisplay* guest_x11 = nullptr;
|
|
+ auto host = HostNativeDisplay(0, native.force_get_host_pointer(), &guest_x11);
|
|
+ return TrackDisplay(fexldr_ptr_libEGL_eglGetDisplay(static_cast<EGLNativeDisplayType>(host)), guest_x11);
|
|
+}
|
|
+
|
|
+EGLDisplay fexfn_impl_libEGL_eglGetPlatformDisplay(EGLenum platform, void* native, const EGLAttrib* attribs) {
|
|
+ _XDisplay* guest_x11 = nullptr;
|
|
+ auto host = HostNativeDisplay(platform, native, &guest_x11);
|
|
+ return TrackDisplay(fexldr_ptr_libEGL_eglGetPlatformDisplay(platform, host, attribs), guest_x11);
|
|
+}
|
|
+
|
|
+EGLDisplay fexfn_impl_libEGL_eglGetPlatformDisplayEXT(EGLenum platform, void* native, const EGLint* attribs) {
|
|
+ _XDisplay* guest_x11 = nullptr;
|
|
+ auto host = HostNativeDisplay(platform, native, &guest_x11);
|
|
+ return TrackDisplay(fexldr_ptr_libEGL_eglGetPlatformDisplayEXT(platform, host, attribs), guest_x11);
|
|
+}
|
|
+
|
|
+EGLSurface fexfn_impl_libEGL_eglCreateWindowSurface(EGLDisplay display, EGLConfig config, EGLNativeWindowType window, const EGLint* attribs) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCreateWindowSurface(display, config, window, attribs);
|
|
+}
|
|
+
|
|
+EGLSurface fexfn_impl_libEGL_eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* attribs) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCreatePixmapSurface(display, config, pixmap, attribs);
|
|
+}
|
|
+
|
|
+EGLSurface fexfn_impl_libEGL_eglCreatePlatformWindowSurface(EGLDisplay display, EGLConfig config, void* window, const EGLAttrib* attribs) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCreatePlatformWindowSurface(display, config, window, attribs);
|
|
+}
|
|
+
|
|
+EGLSurface fexfn_impl_libEGL_eglCreatePlatformPixmapSurface(EGLDisplay display, EGLConfig config, void* pixmap, const EGLAttrib* attribs) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCreatePlatformPixmapSurface(display, config, pixmap, attribs);
|
|
+}
|
|
+
|
|
+EGLSurface fexfn_impl_libEGL_eglCreatePlatformWindowSurfaceEXT(EGLDisplay display, EGLConfig config, void* window, const EGLint* attribs) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCreatePlatformWindowSurfaceEXT(display, config, window, attribs);
|
|
+}
|
|
+
|
|
+EGLSurface fexfn_impl_libEGL_eglCreatePlatformPixmapSurfaceEXT(EGLDisplay display, EGLConfig config, void* pixmap, const EGLint* attribs) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCreatePlatformPixmapSurfaceEXT(display, config, pixmap, attribs);
|
|
+}
|
|
+
|
|
+EGLBoolean fexfn_impl_libEGL_eglCopyBuffers(EGLDisplay display, EGLSurface surface, EGLNativePixmapType pixmap) {
|
|
+ SyncGuestDisplay(display);
|
|
+ return fexldr_ptr_libEGL_eglCopyBuffers(display, surface, pixmap);
|
|
+}
|
|
+
|
|
EXPORTS(libEGL)
|
|
diff --git a/ThunkLibs/libEGL/libEGL_interface.cpp b/ThunkLibs/libEGL/libEGL_interface.cpp
|
|
index 27de16d..19f8b86 100644
|
|
--- a/ThunkLibs/libEGL/libEGL_interface.cpp
|
|
+++ b/ThunkLibs/libEGL/libEGL_interface.cpp
|
|
@@ -1,51 +1,170 @@
|
|
#include <common/GeneratorInterface.h>
|
|
|
|
+#define EGL_EGLEXT_PROTOTYPES 1
|
|
#include <EGL/egl.h>
|
|
+#include <EGL/eglext.h>
|
|
+#include <X11/Xlib.h>
|
|
|
|
template<auto>
|
|
struct fex_gen_config {
|
|
unsigned version = 1;
|
|
};
|
|
|
|
-// Function, parameter index, parameter type [optional]
|
|
template<auto, int, typename = void>
|
|
struct fex_gen_param {};
|
|
|
|
+template<typename>
|
|
+struct fex_gen_type {};
|
|
+
|
|
+template<>
|
|
+struct fex_gen_type<void> : fexgen::opaque_type {};
|
|
+template<>
|
|
+struct fex_gen_type<_XDisplay> : fexgen::opaque_type {};
|
|
+
|
|
+void EGL_SetGuestXSync(uintptr_t, uintptr_t);
|
|
+void EGL_SetGuestXDisplayString(uintptr_t, uintptr_t);
|
|
+template<>
|
|
+struct fex_gen_config<EGL_SetGuestXSync> : fexgen::custom_guest_entrypoint, fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<EGL_SetGuestXDisplayString> : fexgen::custom_guest_entrypoint, fexgen::custom_host_impl {};
|
|
+
|
|
template<>
|
|
struct fex_gen_config<eglBindAPI> {};
|
|
template<>
|
|
+struct fex_gen_config<eglBindTexImage> {};
|
|
+template<>
|
|
struct fex_gen_config<eglChooseConfig> {};
|
|
template<>
|
|
+struct fex_gen_config<eglClientWaitSync> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreateContext> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreateImage> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreatePbufferFromClientBuffer> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreatePbufferSurface> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreateSync> {};
|
|
+template<>
|
|
struct fex_gen_config<eglDestroyContext> {};
|
|
template<>
|
|
+struct fex_gen_config<eglDestroyImage> {};
|
|
+template<>
|
|
struct fex_gen_config<eglDestroySurface> {};
|
|
template<>
|
|
+struct fex_gen_config<eglDestroySync> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetConfigAttrib> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetConfigs> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetCurrentContext> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetCurrentDisplay> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetCurrentSurface> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetError> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetSyncAttrib> {};
|
|
+template<>
|
|
struct fex_gen_config<eglInitialize> {};
|
|
template<>
|
|
struct fex_gen_config<eglMakeCurrent> {};
|
|
template<>
|
|
+struct fex_gen_config<eglQueryAPI> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryContext> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryString> : fexgen::custom_guest_entrypoint {};
|
|
+template<>
|
|
struct fex_gen_config<eglQuerySurface> {};
|
|
template<>
|
|
+struct fex_gen_config<eglReleaseTexImage> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglReleaseThread> {};
|
|
+template<>
|
|
struct fex_gen_config<eglSurfaceAttrib> {};
|
|
template<>
|
|
struct fex_gen_config<eglSwapBuffers> {};
|
|
template<>
|
|
+struct fex_gen_config<eglSwapInterval> {};
|
|
+template<>
|
|
struct fex_gen_config<eglTerminate> {};
|
|
template<>
|
|
-struct fex_gen_config<eglGetError> {};
|
|
+struct fex_gen_config<eglWaitClient> {};
|
|
template<>
|
|
-struct fex_gen_config<eglCreateContext> {};
|
|
+struct fex_gen_config<eglWaitGL> {};
|
|
template<>
|
|
-struct fex_gen_config<eglCreateWindowSurface> {};
|
|
+struct fex_gen_config<eglWaitNative> {};
|
|
template<>
|
|
-struct fex_gen_config<eglGetCurrentContext> {};
|
|
+struct fex_gen_config<eglWaitSync> {};
|
|
template<>
|
|
-struct fex_gen_config<eglGetCurrentDisplay> {};
|
|
+struct fex_gen_config<eglGetDisplay> : fexgen::custom_host_impl {};
|
|
template<>
|
|
-struct fex_gen_config<eglGetCurrentSurface> {};
|
|
+struct fex_gen_config<eglGetPlatformDisplay> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreateWindowSurface> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreatePixmapSurface> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreatePlatformWindowSurface> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreatePlatformPixmapSurface> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCopyBuffers> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_param<eglGetDisplay, 0, EGLNativeDisplayType> : fexgen::ptr_passthrough {};
|
|
+
|
|
+namespace ext {
|
|
+template<auto>
|
|
+struct fex_gen_config {
|
|
+ const char* load_host_endpoint_via = "fex_egl_get_proc_address";
|
|
+};
|
|
|
|
-// EGLNativeDisplayType is a pointer to opaque data (wl_display/(X)Display/...)
|
|
template<>
|
|
-struct fex_gen_config<eglGetDisplay> {};
|
|
+struct fex_gen_config<eglSwapBuffersWithDamageKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglSwapBuffersWithDamageEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglSetDamageRegionKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreateImageKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglDestroyImageKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreateSyncKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglDestroySyncKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglClientWaitSyncKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetSyncAttribKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglWaitSyncKHR> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglDupNativeFenceFDANDROID> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryDmaBufFormatsEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryDmaBufModifiersEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglExportDMABUFImageMESA> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglExportDMABUFImageQueryMESA> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryDisplayAttribEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryDeviceStringEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryDeviceAttribEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglQueryDevicesEXT> {};
|
|
+template<>
|
|
+struct fex_gen_config<eglGetPlatformDisplayEXT> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_config<eglCreatePlatformWindowSurfaceEXT> : fexgen::custom_host_impl {};
|
|
template<>
|
|
-struct fex_gen_param<eglGetDisplay, 0, EGLNativeDisplayType> : fexgen::assume_compatible_data_layout {};
|
|
+struct fex_gen_config<eglCreatePlatformPixmapSurfaceEXT> : fexgen::custom_host_impl {};
|
|
+}
|
|
diff --git a/ThunkLibs/libwayland-client/Guest.cpp b/ThunkLibs/libwayland-client/Guest.cpp
|
|
index 2f887a6..8fa6476 100644
|
|
--- a/ThunkLibs/libwayland-client/Guest.cpp
|
|
+++ b/ThunkLibs/libwayland-client/Guest.cpp
|
|
@@ -42,8 +42,11 @@ extern "C" const wl_interface wl_subsurface_interface {};
|
|
#include <charconv>
|
|
#include <cstdio>
|
|
#include <cstdarg>
|
|
+#include <cstdint>
|
|
+#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
+#include <utility>
|
|
|
|
#include "common/Guest.h"
|
|
|
|
@@ -92,18 +95,39 @@ static uint64_t WaylandAllocateHostTrampolineForGuestListener(void (*callback)()
|
|
}
|
|
|
|
#define WL_CLOSURE_MAX_ARGS 20
|
|
+#define WAYLAND_UNIFORM_MAX_ARGS 17
|
|
+
|
|
+template<std::size_t... I>
|
|
+static uint64_t WaylandAllocateUniformHostTrampoline(void (*callback)(), std::index_sequence<I...>) {
|
|
+ using cb = void(void*, wl_proxy*, std::conditional_t<true, uintptr_t, std::integral_constant<std::size_t, I>>...);
|
|
+ return (uint64_t)(uintptr_t)(void*)AllocateHostTrampolineForGuestFunction((cb*)callback);
|
|
+}
|
|
+
|
|
+template<std::size_t... Counts>
|
|
+static uint64_t WaylandAllocateUniformHostTrampoline(void (*callback)(), std::size_t count, std::index_sequence<Counts...>) {
|
|
+ using allocator = uint64_t (*)(void (*)());
|
|
+ static constexpr allocator allocators[] = {
|
|
+ [](void (*cb)()) { return WaylandAllocateUniformHostTrampoline(cb, std::make_index_sequence<Counts> {}); }...};
|
|
+ return allocators[count](callback);
|
|
+}
|
|
|
|
extern "C" int wl_proxy_add_listener(wl_proxy* proxy, void (**callback)(void), void* data) {
|
|
// Replace guest-provided callback table with host-callable function pointers
|
|
// NOTE: A reference to this table is stored in the wl_proxy, so the data
|
|
// must remain valid until the proxy is destroyed (or another listener
|
|
// is added)
|
|
- delete[] (uint64_t*)wl_proxy_get_listener(proxy); // Delete previous substitute, if any
|
|
- auto host_callbacks = new uint64_t[WL_CLOSURE_MAX_ARGS];
|
|
+ if (wl_proxy_get_listener(proxy)) {
|
|
+ fprintf(stderr, "proxy %p already has listener\n", proxy);
|
|
+ return -1;
|
|
+ }
|
|
+ auto host_callbacks = new uint64_t[std::max(fex_wl_get_interface_event_count(proxy), WL_CLOSURE_MAX_ARGS)];
|
|
|
|
for (int i = 0; i < fex_wl_get_interface_event_count(proxy); ++i) {
|
|
- char event_signature[16];
|
|
- fex_wl_get_interface_event_signature(proxy, i, event_signature);
|
|
+ char event_signature[64];
|
|
+ if (fex_wl_get_interface_event_signature(proxy, i, event_signature, sizeof(event_signature)) >= sizeof(event_signature)) {
|
|
+ fprintf(stderr, "TODO: Unknown wayland event signature descriptor %s\n", event_signature);
|
|
+ std::abort();
|
|
+ }
|
|
auto signature2 = std::string_view {event_signature};
|
|
|
|
// A leading number indicates the minimum protocol version
|
|
@@ -227,13 +251,19 @@ extern "C" int wl_proxy_add_listener(wl_proxy* proxy, void (**callback)(void), v
|
|
} else if (signature == "sii") {
|
|
// E.g. zwp_text_input_v3::preedit_string
|
|
host_callbacks[i] = WaylandAllocateHostTrampolineForGuestListener<'s', 'i', 'i'>(callback[i]);
|
|
+ } else if (signature.size() <= WAYLAND_UNIFORM_MAX_ARGS) {
|
|
+ host_callbacks[i] = WaylandAllocateUniformHostTrampoline(callback[i], signature.size(), std::make_index_sequence<WAYLAND_UNIFORM_MAX_ARGS + 1> {});
|
|
} else {
|
|
fprintf(stderr, "TODO: Unknown wayland event signature descriptor %s\n", signature.data());
|
|
std::abort();
|
|
}
|
|
}
|
|
|
|
- return fexfn_pack_wl_proxy_add_listener(proxy, (void (**)())host_callbacks, data);
|
|
+ int result = fexfn_pack_wl_proxy_add_listener(proxy, (void (**)())host_callbacks, data);
|
|
+ if (result != 0) {
|
|
+ delete[] host_callbacks;
|
|
+ }
|
|
+ return result;
|
|
}
|
|
|
|
extern "C" void wl_proxy_destroy(wl_proxy* proxy) {
|
|
@@ -353,6 +383,92 @@ extern "C" void wl_log_set_handler_client(wl_log_func_t handler) {
|
|
// Ignore
|
|
}
|
|
|
|
+extern "C" void wl_list_init(wl_list* list) {
|
|
+ list->prev = list;
|
|
+ list->next = list;
|
|
+}
|
|
+
|
|
+extern "C" void wl_list_insert(wl_list* list, wl_list* elm) {
|
|
+ elm->prev = list;
|
|
+ elm->next = list->next;
|
|
+ list->next = elm;
|
|
+ elm->next->prev = elm;
|
|
+}
|
|
+
|
|
+extern "C" void wl_list_remove(wl_list* elm) {
|
|
+ elm->prev->next = elm->next;
|
|
+ elm->next->prev = elm->prev;
|
|
+ elm->next = nullptr;
|
|
+ elm->prev = nullptr;
|
|
+}
|
|
+
|
|
+extern "C" int wl_list_length(const wl_list* list) {
|
|
+ int count = 0;
|
|
+ for (auto e = list->next; e != list; e = e->next) {
|
|
+ ++count;
|
|
+ }
|
|
+ return count;
|
|
+}
|
|
+
|
|
+extern "C" int wl_list_empty(const wl_list* list) {
|
|
+ return list->next == list;
|
|
+}
|
|
+
|
|
+extern "C" void wl_list_insert_list(wl_list* list, wl_list* other) {
|
|
+ if (wl_list_empty(other)) {
|
|
+ return;
|
|
+ }
|
|
+ other->next->prev = list;
|
|
+ other->prev->next = list->next;
|
|
+ list->next->prev = other->prev;
|
|
+ list->next = other->next;
|
|
+}
|
|
+
|
|
+extern "C" void wl_array_init(wl_array* array) {
|
|
+ memset(array, 0, sizeof(*array));
|
|
+}
|
|
+
|
|
+extern "C" void wl_array_release(wl_array* array) {
|
|
+ free(array->data);
|
|
+ array->data = (void*)4;
|
|
+}
|
|
+
|
|
+extern "C" void* wl_array_add(wl_array* array, size_t size) {
|
|
+ if (size > SIZE_MAX - array->size) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ size_t needed = array->size + size;
|
|
+ size_t alloc = array->alloc > 0 ? array->alloc : 16;
|
|
+ while (alloc < needed) {
|
|
+ alloc = alloc > SIZE_MAX / 2 ? needed : alloc * 2;
|
|
+ }
|
|
+ if (array->alloc < alloc) {
|
|
+ void* data = array->alloc > 0 ? realloc(array->data, alloc) : malloc(alloc);
|
|
+ if (!data) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ array->data = data;
|
|
+ array->alloc = alloc;
|
|
+ }
|
|
+ void* p = (char*)array->data + array->size;
|
|
+ array->size += size;
|
|
+ return p;
|
|
+}
|
|
+
|
|
+extern "C" int wl_array_copy(wl_array* array, wl_array* source) {
|
|
+ if (array->size < source->size) {
|
|
+ if (!wl_array_add(array, source->size - array->size)) {
|
|
+ return -1;
|
|
+ }
|
|
+ } else {
|
|
+ array->size = source->size;
|
|
+ }
|
|
+ if (source->size > 0) {
|
|
+ memcpy(array->data, source->data, source->size);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
|
|
void OnInit() {
|
|
fex_wl_exchange_interface_pointer(const_cast<wl_interface*>(&wl_output_interface), "wl_output_interface");
|
|
diff --git a/ThunkLibs/libwayland-client/Host.cpp b/ThunkLibs/libwayland-client/Host.cpp
|
|
index 68c2ded..25f964c 100644
|
|
--- a/ThunkLibs/libwayland-client/Host.cpp
|
|
+++ b/ThunkLibs/libwayland-client/Host.cpp
|
|
@@ -22,6 +22,7 @@ $end_info$
|
|
#include <map>
|
|
#include <span>
|
|
#include <string>
|
|
+#include <utility>
|
|
|
|
#include <ranges>
|
|
|
|
@@ -166,6 +167,7 @@ static wl_proxy* fexfn_impl_libwayland_client_wl_proxy_create(wl_proxy* proxy, g
|
|
}
|
|
|
|
#define WL_CLOSURE_MAX_ARGS 20
|
|
+#define WAYLAND_UNIFORM_MAX_ARGS 17
|
|
static auto fex_wl_remap_argument_list(guest_layout<wl_argument*> args, const wl_message& message) {
|
|
#ifndef IS_32BIT_THUNK
|
|
// Cast to host layout and return as std::span
|
|
@@ -309,6 +311,21 @@ static void WaylandFinalizeHostTrampolineForGuestListener(void (*callback)()) {
|
|
FinalizeHostTrampolineForGuestFunction((cb*)callback);
|
|
}
|
|
|
|
+
|
|
+template<std::size_t... I>
|
|
+static void WaylandFinalizeUniformHostTrampoline(void (*callback)(), std::index_sequence<I...>) {
|
|
+ using cb = void(void*, wl_proxy*, std::conditional_t<true, uint64_t, std::integral_constant<std::size_t, I>>...);
|
|
+ FinalizeHostTrampolineForGuestFunction((cb*)callback);
|
|
+}
|
|
+
|
|
+template<std::size_t... Counts>
|
|
+static void WaylandFinalizeUniformHostTrampoline(void (*callback)(), std::size_t count, std::index_sequence<Counts...>) {
|
|
+ using finalizer = void (*)(void (*)());
|
|
+ static constexpr finalizer finalizers[] = {
|
|
+ [](void (*cb)()) { WaylandFinalizeUniformHostTrampoline(cb, std::make_index_sequence<Counts> {}); }...};
|
|
+ finalizers[count](callback);
|
|
+}
|
|
+
|
|
extern "C" int
|
|
fexfn_impl_libwayland_client_wl_proxy_add_listener(struct wl_proxy* proxy, guest_layout<void (**)(void)> callback_table_raw, void* data) {
|
|
auto interface = get_proxy_interface(proxy);
|
|
@@ -446,6 +463,8 @@ fexfn_impl_libwayland_client_wl_proxy_add_listener(struct wl_proxy* proxy, guest
|
|
WaylandFinalizeHostTrampolineForGuestListener<'s', 'i', 'i'>(callback);
|
|
} else if (signature == "ss") {
|
|
WaylandFinalizeHostTrampolineForGuestListener<'s', 's'>(callback);
|
|
+ } else if (signature.size() <= WAYLAND_UNIFORM_MAX_ARGS) {
|
|
+ WaylandFinalizeUniformHostTrampoline(callback, signature.size(), std::make_index_sequence<WAYLAND_UNIFORM_MAX_ARGS + 1> {});
|
|
} else {
|
|
fprintf(stderr, "TODO: Unknown wayland event signature descriptor %s\n", signature.data());
|
|
std::abort();
|
|
@@ -514,8 +533,35 @@ void fexfn_impl_libwayland_client_fex_wl_get_interface_event_name(wl_proxy* prox
|
|
strcpy(out, get_proxy_interface(proxy)->events[i].name);
|
|
}
|
|
|
|
-void fexfn_impl_libwayland_client_fex_wl_get_interface_event_signature(wl_proxy* proxy, int i, char* out) {
|
|
- strcpy(out, get_proxy_interface(proxy)->events[i].signature);
|
|
+size_t fexfn_impl_libwayland_client_fex_wl_get_interface_event_signature(wl_proxy* proxy, int i, char* out, size_t size) {
|
|
+ const char* signature = get_proxy_interface(proxy)->events[i].signature;
|
|
+ size_t length = strlen(signature);
|
|
+ if (size > 0) {
|
|
+ size_t copied = std::min(length, size - 1);
|
|
+ memcpy(out, signature, copied);
|
|
+ out[copied] = '\0';
|
|
+ }
|
|
+ return length;
|
|
+}
|
|
+
|
|
+uint32_t fexfn_impl_libwayland_client_wl_display_get_protocol_error(wl_display* display, guest_layout<const wl_interface**> guest_interface,
|
|
+ uint32_t* id) {
|
|
+ const wl_interface* host_interface = nullptr;
|
|
+ auto code = fexldr_ptr_libwayland_client_wl_display_get_protocol_error(display, &host_interface, id);
|
|
+ if (!guest_interface.force_get_host_pointer()) {
|
|
+ return code;
|
|
+ }
|
|
+ uintptr_t result = 0;
|
|
+ for (auto& [guest, host] : guest_to_host_interface) {
|
|
+ if (host == host_interface) {
|
|
+ result = reinterpret_cast<uintptr_t>(guest);
|
|
+ }
|
|
+ }
|
|
+ if (!result) {
|
|
+ result = reinterpret_cast<uintptr_t>(host_interface);
|
|
+ }
|
|
+ guest_interface.get_pointer()->data = result;
|
|
+ return code;
|
|
}
|
|
|
|
EXPORTS(libwayland_client)
|
|
diff --git a/ThunkLibs/libwayland-client/libwayland-client_interface.cpp b/ThunkLibs/libwayland-client/libwayland-client_interface.cpp
|
|
index 575d2e1..9723a3c 100644
|
|
--- a/ThunkLibs/libwayland-client/libwayland-client_interface.cpp
|
|
+++ b/ThunkLibs/libwayland-client/libwayland-client_interface.cpp
|
|
@@ -83,6 +83,16 @@ struct fex_gen_config<wl_display_get_fd> {};
|
|
|
|
template<>
|
|
struct fex_gen_config<wl_event_queue_destroy> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_event_queue_get_name> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_display_create_queue_with_name> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_display_set_max_buffer_size> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_display_get_protocol_error> : fexgen::custom_host_impl {};
|
|
+template<>
|
|
+struct fex_gen_param<wl_display_get_protocol_error, 1, const wl_interface**> : fexgen::ptr_passthrough {};
|
|
|
|
template<>
|
|
struct fex_gen_config<wl_proxy_add_listener> : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint {};
|
|
@@ -101,6 +111,10 @@ struct fex_gen_config<wl_proxy_create_wrapper> {};
|
|
template<>
|
|
struct fex_gen_config<wl_proxy_get_class> {};
|
|
template<>
|
|
+struct fex_gen_config<wl_proxy_get_display> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_proxy_get_queue> {};
|
|
+template<>
|
|
struct fex_gen_config<wl_proxy_get_id> {};
|
|
template<>
|
|
struct fex_gen_config<wl_proxy_get_listener> {};
|
|
@@ -164,6 +178,6 @@ struct fex_gen_config<fex_wl_get_interface_event_count> : fexgen::custom_host_im
|
|
void fex_wl_get_interface_event_name(wl_proxy*, int, char*);
|
|
template<>
|
|
struct fex_gen_config<fex_wl_get_interface_event_name> : fexgen::custom_host_impl {};
|
|
-void fex_wl_get_interface_event_signature(wl_proxy*, int, char*);
|
|
+size_t fex_wl_get_interface_event_signature(wl_proxy*, int, char*, size_t);
|
|
template<>
|
|
struct fex_gen_config<fex_wl_get_interface_event_signature> : fexgen::custom_host_impl {};
|
|
diff --git a/ThunkLibs/libwayland-egl/Guest.cpp b/ThunkLibs/libwayland-egl/Guest.cpp
|
|
new file mode 100644
|
|
index 0000000..300a8fc
|
|
--- /dev/null
|
|
+++ b/ThunkLibs/libwayland-egl/Guest.cpp
|
|
@@ -0,0 +1,7 @@
|
|
+#include <wayland-egl.h>
|
|
+
|
|
+#include "common/Guest.h"
|
|
+
|
|
+#include "thunkgen_guest_libwayland-egl.inl"
|
|
+
|
|
+LOAD_LIB(libwayland-egl)
|
|
diff --git a/ThunkLibs/libwayland-egl/Host.cpp b/ThunkLibs/libwayland-egl/Host.cpp
|
|
new file mode 100644
|
|
index 0000000..81ad83b
|
|
--- /dev/null
|
|
+++ b/ThunkLibs/libwayland-egl/Host.cpp
|
|
@@ -0,0 +1,8 @@
|
|
+#include <wayland-egl.h>
|
|
+
|
|
+#include "common/Host.h"
|
|
+#include <dlfcn.h>
|
|
+
|
|
+#include "thunkgen_host_libwayland-egl.inl"
|
|
+
|
|
+EXPORTS(libwayland_egl)
|
|
diff --git a/ThunkLibs/libwayland-egl/libwayland-egl_interface.cpp b/ThunkLibs/libwayland-egl/libwayland-egl_interface.cpp
|
|
new file mode 100644
|
|
index 0000000..bc5d743
|
|
--- /dev/null
|
|
+++ b/ThunkLibs/libwayland-egl/libwayland-egl_interface.cpp
|
|
@@ -0,0 +1,25 @@
|
|
+#include <common/GeneratorInterface.h>
|
|
+
|
|
+#include <wayland-egl.h>
|
|
+
|
|
+template<auto>
|
|
+struct fex_gen_config {
|
|
+ unsigned version = 1;
|
|
+};
|
|
+
|
|
+template<typename>
|
|
+struct fex_gen_type {};
|
|
+
|
|
+template<>
|
|
+struct fex_gen_type<wl_egl_window> : fexgen::opaque_type {};
|
|
+template<>
|
|
+struct fex_gen_type<wl_surface> : fexgen::opaque_type {};
|
|
+
|
|
+template<>
|
|
+struct fex_gen_config<wl_egl_window_create> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_egl_window_destroy> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_egl_window_resize> {};
|
|
+template<>
|
|
+struct fex_gen_config<wl_egl_window_get_attached_size> {};
|