diff options
author | Mikko Harju <mikko.harju@jolla.com> | 2015-10-29 11:03:58 +0200 |
---|---|---|
committer | Gunnar Sletta <gunnar@sletta.org> | 2015-10-29 09:09:02 +0000 |
commit | 426ebb687864f699f74d7d6ad8a22051cd53bb65 (patch) | |
tree | 3402047f166ea4cfa9ea33d29667dce5d27d855e /customcontext | |
parent | 6e24005e3f3c9f2cb9f1da0cca600e669b74004f (diff) |
[hybristextures] Prevent deleting native buffers while still in use
Share the NativeBuffer and release when the last reference is gone.
This prevents too early deletion of the NativeBuffer owned
by the texture factory while the buffer is still being used through
a non-owning HybrisTexture.
Change-Id: I151b616df74b1590341af6fcfdc7674a98b55215
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'customcontext')
-rw-r--r-- | customcontext/texture/hybristexture.cpp | 9 | ||||
-rw-r--r-- | customcontext/texture/hybristexture.h | 8 |
2 files changed, 6 insertions, 11 deletions
diff --git a/customcontext/texture/hybristexture.cpp b/customcontext/texture/hybristexture.cpp index e4db87e..193aa0a 100644 --- a/customcontext/texture/hybristexture.cpp +++ b/customcontext/texture/hybristexture.cpp @@ -272,11 +272,10 @@ NativeBuffer *NativeBuffer::create(const QImage &image) return buffer; } -HybrisTexture::HybrisTexture(NativeBuffer *buffer) +HybrisTexture::HybrisTexture(QSharedPointer<NativeBuffer> buffer) : m_id(0) , m_buffer(buffer) , m_bound(false) - , m_ownsBuffer(false) { Q_ASSERT(buffer); #ifdef CUSTOMCONTEXT_DEBUG @@ -288,8 +287,6 @@ HybrisTexture::~HybrisTexture() { if (m_id) glDeleteTextures(1, &m_id); - if (m_ownsBuffer) - delete m_buffer; } void HybrisTexture::bind() @@ -345,8 +342,7 @@ HybrisTexture *HybrisTexture::create(const QImage &image) NativeBuffer *buffer = NativeBuffer::create(image); if (!buffer) return 0; - HybrisTexture *texture = new HybrisTexture(buffer); - texture->m_ownsBuffer = true; + HybrisTexture *texture = new HybrisTexture(QSharedPointer<NativeBuffer>(buffer)); return texture; } @@ -360,7 +356,6 @@ HybrisTextureFactory::HybrisTextureFactory(NativeBuffer *buffer) HybrisTextureFactory::~HybrisTextureFactory() { - delete m_buffer; } QSGTexture *HybrisTextureFactory::createTexture(QQuickWindow *) const diff --git a/customcontext/texture/hybristexture.h b/customcontext/texture/hybristexture.h index 31018e9..08dca61 100644 --- a/customcontext/texture/hybristexture.h +++ b/customcontext/texture/hybristexture.h @@ -44,6 +44,7 @@ #include <QtQuick/QSGTexture> #include <QtQuick/QQuickTextureFactory> +#include <QSharedPointer> #include <QtGui/qopengl.h> @@ -77,7 +78,7 @@ class HybrisTexture : public QSGTexture { Q_OBJECT public: - HybrisTexture(NativeBuffer *buffer); + HybrisTexture(QSharedPointer<NativeBuffer> buffer); ~HybrisTexture(); virtual int textureId() const; @@ -90,9 +91,8 @@ public: private: mutable GLuint m_id; - NativeBuffer *m_buffer; + QSharedPointer<NativeBuffer> m_buffer; bool m_bound; - bool m_ownsBuffer; }; class HybrisTextureFactory : public QQuickTextureFactory @@ -110,7 +110,7 @@ public: static HybrisTextureFactory *create(const QImage &image); private: - NativeBuffer *m_buffer; + QSharedPointer<NativeBuffer> m_buffer; }; } |