diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-03-17 10:35:35 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-24 09:10:29 +0200 |
commit | af1e32426c50694c0e4c1c292aa5eeee3b38c7bc (patch) | |
tree | 041b8176b646e059b4a2cece890ac33fc1388a39 /tests | |
parent | 787692a09ee3e7e224ddb36b2c602bc3c37e9fab (diff) |
Add public and QPA APIs for adapting existing OpenGL contexts
For now only xcb on GLX is supported. Other platforms will follow later.
Add also some missing documentation for the platform OpenGL context factory
functions.
[ChangeLog] QOpenGLContext is now able to adopt existing native contexts.
Task-number: QTBUG-37552
Change-Id: I5dd959f102df178f646b2df5989203b5dc6de376
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/qopengl/qopengl.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 52 |
2 files changed, 53 insertions, 1 deletions
diff --git a/tests/auto/gui/qopengl/qopengl.pro b/tests/auto/gui/qopengl/qopengl.pro index 12429bbeed..fcf457fec4 100644 --- a/tests/auto/gui/qopengl/qopengl.pro +++ b/tests/auto/gui/qopengl/qopengl.pro @@ -10,3 +10,5 @@ QT += gui-private core-private testlib SOURCES += tst_qopengl.cpp win32-msvc2010:contains(QT_CONFIG, angle):CONFIG += insignificant_test # QTBUG-31611 + +linux:contains(QT_CONFIG, xcb-glx):contains(QT_CONFIG, xcb-xlib): DEFINES += USE_GLX 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" |