+++ ./platform/linuxbsd/wayland/wayland_thread.cpp @@ -96,9 +96,29 @@ return data; } +#include // Based on the wayland book's shared memory boilerplate (PD/CC0). // See: https://wayland-book.com/surfaces/shared-memory.html int WaylandThread::_allocate_shm_file(size_t size) { +#ifdef __ANDROID__ + int fd, ret; + long flags; + fd = open("/dev/ashmem", O_RDWR | O_CLOEXEC); + if (fd < 0) + return fd; + ret = ioctl(fd, /* ASHMEM_SET_SIZE */ _IOW(0x77, 3, size_t), size); + if (ret < 0) + goto err; + flags = fcntl(fd, F_GETFD); + if (flags == -1) + goto err; + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) + goto err; + return fd; + err: + close(fd); + return -1; +#else int retries = 100; do { @@ -132,6 +152,7 @@ } while (retries > 0 && errno == EEXIST); return -1; +#endif } // Return the content of a wl_data_offer.