From 02ac3f58721bb52db612acd3bb2e2c26bfc3e05b Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Mon, 25 Jun 2018 15:21:10 +0200 Subject: AVFoundation: Use opengl context from surface as shared Since few opengl contexts could be used at the same time, CARenderer could use wrong context to render the video frame. If the video surface contains an opengl context then need to use it as shared regardless of existing of current context. Change-Id: Ie7e87682c73c0fd341b40c05e3f3c4a70d563242 Reviewed-by: Andy Nichols --- .../avfoundation/mediaplayer/avfvideoframerenderer.mm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm index 7e2f8722e..0759702e8 100644 --- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm +++ b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm @@ -126,8 +126,14 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay //Get size from AVPlayerLayer m_targetSize = QSize(layer.bounds.size.width, layer.bounds.size.height); + 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 && shareContext != QOpenGLContext::currentContext()) + || (!QOpenGLContext::currentContext() && !m_glContext)) { + //Create Hidden QWindow surface to create context in this thread m_offscreenSurface = new QWindow(); m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); @@ -135,12 +141,6 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay m_offscreenSurface->setGeometry(0, 0, 1, 1); m_offscreenSurface->create(); - //Create OpenGL context and set share context from surface - QOpenGLContext *shareContext = 0; - if (m_surface) { - //QOpenGLContext *renderThreadContext = 0; - shareContext = qobject_cast(m_surface->property("GLContext").value()); - } m_glContext = new QOpenGLContext(); m_glContext->setFormat(m_offscreenSurface->requestedFormat()); -- cgit v1.2.3