From 66c5bb0efa6ac2a9a7bef8a4776150fdaf129353 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Mon, 9 Aug 2021 10:01:13 +0200 Subject: [PATCH] qtquicksettings: Add workaround for Nvidia Wayland If using threaded rendering on wayland, QtQuick windows stop working when they are resized. As a workaround we can use the basic render loop. See also QTBUG-95817. CCBUG:432062 --- src/quickaddons/qtquicksettings.cpp | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/quickaddons/qtquicksettings.cpp b/src/quickaddons/qtquicksettings.cpp index 8ab0ce55..29595aef 100644 --- a/src/quickaddons/qtquicksettings.cpp +++ b/src/quickaddons/qtquicksettings.cpp @@ -1,6 +1,7 @@ /* SPDX-FileCopyrightText: 2016 David Edmundson SPDX-FileCopyrightText: 2020 Piotr Henryk Dabrowski + SPDX-FileCopyrightText: 2021 David Redondo SPDX-License-Identifier: LGPL-2.0-or-later */ @@ -10,7 +11,9 @@ #include #include +#include #include +#include #include #include #include @@ -22,7 +25,7 @@ * * @returns true if the selected backend is supported, false on fallback to software mode. */ -static bool checkBackend() +static bool checkBackend(QOpenGLContext &checkContext) { if (!QQuickWindow::sceneGraphBackend().isEmpty()) { return true; // QtQuick is not configured to use the OpenGL backend @@ -38,9 +41,7 @@ static bool checkBackend() #ifdef QT_NO_OPENGL bool ok = false; #else - QOpenGLContext *gl = new QOpenGLContext(); - bool ok = gl->create(); - delete gl; + bool ok = checkContext.create(); #endif if (!ok) { qWarning("Warning: fallback to QtQuick software backend."); @@ -57,15 +58,29 @@ void KQuickAddons::QtQuickSettings::init() } PlasmaQtQuickSettings::RendererSettings s; - if (!s.renderLoop().isEmpty() && !qEnvironmentVariableIsSet("QSG_RENDER_LOOP")) { - qputenv("QSG_RENDER_LOOP", s.renderLoop().toLatin1()); - } - + QOpenGLContext checkContext; if (!s.sceneGraphBackend().isEmpty()) { QQuickWindow::setSceneGraphBackend(s.sceneGraphBackend()); } else { QQuickWindow::setSceneGraphBackend(QStringLiteral("")); - checkBackend(); + checkBackend(checkContext); + } + + if (!qEnvironmentVariableIsSet("QSG_RENDER_LOOP")) { + if (!s.renderLoop().isEmpty()) { + qputenv("QSG_RENDER_LOOP", s.renderLoop().toLatin1()); + } else if (QGuiApplication::platformName() == QLatin1String("wayland")) { + // Workaround for Bug 432062 / QTBUG-95817 + QOffscreenSurface surface; + surface.create(); + if (checkContext.makeCurrent(&surface)) { + const char *vendor = reinterpret_cast(checkContext.functions()->glGetString(GL_VENDOR)); + if (qstrcmp(vendor, "NVIDIA Corporation") == 0) { + // Otherwise Qt Quick Windows break when resized + qputenv("QSG_RENDER_LOOP", "basic"); + } + } + } } auto format = QSurfaceFormat::defaultFormat(); -- GitLab