mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 07:01:30 +00:00
[client] wayland: marshal resize requests to the event-loop thread
setWindowSize is called from the render, frame and transport threads, but shellResize issues shell requests and, with the libdecor GTK plugin, renders the window decorations through pango, none of which is thread safe. A frame thread exiting after such a call crashed in the pango fontmap destructor during thread teardown. Publish the requested size atomically and wake the event loop through an eventfd registered in the epoll; the poll callback applies the size on the event-loop thread. Concurrent requests coalesce into the most recent one.
This commit is contained in:
committed by
Geoffrey McRae
parent
574e8edbae
commit
c66a974f1d
@@ -119,6 +119,8 @@ static bool waylandInit(const LG_DSInitParams params)
|
|||||||
atomic_init(&wlWm.cmCanDoHDR, false);
|
atomic_init(&wlWm.cmCanDoHDR, false);
|
||||||
atomic_init(&wlWm.hdrPQWhiteLevel, 203);
|
atomic_init(&wlWm.hdrPQWhiteLevel, 203);
|
||||||
atomic_init(&wlWm.hdrScRGBWhiteLevel, 80);
|
atomic_init(&wlWm.hdrScRGBWhiteLevel, 80);
|
||||||
|
atomic_init(&wlWm.pendingResize, 0);
|
||||||
|
wlWm.resizeEventFd = -1;
|
||||||
|
|
||||||
wlWm.display = wl_display_connect(NULL);
|
wlWm.display = wl_display_connect(NULL);
|
||||||
if (!wlWm.display)
|
if (!wlWm.display)
|
||||||
@@ -184,7 +186,10 @@ static bool waylandInit(const LG_DSInitParams params)
|
|||||||
|
|
||||||
if (!waylandEGLInit(waylandScaleMulInt(wlWm.scale, width),
|
if (!waylandEGLInit(waylandScaleMulInt(wlWm.scale, width),
|
||||||
waylandScaleMulInt(wlWm.scale, height)))
|
waylandScaleMulInt(wlWm.scale, height)))
|
||||||
|
{
|
||||||
|
waylandWindowFree();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
app_handleResizeEvent(width, height, waylandScaleToDouble(wlWm.scale),
|
app_handleResizeEvent(width, height, waylandScaleToDouble(wlWm.scale),
|
||||||
(struct Border) {0, 0, 0, 0});
|
(struct Border) {0, 0, 0, 0});
|
||||||
@@ -193,7 +198,10 @@ static bool waylandInit(const LG_DSInitParams params)
|
|||||||
|
|
||||||
#ifdef ENABLE_OPENGL
|
#ifdef ENABLE_OPENGL
|
||||||
if (params.opengl && !waylandOpenGLInit())
|
if (params.opengl && !waylandOpenGLInit())
|
||||||
|
{
|
||||||
|
waylandWindowFree();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ struct WaylandDSState
|
|||||||
bool warpSupport;
|
bool warpSupport;
|
||||||
struct WlMotion motion;
|
struct WlMotion motion;
|
||||||
|
|
||||||
|
_Atomic(uint64_t) pendingResize; // 0 = none, else (width << 32) | height
|
||||||
|
int resizeEventFd; // wakes the event loop to apply it
|
||||||
|
|
||||||
#if defined(ENABLE_EGL) || defined(ENABLE_OPENGL)
|
#if defined(ENABLE_EGL) || defined(ENABLE_OPENGL)
|
||||||
struct wl_egl_window * eglWindow;
|
struct wl_egl_window * eglWindow;
|
||||||
struct SwapWithDamageData swapWithDamage;
|
struct SwapWithDamageData swapWithDamage;
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/epoll.h>
|
||||||
|
#include <sys/eventfd.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
@@ -132,6 +136,29 @@ static const struct wp_fractional_scale_v1_listener fractionalScaleListener = {
|
|||||||
.preferred_scale = fractionalScalePreferredScale,
|
.preferred_scale = fractionalScalePreferredScale,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void resizePollCallback(uint32_t events, void * opaque)
|
||||||
|
{
|
||||||
|
eventfd_t value;
|
||||||
|
eventfd_read(wlWm.resizeEventFd, &value);
|
||||||
|
|
||||||
|
const uint64_t pending = atomic_exchange_explicit(&wlWm.pendingResize, 0,
|
||||||
|
memory_order_acquire);
|
||||||
|
if (!pending || !app_isRunning())
|
||||||
|
return;
|
||||||
|
|
||||||
|
wlWm.desktop->shellResize((int)(pending >> 32), (int)(uint32_t)pending);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resizeEventFdFree(void)
|
||||||
|
{
|
||||||
|
if (wlWm.resizeEventFd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
waylandPollUnregister(wlWm.resizeEventFd);
|
||||||
|
close(wlWm.resizeEventFd);
|
||||||
|
wlWm.resizeEventFd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool waylandWindowInit(const char * title, const char * appId, bool fullscreen, bool maximize, bool borderless, bool resizable)
|
bool waylandWindowInit(const char * title, const char * appId, bool fullscreen, bool maximize, bool borderless, bool resizable)
|
||||||
{
|
{
|
||||||
wlWm.scale = waylandScaleFromInt(1);
|
wlWm.scale = waylandScaleFromInt(1);
|
||||||
@@ -142,11 +169,29 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
|
|||||||
DEBUG_ERROR("Failed to initialize event for waitFrame");
|
DEBUG_ERROR("Failed to initialize event for waitFrame");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
waylandSignalFrame(LG_DS_WAIT_FRAME_INTERRUPTED);
|
waylandSignalFrame(LG_DS_WAIT_FRAME_INTERRUPTED);
|
||||||
|
|
||||||
|
wlWm.resizeEventFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
||||||
|
if (wlWm.resizeEventFd < 0)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to create the resize eventfd: %s", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!waylandPollRegister(wlWm.resizeEventFd, resizePollCallback, NULL,
|
||||||
|
EPOLLIN))
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to register the resize eventfd");
|
||||||
|
close(wlWm.resizeEventFd);
|
||||||
|
wlWm.resizeEventFd = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wlWm.compositor)
|
if (!wlWm.compositor)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Compositor missing wl_compositor (version 3+), will not proceed");
|
DEBUG_ERROR("Compositor missing wl_compositor (version 3+), will not proceed");
|
||||||
|
resizeEventFdFree();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +199,7 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
|
|||||||
if (!wlWm.surface)
|
if (!wlWm.surface)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to create wl_surface");
|
DEBUG_ERROR("Failed to create wl_surface");
|
||||||
|
resizeEventFdFree();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +222,10 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
|
|||||||
|
|
||||||
if (!wlWm.desktop->shellInit(wlWm.display, wlWm.surface,
|
if (!wlWm.desktop->shellInit(wlWm.display, wlWm.surface,
|
||||||
title, appId, fullscreen, maximize, borderless, resizable))
|
title, appId, fullscreen, maximize, borderless, resizable))
|
||||||
|
{
|
||||||
|
resizeEventFdFree();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
INTERLOCKED_SECTION(wlWm.surfaceLock,
|
INTERLOCKED_SECTION(wlWm.surfaceLock,
|
||||||
{
|
{
|
||||||
@@ -190,6 +239,7 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
|
|||||||
if (wl_display_roundtrip(wlWm.display) < 0)
|
if (wl_display_roundtrip(wlWm.display) < 0)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed waiting for the initial Wayland configure");
|
DEBUG_ERROR("Failed waiting for the initial Wayland configure");
|
||||||
|
resizeEventFdFree();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +249,8 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
|
|||||||
|
|
||||||
void waylandWindowFree(void)
|
void waylandWindowFree(void)
|
||||||
{
|
{
|
||||||
|
resizeEventFdFree();
|
||||||
|
|
||||||
struct SurfaceOutput * output;
|
struct SurfaceOutput * output;
|
||||||
struct SurfaceOutput * temp;
|
struct SurfaceOutput * temp;
|
||||||
wl_list_for_each_safe(output, temp, &wlWm.surfaceOutputs, link)
|
wl_list_for_each_safe(output, temp, &wlWm.surfaceOutputs, link)
|
||||||
@@ -217,7 +269,10 @@ void waylandWindowFree(void)
|
|||||||
|
|
||||||
void waylandSetWindowSize(int x, int y)
|
void waylandSetWindowSize(int x, int y)
|
||||||
{
|
{
|
||||||
wlWm.desktop->shellResize(x, y);
|
// The shell resize must run on the event-loop thread; see resizePollCallback
|
||||||
|
atomic_store_explicit(&wlWm.pendingResize,
|
||||||
|
(uint64_t)(uint32_t)x << 32 | (uint32_t)y, memory_order_release);
|
||||||
|
eventfd_write(wlWm.resizeEventFd, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waylandIsValidPointerPos(int x, int y)
|
bool waylandIsValidPointerPos(int x, int y)
|
||||||
|
|||||||
Reference in New Issue
Block a user