diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-08-13 08:13:57 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-08-31 15:19:50 +0200 |
commit | 307a82a2de4de48cae05a6aed26c7310d5325d12 (patch) | |
tree | c6f296a292595d226ca9aa10fb6f7190d31d96e2 | |
parent | 3ff4cd600454d1589228aeb68230336d6b721839 (diff) |
Keep reference to buffer until it has been replaced
For the code path which uses QWaylandBufferMaterial, the buffer
could potentially be deleted before the material had been
updated, which could cause issues if the render thread was
currently using the textures.
In the default code path this was handled by keeping a reference
to the buffer in the texture provider, but in the alternative YUV
format code path, we did not increase the reference count of the
buffer, so it would be deleted immediately when it was replaced
rather than wait for the sync with the render thread.
Task-number: QTBUG-95715
Change-Id: Ic6038ea8281e2a2e292d12150d1fffedb5c3b76e
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
(cherry picked from commit 6b9a27d77e226a3d0ce9fa9b4974f70c9ef4a30e)
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem.cpp | 15 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem_p.h | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp index 95bf0f913..3064a20e6 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.cpp +++ b/src/compositor/compositor_api/qwaylandquickitem.cpp @@ -253,6 +253,16 @@ void QWaylandBufferMaterial::ensureTextures(int count) m_textures << nullptr; } } + +void QWaylandBufferMaterial::setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref) +{ + Q_UNUSED(surfaceItem); + m_bufferRef = ref; + for (int plane = 0; plane < bufferTypes[ref.bufferFormatEgl()].planeCount; plane++) + if (auto texture = ref.toOpenGLTexture(plane)) + setTextureForPlane(plane, texture); + bind(); +} #endif // QT_CONFIG(opengl) QMutex *QWaylandQuickItemPrivate::mutex = nullptr; @@ -1411,10 +1421,7 @@ 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); - material->bind(); + material->setBufferRef(this, ref); } const QSize surfaceSize = ref.size() / surface()->bufferScale(); diff --git a/src/compositor/compositor_api/qwaylandquickitem_p.h b/src/compositor/compositor_api/qwaylandquickitem_p.h index 1c7ce55cd..e8a4f0b6c 100644 --- a/src/compositor/compositor_api/qwaylandquickitem_p.h +++ b/src/compositor/compositor_api/qwaylandquickitem_p.h @@ -80,6 +80,7 @@ public: ~QWaylandBufferMaterial() override; void setTextureForPlane(int plane, QOpenGLTexture *texture); + void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref); void bind(); @@ -92,6 +93,7 @@ private: const QWaylandBufferRef::BufferFormatEgl m_format; QVarLengthArray<QOpenGLTexture*, 3> m_textures; + QWaylandBufferRef m_bufferRef; }; #endif // QT_CONFIG(opengl) |