From 20b9aa15dcbcf9e76204976a16061bf133b47999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 24 Oct 2012 17:51:08 +0200 Subject: Prevent leaking texture ids. We need to call glDeleteTextures() in the correct thread (and when the correct context is current). Luckily, QOpenGLSharedResourceGuard is designed to solve that problem. Change-Id: Ifc04fb9040ef82947189b098e1e1c4c8d787551f Reviewed-by: Andy Nichols --- src/compositor/wayland_wrapper/wlsurfacebuffer.cpp | 18 ++++++++++++++---- src/compositor/wayland_wrapper/wlsurfacebuffer.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp b/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp index c4bad7662..6dd76532c 100644 --- a/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp +++ b/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp @@ -62,6 +62,7 @@ SurfaceBuffer::SurfaceBuffer(Surface *surface) , m_page_flipper_has_buffer(false) , m_is_displayed(false) , m_texture(0) + , m_guard(0) , m_is_shm_resolved(false) , m_is_shm(false) { @@ -77,6 +78,7 @@ void SurfaceBuffer::initialize(wl_buffer *buffer) { m_buffer = buffer; m_texture = 0; + m_guard = 0; m_is_registered_for_buffer = true; m_surface_has_buffer = true; m_page_flipper_has_buffer = false; @@ -180,10 +182,12 @@ void SurfaceBuffer::setDamage(const QRect &rect) void SurfaceBuffer::destroyTexture() { #ifdef QT_COMPOSITOR_WAYLAND_GL - if (m_texture) { - glDeleteTextures(1,&m_texture); - m_texture = 0; - } + if (m_texture) { + Q_ASSERT(m_guard); + m_guard->free(); + m_guard = 0; + m_texture = 0; + } #endif } @@ -232,10 +236,16 @@ void SurfaceBuffer::destroy_listener_callback(wl_listener *listener, void *data) d->m_buffer = 0; } +void freeTexture(QOpenGLFunctions *, GLuint id) +{ + glDeleteTextures(1, &id); +} + void SurfaceBuffer::createTexture(GraphicsHardwareIntegration *hwIntegration, QOpenGLContext *context) { #ifdef QT_COMPOSITOR_WAYLAND_GL m_texture = hwIntegration->createTextureFromBuffer(m_buffer, context); + m_guard = new QOpenGLSharedResourceGuard(QOpenGLContext::currentContext(), m_texture, freeTexture); #else Q_UNUSED(hwIntegration); Q_UNUSED(context); diff --git a/src/compositor/wayland_wrapper/wlsurfacebuffer.h b/src/compositor/wayland_wrapper/wlsurfacebuffer.h index 3ae351ae6..141fc4ca9 100644 --- a/src/compositor/wayland_wrapper/wlsurfacebuffer.h +++ b/src/compositor/wayland_wrapper/wlsurfacebuffer.h @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -117,6 +118,7 @@ private: bool m_is_displayed; #ifdef QT_COMPOSITOR_WAYLAND_GL GLuint m_texture; + QOpenGLSharedResourceGuard *m_guard; #else uint m_texture; #endif -- cgit v1.2.3