diff options
author | Jøger Hansegård <joger.hansegard@qt.io> | 2023-09-04 18:40:22 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-09-04 21:29:34 +0000 |
commit | e7b724c0106bb5f4b3cc615f60fb0c48937203b2 (patch) | |
tree | 40c420e07f382294a2f81bd6cdfe14bb3b622c82 | |
parent | 0ac61fbf6e26a9ccebd73fa40118aa66a5b0b09b (diff) |
Hold textures by value instead of using scoped pointers
While investigating a crash, I found some unnecessary indirections in
QSGVideoMaterial where QSGVideoTexture instances were owned as scoped
pointers instead of being held by value.
To make buffer overflows easier to detect in Debug, we also change from
raw array to std::array as a container type.
This patch should not have any impact on the reported crash, but makes
the code a bit easier to reason around.
Task-number: QTBUG-116533
Change-Id: Ia36d48b9940d25032897418d2c36596aadf4dbcb
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
(cherry picked from commit 565ef43e225ce9538dee5e26d4c5a1c7b51da8ac)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/multimediaquick/qsgvideonode_p.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/multimediaquick/qsgvideonode_p.cpp b/src/multimediaquick/qsgvideonode_p.cpp index 2734ff9e5..b42b0be41 100644 --- a/src/multimediaquick/qsgvideonode_p.cpp +++ b/src/multimediaquick/qsgvideonode_p.cpp @@ -78,11 +78,11 @@ public: int compare(const QSGMaterial *other) const override { const QSGVideoMaterial *m = static_cast<const QSGVideoMaterial *>(other); - qint64 diff = m_textures[0]->comparisonKey() - m->m_textures[0]->comparisonKey(); + qint64 diff = m_textures[0].comparisonKey() - m->m_textures[0].comparisonKey(); if (!diff) - diff = m_textures[1]->comparisonKey() - m->m_textures[1]->comparisonKey(); + diff = m_textures[1].comparisonKey() - m->m_textures[1].comparisonKey(); if (!diff) - diff = m_textures[2]->comparisonKey() - m->m_textures[2]->comparisonKey(); + diff = m_textures[2].comparisonKey() - m->m_textures[2].comparisonKey(); return diff < 0 ? -1 : (diff > 0 ? 1 : 0); } @@ -110,7 +110,7 @@ public: enum { NVideoFrameSlots = 4 }; QVideoFrame m_videoFrameSlots[NVideoFrameSlots]; - QScopedPointer<QSGVideoTexture> m_textures[3]; + std::array<QSGVideoTexture, 3> m_textures; std::unique_ptr<QVideoFrameTextures> m_videoFrameTextures; }; @@ -127,7 +127,7 @@ void QSGVideoMaterial::updateTextures(QRhi *rhi, QRhiResourceUpdateBatch *resour // update and upload all textures m_videoFrameTextures = QVideoTextureHelper::createTextures(m_currentFrame, rhi, resourceUpdates, std::move(m_videoFrameTextures)); for (int plane = 0; plane < 3; ++plane) - m_textures[plane]->setRhiTexture(m_videoFrameTextures->texture(plane)); + m_textures[plane].setRhiTexture(m_videoFrameTextures->texture(plane)); m_texturesDirty = false; } @@ -167,17 +167,13 @@ void QSGVideoMaterialRhiShader::updateSampledImage(RenderState &state, int bindi return; auto m = static_cast<QSGVideoMaterial *>(newMaterial); - *texture = m->m_textures[binding - 1].data(); + *texture = &m->m_textures[binding - 1]; } QSGVideoMaterial::QSGVideoMaterial(const QVideoFrameFormat &format) : m_format(format), m_opacity(1.0) { - m_textures[0].reset(new QSGVideoTexture); - m_textures[1].reset(new QSGVideoTexture); - m_textures[2].reset(new QSGVideoTexture); - setFlag(Blending, false); } |