Add QWidgetPrivate::rhi() helper method

For accessing the RHI managed by the widget compositing machinery.

Pick-to: 6.5
Change-Id: Ia3c1227cc2d9cfebe95611cad3dbcd7aa6f6f8c7
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit f451b01791536fede40c8d4fb90799c2e23e9386)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 9dbb295279f958e4ddd480bf9312b77643c80c0e)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2024-02-29 13:21:25 +01:00
parent e8b2047a9b
commit 32f9825efa
3 changed files with 14 additions and 9 deletions

View File

@ -779,9 +779,7 @@ void QOpenGLWidgetPrivate::ensureRhiDependentResources()
{
Q_Q(QOpenGLWidget);
QRhi *rhi = nullptr;
if (QWidgetRepaintManager *repaintManager = QWidgetPrivate::get(q->window())->maybeRepaintManager())
rhi = repaintManager->rhi();
QRhi *rhi = QWidgetPrivate::rhi();
// If there is no rhi, because we are completely offscreen, then there's no wrapperTexture either
if (rhi && rhi->backend() == QRhi::OpenGLES2) {
@ -827,7 +825,6 @@ void QOpenGLWidgetPrivate::initialize()
// If no global shared context get our toplevel's context with which we
// will share in order to make the texture usable by the underlying window's backingstore.
QWidget *tlw = q->window();
QWidgetPrivate *tlwd = get(tlw);
// Do not include the sample count. Requesting a multisampled context is not necessary
// since we render into an FBO, never to an actual surface. What's more, attempting to
@ -836,9 +833,7 @@ void QOpenGLWidgetPrivate::initialize()
requestedSamples = requestedFormat.samples();
requestedFormat.setSamples(0);
QRhi *rhi = nullptr;
if (QWidgetRepaintManager *repaintManager = tlwd->maybeRepaintManager())
rhi = repaintManager->rhi();
QRhi *rhi = QWidgetPrivate::rhi();
// Could be that something else already initialized the window with some
// other graphics API for the QRhi, that's not good.
@ -1686,8 +1681,8 @@ bool QOpenGLWidget::event(QEvent *e)
if (!QCoreApplication::testAttribute(Qt::AA_ShareOpenGLContexts))
d->reset();
}
if (QWidgetRepaintManager *repaintManager = QWidgetPrivate::get(window())->maybeRepaintManager()) {
if (!d->initialized && !size().isEmpty() && repaintManager->rhi()) {
if (d->rhi()) {
if (!d->initialized && !size().isEmpty()) {
d->initialize();
if (d->initialized) {
d->recreateFbos();

View File

@ -1021,6 +1021,14 @@ void QWidgetPrivate::createRecursively()
}
}
QRhi *QWidgetPrivate::rhi() const
{
if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
return repaintManager->rhi();
else
return nullptr;
}
/*!
\internal
Returns the closest parent widget that has a QWindow window handle

View File

@ -222,6 +222,8 @@ public:
void setSharedPainter(QPainter *painter);
QWidgetRepaintManager *maybeRepaintManager() const;
QRhi *rhi() const;
enum class WindowHandleMode {
Direct,
Closest,