mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00: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.
152 lines
6.9 KiB
Python
152 lines
6.9 KiB
Python
import re
|
|
import runpy
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
PATCH = REPO / "tools/fex/patches/0019-wayland-and-egl-thunks-for-64-bit-guests.patch"
|
|
LAUNCHER = REPO / "tools/linuxfs/overlay/usr/local/bin/droiddeck-fex"
|
|
THUNKS = {"WaylandClient": "wayland-client", "EGL": "EGL", "WaylandEGL": "wayland-egl"}
|
|
|
|
|
|
def blocks():
|
|
return {re.match(r"a/(\S+) ", block).group(1): block
|
|
for block in re.split(r"^diff --git ", PATCH.read_text(), flags=re.M)[1:]}
|
|
|
|
|
|
def files():
|
|
return {name: [line[1:] for line in block.splitlines() if line.startswith("+") and not line.startswith("+++")]
|
|
for name, block in blocks().items()}
|
|
|
|
|
|
def built_libs(block):
|
|
out, base, stack = set(), False, []
|
|
for line in block.splitlines():
|
|
if line.startswith("@@"):
|
|
base, stack = "BITNESS EQUAL 64" in line, []
|
|
continue
|
|
if line[:1] == "-":
|
|
continue
|
|
text = line[1:].strip()
|
|
if text.startswith("if ("):
|
|
stack.append("gate" if "BITNESS EQUAL 64" in text else "other")
|
|
elif text.startswith("else"):
|
|
if stack:
|
|
stack[-1] = {"gate": "inverted", "inverted": "gate"}.get(stack[-1], stack[-1])
|
|
else:
|
|
base = False
|
|
elif text == "endif()":
|
|
if stack:
|
|
stack.pop()
|
|
else:
|
|
base = False
|
|
found = re.match(r"add_(?:guest|host)_lib\(([\w-]+)", text)
|
|
if found and line[:1] == "+":
|
|
out.add((found.group(1), "inverted" not in stack and (base or "gate" in stack)))
|
|
return out
|
|
|
|
|
|
def database():
|
|
entries, name = {}, None
|
|
for line in blocks()["Data/ThunksDB.json"].splitlines():
|
|
if line[:1] == "-":
|
|
continue
|
|
found = re.match(r'[ +]\s*"(\w+)": \{', line)
|
|
if found:
|
|
name = found.group(1)
|
|
found = re.search(r'"Library" : "([^"]+)"', line)
|
|
if found and name:
|
|
entries[name] = found.group(1)
|
|
return entries
|
|
|
|
|
|
class FexWaylandEglThunksTest(unittest.TestCase):
|
|
def test_only_thunk_sources_and_the_thunk_database_change(self):
|
|
for name in files():
|
|
with self.subTest(name=name):
|
|
self.assertTrue(name == "Data/ThunksDB.json" or name.startswith("ThunkLibs/"))
|
|
|
|
def test_each_enabled_thunk_maps_to_the_guest_library_the_build_ships(self):
|
|
launcher = runpy.run_path(str(LAUNCHER), run_name="droiddeck_fex")["WAYLAND_THUNKS"]
|
|
self.assertEqual(set(THUNKS), set(launcher))
|
|
built = {name for name, _ in built_libs(blocks()["ThunkLibs/GuestLibs/CMakeLists.txt"])}
|
|
entries = database()
|
|
for name, lib in THUNKS.items():
|
|
with self.subTest(name=name):
|
|
self.assertIn(lib, built)
|
|
self.assertEqual(f"lib{lib}-guest.so", launcher[name])
|
|
if name in entries:
|
|
self.assertEqual(launcher[name], entries[name])
|
|
self.assertEqual({"EGL", "WaylandEGL"}, set(entries) & set(THUNKS))
|
|
|
|
def test_the_upstream_wayland_client_entry_is_left_unchanged(self):
|
|
changed = [line for line in blocks()["Data/ThunksDB.json"].splitlines()
|
|
if line[:1] in "+-" and not line.startswith(("+++", "---"))]
|
|
self.assertFalse([line for line in changed if "WaylandClient" in line or "wayland-client" in line])
|
|
|
|
def test_an_extension_is_advertised_only_with_every_entrypoint(self):
|
|
guest = "\n".join(files()["ThunkLibs/libEGL/libEGL_Guest.cpp"])
|
|
table = dict(re.findall(r'\{"(EGL_\w+)", "([\w ]+)"\}', guest))
|
|
self.assertEqual("eglQueryNativeDisplayNV eglQueryNativeWindowNV eglQueryNativePixmapNV",
|
|
table["EGL_NV_native_query"])
|
|
self.assertIn("eglSignalSyncKHR", table["EGL_KHR_reusable_sync"].split())
|
|
self.assertIn("eglCreateSyncKHR", table["EGL_KHR_reusable_sync"].split())
|
|
body = re.search(r"static bool GuestHasEntrypoints\(.*?\n\}", guest, re.S).group(0)
|
|
self.assertRegex(body, r"while \(!rest\.empty\(\)\)")
|
|
self.assertRegex(body, r"dlsym\(Self\(\), .*rest\.substr\(0, end\)")
|
|
|
|
def test_a_legacy_display_follows_the_platform_mesa_would_pick(self):
|
|
host = "\n".join(files()["ThunkLibs/libEGL/libEGL_Host.cpp"])
|
|
env = re.search(r"static std::string_view EnvPlatform\(\) \{.*?\n\}", host, re.S).group(0)
|
|
self.assertLess(env.index('getenv("EGL_PLATFORM")'), env.index('getenv("EGL_DISPLAY")'))
|
|
legacy = re.search(r"case 0:\n(.*?)\n default:", host, re.S).group(1)
|
|
self.assertLess(legacy.index("EnvPlatform()"), legacy.index("IsWaylandDisplay(native)"))
|
|
self.assertIn('env == "xcb"', legacy)
|
|
self.assertIn('env != "x11"', legacy)
|
|
self.assertNotIn("IsHostDevice", host)
|
|
|
|
def test_gles_is_overlaid_only_by_the_64_bit_egl_thunk(self):
|
|
overlays, name = {}, None
|
|
for line in blocks()["Data/ThunksDB.json"].splitlines():
|
|
found = re.match(r'[ +]\s*"(\w+)": \{', line)
|
|
if found:
|
|
name = found.group(1)
|
|
if "libGLESv2" in line:
|
|
overlays.setdefault(line[:1], set()).add(name)
|
|
self.assertEqual({"EGL"}, overlays.get("+"))
|
|
self.assertNotIn("-", overlays)
|
|
|
|
def test_guest_and_host_libraries_are_built_for_64_bit_guests_only(self):
|
|
changed = blocks()
|
|
for side in ("GuestLibs", "HostLibs"):
|
|
built = built_libs(changed[f"ThunkLibs/{side}/CMakeLists.txt"])
|
|
for lib in THUNKS.values():
|
|
with self.subTest(side=side, lib=lib):
|
|
self.assertEqual({(lib, True)}, {entry for entry in built if entry[0] == lib})
|
|
|
|
def test_listener_trampolines_stay_inside_the_packed_argument_limit(self):
|
|
guest = "\n".join(files()["ThunkLibs/libwayland-client/Guest.cpp"])
|
|
limit = int(re.search(r"#define WAYLAND_UNIFORM_MAX_ARGS (\d+)", guest).group(1))
|
|
self.assertLessEqual(limit + 2, 19)
|
|
|
|
def test_the_guest_provides_the_inline_list_and_array_helpers(self):
|
|
guest = "\n".join(files()["ThunkLibs/libwayland-client/Guest.cpp"])
|
|
for name in ("wl_list_init", "wl_list_insert", "wl_list_remove", "wl_list_length", "wl_list_empty",
|
|
"wl_list_insert_list", "wl_array_init", "wl_array_release", "wl_array_add", "wl_array_copy"):
|
|
with self.subTest(name=name):
|
|
self.assertRegex(guest, rf"\b{name}\(")
|
|
|
|
def test_the_inverse_branch_of_the_bitness_gate_is_not_64_bit_only(self):
|
|
block = "@@ -1 +1 @@\n+if (GUEST_BITNESS EQUAL 64)\n+else()\n+ add_host_lib(EGL ${GUEST_BITNESS})\n+endif()\n"
|
|
self.assertEqual({("EGL", False)}, built_libs(block))
|
|
|
|
def test_no_comments_are_added(self):
|
|
for name, lines in files().items():
|
|
for line in lines:
|
|
with self.subTest(name=name, line=line):
|
|
self.assertNotRegex(line, r"(^|\s)(//|/\*)|\$info\$")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|