diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-07-01 09:25:29 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-07-05 13:04:09 +0200 |
commit | a09e518f6589fff7789ad7224badf24593240711 (patch) | |
tree | 301e00ecf67769cef433a059ae76477b0b46720c /src/gui | |
parent | 5a136716a93d27bca1e46eae98b05660d81ea1b9 (diff) |
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>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qbackingstorerhisupport.cpp | 21 | ||||
-rw-r--r-- | src/gui/painting/qbackingstorerhisupport_p.h | 1 | ||||
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 17 | ||||
-rw-r--r-- | src/gui/rhi/qrhi_p.h | 1 |
4 files changed, 15 insertions, 25 deletions
diff --git a/src/gui/painting/qbackingstorerhisupport.cpp b/src/gui/painting/qbackingstorerhisupport.cpp index 81b3f0eb7d..f55fbc5a15 100644 --- a/src/gui/painting/qbackingstorerhisupport.cpp +++ b/src/gui/painting/qbackingstorerhisupport.cpp @@ -232,25 +232,6 @@ QRhi::Implementation QBackingStoreRhiSupport::apiToRhiBackend(QPlatformBackingSt 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) { static QPlatformBackingStoreRhiConfig config; @@ -304,7 +285,7 @@ bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outC } 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()) { diff --git a/src/gui/painting/qbackingstorerhisupport_p.h b/src/gui/painting/qbackingstorerhisupport_p.h index c67ea6dd6a..c8aa8f46ea 100644 --- a/src/gui/painting/qbackingstorerhisupport_p.h +++ b/src/gui/painting/qbackingstorerhisupport_p.h @@ -44,7 +44,6 @@ public: static bool checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType); static QRhi::Implementation apiToRhiBackend(QPlatformBackingStoreRhiConfig::Api api); - static const char *apiName(QPlatformBackingStoreRhiConfig::Api api); QRhi *rhi() const { return m_rhi; } diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index d5c9cebac8..402902e24f 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -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: return "Null"; case QRhi::Vulkan: @@ -5474,7 +5475,15 @@ const char *QRhi::backendName() const } Q_UNREACHABLE(); - return nullptr; + return "Unknown"; +} + +/*! + \return the backend type as string for this QRhi. + */ +const char *QRhi::backendName() const +{ + return backendName(d->implType); } /*! diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index f825866585..6e95e4542b 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -1701,6 +1701,7 @@ public: Implementation backend() const; const char *backendName() const; + static const char *backendName(Implementation impl); QRhiDriverInfo driverInfo() const; QThread *thread() const; |