Browse Source

Make GL type a (hidden) setting, and enable ANGLE by default

We have much too many problems with desktop GL. Our hope is that ANGLE
will behave better.

This is messy due to interaction with QtWebEngine and the fact that it
will make QGuiApplication create/decide the GL type in the constructor.
On the other hand, most Qt stuff is not safe to be used before this
constructor is run. Our settings code definitely should run after it
(and changing it would cause an even larger mess).

To fix this, "mirror" the GL type setting as a special "use_opengl"
file, whose existence decides the GL type on init. If we make the
setting visible at a later point, the normal settings system will work,
except that it will require a restart (which needs to be done anyway).

For now, leave the setting hidden, though.
Vincent Lang 9 years ago
parent
commit
a172138813
2 changed files with 36 additions and 3 deletions
  1. 6 0
      resources/settings/settings_description.json
  2. 30 3
      src/main.cpp

+ 6 - 0
resources/settings/settings_description.json

@@ -73,6 +73,12 @@
           [ "fatal", "fatal" ],
           [ "disable", "disable" ]
         ]
+      },
+      {
+        "value": "useOpenGL",
+        "default": false,
+        "hidden": true,
+        "platforms": [ "windows" ]
       }
     ]
   },

+ 30 - 3
src/main.cpp

@@ -15,6 +15,7 @@
 #include "breakpad/CrashDumps.h"
 #include "Version.h"
 #include "settings/SettingsComponent.h"
+#include "settings/SettingsSection.h"
 #include "ui/KonvergoWindow.h"
 #include "ui/KonvergoEngine.h"
 #include "UniqueApplication.h"
@@ -27,13 +28,33 @@
 using namespace QsLogging;
 
 /////////////////////////////////////////////////////////////////////////////////////////
-void initQt(QGuiApplication* app)
+static void preinitQt()
 {
   QCoreApplication::setApplicationName(Names::MainName());
   QCoreApplication::setApplicationVersion(Version::GetVersionString());
   QCoreApplication::setOrganizationDomain("plex.tv");
 
-  app->setWindowIcon(QIcon(":/images/icon.png"));
+#ifdef Q_OS_WIN32
+  if (QFile::exists(Paths::dataDir("use_opengl")))
+    QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
+  else
+    QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
+#endif
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+static void updateGL(const QVariantMap& values)
+{
+#ifdef Q_OS_WIN32
+  QString path = Paths::dataDir("use_opengl");
+  if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "useOpenGL").toBool())
+  {
+    QFile f(path);
+    f.open(QIODevice::WriteOnly);
+  }
+  else
+    QFile::remove(path);
+#endif
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -199,8 +220,9 @@ int main(int argc, char *argv[])
     QSurfaceFormat::setDefaultFormat(format);
 #endif
 
+    preinitQt();
     QGuiApplication app(newArgc, newArgv);
-    initQt(&app);
+    app.setWindowIcon(QIcon(":/images/icon.png"));
 
     // init breakpad.
     setupCrashDumper();
@@ -240,6 +262,11 @@ int main(int argc, char *argv[])
     //
     ComponentManager::Get().initialize();
 
+    auto mainSection = SettingsComponent::Get().getSection("main");
+    if (mainSection)
+      QObject::connect(mainSection, &SettingsSection::valuesUpdated, &updateGL);
+    updateGL(QVariantMap{});
+
     // enable remote inspection if we have the correct setting for it.
     if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
       qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");