KDeclarative

qtquicksettings.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 David Edmundson <[email protected]>
3  SPDX-FileCopyrightText: 2020 Piotr Henryk Dabrowski <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "qtquicksettings.h"
9 #include "renderersettings.h"
10 
11 #include <QSurfaceFormat>
12 #include <QQuickWindow>
13 #include <QLibraryInfo>
14 #include <QVersionNumber>
15 #include <QGuiApplication>
16 #include <QOpenGLContext>
17 
25 static bool checkBackend()
26 {
27  if (!QQuickWindow::sceneGraphBackend().isEmpty()) {
28  return true; // QtQuick is not configured to use the OpenGL backend
29  }
30 
31  // kwin wayland has it's own QPA, it is unable to create a GL context at this point.
32  // KF6 TODO, drop this . The issue will be resolved in future kwin releases.
33  QString platformName = qApp->platformName();
34  if (platformName == QLatin1String("wayland-org.kde.kwin.qpa")) {
35  return true;
36  }
37 
38  QOpenGLContext* gl = new QOpenGLContext();
39  bool ok = gl->create();
40  if (!ok) {
41  qWarning("Warning: fallback to QtQuick software backend.");
42  QQuickWindow::setSceneGraphBackend(QStringLiteral("software"));
43  }
44  delete gl;
45  return ok;
46 }
47 
49 {
50  if (!(qobject_cast<QGuiApplication*>qApp)) {
51  qWarning("Error: cannot call KQuickAddons::QtQuickSettings::init() before QGuiApplication is created.");
52  return;
53  }
54 
55  PlasmaQtQuickSettings::RendererSettings s;
56  if (!s.renderLoop().isEmpty() && !qEnvironmentVariableIsSet("QSG_RENDER_LOOP")) {
57  qputenv("QSG_RENDER_LOOP", s.renderLoop().toLatin1());
58  }
59 
60  if (!s.sceneGraphBackend().isEmpty()) {
61  QQuickWindow::setSceneGraphBackend(s.sceneGraphBackend());
62  } else {
63  QQuickWindow::setSceneGraphBackend(QStringLiteral(""));
64  checkBackend();
65  }
66 
67  auto format = QSurfaceFormat::defaultFormat();
68  if (s.forceGlCoreProfile()) {
69  format.setVersion(3,2);
70  format.setProfile(QSurfaceFormat::CoreProfile);
71  }
72  // Before Qt 5.12.2 this setting was somewhat unstable
73  // it was opt-in to find bugs both in KDE and Qt
74  // For 5.13 with modern plasma it should be fine
75  if (s.graphicsResetNotifications() ||
76  QLibraryInfo::version() >= QVersionNumber(5, 13, 0)) {
77  format.setOption(QSurfaceFormat::ResetNotification);
78  }
80 }
void setDefaultFormat(const QSurfaceFormat &format)
QString sceneGraphBackend()
void setSceneGraphBackend(QSGRendererInterface::GraphicsApi api)
QSurfaceFormat defaultFormat()
QUICKADDONS_EXPORT void init()
Load settings from the appConfig (app + kdeglobals) which relate to QtQuick rendering.
QVersionNumber version()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.