From 614252bcba29e5ac4909869b5dac00aee2dec778 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 23 Jun 2020 12:43:50 +0200 Subject: QWaylandQuickItem: Fix buffer formats with multiple planes We create the QSGTexture at the same time as the OpenGLTexture and store it in the material for later updates. Task-number: QTBUG-78673 Change-Id: I09a0e073f538934798cb80e1ff98d1d786225c89 Reviewed-by: Laszlo Agocs --- .../compositor_api/qwaylandquickitem.cpp | 38 ++++++++++++++++------ .../compositor_api/qwaylandquickitem_p.h | 6 +++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp index bffa358b2..93fa97b0d 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.cpp +++ b/src/compositor/compositor_api/qwaylandquickitem.cpp @@ -167,17 +167,16 @@ void QWaylandBufferMaterialShader::updateSampledImage(RenderState &state, int bi { Q_UNUSED(state); - QWaylandBufferMaterial *material = static_cast(newMaterial); //###@@@??? - Q_UNUSED(material); + QWaylandBufferMaterial *material = static_cast(newMaterial); switch (binding) { case 1: - // *texture = ?? where do we get a QSGTexture wrapping the QOpenGLTexture's underlying texture from? + *texture = material->m_scenegraphTextures.at(0); break; case 2: - // *texture = ?? + *texture = material->m_scenegraphTextures.at(1); break; case 3: - // *texture = ?? + *texture = material->m_scenegraphTextures.at(2); break; default: return; @@ -198,9 +197,12 @@ QWaylandBufferMaterial::QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEg QWaylandBufferMaterial::~QWaylandBufferMaterial() { + qDeleteAll(m_scenegraphTextures); } -void QWaylandBufferMaterial::setTextureForPlane(int plane, QOpenGLTexture *texture) +void QWaylandBufferMaterial::setTextureForPlane(int plane, + QOpenGLTexture *texture, + QSGTexture *scenegraphTexture) { if (plane < 0 || plane >= bufferTypes[m_format].planeCount) { qWarning("plane index is out of range"); @@ -212,10 +214,15 @@ void QWaylandBufferMaterial::setTextureForPlane(int plane, QOpenGLTexture *textu ensureTextures(plane - 1); - if (m_textures.size() <= plane) + if (m_textures.size() <= plane) { m_textures << texture; - else + m_scenegraphTextures << scenegraphTexture; + } else { + delete m_scenegraphTextures[plane]; + m_textures[plane] = texture; + m_scenegraphTextures[plane] = scenegraphTexture; + } } void QWaylandBufferMaterial::bind() @@ -263,6 +270,7 @@ void QWaylandBufferMaterial::ensureTextures(int count) { for (int plane = m_textures.size(); plane < count; plane++) { m_textures << nullptr; + m_scenegraphTextures << nullptr; } } #endif // QT_CONFIG(opengl) @@ -1379,8 +1387,18 @@ QSGNode *QWaylandQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat if (d->newTexture) { d->newTexture = false; for (int plane = 0; plane < bufferTypes[ref.bufferFormatEgl()].planeCount; plane++) - if (auto texture = ref.toOpenGLTexture(plane)) - material->setTextureForPlane(plane, texture); + if (auto texture = ref.toOpenGLTexture(plane)) { + QQuickWindow::CreateTextureOptions opt; + QWaylandQuickSurface *waylandSurface = qobject_cast(surface()); + if (waylandSurface != nullptr && waylandSurface->useTextureAlpha()) + opt |= QQuickWindow::TextureHasAlphaChannel; + QSGTexture *scenegraphTexture = QPlatformInterface::QSGOpenGLTexture::fromNative(texture->textureId(), + window(), + ref.size(), + opt); + scenegraphTexture->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest); + material->setTextureForPlane(plane, texture, scenegraphTexture); + } material->bind(); } diff --git a/src/compositor/compositor_api/qwaylandquickitem_p.h b/src/compositor/compositor_api/qwaylandquickitem_p.h index 6ee267f75..4ee3ca056 100644 --- a/src/compositor/compositor_api/qwaylandquickitem_p.h +++ b/src/compositor/compositor_api/qwaylandquickitem_p.h @@ -75,19 +75,23 @@ public: QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEgl format); ~QWaylandBufferMaterial() override; - void setTextureForPlane(int plane, QOpenGLTexture *texture); + void setTextureForPlane(int plane, QOpenGLTexture *texture, QSGTexture *scenegraphTexture); void bind(); + void updateScenegraphTextures(QRhi *rhi); QSGMaterialType *type() const override; QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override; private: + friend QWaylandBufferMaterialShader; + void setTextureParameters(GLenum target); void ensureTextures(int count); const QWaylandBufferRef::BufferFormatEgl m_format; QVarLengthArray m_textures; + QVarLengthArray m_scenegraphTextures; }; #endif // QT_CONFIG(opengl) -- cgit v1.2.3