From 9807af617da28104a48c30ce50523f75a567e397 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 11 Apr 2023 10:05:09 +0200 Subject: [PATCH] rhi: Move generic setup code out of create() Change-Id: I5222dd5479fe5c23b20bd08a2908a85be4d25e45 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhi.cpp | 32 ++++++++++++++++++-------------- src/gui/rhi/qrhi_p_p.h | 2 ++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index ab920abaebd..ba24e44f762 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -5507,6 +5507,22 @@ QRhi::~QRhi() delete d; } +void QRhiImplementation::prepareForCreate(QRhi *rhi, QRhi::Implementation impl, QRhi::Flags flags) +{ + q = rhi; + + // Play nice with QSG_INFO since that is still the most commonly used + // way to get graphics info printed from Qt Quick apps, and the Quick + // scenegraph is our primary user. + if (qEnvironmentVariableIsSet("QSG_INFO")) + const_cast(QRHI_LOG_INFO()).setEnabled(QtDebugMsg, true); + + debugMarkers = flags.testFlag(QRhi::EnableDebugMarkers); + + implType = impl; + implThread = QThread::currentThread(); +} + /*! \return a new QRhi instance with a backend for the graphics API specified by \a impl with the specified \a flags. @@ -5594,21 +5610,9 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh } if (r->d) { - r->d->q = r.get(); - - // Play nice with QSG_INFO since that is still the most commonly used - // way to get graphics info printed from Qt Quick apps, and the Quick - // scenegraph is our primary user. - if (qEnvironmentVariableIsSet("QSG_INFO")) - const_cast(QRHI_LOG_INFO()).setEnabled(QtDebugMsg, true); - - r->d->debugMarkers = flags.testFlag(EnableDebugMarkers); - - if (r->d->create(flags)) { - r->d->implType = impl; - r->d->implThread = QThread::currentThread(); + r->d->prepareForCreate(r.get(), impl, flags); + if (r->d->create(flags)) return r.release(); - } } return nullptr; diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h index be31eee2d1e..7b2128024f6 100644 --- a/src/gui/rhi/qrhi_p_p.h +++ b/src/gui/rhi/qrhi_p_p.h @@ -140,6 +140,8 @@ public: virtual QByteArray pipelineCacheData() = 0; virtual void setPipelineCacheData(const QByteArray &data) = 0; + void prepareForCreate(QRhi *rhi, QRhi::Implementation impl, QRhi::Flags flags); + bool isCompressedFormat(QRhiTexture::Format format) const; void compressedFormatInfo(QRhiTexture::Format format, const QSize &size, quint32 *bpl, quint32 *byteSize,