diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-06-08 20:00:36 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-07-02 10:27:50 +0200 |
commit | 6ff79478a44fce12ca18832a56db4a370a9ff417 (patch) | |
tree | 2bcd7ab7bac46fe28e0828e0a704649bbc025e8f /tests | |
parent | 037dce81fc27ec241edb6829f6df41927b80666e (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 'tests')
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 38 | ||||
-rw-r--r-- | tests/manual/qopenglcontext/qopenglcontext.pro | 2 | ||||
-rw-r--r-- | tests/manual/qopenglcontext/qopenglcontextwindow.cpp | 16 | ||||
-rw-r--r-- | tests/manual/qopenglcontext/qopenglcontextwindow.h | 2 |
4 files changed, 23 insertions, 35 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index c093885951..b43defd2f3 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -52,15 +52,6 @@ #include <QSignalSpy> -#ifdef USE_GLX -// Must be included last due to the X11 types -#include <QtPlatformHeaders/QGLXNativeContext> -#endif - -#if defined(Q_OS_WIN32) && !QT_CONFIG(opengles2) -#include <QtPlatformHeaders/QWGLNativeContext> -#endif - Q_DECLARE_METATYPE(QImage::Format) class tst_QOpenGL : public QObject @@ -1480,6 +1471,8 @@ void tst_QOpenGL::defaultSurfaceFormat() QCOMPARE(context->format(), fmt); } +using namespace QPlatformInterface; + #ifdef USE_GLX void tst_QOpenGL::glxContextWrap() { @@ -1496,17 +1489,14 @@ void tst_QOpenGL::glxContextWrap() QOpenGLContext *ctx0 = new QOpenGLContext; ctx0->setFormat(window->format()); QVERIFY(ctx0->create()); - QVariant v = ctx0->nativeHandle(); - QVERIFY(!v.isNull()); - QVERIFY(v.canConvert<QGLXNativeContext>()); - GLXContext context = v.value<QGLXNativeContext>().context(); + auto *glxContextIf = ctx0->platformInterface<QGLXContext>(); + QVERIFY(glxContextIf); + GLXContext context = glxContextIf->nativeContext(); QVERIFY(context); // Then create another QOpenGLContext wrapping it. - QOpenGLContext *ctx = new QOpenGLContext; - ctx->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(QGLXNativeContext(context))); - QVERIFY(ctx->create()); - QCOMPARE(ctx->nativeHandle().value<QGLXNativeContext>().context(), context); + QOpenGLContext *ctx = QGLXContext::fromNative(context); + QVERIFY(ctx); QVERIFY(nativeIf->nativeResourceForContext(QByteArrayLiteral("glxcontext"), ctx) == (void *) context); QVERIFY(ctx->makeCurrent(window)); @@ -1533,11 +1523,9 @@ void tst_QOpenGL::wglContextWrap() window->show(); QVERIFY(QTest::qWaitForWindowExposed(window.data())); - QVariant v = ctx->nativeHandle(); - QVERIFY(!v.isNull()); - QVERIFY(v.canConvert<QWGLNativeContext>()); - QWGLNativeContext nativeContext = v.value<QWGLNativeContext>(); - QVERIFY(nativeContext.context()); + auto *wglContext = ctx->platformInterface<QWGLContext>(); + QVERIFY(wglContext); + QVERIFY(wglContext->nativeContext()); // Now do a makeCurrent() do make sure the pixel format on the native // window (the HWND we are going to retrieve below) is set. @@ -1547,9 +1535,9 @@ void tst_QOpenGL::wglContextWrap() HWND wnd = (HWND) qGuiApp->platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("handle"), window.data()); QVERIFY(wnd); - QScopedPointer<QOpenGLContext> adopted(new QOpenGLContext); - adopted->setNativeHandle(QVariant::fromValue<QWGLNativeContext>(QWGLNativeContext(nativeContext.context(), wnd))); - QVERIFY(adopted->create()); + QScopedPointer<QOpenGLContext> adopted(QWGLContext::fromNative(wglContext->nativeContext(), wnd)); + QVERIFY(!adopted.isNull()); + QVERIFY(adopted->isValid()); // This tests two things: that a regular, non-adopted QOpenGLContext is // able to return a QSurfaceFormat containing the real values after diff --git a/tests/manual/qopenglcontext/qopenglcontext.pro b/tests/manual/qopenglcontext/qopenglcontext.pro index 08a9ab407c..06e2fc2e3b 100644 --- a/tests/manual/qopenglcontext/qopenglcontext.pro +++ b/tests/manual/qopenglcontext/qopenglcontext.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = qopenglcontext -QT += gui-private egl_support-private +QT += gui-private egl_support-private opengl HEADERS += $$PWD/qopenglcontextwindow.h diff --git a/tests/manual/qopenglcontext/qopenglcontextwindow.cpp b/tests/manual/qopenglcontext/qopenglcontextwindow.cpp index 0763d7244c..67898c0028 100644 --- a/tests/manual/qopenglcontext/qopenglcontextwindow.cpp +++ b/tests/manual/qopenglcontext/qopenglcontextwindow.cpp @@ -34,7 +34,6 @@ #include <qpa/qplatformnativeinterface.h> #include <QtEglSupport/private/qeglconvenience_p.h> -#include <QtPlatformHeaders/QEGLNativeContext> QOpenGLContextWindow::QOpenGLContextWindow() : m_blitter(0) @@ -98,7 +97,12 @@ void QOpenGLContextWindow::createForeignContext() // underlying native context. This way the texture, that belongs to the context // created here, will be accessible from m_context too. - EGLContext shareCtx = m_context->nativeHandle().value<QEGLNativeContext>().context(); + using namespace QPlatformInterface; + auto *eglContext = m_context->platformInterface<QEGLContext>(); + if (!eglContext) + qFatal("Not running with EGL backend"); + + EGLContext shareCtx = eglContext->nativeContext(); Q_ASSERT(shareCtx != EGL_NO_CONTEXT); EGLDisplay dpy = (EGLDisplay) qGuiApp->platformNativeInterface()->nativeResourceForWindow( @@ -127,12 +131,8 @@ void QOpenGLContextWindow::createForeignContext() Q_ASSERT(ctx != EGL_NO_CONTEXT); // Wrap ctx into a QOpenGLContext. - QOpenGLContext *ctxWrap = new QOpenGLContext; - ctxWrap->setNativeHandle(QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(ctx, dpy))); - ctxWrap->setShareContext(m_context); // only needed for correct bookkeeping - if (!ctxWrap->create()) - qFatal("Failed to created wrapping context"); - Q_ASSERT(ctxWrap->nativeHandle().value<QEGLNativeContext>().context() == ctx); + QOpenGLContext *ctxWrap = QEGLContext::fromNative(ctx, dpy, m_context); + Q_ASSERT(ctxWrap->platformInterface<QEGLContext>()->nativeContext() == ctx); QOffscreenSurface surface; surface.setFormat(fmt); diff --git a/tests/manual/qopenglcontext/qopenglcontextwindow.h b/tests/manual/qopenglcontext/qopenglcontextwindow.h index 37ff1b2082..1a497a750c 100644 --- a/tests/manual/qopenglcontext/qopenglcontextwindow.h +++ b/tests/manual/qopenglcontext/qopenglcontextwindow.h @@ -31,7 +31,7 @@ #include <QtGui/QWindow> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTextureBlitter> +#include <QtOpenGL/QOpenGLTextureBlitter> #include <QtGui/QImage> #include <QtCore/QVariant> |