From 127a0db704b588183a718892d416048e9cb42a33 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Tue, 30 Jun 2020 15:08:39 +0200 Subject: Android: Use current gl context as share If a video surface contains gl context, it is now used as a share. Otherwise nothing is rendered. The gl context is set when updatePaintNode is called for the video output quick item. Also context's offscreen window now should be on the same thread as the surface. Task-number: QTBUG-78678 Change-Id: I8f2bdd56a5ce209edc206b74ffa5c48e34e7218f Reviewed-by: Laszlo Agocs --- src/plugins/android/src/common/qandroidvideooutput.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/android/src/common/qandroidvideooutput.cpp b/src/plugins/android/src/common/qandroidvideooutput.cpp index fd6eb0e8b..27cea76ad 100644 --- a/src/plugins/android/src/common/qandroidvideooutput.cpp +++ b/src/plugins/android/src/common/qandroidvideooutput.cpp @@ -349,14 +349,19 @@ bool QAndroidTextureVideoOutput::renderFrameToFbo() if (!m_nativeSize.isValid() || !m_surfaceTexture) return false; + QOpenGLContext *shareContext = !m_glContext && m_surface + ? qobject_cast(m_surface->property("GLContext").value()) + : nullptr; + // Make sure we have an OpenGL context to make current. - if (!QOpenGLContext::currentContext() && !m_glContext) { + if (shareContext || (!QOpenGLContext::currentContext() && !m_glContext)) { // Create Hidden QWindow surface to create context in this thread. m_offscreenSurface = new QWindow(); m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); // Needs geometry to be a valid surface, but size is not important. m_offscreenSurface->setGeometry(0, 0, 1, 1); m_offscreenSurface->create(); + m_offscreenSurface->moveToThread(m_surface->thread()); // Create OpenGL context and set share context from surface. m_glContext = new QOpenGLContext(); @@ -365,7 +370,6 @@ bool QAndroidTextureVideoOutput::renderFrameToFbo() auto surface = qobject_cast(m_surface->property("videoSurface").value()); if (!surface) surface = m_surface; - auto shareContext = qobject_cast(surface->property("GLContext").value()); if (shareContext) m_glContext->setShareContext(shareContext); -- cgit v1.2.3