瀏覽代碼

Avoid a fullscreen copy on Windows/ANGLE

Request native surface orientation from Qt, which will do the same from
ANGLE. This allows ANGLE to skip a fullscreen copy on each frame, which
is done only to invert the coordinate system. It should give us some
speedup.

As a consequence, we also have to flip our own OpenGL rendering if the
coordinate system is inverted.

This relies on a custom Qt patch, and it's not clear whether it's going
to be upstreamed. It will still build even if the patch is not applied,
because the API extension is detected at configure time.
Vincent Lang 8 年之前
父節點
當前提交
4c2491198e
共有 3 個文件被更改,包括 29 次插入2 次删除
  1. 17 0
      CMakeModules/QtConfiguration.cmake
  2. 3 0
      src/player/OpenGLDetect.cpp
  3. 9 2
      src/player/PlayerQuickItem.cpp

+ 17 - 0
CMakeModules/QtConfiguration.cmake

@@ -72,3 +72,20 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QT5_CFLAGS}")
 
 set(CMAKE_REQUIRED_INCLUDES ${Qt5WebEngine_INCLUDE_DIRS};${Qt5WebEngine_PRIVATE_INCLUDE_DIRS})
 set(CMAKE_REQUIRED_LIBRARIES ${QT5_LIBRARIES})
+
+include(CheckCXXSourceCompiles)
+
+CHECK_CXX_SOURCE_COMPILES(
+"
+  #include <QSurfaceFormat>
+
+  int main(int argc, char** argv) {
+    QSurfaceFormat::FormatOption o = QSurfaceFormat::UseOptimalOrientation;
+    return 0;
+  }
+" QT5_HAVE_OPTIMALORIENTATION)
+
+if(QT5_HAVE_OPTIMALORIENTATION)
+  message(STATUS "QSurfaceFormat::UseOptimalOrientation found")
+  add_definitions(-DHAVE_OPTIMALORIENTATION)
+endif()

+ 3 - 0
src/player/OpenGLDetect.cpp

@@ -90,6 +90,9 @@ void detectOpenGLLate()
     QLOG_INFO() << "Trying GLES version" << version;
     QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
     fmt.setMajorVersion(version);
+#ifdef HAVE_OPTIMALORIENTATION
+    fmt.setOption(QSurfaceFormat::UseOptimalOrientation);
+#endif
     QOpenGLContext ctx;
     ctx.setFormat(fmt);
     if (ctx.create())

+ 9 - 2
src/player/PlayerQuickItem.cpp

@@ -200,14 +200,21 @@ PlayerRenderer::~PlayerRenderer()
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 void PlayerRenderer::render()
 {
+  QOpenGLContext *context = QOpenGLContext::currentContext();
+
   GLint fbo = 0;
-  QOpenGLContext::currentContext()->functions()->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
+  context->functions()->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
 
   m_window->resetOpenGLState();
 
+  bool flip = true;
+#if HAVE_OPTIMALORIENTATION
+  flip = !(context->format().orientationFlags() & QSurfaceFormat::MirrorVertically);
+#endif
+
   // The negative height signals to mpv that the video should be flipped
   // (according to the flipped OpenGL coordinate system).
-  mpv_opengl_cb_draw(m_mpvGL, fbo, m_size.width(), -m_size.height());
+  mpv_opengl_cb_draw(m_mpvGL, fbo, m_size.width(), (flip ? -1 : 1) * m_size.height());
 
   m_window->resetOpenGLState();
 }