diff --git a/x11-packages/xwayland/build.sh b/x11-packages/xwayland/build.sh index 534889a7dd6..e260cbc43a0 100644 --- a/x11-packages/xwayland/build.sh +++ b/x11-packages/xwayland/build.sh @@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Wayland X11 server" TERMUX_PKG_LICENSE="MIT" TERMUX_PKG_MAINTAINER="@termux" TERMUX_PKG_VERSION="24.1.12" +TERMUX_PKG_REVISION=1 TERMUX_PKG_SRCURL=https://xorg.freedesktop.org/releases/individual/xserver/xwayland-${TERMUX_PKG_VERSION}.tar.xz TERMUX_PKG_SHA256=6df02c511b92c1b9848734d9d1b03a4c24f8375ba3cada44e9684a21b5f78e21 TERMUX_PKG_AUTO_UPDATE=true @@ -29,6 +30,9 @@ TERMUX_PKG_EXTRA_CONFIGURE_ARGS=" -Dipv6=true -Dsha1=libcrypto -Ddefault_font_path=$TERMUX_PREFIX/share/fonts +-Dxkb_dir=$TERMUX_PREFIX/share/xkeyboard-config-2 +-Dxkb_output_dir=$TERMUX_PREFIX/tmp +-Dxkb_bin_dir=$TERMUX_PREFIX/bin " # Remove files conflicting with xorg-server: diff --git a/x11-packages/xwayland/support-kgsl-dmabuf-v3-fallback-paths.patch b/x11-packages/xwayland/support-kgsl-dmabuf-v3-fallback-paths.patch new file mode 100644 index 00000000000..2acb9774768 --- /dev/null +++ b/x11-packages/xwayland/support-kgsl-dmabuf-v3-fallback-paths.patch @@ -0,0 +1,142 @@ +From e910fc1dda09b916e190f5f8645abae5b6ebfda3 Mon Sep 17 00:00:00 2001 +From: superturtlee <160681686+superturtlee@users.noreply.github.com> +Date: Mon, 6 Jul 2026 09:56:24 +0800 +Subject: [PATCH] xwayland: support kgsl dmabuf v3 fallback paths + +Allow glamor to initialize with linux-dmabuf v3 when wl_drm and dmabuf +feedback are unavailable, fall back to a configurable GBM render node, and +handle implicit or bogus linear modifiers used by kgsl/freedreno stacks. + +Based-on-patch: https://github.com/superturtlee/anland/blob/1.11/producers/kde/ubuntu2604/xwayland.patch + +Co-authored-by: lfdevs +--- + hw/xwayland/xwayland-glamor-gbm.c | 65 ++++++++++++++++++++++--------- + hw/xwayland/xwayland-glamor.c | 9 +++++ + 2 files changed, 56 insertions(+), 18 deletions(-) + +diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c +index 05668b8e9..5ce344b3c 100644 +--- a/hw/xwayland/xwayland-glamor-gbm.c ++++ b/hw/xwayland/xwayland-glamor-gbm.c +@@ -33,6 +33,7 @@ + #include + #include + #include ++#include + #ifdef DRI3 + #include + #endif /* DRI3 */ +@@ -590,8 +591,17 @@ xwl_glamor_pixmap_get_wl_buffer(PixmapPtr pixmap) + return NULL; + } + ++ /* An implicit-modifier buffer (DRM_FORMAT_MOD_INVALID) is never listed in ++ * the compositor's advertised modifier set, so the regular support check ++ * fails. On the kgsl/turnip stack - where the buffer is allocated on the ++ * display node but composited by turnip - that left both the dmabuf and ++ * the (absent) wl_drm path unusable, so no wl_buffer was created and the ++ * X11 window stayed black. Per the linux-dmabuf protocol, INVALID means ++ * "let the compositor infer the layout", so submit it through the dmabuf ++ * path directly instead of rejecting it. */ + if (xwl_screen->dmabuf && +- xwl_glamor_is_modifier_supported(xwl_screen, format, modifier)) { ++ (modifier == DRM_FORMAT_MOD_INVALID || ++ xwl_glamor_is_modifier_supported(xwl_screen, format, modifier))) { + struct zwp_linux_buffer_params_v1 *params; + + params = zwp_linux_dmabuf_v1_create_params(xwl_screen->dmabuf); +@@ -773,6 +783,15 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds, + strides[0] < width * bpp / 8) + goto error; + ++ /* Some freedreno/kgsl mesa builds (the on-device dev tree) rewrite a ++ * LINEAR modifier (0) to a bogus 1274 (0x4FA) in the loader_dri3 ++ * pixmap_from_buffers path. 1274 is not a valid DRM modifier, so the ++ * gbm_bo_import() below rejects it and the X11 GL client gets BadAlloc ++ * (dri3_alloc_render_buffer -> pixmap_from_buffer[s] failed -> segfault). ++ * The buffer is really linear, so map the bogus value back to LINEAR. */ ++ if (modifier == 1274ULL) ++ modifier = DRM_FORMAT_MOD_LINEAR; ++ + if (xwl_gbm->dmabuf_capable && modifier != DRM_FORMAT_MOD_INVALID) { + #ifdef GBM_BO_WITH_MODIFIERS + struct gbm_import_fd_modifier_data data; +@@ -1665,27 +1684,37 @@ static Bool + xwl_glamor_gbm_init_main_dev(struct xwl_screen *xwl_screen) + { + struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen); +- drmDevice *main_dev; +- +- while (!xwl_screen->default_feedback.feedback_done) { +- if (wl_display_dispatch(xwl_screen->display) < 0) { +- ErrorF("Failed to dispatch Wayland display\n"); +- return FALSE; ++ drmDevice *main_dev = NULL; ++ ++ /* linux-dmabuf feedback (and thus a main device) only exists from protocol ++ * version 4. On the kgsl/turnip stack the compositor only speaks v3, so ++ * there is no feedback to wait for - skip the wait and go straight to the ++ * fallback render node below instead of blocking forever on feedback_done. */ ++ if (xwl_screen->dmabuf_protocol_version >= 4) { ++ while (!xwl_screen->default_feedback.feedback_done) { ++ if (wl_display_dispatch(xwl_screen->display) < 0) { ++ ErrorF("Failed to dispatch Wayland display\n"); ++ return FALSE; ++ } + } ++ main_dev = xwl_screen->default_feedback.main_dev; + } + +- main_dev = xwl_screen->default_feedback.main_dev; +- if (!main_dev) { +- ErrorF("No main linux-dmabuf device advertised by compositor\n"); +- return FALSE; +- } +- +- if (!(main_dev->available_nodes & (1 << DRM_NODE_RENDER))) { +- ErrorF("Main linux-dmabuf device has no render node\n"); +- return FALSE; ++ /* On the kgsl-backed turnip stack the compositor advertises no usable DRM ++ * render node (the GPU is exposed through kgsl, not a standard DRM node), ++ * so main_dev is NULL or render-node-less. Rather than dereferencing NULL ++ * (-> crash) or bailing out, fall back to a default render node, which the ++ * patched freedreno mesa redirects to /dev/kgsl-3d0 for native GL. */ ++ if (!main_dev || !(main_dev->available_nodes & (1 << DRM_NODE_RENDER))) { ++ const char *fallback = getenv("XWAYLAND_GBM_DEVICE"); ++ if (!fallback) ++ fallback = "/dev/dri/renderD128"; ++ ErrorF("No usable linux-dmabuf main device, falling back to %s\n", ++ fallback); ++ xwl_gbm->device_name = strdup(fallback); ++ } else { ++ xwl_gbm->device_name = strdup(main_dev->nodes[DRM_NODE_RENDER]); + } +- +- xwl_gbm->device_name = strdup(main_dev->nodes[DRM_NODE_RENDER]); + if (!xwl_gbm->device_name) { + return FALSE; + } +diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c +index 88ced5da0..35d1e0391 100644 +--- a/hw/xwayland/xwayland-glamor.c ++++ b/hw/xwayland/xwayland-glamor.c +@@ -123,6 +123,15 @@ xwl_glamor_has_wl_interfaces(struct xwl_screen *xwl_screen) + { + if (!xwl_glamor_has_wl_drm(xwl_screen) && + xwl_screen->dmabuf_protocol_version < 4) { ++ /* No wl_drm and no linux-dmabuf feedback (v4). On the kgsl/turnip stack ++ * the compositor exposes neither (the GPU lives behind /dev/kgsl-3d0, ++ * not a DRM render node, so there is no main device to advertise), but ++ * it does speak linux-dmabuf v3. We can still bring glamor up by opening ++ * a fallback render node directly (see xwl_glamor_gbm_init_main_dev) and ++ * submitting buffers over dmabuf v3, so keep glamor available as long as ++ * v3 is present. */ ++ if (xwl_screen->dmabuf_protocol_version >= 3) ++ return TRUE; + LogMessageVerb(X_INFO, 3, "glamor: 'wl_drm' not supported and linux-dmabuf v4 not supported\n"); + return FALSE; + } +-- +2.47.3 +