diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-06-24 17:34:45 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-07-04 19:48:28 +0200 |
commit | ae4765265b2ed9458b6ba9983284d850cc8e2d6d (patch) | |
tree | 70da3c8cbbc7e5e0bf8ab8237c79dfb5bb1ba6cc /src/quick | |
parent | 40ded579bd977dc8fc41aaa1cdfca36822d14fc6 (diff) |
Enable request setting the (gl) context current on rhi path
This was disabled due to the unmerged qtbase api change.
Change-Id: I38beb8f2aa11dc233765bcfe06e91940b64b5758
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/scenegraph/qsgrenderloop.cpp | 28 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgthreadedrenderloop.cpp | 31 |
2 files changed, 40 insertions, 19 deletions
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp index f3812f474a..d38b5649c7 100644 --- a/src/quick/scenegraph/qsgrenderloop.cpp +++ b/src/quick/scenegraph/qsgrenderloop.cpp @@ -149,9 +149,9 @@ void QSGRenderLoop::postJob(QQuickWindow *window, QRunnable *job) job->run(); } } else { - // ### needs https://codereview.qt-project.org/c/qt/qtbase/+/265231 -// if (window->rhi()) -// window->rhi()->makeThreadLocalNativeContextCurrent(); + QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window); + if (cd->rhi) + cd->rhi->makeThreadLocalNativeContextCurrent(); job->run(); } #else @@ -396,10 +396,12 @@ void QSGGuiThreadRenderLoop::windowDestroyed(QQuickWindow *window) // There may be no platform window if the window got closed. if (!window->handle()) surface = offscreenSurface; - if (!rhi) - current = gl->makeCurrent(surface); - else + if (rhi) { + rhi->makeThreadLocalNativeContextCurrent(); current = true; + } else { + current = gl->makeCurrent(surface); + } } if (Q_UNLIKELY(!current)) qCDebug(QSG_LOG_RENDERLOOP, "cleanup without an OpenGL context"); @@ -497,6 +499,7 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window) QSGRhiProfileConnection::instance()->initialize(rhi); current = true; + rhi->makeThreadLocalNativeContextCurrent(); // The sample count cannot vary between windows as we use the same // rendercontext for all of them. Decide it here and now. @@ -542,10 +545,17 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window) cd->context->initialize(&rcParams); } } else { - if (!rhi) - current = gl->makeCurrent(window); - else + if (rhi) { current = true; + // With the rhi making the (OpenGL) context current serves only one + // purpose: to enable external OpenGL rendering connected to one of + // the QQuickWindow signals (beforeSynchronizing, beforeRendering, + // etc.) to function like it did on the direct OpenGL path. For our + // own rendering this call would not be necessary. + rhi->makeThreadLocalNativeContextCurrent(); + } else { + current = gl->makeCurrent(window); + } } if (enableRhi && rhi && !cd->swapchain) { diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index b0e2e3acbf..db8e17a8e6 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -454,6 +454,7 @@ bool QSGRenderThread::event(QEvent *e) const bool alpha = ce->window->format().alphaBufferSize() > 0 && ce->window->color().alpha() != 255; const QSize readbackSize = windowSize * ce->window->effectiveDevicePixelRatio(); if (rhi) { + rhi->makeThreadLocalNativeContextCurrent(); syncAndRender(ce->image); } else { gl->makeCurrent(ce->window); @@ -482,12 +483,10 @@ bool QSGRenderThread::event(QEvent *e) WMJobEvent *ce = static_cast<WMJobEvent *>(e); Q_ASSERT(ce->window == window); if (window) { - if (rhi) { - // ### needs https://codereview.qt-project.org/c/qt/qtbase/+/265231 - //rhi->makeThreadLocalNativeContextCurrent(); - } else { + if (rhi) + rhi->makeThreadLocalNativeContextCurrent(); + else gl->makeCurrent(window); - } ce->job->run(); delete ce->job; ce->job = nullptr; @@ -543,6 +542,8 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor, bool current = true; if (gl) current = gl->makeCurrent(fallback ? static_cast<QSurface *>(fallback) : static_cast<QSurface *>(window)); + else if (rhi) + rhi->makeThreadLocalNativeContextCurrent(); if (Q_UNLIKELY(!current)) { qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- cleanup without an OpenGL context"); @@ -610,10 +611,12 @@ void QSGRenderThread::sync(bool inExpose, bool inGrab) Q_ASSERT_X(wm->m_lockedForSync, "QSGRenderThread::sync()", "sync triggered on bad terms as gui is not already locked..."); - bool current = false; + bool current = true; if (gl) { if (windowSize.width() > 0 && windowSize.height() > 0) current = gl->makeCurrent(window); + else + current = false; // Check for context loss. if (!current && !gl->isValid()) { QQuickWindowPrivate::get(window)->cleanupNodesOnShutdown(); @@ -629,7 +632,12 @@ void QSGRenderThread::sync(bool inExpose, bool inGrab) } } } else { - current = true; + // With the rhi making the (OpenGL) context current serves only one + // purpose: to enable external OpenGL rendering connected to one of + // the QQuickWindow signals (beforeSynchronizing, beforeRendering, + // etc.) to function like it did on the direct OpenGL path. For our + // own rendering this call would not be necessary. + rhi->makeThreadLocalNativeContextCurrent(); } if (current) { QQuickWindowPrivate *d = QQuickWindowPrivate::get(window); @@ -758,12 +766,14 @@ void QSGRenderThread::syncAndRender(QImage *grabImage) d->animationController->unlock(); } - bool current = false; + bool current = true; if (d->renderer && windowSize.width() > 0 && windowSize.height() > 0) { if (gl) current = gl->makeCurrent(window); - else - current = true; + else if (rhi) + rhi->makeThreadLocalNativeContextCurrent(); + } else { + current = false; } // Check for context loss (GL, RHI case handled after the beginFrame() above) if (gl) { @@ -892,6 +902,7 @@ void QSGRenderThread::run() } } if (!sgrc->rhi() && windowSize.width() > 0 && windowSize.height() > 0) { + rhi->makeThreadLocalNativeContextCurrent(); QSGDefaultRenderContext::InitParams rcParams; rcParams.rhi = rhi; rcParams.sampleCount = rhiSampleCount; |