ソースを参照

Probe ANGLE GLES version

The tricky part here is that ANGLE does not provide a way to do this
automatically. If you request 2, you get 2. If you request 3, and 3
can't be provided, it will fail. So we have to probe this manually.

This implies Qt has been patched to pass --disable-gpu to chromium.
(Because on Windows, chromium/QtWebEngine ignores the command line it is
given.)

Using GLES 3.x allows us to do higher quality video rendering. (Though
this also has to be manually enabled, and we don't provide an automatic
setting yet.)

Unfortunately, probing for ANGLE on Windows and EGL on Linux is very
different. For ANGLE, we actually want to try create a GL context with
the specified version, so this must happen _after_ Qt loads the platform
plugin. For EGL, we want to control which platform plugin gets loaded,
so we obviously have to do before that.

The OSX-specific code could run at any point, at least as long as we
pass --disable-gpu to QtWebEngine.

This also sets QML_USE_GLYPHCACHE_WORKAROUND, which is needed to make
the debug overlay render correctly on ES 3. We expect that Qt will make
a proper fix eventually.
Vincent Lang 8 年 前
コミット
36fc748a9e
3 ファイル変更65 行追加10 行削除
  1. 7 5
      src/main.cpp
  2. 56 4
      src/player/OpenGLDetect.cpp
  3. 2 1
      src/player/OpenGLDetect.h

+ 7 - 5
src/main.cpp

@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
     qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false");
 #endif
 
-    detectOpenGL();
+    detectOpenGLEarly();
 
     preinitQt();
 
@@ -146,14 +146,16 @@ int main(int argc, char *argv[])
       return 0;
     }
 
-#ifdef Q_OS_WIN32
-    initD3DDevice();
-#endif
-
 #ifdef Q_OS_UNIX
     setlocale(LC_NUMERIC, "C");
 #endif
 
+    detectOpenGLLate();
+
+#ifdef Q_OS_WIN32
+    initD3DDevice();
+#endif
+
     Codecs::preinitCodecs();
 
     // Initialize all the components. This needs to be done

+ 56 - 4
src/player/OpenGLDetect.cpp

@@ -1,15 +1,19 @@
 #include <QtGlobal>
 #include <QSurfaceFormat>
+#include <QCoreApplication>
+#include <QOpenGLContext>
 
 #include <mpv/client.h>
 #include <mpv/qthelper.hpp>
 
+#include "QsLog.h"
+
 #include "OpenGLDetect.h"
 
 #if defined(Q_OS_MAC)
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-void detectOpenGL()
+void detectOpenGLEarly()
 {
     // Request OpenGL 4.1 if possible on OSX, otherwise it defaults to 2.0
     // This needs to be done before we create the QGuiApplication
@@ -21,6 +25,11 @@ void detectOpenGL()
     QSurfaceFormat::setDefaultFormat(format);
 }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+void detectOpenGLLate()
+{
+}
+
 #elif defined(Q_OS_LINUX)
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -46,19 +55,62 @@ static QString probeHwdecInterop()
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-void detectOpenGL()
+void detectOpenGLEarly()
 {
   // The putenv call must happen before Qt initializes its platform stuff.
   if (probeHwdecInterop() == "vaapi-egl")
     qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl");
 }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+void detectOpenGLLate()
+{
+}
+
+#elif defined(Q_OS_WIN)
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+void detectOpenGLEarly()
+{
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+void detectOpenGLLate()
+{
+  if (!QCoreApplication::testAttribute(Qt::AA_UseOpenGLES))
+    return;
+
+  // Workaround for broken QSGDefaultDistanceFieldGlyphCache::resizeTexture in ES 3 mode
+  qputenv("QML_USE_GLYPHCACHE_WORKAROUND", "1");
+
+  QList<int> versions = { 3, 2 };
+  for (auto version : versions)
+  {
+    QLOG_INFO() << "Trying GLES version" << version;
+    QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
+    fmt.setMajorVersion(version);
+    QOpenGLContext ctx;
+    ctx.setFormat(fmt);
+    if (ctx.create())
+    {
+      QLOG_INFO() << "Using GLES version" << version;
+      QSurfaceFormat::setDefaultFormat(fmt);
+      break;
+    }
+  }
+}
+
 #else
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-void detectOpenGL()
+void detectOpenGLEarly()
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+void detectOpenGLLate()
 {
-  // nothing to do
 }
 
 #endif

+ 2 - 1
src/player/OpenGLDetect.h

@@ -1,6 +1,7 @@
 #ifndef OPENGLDETECT_H
 #define OPENGLDETECT_H
 
-void detectOpenGL();
+void detectOpenGLEarly();
+void detectOpenGLLate();
 
 #endif // OPENGLDETECT_H