diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-08-26 18:00:21 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-08-31 11:26:10 +0200 |
commit | 0bf9faf0906de18d4fa8f36d99708b4a79df17e8 (patch) | |
tree | af614db7d0424a66177b7af05b6a9e365c02a653 /src/quick/scenegraph/qsgthreadedrenderloop.cpp | |
parent | 8d24373a79020105908f0077e25e6cb2e7a8c78e (diff) |
Make it possible to adopt an existing QRhi via QQuickGraphicsDevice
Just as QQuickRenderTarget allows with its (also \internal)
fromRhiRenderTarget to import (but not own) and existing
QRhiRenderTarget for a QQuickWindow, we can have the same for the QRhi
itself.
Having a fromRhi() in QQuickGraphicsDevice allows telling a
QQuickWindow to use an existing QRhi. This makes sense in particular
with QQuickRenderControl: one can now render two or more scenes (each
with its own QQuickWindow and QQuickRenderControl, but all using the
same QRhi under the hood) and then use the resulting textures with the
QRhi, because the QRhiTextures all belong to it to begin with.
While this is useful for applications in general, it is also an
enabler for modernizing QQuickWidget in the future, in case we choose
to do so.
Comes with an autotest case that, besides testing, is also a
demonstration of the feature. Once an application has rendered a frame
with the same QRhi from all the Qt Quick scenes, it can go on to do
something with the textures (e.g. compose them together in some other
window) because both belong to the same one QRhi.
Note that this comes with certain limitations, similarly to
QQuickGraphicsDevice::fromOpenGLContext. (the docs are noting this for
both functions now) For example, one cannot just pull out a QRhi from
under an on-screen QQuickWindow or QQuickView and expect it to be
usable in all cases, without limitations. For example, if the threaded
render loop is in use, using the QRhi extracted from the QQuickView is
a very bad idea. However, in the common QQuickRenderControl-based
cases this is not an issue because there one would render frames from
the (offscreen) QQuickWindows one by one on the same thread.
Change-Id: I91b8b1f11f1cb4a84824c47d3b1d4f31833dd61b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/scenegraph/qsgthreadedrenderloop.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgthreadedrenderloop.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index e89aaa26ef..d7502054df 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -275,6 +275,7 @@ public: QSGRenderThread(QSGThreadedRenderLoop *w, QSGRenderContext *renderContext) : wm(w) , rhi(nullptr) + , ownRhi(true) , offscreenSurface(nullptr) , animatorDriver(nullptr) , pendingUpdate(0) @@ -336,6 +337,7 @@ public: QSGThreadedRenderLoop *wm; QRhi *rhi; + bool ownRhi; QSGDefaultRenderContext *sgrc; QOffscreenSurface *offscreenSurface; @@ -555,7 +557,8 @@ void QSGRenderThread::invalidateGraphics(QQuickWindow *window, bool inDestructor window, dd->swapchain); } } - QSGRhiSupport::instance()->destroyRhi(rhi); + if (ownRhi) + QSGRhiSupport::instance()->destroyRhi(rhi); rhi = nullptr; qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- QRhi destroyed"); } else { @@ -636,7 +639,8 @@ void QSGRenderThread::handleDeviceLoss() sgrc->invalidate(); wm->releaseSwapchain(window); rhiDeviceLost = true; - QSGRhiSupport::instance()->destroyRhi(rhi); + if (ownRhi) + QSGRhiSupport::instance()->destroyRhi(rhi); rhi = nullptr; } @@ -898,7 +902,9 @@ void QSGRenderThread::ensureRhi() if (rhiDoomed) // no repeated attempts if the initial attempt failed return; QSGRhiSupport *rhiSupport = QSGRhiSupport::instance(); - rhi = rhiSupport->createRhi(window, offscreenSurface); + QSGRhiSupport::RhiCreateResult rhiResult = rhiSupport->createRhi(window, offscreenSurface); + rhi = rhiResult.rhi; + ownRhi = rhiResult.own; if (rhi) { rhiDeviceLost = false; rhiSampleCount = rhiSupport->chooseSampleCountForWindowWithRhi(window, rhi); |