summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVaL Doroshchuk <valentyn.doroshchuk@qt.io>2020-08-01 16:52:54 +0200
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2020-08-03 11:34:12 +0200
commit164e22b24056b36910dee15cfa2df35e35f4eaea (patch)
tree3c8746674c24ebf25243c20facd4b5b4de87fa75
parent9c9bc7e6b95bb3c3d4f5347b6c70cbd15c74c69c (diff)
Quick: Copy texture data when updating
When the video frame is unmapped, the data might be invalid Change-Id: I0f5db581995ceb0a52ccd69a81a8f04690f3ebfc Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r--src/qtmultimediaquicktools/qsgvideotexture.cpp13
-rw-r--r--src/qtmultimediaquicktools/qsgvideotexture_p.h2
2 files changed, 7 insertions, 8 deletions
diff --git a/src/qtmultimediaquicktools/qsgvideotexture.cpp b/src/qtmultimediaquicktools/qsgvideotexture.cpp
index c138090b4..92b9245cb 100644
--- a/src/qtmultimediaquicktools/qsgvideotexture.cpp
+++ b/src/qtmultimediaquicktools/qsgvideotexture.cpp
@@ -53,8 +53,7 @@ private:
QSGVideoTexture *q_ptr = nullptr;
QRhiTexture::Format m_format;
QSize m_size;
- const uchar *m_data = nullptr;
- qsizetype m_bytes = 0;
+ QByteArray m_data;
QScopedPointer<QRhiTexture> m_texture;
quint64 m_nativeObject = 0;
@@ -104,13 +103,12 @@ bool QSGVideoTexture::hasMipmaps() const
return mipmapFiltering() != QSGTexture::None;
}
-void QSGVideoTexture::setData(QRhiTexture::Format f, const QSize &s, const uchar *data, qsizetype bytes)
+void QSGVideoTexture::setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes)
{
Q_D(QSGVideoTexture);
d->m_size = s;
d->m_format = f;
- d->m_data = data;
- d->m_bytes = bytes;
+ d->m_data = {reinterpret_cast<const char *>(data), bytes};
}
void QSGVideoTexture::setNativeObject(quint64 obj, const QSize &s)
@@ -149,13 +147,14 @@ void QSGVideoTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch
}
}
- if (m_bytes) {
- QRhiTextureSubresourceUploadDescription subresDesc(m_data, m_bytes);
+ if (!m_data.isEmpty()) {
+ QRhiTextureSubresourceUploadDescription subresDesc(m_data.constData(), m_data.size());
subresDesc.setSourceSize(m_size);
subresDesc.setDestinationTopLeft(QPoint(0, 0));
QRhiTextureUploadEntry entry(0, 0, subresDesc);
QRhiTextureUploadDescription desc({ entry });
resourceUpdates->uploadTexture(m_texture.data(), desc);
+ m_data.clear();
}
}
diff --git a/src/qtmultimediaquicktools/qsgvideotexture_p.h b/src/qtmultimediaquicktools/qsgvideotexture_p.h
index 837bfdf9c..1cae713b8 100644
--- a/src/qtmultimediaquicktools/qsgvideotexture_p.h
+++ b/src/qtmultimediaquicktools/qsgvideotexture_p.h
@@ -72,7 +72,7 @@ public:
bool hasAlphaChannel() const override;
bool hasMipmaps() const override;
void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
- void setData(QRhiTexture::Format f, const QSize &s, const uchar *data, qsizetype bytes);
+ void setData(QRhiTexture::Format f, const QSize &s, const uchar *data, int bytes);
void setNativeObject(quint64 obj, const QSize &s);
protected: