From 4b810833b5268bbc77be236975986e2bd9027c88 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Wed, 16 Mar 2022 16:57:09 +0100 Subject: [PATCH] Use new nativeInterface() API to get EGL/GLX contexts with Qt6 --- src/backends/x11/standalone/eglbackend.cpp | 13 +++++++++++++ src/backends/x11/standalone/glxbackend.cpp | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/backends/x11/standalone/eglbackend.cpp b/src/backends/x11/standalone/eglbackend.cpp index 2173779829..2b7abaa637 100644 --- a/src/backends/x11/standalone/eglbackend.cpp +++ b/src/backends/x11/standalone/eglbackend.cpp @@ -19,7 +19,9 @@ #include "x11_platform.h" #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif namespace KWin { @@ -61,6 +63,7 @@ void EglBackend::init() EGLContext shareContext = EGL_NO_CONTEXT; if (qtShareContext) { qDebug(KWIN_X11STANDALONE) << "Global share context format:" << qtShareContext->format(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const QVariant nativeHandle = qtShareContext->nativeHandle(); if (!nativeHandle.canConvert()) { setFailed(QStringLiteral("Invalid QOpenGLContext::globalShareContext()")); @@ -70,6 +73,16 @@ void EglBackend::init() shareContext = handle.context(); shareDisplay = handle.display(); } +#else + const auto nativeHandle = qtShareContext->nativeInterface(); + if (nativeHandle) { + shareContext = nativeHandle->nativeContext(); + shareDisplay = nativeHandle->display(); + } else { + setFailed(QStringLiteral("Invalid QOpenGLContext::globalShareContext()")); + return; + } +#endif } if (shareContext == EGL_NO_CONTEXT) { setFailed(QStringLiteral("QOpenGLContext::globalShareContext() is required")); diff --git a/src/backends/x11/standalone/glxbackend.cpp b/src/backends/x11/standalone/glxbackend.cpp index e9297ec3b0..07032bb678 100644 --- a/src/backends/x11/standalone/glxbackend.cpp +++ b/src/backends/x11/standalone/glxbackend.cpp @@ -43,7 +43,9 @@ #else #include #endif +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif // system #include @@ -322,6 +324,7 @@ bool GlxBackend::initRenderingContext() GLXContext globalShareContext = nullptr; if (qtGlobalShareContext) { qDebug(KWIN_X11STANDALONE) << "Global share context format:" << qtGlobalShareContext->format(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const QVariant nativeHandle = qtGlobalShareContext->nativeHandle(); if (!nativeHandle.canConvert()) { qCDebug(KWIN_X11STANDALONE) << "Invalid QOpenGLContext::globalShareContext()"; @@ -330,6 +333,15 @@ bool GlxBackend::initRenderingContext() QGLXNativeContext handle = qvariant_cast(nativeHandle); globalShareContext = handle.context(); } +#else + const auto nativeHandle = qtGlobalShareContext->nativeInterface(); + if (nativeHandle) { + globalShareContext = nativeHandle->nativeContext(); + } else { + qCDebug(KWIN_X11STANDALONE) << "Invalid QOpenGLContext::globalShareContext()"; + return false; + } +#endif } if (!globalShareContext) { qCWarning(KWIN_X11STANDALONE) << "QOpenGLContext::globalShareContext() is required";