Use new nativeInterface() API to get EGL/GLX contexts with Qt6

This commit is contained in:
Volker Krause 2022-03-16 16:57:09 +01:00 committed by Vlad Zahorodnii
parent 1679452f41
commit 4b810833b5
2 changed files with 25 additions and 0 deletions

View file

@ -19,7 +19,9 @@
#include "x11_platform.h"
#include <QOpenGLContext>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtPlatformHeaders/QEGLNativeContext>
#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<QEGLNativeContext>()) {
setFailed(QStringLiteral("Invalid QOpenGLContext::globalShareContext()"));
@ -70,6 +73,16 @@ void EglBackend::init()
shareContext = handle.context();
shareDisplay = handle.display();
}
#else
const auto nativeHandle = qtShareContext->nativeInterface<QNativeInterface::QEGLContext>();
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"));

View file

@ -43,7 +43,9 @@
#else
#include <QX11Info>
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtPlatformHeaders/QGLXNativeContext>
#endif
// system
#include <unistd.h>
@ -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<QGLXNativeContext>()) {
qCDebug(KWIN_X11STANDALONE) << "Invalid QOpenGLContext::globalShareContext()";
@ -330,6 +333,15 @@ bool GlxBackend::initRenderingContext()
QGLXNativeContext handle = qvariant_cast<QGLXNativeContext>(nativeHandle);
globalShareContext = handle.context();
}
#else
const auto nativeHandle = qtGlobalShareContext->nativeInterface<QNativeInterface::QGLXContext>();
if (nativeHandle) {
globalShareContext = nativeHandle->nativeContext();
} else {
qCDebug(KWIN_X11STANDALONE) << "Invalid QOpenGLContext::globalShareContext()";
return false;
}
#endif
}
if (!globalShareContext) {
qCWarning(KWIN_X11STANDALONE) << "QOpenGLContext::globalShareContext() is required";