summaryrefslogtreecommitdiffstats
path: root/src/compositor/compositor_api/qwaylandquickitem.cpp
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2016-03-02 11:27:46 +0100
committerDominik Holland <dominik.holland@pelagicore.com>2016-05-18 15:08:53 +0000
commitc7832b0a1d4e5e095e56315c43145bb8964f7030 (patch)
tree30e63aa55221255e9d759be7cdaae924e6e0798e /src/compositor/compositor_api/qwaylandquickitem.cpp
parent959d9d604da402e768ce329d43510d2b03756d89 (diff)
Fixed eglStream compositing
When creating the eglStream from the fd we also need to create the texture and call stream_consumer_gltexture. Otherwise the wayland client can't create the wayland client surface. Fixed the qwindow-compositor example to use the texture associated to the QWaylandBufferRef when compositing a EXTERNAL_OES target. QML compositing only works when QSG_RENDER_LOOP is set to basic as we need to generate a texture from the gui thread. As the texture is created by the bufferintegration it might end up in a different gl context than the quick item using it. The texture is also deleted together with the buffer, which prevents the use of the texture afterwards. Both problems need to be fixed in follow up commits. Task-number: QTBUG-50850 Change-Id: Ifec67bbe9e4b2a680c871dc4aced37b71b7b6f80 Reviewed-by: Louai Al-Khanji <louai.al-khanji@qt.io> Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
Diffstat (limited to 'src/compositor/compositor_api/qwaylandquickitem.cpp')
-rw-r--r--src/compositor/compositor_api/qwaylandquickitem.cpp64
1 files changed, 53 insertions, 11 deletions
diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp
index 9fa81cfb2..ab11ff4f8 100644
--- a/src/compositor/compositor_api/qwaylandquickitem.cpp
+++ b/src/compositor/compositor_api/qwaylandquickitem.cpp
@@ -179,17 +179,6 @@ QWaylandBufferMaterial::QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEg
{
QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
- for (int i = 0; i < bufferTypes[m_format].planeCount; i++) {
- GLuint texture;
- gl->glGenTextures(1, &texture);
- gl->glBindTexture(bufferTypes[m_format].textureTarget, texture);
- gl->glTexParameteri(bufferTypes[m_format].textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- gl->glTexParameteri(bufferTypes[m_format].textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- gl->glTexParameteri(bufferTypes[m_format].textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- gl->glTexParameteri(bufferTypes[m_format].textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- m_textures << texture;
- }
-
gl->glBindTexture(bufferTypes[m_format].textureTarget, 0);
setFlag(bufferTypes[m_format].materialFlags);
}
@@ -202,11 +191,36 @@ QWaylandBufferMaterial::~QWaylandBufferMaterial()
gl->glDeleteTextures(1, &texture);
}
+void QWaylandBufferMaterial::setTextureForPlane(int plane, uint texture)
+{
+ if (plane < 0 || plane >= bufferTypes[m_format].planeCount) {
+ qWarning("plane index is out of range");
+ return;
+ }
+
+ QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
+ const GLenum target = bufferTypes[m_format].textureTarget;
+
+ gl->glBindTexture(target, texture);
+ setTextureParameters(target);
+
+ ensureTextures(plane - 1);
+
+ if (m_textures.size() <= plane) {
+ m_textures << texture;
+ } else {
+ std::swap(m_textures[plane], texture);
+ gl->glDeleteTextures(1, &texture);
+ }
+}
+
void QWaylandBufferMaterial::bind()
{
QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
const GLenum target = bufferTypes[m_format].textureTarget;
+ ensureTextures(bufferTypes[m_format].planeCount);
+
switch (m_textures.size()) {
case 3:
gl->glActiveTexture(GL_TEXTURE2);
@@ -230,6 +244,31 @@ QSGMaterialShader *QWaylandBufferMaterial::createShader() const
return new QWaylandBufferMaterialShader(m_format);
}
+
+void QWaylandBufferMaterial::setTextureParameters(GLenum target)
+{
+ QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
+ gl->glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ gl->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ gl->glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ gl->glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+}
+
+//TODO move this into a separate centralized texture management class
+void QWaylandBufferMaterial::ensureTextures(int count)
+{
+ QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions();
+ const GLenum target = bufferTypes[m_format].textureTarget;
+ GLuint texture;
+
+ for (int plane = m_textures.size(); plane < count; plane++) {
+ gl->glGenTextures(1, &texture);
+ gl->glBindTexture(target, texture);
+ setTextureParameters(target);
+ m_textures << texture;
+ }
+}
+
QMutex *QWaylandQuickItemPrivate::mutex = 0;
class QWaylandSurfaceTextureProvider : public QSGTextureProvider
@@ -1047,6 +1086,9 @@ QSGNode *QWaylandQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat
if (d->newTexture) {
d->newTexture = false;
+ for (int plane = 0; plane < bufferTypes[ref.bufferFormatEgl()].planeCount; plane++)
+ if (uint texture = ref.textureForPlane(plane))
+ material->setTextureForPlane(plane, texture);
material->bind();
ref.bindToTexture();
}