summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@digia.com>2012-10-24 17:51:08 +0200
committerAndy Nichols <andy.nichols@digia.com>2012-10-24 18:01:57 +0200
commit20b9aa15dcbcf9e76204976a16061bf133b47999 (patch)
tree0ba76adfb3d6f32ed97b4108f6162ef8294a45da /src
parent3a192e2ef2d27e8b4a0b1b3e8d2f409d34a9e2bf (diff)
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 <andy.nichols@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/compositor/wayland_wrapper/wlsurfacebuffer.cpp18
-rw-r--r--src/compositor/wayland_wrapper/wlsurfacebuffer.h2
2 files changed, 16 insertions, 4 deletions
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 <QtCore/QRect>
#include <QtGui/qopengl.h>
+#include <QtGui/private/qopenglcontext_p.h>
#include <qpa/qplatformscreenpageflipper.h>
#include <wayland-server.h>
@@ -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