diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-06-10 09:26:52 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-06-11 22:23:50 +0200 |
commit | 132e2fb2bf28c6aa3c1598deecf4d723f83396ec (patch) | |
tree | 805c55e6e49b2b05500b5ecf1f563fdf15e068be | |
parent | 2cb24f7054e1105be0dcb1a4d61a5b52d62d1a55 (diff) |
Make openglContext getter in QQuickWindow private
Fix up the scenegraph and qquickwindow autotests as well. (direct OpenGL
specifics are now completely removed from both, i.e. the remaning OpenGL
specific tests are now run (and not skipped) with OpenGL-on-RHI)
[ChangeLog][Qt Quick][QQuickWindow] openglContext() has been removed
from QQuickWindow. Use QSGRendererInterface to query the QOpenGLContext.
Change-Id: If5c9802b71ac5f9cffc695827e286eb2a2d03580
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/quick/items/qquickframebufferobject.cpp | 3 | ||||
-rw-r--r-- | src/quick/items/qquickgraphicsinfo.cpp | 5 | ||||
-rw-r--r-- | src/quick/items/qquickpainteditem.cpp | 6 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 30 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.h | 3 | ||||
-rw-r--r-- | src/quick/items/qquickwindow_p.h | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp | 17 | ||||
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 14 | ||||
-rw-r--r-- | tests/auto/quick/scenegraph/tst_scenegraph.cpp | 31 |
9 files changed, 35 insertions, 76 deletions
diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp index 1463d02c65..9026591119 100644 --- a/src/quick/items/qquickframebufferobject.cpp +++ b/src/quick/items/qquickframebufferobject.cpp @@ -44,6 +44,7 @@ #include <private/qquickitem_p.h> #include <private/qsgadaptationlayer_p.h> #include <qsgtextureprovider.h> +#include <QtGui/private/qrhi_p.h> #include <QSGSimpleTextureNode> #include <QSGRendererInterface> @@ -381,7 +382,7 @@ QSGTextureProvider *QQuickFramebufferObject::textureProvider() const Q_D(const QQuickFramebufferObject); QQuickWindow *w = window(); - if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) { + if (!w || !w->isSceneGraphInitialized() || QThread::currentThread() != QQuickWindowPrivate::get(w)->context->thread()) { qWarning("QQuickFramebufferObject::textureProvider: can only be queried on the rendering thread of an exposed window"); return nullptr; } diff --git a/src/quick/items/qquickgraphicsinfo.cpp b/src/quick/items/qquickgraphicsinfo.cpp index 0e711afcf2..c92ac611db 100644 --- a/src/quick/items/qquickgraphicsinfo.cpp +++ b/src/quick/items/qquickgraphicsinfo.cpp @@ -38,8 +38,7 @@ ****************************************************************************/ #include "qquickgraphicsinfo_p.h" -#include "qquickwindow.h" -#include "qquickitem.h" +#include <private/qquickitem_p.h> #include <qopenglcontext.h> QT_BEGIN_NAMESPACE @@ -265,7 +264,7 @@ void QQuickGraphicsInfo::updateInfo() QSurfaceFormat format = QSurfaceFormat::defaultFormat(); #if QT_CONFIG(opengl) if (m_window && m_window->isSceneGraphInitialized()) { - QOpenGLContext *context = m_window->openglContext(); + QOpenGLContext *context = QQuickWindowPrivate::get(m_window)->openglContext(); if (context) format = context->format(); } diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp index 1eb852f6bf..f7ceac9f29 100644 --- a/src/quick/items/qquickpainteditem.cpp +++ b/src/quick/items/qquickpainteditem.cpp @@ -44,9 +44,7 @@ #include <QtQuick/private/qsgcontext_p.h> #include <private/qsgadaptationlayer_p.h> #include <qsgtextureprovider.h> -#if QT_CONFIG(opengl) -#include <QOpenGLContext> -#endif // QT_CONFIG(opengl) +#include <QtGui/private/qrhi_p.h> #include <qmath.h> @@ -662,7 +660,7 @@ QSGTextureProvider *QQuickPaintedItem::textureProvider() const Q_D(const QQuickPaintedItem); #if QT_CONFIG(opengl) QQuickWindow *w = window(); - if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) { + if (!w || !w->isSceneGraphInitialized() || QThread::currentThread() != QQuickWindowPrivate::get(w)->context->thread()) { qWarning("QQuickPaintedItem::textureProvider: can only be queried on the rendering thread of an exposed window"); return nullptr; } diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index f7bebeff5a..7925d1a483 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -4012,23 +4012,14 @@ void QQuickWindow::setTransientParent_helper(QQuickWindow *window) this, SLOT(setTransientParent_helper(QQuickWindow*))); } -/*! - Returns the OpenGL context used for rendering. - - \note If the scene graph is not ready, or the scene graph is not using - OpenGL (or RHI over OpenGL), this function will return null. - - \sa sceneGraphInitialized(), sceneGraphInvalidated() - */ -QOpenGLContext *QQuickWindow::openglContext() const +QOpenGLContext *QQuickWindowPrivate::openglContext() { #if QT_CONFIG(opengl) - Q_D(const QQuickWindow); - if (d->context && d->context->isValid()) { - QSGRendererInterface *rif = d->context->sceneGraphContext()->rendererInterface(d->context); + if (context && context->isValid()) { + QSGRendererInterface *rif = context->sceneGraphContext()->rendererInterface(context); if (rif) { - return reinterpret_cast<QOpenGLContext *>(rif->getResource(const_cast<QQuickWindow *>(this), - QSGRendererInterface::OpenGLContextResource)); + Q_Q(QQuickWindow); + return reinterpret_cast<QOpenGLContext *>(rif->getResource(q, QSGRendererInterface::OpenGLContextResource)); } } #endif @@ -4981,12 +4972,11 @@ void QQuickWindow::resetOpenGLState() { Q_D(QQuickWindow); - if (!openglContext()) + QOpenGLContext *ctx = d->openglContext(); + if (!ctx) return; - QOpenGLContext *ctx = openglContext(); QOpenGLFunctions *gl = ctx->functions(); - gl->glBindBuffer(GL_ARRAY_BUFFER, 0); gl->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); @@ -5635,11 +5625,7 @@ void QQuickWindow::scheduleRenderJob(QRunnable *job, RenderStage stage) } else if (stage == AfterSwapStage) { d->afterSwapJobs << job; } else if (stage == NoStage) { - if (d->renderControl && openglContext() -#if QT_CONFIG(opengl) - && openglContext()->thread() == QThread::currentThread() -#endif - ) { + if (d->renderControl && d->rhi && d->rhi->thread() == QThread::currentThread()) { job->run(); delete job; } else if (isExposed()) { diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h index 28ff08786a..acd289ff4a 100644 --- a/src/quick/items/qquickwindow.h +++ b/src/quick/items/qquickwindow.h @@ -58,7 +58,6 @@ class QSGTexture; class QInputMethodEvent; class QQuickWindowPrivate; class QQuickWindowAttached; -class QOpenGLContext; class QQmlIncubationController; class QInputMethodEvent; class QQuickCloseEvent; @@ -176,8 +175,6 @@ public: void setPersistentSceneGraph(bool persistent); bool isPersistentSceneGraph() const; - QOpenGLContext *openglContext() const; // ### Qt 6 consider if this is kept or not - bool isSceneGraphInitialized() const; void scheduleRenderJob(QRunnable *job, RenderStage schedule); diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index 89dbe2f5dd..6d2ff3753b 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -71,6 +71,7 @@ QT_BEGIN_NAMESPACE +class QOpenContext; class QOpenGLVertexArrayObjectHelper; class QQuickAnimatorController; class QQuickDragGrabber; @@ -336,6 +337,7 @@ public: QList<QRunnable *> afterSwapJobs; void runAndClearJobs(QList<QRunnable *> *jobs); + QOpenGLContext *openglContext(); QQuickWindow::GraphicsStateInfo rhiStateInfo; QRhi *rhi = nullptr; diff --git a/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp b/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp index aff081c4a8..09c423890b 100644 --- a/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp +++ b/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp @@ -35,11 +35,6 @@ #include "../../shared/util.h" -#if QT_CONFIG(opengl) -#include <qopenglcontext.h> -#include <QtGui/qsurfaceformat.h> -#endif - class tst_QQuickGraphicsInfo : public QQmlDataTest { Q_OBJECT @@ -66,18 +61,6 @@ void tst_QQuickGraphicsInfo::testProperties() const int expectedAPI = rif ? rif->graphicsApi() : QSGRendererInterface::Unknown; QCOMPARE(obj->property("api").toInt(), expectedAPI); - -#if QT_CONFIG(opengl) - if (expectedAPI == QSGRendererInterface::OpenGL) { - QCOMPARE(obj->property("shaderType").toInt(), int(QSGRendererInterface::GLSL)); - QVERIFY(view.openglContext()); - QSurfaceFormat format = view.openglContext()->format(); - QCOMPARE(obj->property("majorVersion").toInt(), format.majorVersion()); - QCOMPARE(obj->property("minorVersion").toInt(), format.minorVersion()); - QCOMPARE(obj->property("profile").toInt(), static_cast<int>(format.profile())); - QCOMPARE(obj->property("renderableType").toInt(), static_cast<int>(format.renderableType())); - } -#endif } QTEST_MAIN(tst_QQuickGraphicsInfo) diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index cd551c1837..871f80b027 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -2409,10 +2409,11 @@ void tst_qquickwindow::defaultSurfaceFormat() // Depth and stencil should be >= what has been requested. For real. But use // the context since the window's surface format is only partially updated // on most platforms. - const QOpenGLContext *openglContext = nullptr; - QTRY_VERIFY((openglContext = window.openglContext()) != nullptr); - QVERIFY(openglContext->format().depthBufferSize() >= 16); - QVERIFY(openglContext->format().stencilBufferSize() >= 8); + const QOpenGLContext *ctx = nullptr; + QTRY_VERIFY((ctx = static_cast<QOpenGLContext *>(window.rendererInterface()->getResource( + &window, QSGRendererInterface::OpenGLContextResource))) != nullptr); + QVERIFY(ctx->format().depthBufferSize() >= 16); + QVERIFY(ctx->format().stencilBufferSize() >= 8); #endif QSurfaceFormat::setDefaultFormat(savedDefaultFormat); } @@ -2539,7 +2540,10 @@ void tst_qquickwindow::testRenderJob() // Do a synchronized GL job. GLubyte readPixel[4] = {0, 0, 0, 0}; GlRenderJob *glJob = new GlRenderJob(readPixel); - if (window.openglContext()->thread() != QThread::currentThread()) { + QOpenGLContext *ctx = static_cast<QOpenGLContext *>(window.rendererInterface()->getResource( + &window, QSGRendererInterface::OpenGLContextResource)); + QVERIFY(ctx); + if (ctx->thread() != QThread::currentThread()) { QMutex mutex; QWaitCondition condition; glJob->mutex = &mutex; diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 34e2630019..8e79f89dc6 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -118,7 +118,6 @@ private slots: private: QQuickView *createView(const QString &file, QWindow *parent = nullptr, int x = -1, int y = -1, int w = -1, int h = -1); - bool isRunningOnOpenGLDirectly(); bool isRunningOnRhi(); }; @@ -411,8 +410,8 @@ void tst_SceneGraph::render_data() void tst_SceneGraph::render() { - if (!isRunningOnOpenGLDirectly() && !isRunningOnRhi()) - QSKIP("Skipping complex rendering tests due to not running with OpenGL or QRhi"); + if (!isRunningOnRhi()) + QSKIP("Skipping complex rendering tests due to not running with QRhi"); QFETCH(QString, file); QFETCH(QList<Sample>, baseStage); @@ -462,8 +461,8 @@ void tst_SceneGraph::render() // current on the other window. void tst_SceneGraph::hideWithOtherContext() { - if (!isRunningOnOpenGLDirectly()) - QSKIP("Skipping OpenGL context test due to not running with OpenGL"); + if (!isRunningOnRhi()) + QSKIP("Skipping OpenGL context test due to not running with QRhi"); QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); @@ -480,7 +479,12 @@ void tst_SceneGraph::hideWithOtherContext() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - renderingOnMainThread = view.openglContext()->thread() == QGuiApplication::instance()->thread(); + if (view.rendererInterface()->graphicsApi() != QSGRendererInterface::OpenGLRhi) + QSKIP("Skipping OpenGL context test due to not using OpenGL"); + + QOpenGLContext *ctx = static_cast<QOpenGLContext *>(view.rendererInterface()->getResource( + &view, QSGRendererInterface::OpenGLContextResource)); + renderingOnMainThread = ctx->thread() == QGuiApplication::instance()->thread(); // Make the local context current on the local window... context.makeCurrent(&window); @@ -526,21 +530,6 @@ void tst_SceneGraph::createTextureFromImage() QCOMPARE(texture->hasAlphaChannel(), expectedAlpha); } -bool tst_SceneGraph::isRunningOnOpenGLDirectly() -{ - static bool retval = false; - static bool decided = false; - if (!decided) { - decided = true; - QQuickView dummy; - dummy.show(); - if (QTest::qWaitForWindowExposed(&dummy)) - retval = dummy.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL; - dummy.hide(); - } - return retval; -} - bool tst_SceneGraph::isRunningOnRhi() { static bool retval = false; |