summaryrefslogtreecommitdiffstats
path: root/src/plugins/android/src/common
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-11-14 09:53:30 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-11-14 09:53:30 +0100
commit1d17e3973dda183545025e6d8f99dc3f219344e5 (patch)
tree52421d106b2f86a1d948025f215839a932954fdc /src/plugins/android/src/common
parent2eabff2d4a8fb4afc9ab3eb06bfddf8ffc0ba2b2 (diff)
parentf9a576826c0d770aaae8aadbedaf83e1c0b72e0a (diff)
Merge remote-tracking branch 'origin/5.13' into 5.14
Diffstat (limited to 'src/plugins/android/src/common')
-rw-r--r--src/plugins/android/src/common/qandroidvideooutput.cpp33
-rw-r--r--src/plugins/android/src/common/qandroidvideooutput.h5
2 files changed, 38 insertions, 0 deletions
diff --git a/src/plugins/android/src/common/qandroidvideooutput.cpp b/src/plugins/android/src/common/qandroidvideooutput.cpp
index 25e67e865..fd6eb0e8b 100644
--- a/src/plugins/android/src/common/qandroidvideooutput.cpp
+++ b/src/plugins/android/src/common/qandroidvideooutput.cpp
@@ -49,6 +49,8 @@
#include <qopenglshaderprogram.h>
#include <qopenglframebufferobject.h>
#include <QtCore/private/qjnihelpers_p.h>
+#include <QtGui/QWindow>
+#include <QtGui/QOffscreenSurface>
QT_BEGIN_NAMESPACE
@@ -182,6 +184,8 @@ QAndroidTextureVideoOutput::QAndroidTextureVideoOutput(QObject *parent)
QAndroidTextureVideoOutput::~QAndroidTextureVideoOutput()
{
+ delete m_offscreenSurface;
+ delete m_glContext;
clearSurfaceTexture();
if (m_glDeleter) { // Make sure all of these are deleted on the render thread.
@@ -345,6 +349,35 @@ bool QAndroidTextureVideoOutput::renderFrameToFbo()
if (!m_nativeSize.isValid() || !m_surfaceTexture)
return false;
+ // Make sure we have an OpenGL context to make current.
+ if (!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();
+
+ // Create OpenGL context and set share context from surface.
+ m_glContext = new QOpenGLContext();
+ m_glContext->setFormat(m_offscreenSurface->requestedFormat());
+
+ auto surface = qobject_cast<QAbstractVideoSurface *>(m_surface->property("videoSurface").value<QObject *>());
+ if (!surface)
+ surface = m_surface;
+ auto shareContext = qobject_cast<QOpenGLContext *>(surface->property("GLContext").value<QObject *>());
+ if (shareContext)
+ m_glContext->setShareContext(shareContext);
+
+ if (!m_glContext->create()) {
+ qWarning("Failed to create QOpenGLContext");
+ return false;
+ }
+ }
+
+ if (m_glContext)
+ m_glContext->makeCurrent(m_offscreenSurface);
+
createGLResources();
m_surfaceTexture->updateTexImage();
diff --git a/src/plugins/android/src/common/qandroidvideooutput.h b/src/plugins/android/src/common/qandroidvideooutput.h
index 2a35247e9..456fe8e22 100644
--- a/src/plugins/android/src/common/qandroidvideooutput.h
+++ b/src/plugins/android/src/common/qandroidvideooutput.h
@@ -51,6 +51,8 @@ class AndroidSurfaceHolder;
class QOpenGLFramebufferObject;
class QOpenGLShaderProgram;
class QAbstractVideoSurface;
+class QWindow;
+class QOpenGLContext;
class QAndroidVideoOutput : public QObject
{
@@ -132,6 +134,9 @@ private:
bool m_surfaceTextureCanAttachToContext;
+ QWindow *m_offscreenSurface = nullptr;
+ QOpenGLContext *m_glContext = nullptr;
+
friend class AndroidTextureVideoBuffer;
};