summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-06-08 20:00:36 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-02 10:27:50 +0200
commit6ff79478a44fce12ca18832a56db4a370a9ff417 (patch)
tree2bcd7ab7bac46fe28e0828e0a704649bbc025e8f /src/plugins
parent037dce81fc27ec241edb6829f6df41927b80666e (diff)
Introduce platform API abstraction for QOpenGLContext
The API is available by including qopenglcontext.h as usual, but scoped in the QPlatformInterface namespace. The namespace exposes platform specific type-safe interfaces that provide: a) Factory functions for adopting native contexts, e.g. QCocoaGLContext::fromNative(nsContext, shareContext); b) Access to underlying native handles, e.g. openGLContext->platformInterface<QCocoaGLContext>->nativeContext() c) Platform specific functionality, e.g. static QWGLContext::openGLModuleHandle() openGLContext->platformInterface<QEGLContext>->doSomething(); The platform interfaces live close to the classes they extend, removing the need for complex indirection and plumbing, and avoids kitchen-sink modules and APIs such as the extras modules, QPlatformFunctions, or QPlatformNativeInterface. In the case of QOpenGLContext these platform APIs are backed by the platform plugin, so dynamic_cast is used to ensure the platform plugin supports the requested interface, but this is and implementation detail. The interface APIs are agnostic to where the implementation lives, while still being available to the user as part of the APIs they extend/augment. The documentation will be restored when the dust settles. Task-number: QTBUG-80233 Change-Id: Iac612403383991c4b24064332542a6e4bcbb3293 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/android/qandroidplatformintegration.cpp10
-rw-r--r--src/plugins/platforms/android/qandroidplatformintegration.h3
-rw-r--r--src/plugins/platforms/android/qandroidplatformopenglcontext.cpp5
-rw-r--r--src/plugins/platforms/android/qandroidplatformopenglcontext.h4
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.h8
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm41
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.h5
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm16
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.h8
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm33
-rw-r--r--src/plugins/platforms/eglfs/api/qeglfscontext.cpp7
-rw-r--r--src/plugins/platforms/eglfs/api/qeglfscontext_p.h5
-rw-r--r--src/plugins/platforms/eglfs/api/qeglfsintegration.cpp18
-rw-r--r--src/plugins/platforms/eglfs/api/qeglfsintegration_p.h3
-rw-r--r--src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp6
-rw-r--r--src/plugins/platforms/offscreen/qoffscreenintegration_x11.h5
-rw-r--r--src/plugins/platforms/windows/qwindowsglcontext.cpp84
-rw-r--r--src/plugins/platforms/windows/qwindowsglcontext.h7
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.cpp27
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.h7
-rw-r--r--src/plugins/platforms/windows/qwindowsopenglcontext.h4
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h11
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp9
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h3
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp85
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h30
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp21
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h4
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp21
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.h5
30 files changed, 232 insertions, 263 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp
index 3d495724c6..f4c292fe73 100644
--- a/src/plugins/platforms/android/qandroidplatformintegration.cpp
+++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp
@@ -71,8 +71,6 @@
#include "qandroidsystemlocale.h"
#include "qandroidplatformoffscreensurface.h"
-#include <QtPlatformHeaders/QEGLNativeContext>
-
#if QT_CONFIG(vulkan)
#include "qandroidplatformvulkanwindow.h"
#include "qandroidplatformvulkaninstance.h"
@@ -307,11 +305,15 @@ QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext
format.setRedBufferSize(8);
format.setGreenBufferSize(8);
format.setBlueBufferSize(8);
- auto ctx = new QAndroidPlatformOpenGLContext(format, context->shareHandle(), m_eglDisplay, context->nativeHandle());
- context->setNativeHandle(QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(ctx->eglContext(), m_eglDisplay)));
+ auto ctx = new QAndroidPlatformOpenGLContext(format, context->shareHandle(), m_eglDisplay);
return ctx;
}
+QOpenGLContext *QAndroidPlatformIntegration::createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const
+{
+ return QEGLPlatformContext::createFrom<QAndroidPlatformOpenGLContext>(context, display, m_eglDisplay, shareContext);
+}
+
QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
if (!QtAndroid::activity())
diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h
index e6a36240d0..30ab42ab34 100644
--- a/src/plugins/platforms/android/qandroidplatformintegration.h
+++ b/src/plugins/platforms/android/qandroidplatformintegration.h
@@ -45,6 +45,7 @@
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformmenu.h>
#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformopenglcontext.h>
#include <EGL/egl.h>
#include <jni.h>
@@ -73,6 +74,7 @@ protected:
};
class QAndroidPlatformIntegration : public QPlatformIntegration
+ , QPlatformInterface::Private::QEGLIntegration
{
friend class QAndroidPlatformScreen;
@@ -88,6 +90,7 @@ public:
QPlatformWindow *createForeignWindow(QWindow *window, WId nativeHandle) const override;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override;
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
+ QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override;
QAbstractEventDispatcher *createEventDispatcher() const override;
QAndroidPlatformScreen *screen() { return m_primaryScreen; }
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
index 8d98882e9e..ecbd282c91 100644
--- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
+++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
@@ -51,9 +51,8 @@
QT_BEGIN_NAMESPACE
-QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
- const QVariant &nativeHandle)
- :QEGLPlatformContext(format, share, display, nullptr, nativeHandle)
+QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display)
+ : QEGLPlatformContext(format, share, display, nullptr)
{
}
diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.h b/src/plugins/platforms/android/qandroidplatformopenglcontext.h
index 8e65b4cc36..50559e281e 100644
--- a/src/plugins/platforms/android/qandroidplatformopenglcontext.h
+++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.h
@@ -48,13 +48,13 @@ QT_BEGIN_NAMESPACE
class QAndroidPlatformOpenGLContext : public QEGLPlatformContext
{
public:
- QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, const QVariant &nativeHandle);
+ using QEGLPlatformContext::QEGLPlatformContext;
+ QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display);
void swapBuffers(QPlatformSurface *surface) override;
bool makeCurrent(QPlatformSurface *surface) override;
private:
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override;
-
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h
index f1851a2336..9dbd1a11bf 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.h
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h
@@ -43,7 +43,8 @@
#include <QtCore/QPointer>
#include <QtCore/private/qcore_mac_p.h>
#include <qpa/qplatformopenglcontext.h>
-#include <QtGui/QOpenGLContext>
+#include <QtGui/qopenglcontext.h>
+#include <QtGui/private/qopenglcontext_p.h>
#include <QtGui/QWindow>
Q_FORWARD_DECLARE_OBJC_CLASS(NSOpenGLContext);
@@ -53,10 +54,11 @@ QT_BEGIN_NAMESPACE
class QCocoaWindow;
-class QCocoaGLContext : public QPlatformOpenGLContext
+class QCocoaGLContext : public QPlatformOpenGLContext, public QPlatformInterface::QCocoaGLContext
{
public:
QCocoaGLContext(QOpenGLContext *context);
+ QCocoaGLContext(NSOpenGLContext *context);
~QCocoaGLContext();
void initialize() override;
@@ -71,7 +73,7 @@ public:
bool isSharing() const override;
bool isValid() const override;
- NSOpenGLContext *nativeContext() const;
+ NSOpenGLContext *nativeContext() const override;
QFunctionPointer getProcAddress(const char *procName) override;
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index c049ca60f2..c2fcb6cdbc 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -45,7 +45,6 @@
#include "qcocoascreen.h"
#include <qdebug.h>
-#include <QtPlatformHeaders/qcocoanativecontext.h>
#include <dlfcn.h>
static inline QByteArray getGlString(GLenum param)
@@ -65,30 +64,23 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
{
}
-void QCocoaGLContext::initialize()
+QCocoaGLContext::QCocoaGLContext(NSOpenGLContext *nativeContext)
+ : QPlatformOpenGLContext()
{
- QVariant nativeHandle = context()->nativeHandle();
- if (!nativeHandle.isNull()) {
- if (!nativeHandle.canConvert<QCocoaNativeContext>()) {
- qCWarning(lcQpaOpenGLContext, "QOpenGLContext native handle must be a QCocoaNativeContext");
- return;
- }
- m_context = nativeHandle.value<QCocoaNativeContext>().context();
- if (!m_context) {
- qCWarning(lcQpaOpenGLContext, "QCocoaNativeContext's NSOpenGLContext cannot be null");
- return;
- }
-
- [m_context retain];
-
- // Note: We have no way of knowing whether the NSOpenGLContext was created with the
- // share context as reported by the QOpenGLContext, but we just have to trust that
- // it was. It's okey, as the only thing we're using it for is to report isShared().
- if (QPlatformOpenGLContext *shareContext = context()->shareHandle())
- m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext();
+ m_context = [nativeContext retain];
+}
- updateSurfaceFormat();
- return;
+void QCocoaGLContext::initialize()
+{
+ if (m_context) {
+ // Note: We have no way of knowing whether the NSOpenGLContext was created with the
+ // share context as reported by the QOpenGLContext, but we just have to trust that
+ // it was. It's okey, as the only thing we're using it for is to report isShared().
+ if (QPlatformOpenGLContext *shareContext = context()->shareHandle())
+ m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext();
+
+ updateSurfaceFormat();
+ return;
}
// ----------- Default case, we own the NSOpenGLContext -----------
@@ -139,9 +131,6 @@ void QCocoaGLContext::initialize()
return;
}
- // The native handle should reflect the underlying context, even if we created it
- context()->setNativeHandle(QVariant::fromValue<QCocoaNativeContext>(m_context));
-
// --------------------- Set NSOpenGLContext properties ---------------------
const GLint interval = m_format.swapInterval() >= 0 ? m_format.swapInterval() : 1;
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h
index d2fffc8e73..f82e0050ae 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.h
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.h
@@ -56,12 +56,14 @@
#include <QtCore/QScopedPointer>
#include <qpa/qplatformintegration.h>
#include <QtGui/private/qcoretextfontdatabase_p.h>
+#include <QtGui/private/qopenglcontext_p.h>
Q_FORWARD_DECLARE_OBJC_CLASS(NSToolbar);
QT_BEGIN_NAMESPACE
-class QCocoaIntegration : public QObject, public QPlatformIntegration
+class QCocoaIntegration : public QObject, public QPlatformIntegration,
+ public QPlatformInterface::Private::QCocoaGLIntegration
{
Q_OBJECT
public:
@@ -82,6 +84,7 @@ public:
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
+ QOpenGLContext *createOpenGLContext(NSOpenGLContext *, QOpenGLContext *shareContext) const override;
#endif
QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const override;
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index 49e8f8eada..b3d3bb34bf 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -64,9 +64,8 @@
#include <qpa/qplatformoffscreensurface.h>
#include <QtCore/qcoreapplication.h>
-#include <QtPlatformHeaders/qcocoanativecontext.h>
-
#include <QtGui/private/qcoregraphics_p.h>
+#include <QtGui/private/qopenglcontext_p.h>
#include <QtGui/private/qfontengine_coretext_p.h>
@@ -308,6 +307,19 @@ QPlatformOpenGLContext *QCocoaIntegration::createPlatformOpenGLContext(QOpenGLCo
{
return new QCocoaGLContext(context);
}
+
+QOpenGLContext *QCocoaIntegration::createOpenGLContext(NSOpenGLContext *nativeContext, QOpenGLContext *shareContext) const
+{
+ if (!nativeContext)
+ return nullptr;
+
+ auto *context = new QOpenGLContext;
+ context->setShareContext(shareContext);
+ auto *contextPrivate = QOpenGLContextPrivate::get(context);
+ contextPrivate->adopt(new QCocoaGLContext(nativeContext));
+ return context;
+}
+
#endif
QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *window) const
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
index 45330cf1b8..7d4c5884b3 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
@@ -59,18 +59,10 @@ class QCocoaNativeInterface : public QPlatformNativeInterface
public:
QCocoaNativeInterface();
-#ifndef QT_NO_OPENGL
- void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) override;
-#endif
void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) override;
NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) override;
-#ifndef QT_NO_OPENGL
- static void *cglContextForContext(QOpenGLContext *context);
- static void *nsOpenGLContextForContext(QOpenGLContext* context);
-#endif
-
QFunctionPointer platformFunction(const QByteArray &function) const override;
public Q_SLOTS:
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index ba4ad719d2..22bab0886d 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -76,20 +76,6 @@ QCocoaNativeInterface::QCocoaNativeInterface()
{
}
-#ifndef QT_NO_OPENGL
-void *QCocoaNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context)
-{
- if (!context)
- return nullptr;
- if (resourceString.toLower() == "nsopenglcontext")
- return nsOpenGLContextForContext(context);
- if (resourceString.toLower() == "cglcontextobj")
- return cglContextForContext(context);
-
- return nullptr;
-}
-#endif
-
void *QCocoaNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
if (!window->handle())
@@ -182,25 +168,6 @@ void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window)
QCocoaMenuBar::updateMenuBarImmediately();
}
-#ifndef QT_NO_OPENGL
-void *QCocoaNativeInterface::cglContextForContext(QOpenGLContext* context)
-{
- NSOpenGLContext *nsOpenGLContext = static_cast<NSOpenGLContext*>(nsOpenGLContextForContext(context));
- if (nsOpenGLContext)
- return [nsOpenGLContext CGLContextObj];
- return nullptr;
-}
-
-void *QCocoaNativeInterface::nsOpenGLContextForContext(QOpenGLContext* context)
-{
- if (context) {
- if (QCocoaGLContext *cocoaGLContext = static_cast<QCocoaGLContext *>(context->handle()))
- return cocoaGLContext->nativeContext();
- }
- return nullptr;
-}
-#endif
-
QFunctionPointer QCocoaNativeInterface::platformFunction(const QByteArray &function) const
{
if (function == QCocoaWindowFunctions::bottomLeftClippedByNSWindowOffsetIdentifier())
diff --git a/src/plugins/platforms/eglfs/api/qeglfscontext.cpp b/src/plugins/platforms/eglfs/api/qeglfscontext.cpp
index 48fafbda8d..2dbf762cf4 100644
--- a/src/plugins/platforms/eglfs/api/qeglfscontext.cpp
+++ b/src/plugins/platforms/eglfs/api/qeglfscontext.cpp
@@ -50,10 +50,9 @@
QT_BEGIN_NAMESPACE
QEglFSContext::QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
- EGLConfig *config, const QVariant &nativeHandle)
- : QEGLPlatformContext(format, share, display, config, nativeHandle,
- qt_egl_device_integration()->supportsSurfacelessContexts() ? Flags() : QEGLPlatformContext::NoSurfaceless),
- m_tempWindow(0)
+ EGLConfig *config)
+ : QEGLPlatformContext(format, share, display, config,
+ qt_egl_device_integration()->supportsSurfacelessContexts() ? Flags() : QEGLPlatformContext::NoSurfaceless)
{
}
diff --git a/src/plugins/platforms/eglfs/api/qeglfscontext_p.h b/src/plugins/platforms/eglfs/api/qeglfscontext_p.h
index af8725b6b3..f3b506ac7f 100644
--- a/src/plugins/platforms/eglfs/api/qeglfscontext_p.h
+++ b/src/plugins/platforms/eglfs/api/qeglfscontext_p.h
@@ -61,8 +61,9 @@ QT_BEGIN_NAMESPACE
class Q_EGLFS_EXPORT QEglFSContext : public QEGLPlatformContext
{
public:
+ using QEGLPlatformContext::QEGLPlatformContext;
QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
- EGLConfig *config, const QVariant &nativeHandle);
+ EGLConfig *config);
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override;
EGLSurface createTemporaryOffscreenSurface() override;
void destroyTemporaryOffscreenSurface(EGLSurface surface) override;
@@ -72,7 +73,7 @@ public:
QEglFSCursorData cursorData;
private:
- EGLNativeWindowType m_tempWindow;
+ EGLNativeWindowType m_tempWindow = 0;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp
index 9b479a21c1..c94a12a198 100644
--- a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp
+++ b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp
@@ -76,8 +76,6 @@
# include <QtOpenGL/private/qopenglcompositorbackingstore_p.h>
#endif
-#include <QtPlatformHeaders/QEGLNativeContext>
-
#if QT_CONFIG(libinput)
#include <QtInputSupport/private/qlibinputhandler_p.h>
#endif
@@ -215,22 +213,20 @@ QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLCo
{
EGLDisplay dpy = context->screen() ? static_cast<QEglFSScreen *>(context->screen()->handle())->display() : display();
QPlatformOpenGLContext *share = context->shareHandle();
- QVariant nativeHandle = context->nativeHandle();
QEglFSContext *ctx;
QSurfaceFormat adjustedFormat = qt_egl_device_integration()->surfaceFormatFor(context->format());
- if (nativeHandle.isNull()) {
- EGLConfig config = QEglFSDeviceIntegration::chooseConfig(dpy, adjustedFormat);
- ctx = new QEglFSContext(adjustedFormat, share, dpy, &config, QVariant());
- } else {
- ctx = new QEglFSContext(adjustedFormat, share, dpy, nullptr, nativeHandle);
- }
- nativeHandle = QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(ctx->eglContext(), dpy));
+ EGLConfig config = QEglFSDeviceIntegration::chooseConfig(dpy, adjustedFormat);
+ ctx = new QEglFSContext(adjustedFormat, share, dpy, &config);
- context->setNativeHandle(nativeHandle);
return ctx;
}
+QOpenGLContext *QEglFSIntegration::createOpenGLContext(EGLContext context, EGLDisplay contextDisplay, QOpenGLContext *shareContext) const
+{
+ return QEGLPlatformContext::createFrom<QEglFSContext>(context, contextDisplay, display(), shareContext);
+}
+
QPlatformOffscreenSurface *QEglFSIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
EGLDisplay dpy = surface->screen() ? static_cast<QEglFSScreen *>(surface->screen()->handle())->display() : display();
diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h b/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h
index 7df1aa3c2c..baf9baadda 100644
--- a/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h
+++ b/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h
@@ -57,6 +57,7 @@
#include <QtGui/QWindow>
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformopenglcontext.h>
#include <qpa/qplatformscreen.h>
QT_BEGIN_NAMESPACE
@@ -67,6 +68,7 @@ class QFbVtHandler;
class QEvdevKeyboardManager;
class Q_EGLFS_EXPORT QEglFSIntegration : public QPlatformIntegration, public QPlatformNativeInterface
+ , public QPlatformInterface::Private::QEGLIntegration
{
public:
QEglFSIntegration();
@@ -86,6 +88,7 @@ public:
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override;
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
+ QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override;
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
#endif
#if QT_CONFIG(vulkan)
diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp
index 84991d751f..53ec3e80c2 100644
--- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp
+++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp
@@ -41,7 +41,6 @@
#include <QByteArray>
#include <QOpenGLContext>
-#include <QtPlatformHeaders/QGLXNativeContext>
#include <X11/Xlib.h>
#include <GL/glx.h>
@@ -241,9 +240,6 @@ QOffscreenX11GLXContext::QOffscreenX11GLXContext(QOffscreenX11Info *x11, QOpenGL
d->window = createDummyWindow(x11, visualInfo);
XFree(visualInfo);
}
- if (d->context)
- context->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(QGLXNativeContext(d->context)));
-
}
QOffscreenX11GLXContext::~QOffscreenX11GLXContext()
@@ -296,7 +292,7 @@ bool QOffscreenX11GLXContext::isValid() const
return d->context && d->window;
}
-void *QOffscreenX11GLXContext::glxContext() const
+GLXContext QOffscreenX11GLXContext::glxContext() const
{
return d->context;
}
diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h
index 5ef51a15a8..005ac26151 100644
--- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h
+++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h
@@ -90,6 +90,7 @@ private:
class QOffscreenX11GLXContextData;
class QOffscreenX11GLXContext : public QPlatformOpenGLContext
+ , public QPlatformInterface::QGLXContext
{
public:
QOffscreenX11GLXContext(QOffscreenX11Info *x11, QOpenGLContext *context);
@@ -104,8 +105,10 @@ public:
bool isSharing() const override;
bool isValid() const override;
+ GLXContext nativeContext() const override { return glxContext(); }
+
void *glxConfig() const;
- void *glxContext() const;
+ GLXContext glxContext() const;
private:
QScopedPointer<QOffscreenX11GLXContextData> d;
diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp
index c1921810e7..aa93b85289 100644
--- a/src/plugins/platforms/windows/qwindowsglcontext.cpp
+++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp
@@ -46,7 +46,6 @@
#include <QtCore/qsysinfo.h>
#include <QtGui/qguiapplication.h>
#include <qpa/qplatformnativeinterface.h>
-#include <QtPlatformHeaders/qwglnativecontext.h>
#include <algorithm>
@@ -225,6 +224,11 @@ QWindowsOpenGLContext *QOpenGLStaticContext::createContext(QOpenGLContext *conte
return new QWindowsGLContext(this, context);
}
+QWindowsOpenGLContext *QOpenGLStaticContext::createContext(HGLRC context, HWND window)
+{
+ return new QWindowsGLContext(this, context, window);
+}
+
template <class MaskType, class FlagType> inline bool testFlag(MaskType mask, FlagType flag)
{
return (mask & MaskType(flag)) != 0;
@@ -1056,48 +1060,6 @@ QWindowsGLContext::QWindowsGLContext(QOpenGLStaticContext *staticContext,
if (!m_staticContext) // Something went very wrong. Stop here, isValid() will return false.
return;
- QVariant nativeHandle = context->nativeHandle();
- if (!nativeHandle.isNull()) {
- // Adopt and existing context.
- if (!nativeHandle.canConvert<QWGLNativeContext>()) {
- qWarning("QWindowsGLContext: Requires a QWGLNativeContext");
- return;
- }
- auto handle = nativeHandle.value<QWGLNativeContext>();
- HGLRC wglcontext = handle.context();
- HWND wnd = handle.window();
- if (!wglcontext || !wnd) {
- qWarning("QWindowsGLContext: No context and window given");
- return;
- }
-
- HDC dc = GetDC(wnd);
- // A window with an associated pixel format is mandatory.
- // When no SetPixelFormat() call has been made, the following will fail.
- m_pixelFormat = GetPixelFormat(dc);
- bool ok = m_pixelFormat != 0;
- if (!ok)
- qWarning("QWindowsGLContext: Failed to get pixel format");
- ok = DescribePixelFormat(dc, m_pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &m_obtainedPixelFormatDescriptor);
- if (!ok) {
- qWarning("QWindowsGLContext: Failed to describe pixel format");
- } else {
- QWindowsOpenGLAdditionalFormat obtainedAdditional;
- m_obtainedFormat = GDI::qSurfaceFormatFromPixelFormat(m_obtainedPixelFormatDescriptor, &obtainedAdditional);
- m_renderingContext = wglcontext;
- ok = updateObtainedParams(dc);
- }
-
- ReleaseDC(wnd, dc);
-
- if (ok)
- m_ownsContext = false;
- else
- m_renderingContext = nullptr;
-
- return;
- }
-
QSurfaceFormat format = context->format();
if (format.renderableType() == QSurfaceFormat::DefaultRenderableType)
format.setRenderableType(QSurfaceFormat::OpenGL);
@@ -1199,11 +1161,6 @@ QWindowsGLContext::QWindowsGLContext(QOpenGLStaticContext *staticContext,
} while (false);
- // Make the HGLRC retrievable via QOpenGLContext::nativeHandle().
- // Do not provide the window since it is the dummy one and it is about to disappear.
- if (m_renderingContext)
- context->setNativeHandle(QVariant::fromValue<QWGLNativeContext>(QWGLNativeContext(m_renderingContext, nullptr)));
-
if (hdc)
ReleaseDC(dummyWindow, hdc);
if (dummyWindow)
@@ -1217,6 +1174,37 @@ QWindowsGLContext::QWindowsGLContext(QOpenGLStaticContext *staticContext,
<< "\n HGLRC=" << m_renderingContext;
}
+QWindowsGLContext::QWindowsGLContext(QOpenGLStaticContext *staticContext, HGLRC wglcontext, HWND wnd)
+ : m_staticContext(staticContext)
+{
+ if (!m_staticContext) // Something went very wrong. Stop here, isValid() will return false.
+ return;
+
+ HDC dc = GetDC(wnd);
+ // A window with an associated pixel format is mandatory.
+ // When no SetPixelFormat() call has been made, the following will fail.
+ m_pixelFormat = GetPixelFormat(dc);
+ bool ok = m_pixelFormat != 0;
+ if (!ok)
+ qWarning("QWindowsGLContext: Failed to get pixel format");
+ ok = DescribePixelFormat(dc, m_pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &m_obtainedPixelFormatDescriptor);
+ if (!ok) {
+ qWarning("QWindowsGLContext: Failed to describe pixel format");
+ } else {
+ QWindowsOpenGLAdditionalFormat obtainedAdditional;
+ m_obtainedFormat = GDI::qSurfaceFormatFromPixelFormat(m_obtainedPixelFormatDescriptor, &obtainedAdditional);
+ m_renderingContext = wglcontext;
+ ok = updateObtainedParams(dc);
+ }
+
+ ReleaseDC(wnd, dc);
+
+ if (ok)
+ m_ownsContext = false;
+ else
+ m_renderingContext = nullptr;
+}
+
QWindowsGLContext::~QWindowsGLContext()
{
if (m_renderingContext && m_ownsContext)
diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h
index 608cc9cfea..2970f3d333 100644
--- a/src/plugins/platforms/windows/qwindowsglcontext.h
+++ b/src/plugins/platforms/windows/qwindowsglcontext.h
@@ -174,6 +174,7 @@ public:
static QByteArray getGlString(unsigned int which);
QWindowsOpenGLContext *createContext(QOpenGLContext *context) override;
+ QWindowsOpenGLContext *createContext(HGLRC context, HWND window) override;
void *moduleHandle() const override { return opengl32.moduleHandle(); }
QOpenGLContext::OpenGLModuleType moduleType() const override
{ return QOpenGLContext::LibGL; }
@@ -199,10 +200,12 @@ public:
static QWindowsOpengl32DLL opengl32;
};
-class QWindowsGLContext : public QWindowsOpenGLContext
+class QWindowsGLContext : public QWindowsOpenGLContext, public QPlatformInterface::QWGLContext
{
public:
explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, QOpenGLContext *context);
+ explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, HGLRC context, HWND window);
+
~QWindowsGLContext() override;
bool isSharing() const override { return context()->shareHandle(); }
bool isValid() const override { return m_renderingContext && !m_lost; }
@@ -219,7 +222,7 @@ public:
HGLRC renderingContext() const { return m_renderingContext; }
- void *nativeContext() const override { return m_renderingContext; }
+ HGLRC nativeContext() const override { return m_renderingContext; }
private:
typedef GLenum (APIENTRY *GlGetGraphicsResetStatusArbType)();
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index 96abfe5b01..ea077bc695 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -475,6 +475,33 @@ QOpenGLContext::OpenGLModuleType QWindowsIntegration::openGLModuleType()
#endif
}
+HMODULE QWindowsIntegration::openGLModuleHandle() const
+{
+ if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext())
+ return static_cast<HMODULE>(staticOpenGLContext->moduleHandle());
+
+ return nullptr;
+}
+
+QOpenGLContext *QWindowsIntegration::createOpenGLContext(HGLRC ctx, HWND window, QOpenGLContext *shareContext) const
+{
+ if (!ctx || !window)
+ return nullptr;
+
+ if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext()) {
+ QScopedPointer<QWindowsOpenGLContext> result(staticOpenGLContext->createContext(ctx, window));
+ if (result->isValid()) {
+ auto *context = new QOpenGLContext;
+ context->setShareContext(shareContext);
+ auto *contextPrivate = QOpenGLContextPrivate::get(context);
+ contextPrivate->adopt(result.take());
+ return context;
+ }
+ }
+
+ return nullptr;
+}
+
QWindowsStaticOpenGLContext *QWindowsIntegration::staticOpenGLContext()
{
QWindowsIntegration *integration = QWindowsIntegration::instance();
diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h
index 3c3763745c..348da5c58c 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.h
+++ b/src/plugins/platforms/windows/qwindowsintegration.h
@@ -44,6 +44,8 @@
#include <qpa/qplatformintegration.h>
#include <QtCore/qscopedpointer.h>
#include <QtGui/private/qwindowsfontdatabase_p.h>
+#include <QtGui/private/qopenglcontext_p.h>
+#include <qpa/qplatformopenglcontext.h>
QT_BEGIN_NAMESPACE
@@ -52,7 +54,7 @@ struct QWindowsWindowData;
class QWindowsWindow;
class QWindowsStaticOpenGLContext;
-class QWindowsIntegration : public QPlatformIntegration
+class QWindowsIntegration : public QPlatformIntegration, public QPlatformInterface::Private::QWindowsGLIntegration
{
Q_DISABLE_COPY_MOVE(QWindowsIntegration)
public:
@@ -87,6 +89,9 @@ public:
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
QOpenGLContext::OpenGLModuleType openGLModuleType() override;
static QWindowsStaticOpenGLContext *staticOpenGLContext();
+
+ HMODULE openGLModuleHandle() const override;
+ QOpenGLContext *createOpenGLContext(HGLRC context, HWND window, QOpenGLContext *shareContext) const;
#endif
QAbstractEventDispatcher *createEventDispatcher() const override;
void initialize() override;
diff --git a/src/plugins/platforms/windows/qwindowsopenglcontext.h b/src/plugins/platforms/windows/qwindowsopenglcontext.h
index 6d9c85f738..78ff23669c 100644
--- a/src/plugins/platforms/windows/qwindowsopenglcontext.h
+++ b/src/plugins/platforms/windows/qwindowsopenglcontext.h
@@ -57,6 +57,7 @@ public:
virtual ~QWindowsStaticOpenGLContext() = default;
virtual QWindowsOpenGLContext *createContext(QOpenGLContext *context) = 0;
+ virtual QWindowsOpenGLContext *createContext(HGLRC context, HWND window) = 0;
virtual void *moduleHandle() const = 0;
virtual QOpenGLContext::OpenGLModuleType moduleType() const = 0;
virtual bool supportsThreadedOpenGL() const { return false; }
@@ -77,9 +78,6 @@ class QWindowsOpenGLContext : public QPlatformOpenGLContext
{
Q_DISABLE_COPY_MOVE(QWindowsOpenGLContext)
public:
- // Returns the native context handle (e.g. HGLRC for WGL).
- virtual void *nativeContext() const = 0;
-
// These should be implemented only for some winsys interfaces, for example EGL.
// For others, like WGL, they are not relevant.
virtual void *nativeDisplay() const { return nullptr; }
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h
index af394d12ed..a2d677a82f 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h
@@ -43,16 +43,15 @@
#include "qxcbeglwindow.h"
#include <QtEglSupport/private/qeglplatformcontext_p.h>
#include <QtEglSupport/private/qeglpbuffer_p.h>
-#include <QtPlatformHeaders/QEGLNativeContext>
QT_BEGIN_NAMESPACE
class QXcbEglContext : public QEGLPlatformContext
{
public:
- QXcbEglContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
- EGLDisplay display, const QVariant &nativeHandle)
- : QEGLPlatformContext(glFormat, share, display, nullptr, nativeHandle)
+ using QEGLPlatformContext::QEGLPlatformContext;
+ QXcbEglContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share, EGLDisplay display)
+ : QEGLPlatformContext(glFormat, share, display, nullptr)
{
}
@@ -86,10 +85,6 @@ public:
else
return static_cast<QEGLPbuffer *>(surface)->pbuffer();
}
-
- QVariant nativeHandle() const {
- return QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(eglContext(), eglDisplay()));
- }
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp
index fe18bc24db..5f6c7bf903 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp
@@ -101,12 +101,15 @@ QPlatformOpenGLContext *QXcbEglIntegration::createPlatformOpenGLContext(QOpenGLC
QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
QXcbEglContext *platformContext = new QXcbEglContext(screen->surfaceFormatFor(context->format()),
context->shareHandle(),
- eglDisplay(),
- context->nativeHandle());
- context->setNativeHandle(platformContext->nativeHandle());
+ eglDisplay());
return platformContext;
}
+QOpenGLContext *QXcbEglIntegration::createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const
+{
+ return QEGLPlatformContext::createFrom<QXcbEglContext>(context, display, eglDisplay(), shareContext);
+}
+
QPlatformOffscreenSurface *QXcbEglIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
QXcbScreen *screen = static_cast<QXcbScreen *>(surface->screen()->handle());
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h
index 54a9f5cd83..ddb4488105 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.h
@@ -45,6 +45,7 @@
#include "qxcbeglwindow.h"
#include <QtGui/QOpenGLContext>
+#include <qpa/qplatformopenglcontext.h>
#include <QtGui/qpa/qplatformscreen.h>
#include <QtGui/QScreen>
@@ -57,6 +58,7 @@ QT_BEGIN_NAMESPACE
class QXcbEglNativeInterfaceHandler;
class QXcbEglIntegration : public QXcbGlIntegration
+ , public QPlatformInterface::Private::QEGLIntegration
{
public:
QXcbEglIntegration();
@@ -66,6 +68,7 @@ public:
QXcbWindow *createWindow(QWindow *window) const override;
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
+ QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override;
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
bool supportsThreadedOpenGL() const override { return true; }
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
index ca9cb4c86a..feae5fa13c 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
@@ -56,7 +56,6 @@
#include "qglxintegration.h"
#include <QtGlxSupport/private/qglxconvenience_p.h>
-#include <QtPlatformHeaders/QGLXNativeContext>
#include "qxcbglintegration.h"
@@ -219,26 +218,11 @@ static void updateFormatFromContext(QSurfaceFormat &format)
}
}
-QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share,
- const QVariant &nativeHandle)
+QGLXContext::QGLXContext(Display *display, QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share)
: QPlatformOpenGLContext()
- , m_display(static_cast<Display *>(screen->connection()->xlib_display()))
- , m_config(nullptr)
- , m_context(nullptr)
- , m_shareContext(nullptr)
+ , m_display(display)
, m_format(format)
- , m_isPBufferCurrent(false)
- , m_ownsContext(nativeHandle.isNull())
- , m_getGraphicsResetStatus(nullptr)
- , m_lost(false)
-{
- if (nativeHandle.isNull())
- init(screen, share);
- else
- init(screen, share, nativeHandle);
-}
-
-void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share)
+ , m_ownsContext(true)
{
if (m_format.renderableType() == QSurfaceFormat::DefaultRenderableType)
#if QT_CONFIG(opengles2)
@@ -423,49 +407,15 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share)
XDestroyWindow(m_display, window);
}
-void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const QVariant &nativeHandle)
+QGLXContext::QGLXContext(Display *display, GLXContext context, void *visualInfo, QPlatformOpenGLContext *share)
+ : QPlatformOpenGLContext()
+ , m_display(display)
{
- if (!nativeHandle.canConvert<QGLXNativeContext>()) {
- qWarning("QGLXContext: Requires a QGLXNativeContext");
- return;
- }
- QGLXNativeContext handle = qvariant_cast<QGLXNativeContext>(nativeHandle);
- GLXContext context = handle.context();
- if (!context) {
- qWarning("QGLXContext: No GLXContext given");
- return;
- }
+ // Legacy contexts created using glXCreateContext are created using a
+ // XVisualInfo. If the user passed one we should use that.
+ XVisualInfo *vinfo = static_cast<XVisualInfo*>(visualInfo);
- // Legacy contexts created using glXCreateContext are created using a visual
- // and the FBConfig cannot be queried. The only way to adapt these contexts
- // is to figure out the visual id.
- XVisualInfo *vinfo = nullptr;
- // If the VisualID is provided use it.
- VisualID vid = handle.visualId();
- if (!vid) {
- // In the absence of the VisualID figure it out from the window.
- Window wnd = handle.window();
- if (wnd) {
- XWindowAttributes attrs;
- XGetWindowAttributes(m_display, wnd, &attrs);
- vid = XVisualIDFromVisual(attrs.visual);
- }
- }
- if (vid) {
- XVisualInfo v;
- v.screen = screen->screenNumber();
- v.visualid = vid;
- int n = 0;
- vinfo = XGetVisualInfo(m_display, VisualScreenMask | VisualIDMask, &v, &n);
- if (n < 1) {
- XFree(vinfo);
- vinfo = nullptr;
- }
- }
-
- // For contexts created with an FBConfig using the modern functions providing the
- // visual or window is not mandatory. Just query the config from the context.
- GLXFBConfig config = nullptr;
+ // Otherwise assume the context was created with an FBConfig using the modern functions
if (!vinfo) {
int configId = 0;
if (glXQueryContext(m_display, context, GLX_FBCONFIG_ID, &configId) != Success) {
@@ -490,19 +440,17 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const
if (configs && numConfigs > 1) // this is suspicious so warn but let it continue
qWarning("QGLXContext: Multiple configs for FBConfig ID %d", configId);
- config = configs[0];
- // Store the config.
- m_config = config;
+ m_config = configs[0];
}
- Q_ASSERT(vinfo || config);
+ Q_ASSERT(vinfo || m_config);
int screenNumber = DefaultScreen(m_display);
Window window;
if (vinfo)
window = createDummyWindow(m_display, vinfo, screenNumber, RootWindow(m_display, screenNumber));
else
- window = createDummyWindow(m_display, config, screenNumber, RootWindow(m_display, screenNumber));
+ window = createDummyWindow(m_display, m_config, screenNumber, RootWindow(m_display, screenNumber));
if (!window) {
qWarning("QGLXContext: Failed to create dummy window");
return;
@@ -522,7 +470,7 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const
if (vinfo)
qglx_surfaceFormatFromVisualInfo(&m_format, m_display, vinfo);
else
- qglx_surfaceFormatFromGLXFBConfig(&m_format, m_display, config);
+ qglx_surfaceFormatFromGLXFBConfig(&m_format, m_display, m_config);
glXMakeCurrent(m_display, prevDrawable, prevContext);
XDestroyWindow(m_display, window);
@@ -553,11 +501,6 @@ static QXcbScreen *screenForPlatformSurface(QPlatformSurface *surface)
return nullptr;
}
-QVariant QGLXContext::nativeHandle() const
-{
- return QVariant::fromValue<QGLXNativeContext>(QGLXNativeContext(m_context));
-}
-
bool QGLXContext::makeCurrent(QPlatformSurface *surface)
{
bool success = false;
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h
index 2a88fd6e59..a7468c8fac 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.h
@@ -53,11 +53,12 @@
QT_BEGIN_NAMESPACE
-class QGLXContext : public QPlatformOpenGLContext
+class QGLXContext : public QPlatformOpenGLContext,
+ public QPlatformInterface::QGLXContext
{
public:
- QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share,
- const QVariant &nativeHandle);
+ QGLXContext(Display *display, QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share);
+ QGLXContext(Display *display, GLXContext context, void *visualInfo, QPlatformOpenGLContext *share);
~QGLXContext();
bool makeCurrent(QPlatformSurface *surface) override;
@@ -69,27 +70,24 @@ public:
bool isSharing() const override;
bool isValid() const override;
+ GLXContext nativeContext() const override { return glxContext(); }
+
GLXContext glxContext() const { return m_context; }
GLXFBConfig glxConfig() const { return m_config; }
- QVariant nativeHandle() const;
-
static bool supportsThreading();
static void queryDummyContext();
private:
- void init(QXcbScreen *screen, QPlatformOpenGLContext *share);
- void init(QXcbScreen *screen, QPlatformOpenGLContext *share, const QVariant &nativeHandle);
-
- Display *m_display;
- GLXFBConfig m_config;
- GLXContext m_context;
- GLXContext m_shareContext;
+ Display *m_display = nullptr;
+ GLXFBConfig m_config = nullptr;
+ GLXContext m_context = nullptr;
+ GLXContext m_shareContext = nullptr;
QSurfaceFormat m_format;
- bool m_isPBufferCurrent;
- bool m_ownsContext;
- GLenum (APIENTRY * m_getGraphicsResetStatus)();
- bool m_lost;
+ bool m_isPBufferCurrent = false;
+ bool m_ownsContext = false;
+ GLenum (APIENTRY * m_getGraphicsResetStatus)() = nullptr;
+ bool m_lost = false;
static bool m_queriedDummyContext;
static bool m_supportsThreading;
};
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp
index 6814dbd844..733df7df51 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp
@@ -49,6 +49,7 @@
#include "qglxintegration.h"
#include <QtGui/QOpenGLContext>
+#include <QtGui/private/qopenglcontext_p.h>
#include "qxcbglxnativeinterfacehandler.h"
@@ -187,10 +188,22 @@ QXcbWindow *QXcbGlxIntegration::createWindow(QWindow *window) const
QPlatformOpenGLContext *QXcbGlxIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
- QGLXContext *platformContext = new QGLXContext(screen, screen->surfaceFormatFor(context->format()),
- context->shareHandle(), context->nativeHandle());
- context->setNativeHandle(platformContext->nativeHandle());
- return platformContext;
+ return new QGLXContext(static_cast<Display *>(m_connection->xlib_display()),
+ screen, screen->surfaceFormatFor(context->format()), context->shareHandle());
+}
+
+QOpenGLContext *QXcbGlxIntegration::createOpenGLContext(GLXContext glxContext, void *visualInfo, QOpenGLContext *shareContext) const
+{
+ if (!glxContext)
+ return nullptr;
+
+ QPlatformOpenGLContext *shareHandle = shareContext ? shareContext->handle() : nullptr;
+
+ auto *context = new QOpenGLContext;
+ auto *contextPrivate = QOpenGLContextPrivate::get(context);
+ auto *display = static_cast<Display *>(m_connection->xlib_display());
+ contextPrivate->adopt(new QGLXContext(display, glxContext, visualInfo, shareHandle));
+ return context;
}
QPlatformOffscreenSurface *QXcbGlxIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h
index 26cb233a59..18c1be9489 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.h
@@ -46,7 +46,8 @@ QT_BEGIN_NAMESPACE
class QXcbNativeInterfaceHandler;
-class QXcbGlxIntegration : public QXcbGlIntegration
+class QXcbGlxIntegration : public QXcbGlIntegration,
+ public QPlatformInterface::Private::QGLXIntegration
{
public:
QXcbGlxIntegration();
@@ -58,6 +59,7 @@ public:
QXcbWindow *createWindow(QWindow *window) const override;
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
+ QOpenGLContext *createOpenGLContext(GLXContext context, void *visualInfo, QOpenGLContext *shareContext) const override;
bool supportsThreadedOpenGL() const override;
bool supportsSwitchableWidgetComposition() const override;
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index ff8b617d3a..fd64185852 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -275,7 +275,26 @@ QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLCont
}
return glIntegration->createPlatformOpenGLContext(context);
}
-#endif
+
+QOpenGLContext *QXcbIntegration::createOpenGLContext(GLXContext context, void *visualInfo, QOpenGLContext *shareContext) const
+{
+ using namespace QPlatformInterface::Private;
+ if (auto *glxIntegration = dynamic_cast<QGLXIntegration*>(m_connection->glIntegration()))
+ return glxIntegration->createOpenGLContext(context, visualInfo, shareContext);
+ else
+ return nullptr;
+}
+
+QOpenGLContext *QXcbIntegration::createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const
+{
+ using namespace QPlatformInterface::Private;
+ if (auto *eglIntegration = dynamic_cast<QEGLIntegration*>(m_connection->glIntegration()))
+ return eglIntegration->createOpenGLContext(context, display, shareContext);
+ else
+ return nullptr;
+}
+
+#endif // QT_NO_OPENGL
QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
{
diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h
index a67e79e0b8..37d2db394c 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.h
+++ b/src/plugins/platforms/xcb/qxcbintegration.h
@@ -43,6 +43,7 @@
#include <QtGui/private/qtguiglobal_p.h>
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformscreen.h>
+#include <qpa/qplatformopenglcontext.h>
#include "qxcbexport.h"
@@ -55,6 +56,8 @@ class QAbstractEventDispatcher;
class QXcbNativeInterface;
class Q_XCB_EXPORT QXcbIntegration : public QPlatformIntegration
+ , public QPlatformInterface::Private::QGLXIntegration
+ , public QPlatformInterface::Private::QEGLIntegration
{
public:
QXcbIntegration(const QStringList &parameters, int &argc, char **argv);
@@ -65,6 +68,8 @@ public:
QPlatformWindow *createForeignWindow(QWindow *window, WId nativeHandle) const override;
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
+ QOpenGLContext *createOpenGLContext(GLXContext context, void *visualInfo, QOpenGLContext *shareContext) const override;
+ QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override;
#endif
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override;