From 4cb9cea3ba6c0a193e8e995c066704b1a761e115 Mon Sep 17 00:00:00 2001 From: Mis012 Date: Fri, 13 Sep 2024 20:36:44 +0200 Subject: [PATCH] native_window: remove UGLY_HACK_FOR_VR, it's not needed because we now emulate pbuffers on wayland; also, using Gtk's X11 backend is always an option --- doc/Envs.md | 1 - src/libandroid/native_window.c | 34 +++++++++++++--------------------- src/main-executable/main.c | 2 +- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/doc/Envs.md b/doc/Envs.md index 430b3ec5..34661961 100644 --- a/doc/Envs.md +++ b/doc/Envs.md @@ -7,6 +7,5 @@ The following environment variables are recognized by the main executable: this is useful for saving screen space on phone screens, as well as working around the fact that we currently don't account for the titlebar when passing screen size to apps `ATL_UGLY_ENABLE_LOCATION=` - if set, apps will be able to get location data using the relevant android APIs. (TODO: use bubblewrap) `ATL_UGLY_ENABLE_WEBVIEW=` - if not set, WebView will be stubbed as a generic View; this will avoid wasting resources on WebViews which are only used for fingerprinting and ads -`UGLY_HACK_FOR_VR` - if set, EGL will use XWayland display on Wayland. This means the app won't be able to draw to it's window, but it will be able to use pbuffers which are not available on wayland. (TODO: just recommend GDK_BACKEND=x11 if pbuffers are needed?) `ATL_FORCE_FULLSCREEN` - if set, will fullscreen the app window on start; this is useful for saving screen space on phone screens, as well as making apps that can't handle arbitrary screen dimensions for some reason happier `ATL_SKIP_NATIVES_EXTRACTION` - if set, natives will not be extracted automatically; it's already possible to replace a native lib, but removing it entirely will normally result in it getting re-extracted, which may not be what you want diff --git a/src/libandroid/native_window.c b/src/libandroid/native_window.c index 34ecd87a..60e9fe44 100644 --- a/src/libandroid/native_window.c +++ b/src/libandroid/native_window.c @@ -452,28 +452,20 @@ void (* bionic_eglGetProcAddress(char const *procname))(void) EGLDisplay bionic_eglGetDisplay(NativeDisplayType native_display) { - // XXX - we can't use pbuffers with wayland EGLDisplay, for now one has to use an env to bypass - // our EGLDisplay substitution in VR usecases (the XWayland display does support pbuffers, but - // is different from the display the SurfaceView is on, which means trying to draw to that will - // not work) - if(getenv("UGLY_HACK_FOR_VR")) { - return eglGetDisplay(native_display); + /* + * On android, at least SDL passes 0 (EGL_DISPLAY_DEFAULT) to eglGetDisplay and uses the resulting display. + * We obviously want to make the app use the correct display, which may happen to be a different one + * than the "default" display (especially on Wayland) + */ + GdkDisplay *display = gtk_root_get_display(GTK_ROOT(window)); + if (GDK_IS_WAYLAND_DISPLAY (display)) { + struct wl_display *wl_display = gdk_wayland_display_get_wl_display(display); + return eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, wl_display, NULL); + } else if (GDK_IS_X11_DISPLAY (display)) { + Display *x11_display = gdk_x11_display_get_xdisplay(display); + return eglGetPlatformDisplay(EGL_PLATFORM_X11_KHR, x11_display, NULL); } else { - /* - * On android, at least SDL passes 0 (EGL_DISPLAY_DEFAULT) to eglGetDisplay and uses the resulting display. - * We obviously want to make the app use the correct display, which may happen to be a different one - * than the "default" display (especially on Wayland) - */ - GdkDisplay *display = gtk_root_get_display(GTK_ROOT(window)); - if (GDK_IS_WAYLAND_DISPLAY (display)) { - struct wl_display *wl_display = gdk_wayland_display_get_wl_display(display); - return eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, wl_display, NULL); - } else if (GDK_IS_X11_DISPLAY (display)) { - Display *x11_display = gdk_x11_display_get_xdisplay(display); - return eglGetPlatformDisplay(EGL_PLATFORM_X11_KHR, x11_display, NULL); - } else { - return NULL; - } + return NULL; } } diff --git a/src/main-executable/main.c b/src/main-executable/main.c index b5b135b5..c84fc5ac 100644 --- a/src/main-executable/main.c +++ b/src/main-executable/main.c @@ -498,7 +498,7 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h printf("WARNING: RUN_FROM_BUILDDIR set and --install given: using current directory in desktop entry\n"); g_string_append_printf(desktop_entry, "-C %s ", g_get_current_dir()); } - char *envs[] = {"RUN_FROM_BUILDDIR", "LD_LIBRARY_PATH", "ANDROID_APP_DATA_DIR", "ATL_UGLY_ENABLE_LOCATION", "ATL_UGLY_ENABLE_WEBVIEW", "ATL_DISABLE_WINDOW_DECORATIONS", "UGLY_HACK_FOR_VR", "ATL_FORCE_FULLSCREEN"}; + char *envs[] = {"RUN_FROM_BUILDDIR", "LD_LIBRARY_PATH", "ANDROID_APP_DATA_DIR", "ATL_UGLY_ENABLE_LOCATION", "ATL_UGLY_ENABLE_WEBVIEW", "ATL_DISABLE_WINDOW_DECORATIONS", "ATL_FORCE_FULLSCREEN"}; for (int i = 0; i < sizeof(envs)/sizeof(envs[0]); i++) { if (getenv(envs[i])) { g_string_append_printf(desktop_entry, "%s=%s ", envs[i], getenv(envs[i]));