rhi: Make it possible to query the backend name beforehand
The goal is to make it possible to implement QSGRhiSupport::backendName() in Qt Quick with just a single line: return QString::fromUtf8(QRhi::backendName(m_rhiBackend)); instead of duplicating the strings and the logic. Similarly, QBackingStoreRhiSupport can now drop its apiName() helper entirely. Change-Id: Ia8cbb1f1243539ed4d7a98e71dcc2ed56b017e40 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
parent
5a136716a9
commit
a09e518f65
@ -232,25 +232,6 @@ QRhi::Implementation QBackingStoreRhiSupport::apiToRhiBackend(QPlatformBackingSt
|
|||||||
return QRhi::Null;
|
return QRhi::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *QBackingStoreRhiSupport::apiName(QPlatformBackingStoreRhiConfig::Api api)
|
|
||||||
{
|
|
||||||
switch (api) {
|
|
||||||
case QPlatformBackingStoreRhiConfig::OpenGL:
|
|
||||||
return "OpenGL";
|
|
||||||
case QPlatformBackingStoreRhiConfig::Metal:
|
|
||||||
return "Metal";
|
|
||||||
case QPlatformBackingStoreRhiConfig::Vulkan:
|
|
||||||
return "Vulkan";
|
|
||||||
case QPlatformBackingStoreRhiConfig::D3D11:
|
|
||||||
return "D3D11";
|
|
||||||
case QPlatformBackingStoreRhiConfig::Null:
|
|
||||||
return "Null";
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
|
bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
|
||||||
{
|
{
|
||||||
static QPlatformBackingStoreRhiConfig config;
|
static QPlatformBackingStoreRhiConfig config;
|
||||||
@ -304,7 +285,7 @@ bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outC
|
|||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(lcQpaBackingStore) << "Check for forced use of QRhi resulted in enable"
|
qCDebug(lcQpaBackingStore) << "Check for forced use of QRhi resulted in enable"
|
||||||
<< config.isEnabled() << "with api" << apiName(config.api());
|
<< config.isEnabled() << "with api" << QRhi::backendName(apiToRhiBackend(config.api()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.isEnabled()) {
|
if (config.isEnabled()) {
|
||||||
|
@ -44,7 +44,6 @@ public:
|
|||||||
static bool checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType);
|
static bool checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType);
|
||||||
|
|
||||||
static QRhi::Implementation apiToRhiBackend(QPlatformBackingStoreRhiConfig::Api api);
|
static QRhi::Implementation apiToRhiBackend(QPlatformBackingStoreRhiConfig::Api api);
|
||||||
static const char *apiName(QPlatformBackingStoreRhiConfig::Api api);
|
|
||||||
|
|
||||||
QRhi *rhi() const { return m_rhi; }
|
QRhi *rhi() const { return m_rhi; }
|
||||||
|
|
||||||
|
@ -5456,11 +5456,12 @@ QRhi::Implementation QRhi::backend() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\return the backend type as string for this QRhi.
|
\return a friendly name for the backend \a impl, usually the name of the 3D
|
||||||
|
API in use.
|
||||||
*/
|
*/
|
||||||
const char *QRhi::backendName() const
|
const char *QRhi::backendName(Implementation impl)
|
||||||
{
|
{
|
||||||
switch (d->implType) {
|
switch (impl) {
|
||||||
case QRhi::Null:
|
case QRhi::Null:
|
||||||
return "Null";
|
return "Null";
|
||||||
case QRhi::Vulkan:
|
case QRhi::Vulkan:
|
||||||
@ -5474,7 +5475,15 @@ const char *QRhi::backendName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
return nullptr;
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\return the backend type as string for this QRhi.
|
||||||
|
*/
|
||||||
|
const char *QRhi::backendName() const
|
||||||
|
{
|
||||||
|
return backendName(d->implType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1701,6 +1701,7 @@ public:
|
|||||||
|
|
||||||
Implementation backend() const;
|
Implementation backend() const;
|
||||||
const char *backendName() const;
|
const char *backendName() const;
|
||||||
|
static const char *backendName(Implementation impl);
|
||||||
QRhiDriverInfo driverInfo() const;
|
QRhiDriverInfo driverInfo() const;
|
||||||
QThread *thread() const;
|
QThread *thread() const;
|
||||||
|
|
||||||
|
@ -255,6 +255,7 @@ void tst_QRhi::create()
|
|||||||
|
|
||||||
QCOMPARE(rhi->backend(), impl);
|
QCOMPARE(rhi->backend(), impl);
|
||||||
QVERIFY(strcmp(rhi->backendName(), ""));
|
QVERIFY(strcmp(rhi->backendName(), ""));
|
||||||
|
QVERIFY(!strcmp(rhi->backendName(), QRhi::backendName(rhi->backend())));
|
||||||
QVERIFY(!rhi->driverInfo().deviceName.isEmpty());
|
QVERIFY(!rhi->driverInfo().deviceName.isEmpty());
|
||||||
QCOMPARE(rhi->thread(), QThread::currentThread());
|
QCOMPARE(rhi->thread(), QThread::currentThread());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user