diff options
Diffstat (limited to 'tests/auto/gui/qopengl/tst_qopengl.cpp')
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 63fe8b9693..07a07210af 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -51,12 +51,19 @@ #include <QtGui/QGenericMatrix> #include <QtGui/QMatrix4x4> #include <QtGui/private/qopengltextureblitter_p.h> - +#include <QtGui/private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> +#include <qpa/qplatformnativeinterface.h> #include <QtTest/QtTest> #include <QSignalSpy> +#ifdef USE_GLX +// Must be included last due to the X11 types +#include <QtPlatformHeaders/QGLXNativeContext> +#endif + class tst_QOpenGL : public QObject { Q_OBJECT @@ -85,6 +92,10 @@ private slots: void textureblitterPartOriginTopLeftSourceRectTransform(); void textureblitterFullTargetRectTransform(); void textureblitterPartTargetRectTransform(); + +#ifdef USE_GLX + void glxContextWrap(); +#endif }; struct SharedResourceTracker @@ -970,6 +981,45 @@ void tst_QOpenGL::textureblitterPartTargetRectTransform() QCOMPARE(targetBottomRight, expectedBottomRight); } +#ifdef USE_GLX +void tst_QOpenGL::glxContextWrap() +{ + QWindow *window = new QWindow; + window->setSurfaceType(QWindow::OpenGLSurface); + window->setGeometry(0, 0, 10, 10); + window->show(); + QTest::qWaitForWindowExposed(window); + + QPlatformNativeInterface *nativeIf = QGuiApplicationPrivate::instance()->platformIntegration()->nativeInterface(); + QVERIFY(nativeIf); + + // Fetch a GLXContext. + 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(); + QVERIFY(context); + + // Then create another QOpenGLContext wrapping it. + QOpenGLContext *ctx = new QOpenGLContext; + ctx->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(QGLXNativeContext(context))); + QVERIFY(ctx->create()); + QVERIFY(ctx->nativeHandle().value<QGLXNativeContext>().context() == context); + QVERIFY(nativeIf->nativeResourceForContext(QByteArrayLiteral("glxcontext"), ctx) == (void *) context); + + QVERIFY(ctx->makeCurrent(window)); + ctx->doneCurrent(); + + delete ctx; + delete ctx0; + + delete window; +} +#endif // USE_GLX + QTEST_MAIN(tst_QOpenGL) #include "tst_qopengl.moc" |