diff options
Diffstat (limited to 'src/gui/painting/qbackingstorerhisupport.cpp')
-rw-r--r-- | src/gui/painting/qbackingstorerhisupport.cpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/gui/painting/qbackingstorerhisupport.cpp b/src/gui/painting/qbackingstorerhisupport.cpp index 05329d61c5..c8bbea2543 100644 --- a/src/gui/painting/qbackingstorerhisupport.cpp +++ b/src/gui/painting/qbackingstorerhisupport.cpp @@ -8,27 +8,14 @@ #if QT_CONFIG(opengl) #include <QtGui/qoffscreensurface.h> #include <QtGui/private/qopenglcontext_p.h> -#include <QtGui/private/qrhigles2_p.h> -#endif - -#ifdef Q_OS_WIN -#include <QtGui/private/qrhid3d11_p.h> -#include <QtGui/private/qrhid3d12_p.h> -#endif - -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) -#include <QtGui/private/qrhimetal_p.h> #endif #if QT_CONFIG(vulkan) -#include <QtGui/private/qrhivulkan_p.h> #include <QtGui/private/qvulkandefaultinstance_p.h> #endif QT_BEGIN_NAMESPACE -Q_DECLARE_LOGGING_CATEGORY(lcQpaBackingStore) - QBackingStoreRhiSupport::~QBackingStoreRhiSupport() { reset(); @@ -67,6 +54,19 @@ bool QBackingStoreRhiSupport::create() QOffscreenSurface *surface = nullptr; QRhi::Flags flags; + // These must be the same env.vars Qt Quick uses (as documented), in order + // to ensure symmetry in the behavior between a QQuickWindow and a + // (QRhi-based) widget top-level window. + if (qEnvironmentVariableIntValue("QSG_RHI_PREFER_SOFTWARE_RENDERER")) + flags |= QRhi::PreferSoftwareRenderer; + if (qEnvironmentVariableIntValue("QSG_RHI_PROFILE")) + flags |= QRhi::EnableDebugMarkers | QRhi::EnableTimestamps; + + if (m_config.api() == QPlatformBackingStoreRhiConfig::Null) { + QRhiNullInitParams params; + rhi = QRhi::create(QRhi::Null, ¶ms, flags); + } + #if QT_CONFIG(opengl) if (!rhi && m_config.api() == QPlatformBackingStoreRhiConfig::OpenGL) { surface = QRhiGles2InitParams::newFallbackSurface(m_format); @@ -86,7 +86,7 @@ bool QBackingStoreRhiSupport::create() params.enableDebugLayer = m_config.isDebugLayerEnabled(); rhi = QRhi::create(QRhi::D3D11, ¶ms, flags); if (!rhi && !flags.testFlag(QRhi::PreferSoftwareRenderer)) { - qCDebug(lcQpaBackingStore, "Failed to create a D3D device with default settings; " + qCDebug(lcQpaBackingStore, "Failed to create a D3D11 device with default settings; " "attempting to get a software rasterizer backed device instead"); flags |= QRhi::PreferSoftwareRenderer; rhi = QRhi::create(QRhi::D3D11, ¶ms, flags); @@ -95,19 +95,25 @@ bool QBackingStoreRhiSupport::create() QRhiD3D12InitParams params; params.enableDebugLayer = m_config.isDebugLayerEnabled(); rhi = QRhi::create(QRhi::D3D12, ¶ms, flags); + if (!rhi && !flags.testFlag(QRhi::PreferSoftwareRenderer)) { + qCDebug(lcQpaBackingStore, "Failed to create a D3D12 device with default settings; " + "attempting to get a software rasterizer backed device instead"); + flags |= QRhi::PreferSoftwareRenderer; + rhi = QRhi::create(QRhi::D3D12, ¶ms, flags); + } } } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (!rhi && m_config.api() == QPlatformBackingStoreRhiConfig::Metal) { QRhiMetalInitParams params; // For parity with Qt Quick, fall back to OpenGL when there is no Metal (f.ex. in macOS virtual machines). if (QRhi::probe(QRhi::Metal, ¶ms)) { rhi = QRhi::create(QRhi::Metal, ¶ms, flags); } else { - qCDebug(lcQpaBackingStore, "Metal does not seem to be supported. Falling back to OpenGL."); - rhi = QRhi::create(QRhi::OpenGLES2, ¶ms, flags); + qCDebug(lcQpaBackingStore, "Metal does not seem to be supported"); + return false; } } #endif @@ -188,13 +194,14 @@ QRhiSwapChain *QBackingStoreRhiSupport::swapChainForWindow(QWindow *window) bool QBackingStoreRhiSupportWindowWatcher::eventFilter(QObject *obj, QEvent *event) { - if (event->type() == QEvent::PlatformSurface - && static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) + if (event->type() == QEvent::WindowAboutToChangeInternal + || (event->type() == QEvent::PlatformSurface + && static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)) { QWindow *window = qobject_cast<QWindow *>(obj); auto it = m_rhiSupport->m_swapchains.find(window); if (it != m_rhiSupport->m_swapchains.end()) { - qCDebug(lcQpaBackingStore) << "SurfaceAboutToBeDestroyed received for tracked window" << window << "cleaning up swapchain"; + qCDebug(lcQpaBackingStore) << event << "received for" << window << "- cleaning up swapchain"; auto data = *it; m_rhiSupport->m_swapchains.erase(it); data.reset(); // deletes 'this' @@ -263,7 +270,7 @@ bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outC if (config.isEnabled()) { #if defined(Q_OS_WIN) config.setApi(QPlatformBackingStoreRhiConfig::D3D11); -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) config.setApi(QPlatformBackingStoreRhiConfig::Metal); #elif QT_CONFIG(opengl) config.setApi(QPlatformBackingStoreRhiConfig::OpenGL); @@ -283,7 +290,7 @@ bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outC if (backend == QStringLiteral("d3d12")) config.setApi(QPlatformBackingStoreRhiConfig::D3D12); #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (backend == QStringLiteral("metal")) config.setApi(QPlatformBackingStoreRhiConfig::Metal); #endif |