Compare commits

...
Author SHA1 Message Date
MaxsTechReview 044c8ee475 fix(gamescope): a composited cursor no longer forwards the default arrow to the host (#3510) 2026-12-01 03:55:33 -05:00
MaxsTechReview ca499115ac fix(zero-copy): merge a second release fence into the pending fence wait (#3509)
When the kernel cannot attach a display release fence to the buffer, the
compositor waits on the fence itself. A second release of the same buffer
before that fence signalled overwrote the pending wait, so the first wait
removed the second one and then fired again with no source to remove,
crashing the compositor and losing the session.

A second unsignalled fence is now merged into the pending wait, and a
signalled or attached one leaves the pending wait in charge of the
deferred release.
2026-12-01 02:55:37 -05:00
5 changed files with 88 additions and 14 deletions

No files matched your search

@@ -7,6 +7,7 @@
#include "droiddeck-ahb-v1-server-protocol.h"
#include <android/hardware_buffer.h>
#include <errno.h>
#include <linux/sync_file.h>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
@@ -145,6 +146,12 @@ static void handle_released(uint64_t id, int fd) {
if (poll(&p, 1, 0) > 0) {
close(fd);
} else {
if (ab->fence_src) {
struct sync_merge_data m = {.name = "droiddeck-release", .fd2 = fd};
if (ioctl(ab->fence_fd, SYNC_IOC_MERGE, &m) == 0) { close(fd); fd = m.fence; }
wl_event_source_remove(ab->fence_src);
close(ab->fence_fd);
}
ab->fence_fd = fd;
ab->fence_src = wl_event_loop_add_fd(g_loop, fd, WL_EVENT_READABLE, on_fence_readable, ab);
if (!ab->fence_src) { close(fd); ab->fence_fd = -1; }
@@ -152,6 +159,7 @@ static void handle_released(uint64_t id, int fd) {
}
}
}
if (ab->fence_src) return;
send_deferred_release(ab);
maybe_free(ab);
}
+4 -3
View File
@@ -21,9 +21,10 @@ library list, before anything is published.
trip to Xwayland on the paint thread; with no image, wlserver's position is used as upstream does.
- `0101-nested-wayland-cursor-routing.patch` - this app: `gamescope_cursor_composite=2` lets the
nested Wayland session paint its cursor in the output using the real X pointer position; client
cursor surfaces are cleared to prevent a duplicate at the host pointer, while Gamescope's original
default host-cursor fallback is preserved when its no-keyboard-focus policy selects it. Empty
client cursor images and Gamescope's hidden flag still suppress the painted cursor.
cursor surfaces are cleared to prevent a duplicate at the host pointer, and so is Gamescope's
default host-cursor fallback, which would otherwise show a second arrow until Gamescope gets
keyboard focus. Empty client cursor images and Gamescope's hidden flag still suppress the
painted cursor.
- `0110-wayland-backend-touch.patch` - this app: the nested Wayland backend bound only the host's
pointer and keyboard, so a finger on the phone's screen never reached Steam. It now binds
`wl_touch` too and hands each finger to wlserver's touch path (`wlserver_touchdown` / `motion` /
@@ -74,7 +74,7 @@ index 0000000..d7c21da
+
+ constexpr bool CursorShouldBeForwardedToHost( int cursorCompositeMode, bool useHostCursorFallback )
+ {
+ return cursorCompositeMode != 2 || useHostCursorFallback;
+ return cursorCompositeMode != 2;
+ }
+
+ constexpr bool CursorImageShouldBePainted( bool imageEmpty, bool cursorHidden )
@@ -176,10 +176,10 @@ index 0000000..9c622db
+ REQUIRE( CursorShouldBeComposited( 2, false, false, true, false ) );
+}
+
+TEST_CASE("manual composition retains only the no-focus default cursor fallback", "[cursor_routing]")
+TEST_CASE("manual composition never forwards a cursor to the host", "[cursor_routing]")
+{
+ REQUIRE_FALSE( CursorShouldBeForwardedToHost( 2, false ) );
+ REQUIRE( CursorShouldBeForwardedToHost( 2, true ) );
+ REQUIRE_FALSE( CursorShouldBeForwardedToHost( 2, true ) );
+ REQUIRE( CursorShouldBeForwardedToHost( 1, false ) );
+ REQUIRE( CursorShouldBeForwardedToHost( 0, false ) );
+}
+2 -2
View File
@@ -1,3 +1,3 @@
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
GAMESCOPE_TAG=gamescope-3.16.29-f3a45b31
GAMESCOPE_SHA256=3908af87b2ee8a328e9780fc805c6a7bddd11d7405b9992d717b94e16c019313
GAMESCOPE_TAG=gamescope-3.16.29-f7dd44d2
GAMESCOPE_SHA256=a034c36d44f9bca4abc804bda3958c8d303f1ce304fb677375e5d7aa233287a9
+71 -6
View File
@@ -35,13 +35,21 @@ STRUCT
static struct wl_list g_bufs;
static struct wl_event_loop *g_loop;
static int g_import_failed_logged;
static int import_ok, imports, imported_flags, deferred_releases, frees, sources;
static struct wl_event_source g_source;
static int import_ok, imports, imported_flags, deferred_releases, frees, sources, removes, merge_ok, merges;
static struct wl_event_source g_sources[4];
static struct wl_event_source *g_removed;
void wl_list_init(struct wl_list *l) { l->prev = l; l->next = l; }
void wl_list_insert(struct wl_list *l, struct wl_list *e) {
e->next = l->next; e->prev = l; l->next->prev = e; l->next = e;
}
static int fake_ioctl(int fd, unsigned long req, void *arg) {
if (req == SYNC_IOC_MERGE) {
struct sync_merge_data *m = arg;
assert(fd >= 0 && m->fd2 >= 0 && fd != m->fd2);
++merges;
if (!merge_ok) { errno = ENOTTY; return -1; }
m->fence = dup(m->fd2); return 0;
}
struct droiddeck_dma_buf_sync_file *f = arg;
(void)fd;
assert(req == DROIDDECK_DMA_BUF_IOCTL_IMPORT_SYNC_FILE);
@@ -54,13 +62,17 @@ static int droiddeck_dmabuf_fd(struct dmabuf_buffer *b) { return b->fd; }
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; }
static struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *l, int fd, uint32_t m,
int (*cb)(int, uint32_t, void *), void *d) {
(void)l; (void)fd; (void)m; (void)cb; (void)d; ++sources; return &g_source;
(void)l; (void)fd; (void)m; (void)cb; (void)d; return &g_sources[sources++];
}
static void wl_event_source_remove(struct wl_event_source *s) { assert(s); ++removes; g_removed = s; }
static int on_fence_readable(int fd, uint32_t mask, void *data) { (void)fd; (void)mask; (void)data; return 0; }
static void send_deferred_release(struct ahb_buf *ab) { ++deferred_releases; ab->release_pending = 0; }
static void maybe_free(struct ahb_buf *ab) { (void)ab; ++frees; }
FUNCTIONS
static void reset(void) { import_ok = imports = imported_flags = deferred_releases = frees = sources = 0; }
static void reset(void) {
import_ok = imports = imported_flags = deferred_releases = frees = sources = removes = merge_ok = merges = 0;
g_removed = NULL;
}
static void run(int display, int can_import, int fence_signalled) {
reset();
wl_list_init(&g_bufs);
@@ -78,12 +90,48 @@ static void run(int display, int can_import, int fence_signalled) {
assert(deferred_releases == 1 && frees == 1 && !ab.fence_src && ab.fence_fd == -1);
errno = 0; assert(fcntl(fds[0], F_GETFD) == -1 && errno == EBADF);
} else {
assert(deferred_releases == 0 && sources == 1 && ab.fence_src == &g_source && ab.fence_fd == fds[0]);
assert(deferred_releases == 0 && sources == 1 && ab.fence_src == &g_sources[0] && ab.fence_fd == fds[0]);
close(fds[0]);
}
close(fds[1]);
}
static int closed(int fd) { errno = 0; return fcntl(fd, F_GETFD) == -1 && errno == EBADF; }
static void rerelease(int can_merge, int second_import, int second_signalled) {
reset();
wl_list_init(&g_bufs);
struct dmabuf_buffer b = {.fd = 7};
struct ahb_buf ab;
memset(&ab, 0, sizeof(ab));
ab.id = 42; ab.b = &b; ab.on_layer = 1; ab.release_pending = 1; ab.fence_fd = -1;
wl_list_insert(&g_bufs, &ab.link);
int first[2], second[2];
assert(pipe(first) == 0 && pipe(second) == 0);
handle_released(42, first[0]);
assert(ab.fence_src == &g_sources[0] && ab.fence_fd == first[0] && deferred_releases == 0);
ab.on_layer = 1;
if (second_signalled) assert(write(second[1], "x", 1) == 1);
import_ok = second_import; merge_ok = can_merge;
handle_released(42, second[0]);
assert(!ab.on_layer && deferred_releases == 0 && frees == 0);
if (second_import || second_signalled) {
assert(removes == 0 && merges == 0 && sources == 1 && ab.fence_src == &g_sources[0] && ab.fence_fd == first[0]);
assert(closed(second[0]));
close(first[0]);
} else {
assert(merges == 1 && removes == 1 && g_removed == &g_sources[0]);
assert(sources == 2 && ab.fence_src == &g_sources[1] && ab.fence_fd >= 0);
assert(closed(first[0]));
if (can_merge) assert(closed(second[0]) && ab.fence_fd != second[0]);
else assert(ab.fence_fd == second[0]);
close(ab.fence_fd);
}
close(first[1]); close(second[1]);
}
int main(int argc, char **argv) {
if (argc == 5 && !strcmp(argv[1], "rerelease")) {
rerelease(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
return 0;
}
assert(argc == 4);
run(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
return 0;
@@ -103,7 +151,7 @@ class ZeroCopyReleaseAtLatchTest(unittest.TestCase):
ahb, re.M))
struct = re.search(r'struct ahb_buf \{.*?\n\};', ahb, re.S).group()
functions = '\n'.join(function(ahb, n) for n in ('find_buf', 'handle_released'))
source = HARNESS.replace('DEFINES', '#include <fcntl.h>\n#include <sys/ioctl.h>\n' + defines)
source = HARNESS.replace('DEFINES', '#include <fcntl.h>\n#include <linux/sync_file.h>\n#include <sys/ioctl.h>\n' + defines)
source = source.replace('STRUCT', struct).replace('FUNCTIONS', functions)
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-release-latch-')
cls.addClassCleanup(cls.tmp.cleanup)
@@ -136,6 +184,23 @@ class ZeroCopyReleaseAtLatchTest(unittest.TestCase):
def test_signalled_fence_releases_without_waiting(self):
self.scenario(1, 0, 1)
def rerelease(self, can_merge, second_import, second_signalled):
result = subprocess.run([str(self.binary), 'rerelease', str(can_merge), str(second_import), str(second_signalled)],
capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_second_unsignalled_fence_merges_into_the_pending_wait(self):
self.rerelease(1, 0, 0)
def test_second_unsignalled_fence_replaces_the_wait_when_merge_fails(self):
self.rerelease(0, 0, 0)
def test_second_imported_fence_keeps_the_pending_wait(self):
self.rerelease(1, 1, 0)
def test_second_signalled_fence_keeps_the_pending_wait(self):
self.rerelease(1, 0, 1)
if __name__ == '__main__':
unittest.main()