Skip to content

Commit

Permalink
Ensure surface textures are deleted from the render thread.
Browse files Browse the repository at this point in the history
Keep a reference to the QWaylandBuffer in QSGTexture instances
wrapping that buffer and destroy the texture in their destructor
to ensure it is also deleted in the render thread rather than
whereever the last reference to QWaylandBuffer expires.

Change-Id: Id83d40b6fea7c679d638b9209cdd1a3bdd37e741
  • Loading branch information
denexter committed Oct 23, 2015
1 parent d955352 commit b611c5c
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/compositor/compositor_api/qwaylandquicksurface.cpp
Expand Up @@ -53,6 +53,40 @@

QT_BEGIN_NAMESPACE

class QWaylandSurfaceTexture : public QSGTexture
{
public:
QWaylandSurfaceTexture(const QWaylandBufferRef &ref, QWaylandQuickSurface *surface)
: m_bufferRef(ref)
, m_textureSize(surface->size())
, m_textureId(m_bufferRef.createTexture())
, m_hasAlphaChannel(surface->useTextureAlpha())
{
}

~QWaylandSurfaceTexture()
{
m_bufferRef.destroyTexture();
}

int textureId() const { return m_textureId; }
QSize textureSize() const { return m_textureSize; }
bool hasAlphaChannel() const { return m_hasAlphaChannel; }
bool hasMipmaps() const { return false; }

void bind()
{
glBindTexture(GL_TEXTURE_2D, m_textureId);
updateBindOptions();
}

private:
QWaylandBufferRef m_bufferRef;
QSize m_textureSize;
int m_textureId;
bool m_hasAlphaChannel;
};

class BufferAttacher : public QWaylandBufferAttacher
{
public:
Expand Down Expand Up @@ -89,11 +123,7 @@ class BufferAttacher : public QWaylandBufferAttacher
if (bufferRef.isShm()) {
texture = window->createTextureFromImage(bufferRef.image());
} else {
QQuickWindow::CreateTextureOptions opt = 0;
if (surface->useTextureAlpha()) {
opt |= QQuickWindow::TextureHasAlphaChannel;
}
texture = window->createTextureFromId(bufferRef.createTexture(), surface->size(), opt);
texture = new QWaylandSurfaceTexture(bufferRef, surface);
}
texture->bind();
}
Expand Down

0 comments on commit b611c5c

Please sign in to comment.