From 7963e85b771852f96a923839cd0530219676914e Mon Sep 17 00:00:00 2001 From: Mikko Levonmaa Date: Tue, 10 Nov 2015 14:46:26 +0200 Subject: Make swap buffer call non-blocking for subsurfaces Allows clients that use subsurfaces in synchronized mode to continue processing the event loop even in cases where a frame callback is not delivered from the compositor pending a parent surface commit Change-Id: I7df38afc4080546b60184dacecde321ba8062fac Reviewed-by: Giulio Camuffo --- src/client/qwaylandsubsurface.cpp | 2 ++ src/client/qwaylandsubsurface_p.h | 3 +++ .../client/wayland-egl/qwaylandglcontext.cpp | 30 +++++++++++++++++++++- .../client/wayland-egl/qwaylandglcontext.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/client/qwaylandsubsurface.cpp b/src/client/qwaylandsubsurface.cpp index 72b80c18f..eac847c75 100644 --- a/src/client/qwaylandsubsurface.cpp +++ b/src/client/qwaylandsubsurface.cpp @@ -58,11 +58,13 @@ QWaylandSubSurface::~QWaylandSubSurface() void QWaylandSubSurface::setSync() { + QMutexLocker l(&m_syncLock); QWaylandSubSurface::set_sync(); } void QWaylandSubSurface::setDeSync() { + QMutexLocker l(&m_syncLock); QWaylandSubSurface::set_desync(); } diff --git a/src/client/qwaylandsubsurface_p.h b/src/client/qwaylandsubsurface_p.h index 5255df5c9..b8ea6aaf3 100644 --- a/src/client/qwaylandsubsurface_p.h +++ b/src/client/qwaylandsubsurface_p.h @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -71,6 +72,7 @@ public: void setSync(); void setDeSync(); bool isSync() const { return m_synchronized; } + QMutex *syncMutex() { return &m_syncLock; } private: @@ -81,6 +83,7 @@ private: QWaylandWindow *m_window; QWaylandWindow *m_parent; bool m_synchronized; + QMutex m_syncLock; }; diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp index 18ed1d61e..b8ba4c631 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include "qwaylandeglwindow.h" @@ -50,6 +51,8 @@ #include #include +#include + // Constants from EGL_KHR_create_context #ifndef EGL_CONTEXT_MINOR_VERSION_KHR #define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB @@ -220,6 +223,7 @@ QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *dis , m_display(display) , m_blitter(0) , mUseNativeDefaultFbo(false) + , mSupportNonBlockingSwap(true) { QSurfaceFormat fmt = format; if (static_cast(QGuiApplicationPrivate::platformIntegration())->display()->supportsWindowDecoration()) @@ -290,6 +294,17 @@ QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *dis return; } + EGLint a = EGL_MIN_SWAP_INTERVAL; + EGLint b = EGL_MAX_SWAP_INTERVAL; + if (!eglGetConfigAttrib(m_eglDisplay, m_config, a, &a) || + !eglGetConfigAttrib(m_eglDisplay, m_config, b, &b) || + a > 0) { + mSupportNonBlockingSwap = false; + } + if (!mSupportNonBlockingSwap) { + qWarning() << "Non-blocking swap buffers not supported. Subsurface rendering can be affected."; + } + updateGLFormat(); } @@ -518,7 +533,20 @@ void QWaylandGLContext::swapBuffers(QPlatformSurface *surface) m_blitter->blit(window); } - eglSwapBuffers(m_eglDisplay, eglSurface); + + QWaylandSubSurface *sub = window->subSurfaceWindow(); + if (sub) { + QMutexLocker l(sub->syncMutex()); + + int si = (sub->isSync() && mSupportNonBlockingSwap) ? 0 : m_format.swapInterval(); + + eglSwapInterval(m_eglDisplay, si); + eglSwapBuffers(m_eglDisplay, eglSurface); + } else { + eglSwapInterval(m_eglDisplay, m_format.swapInterval()); + eglSwapBuffers(m_eglDisplay, eglSurface); + } + window->setCanResize(true); } diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h index bc92c9501..42236c643 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h +++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h @@ -86,6 +86,7 @@ private: DecorationsBlitter *m_blitter; bool mUseNativeDefaultFbo; uint m_api; + bool mSupportNonBlockingSwap; friend class DecorationsBlitter; }; -- cgit v1.2.3