The QSGShaderEffectTexture needs to be deleted in the rendering thread
authorGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 17 Aug 2011 16:46:01 +0000 (18:46 +0200)
committerKim M. Kalland <kim.kalland@nokia.com>
Thu, 18 Aug 2011 08:24:05 +0000 (10:24 +0200)
Change-Id: Id01d65b84e0dc7ab89bc4e90c3b52285ef79ac39
Reviewed-on: http://codereview.qt.nokia.com/3135
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Kim M. Kalland <kim.kalland@nokia.com>
src/declarative/items/qsgshadereffectsource.cpp
src/declarative/items/qsgshadereffectsource_p.h

index 5114d8c..d2854e6 100644 (file)
@@ -76,6 +76,7 @@ QSGShaderEffectTexture::QSGShaderEffectTexture(QSGItem *shaderSource)
 #ifdef QSG_DEBUG_FBO_OVERLAY
     , m_debugOverlay(0)
 #endif
+    , m_context(0)
     , m_mipmap(false)
     , m_live(true)
     , m_recursive(false)
@@ -96,6 +97,17 @@ QSGShaderEffectTexture::~QSGShaderEffectTexture()
 #endif
 }
 
+void QSGShaderEffectTexture::scheduleForCleanup()
+{
+    if (m_context)
+        m_context->scheduleTextureForCleanup(this);
+    else {
+        // Never really been used, hence we can delete it right away..
+        Q_ASSERT(!m_fbo);
+        delete this;
+    }
+}
+
 
 int QSGShaderEffectTexture::textureId() const
 {
@@ -226,10 +238,12 @@ void QSGShaderEffectTexture::grab()
         return;
     }
 
-    QSGContext *context = QSGItemPrivate::get(m_shaderSource)->sceneGraphContext();
+    if (!m_context)
+        m_context = QSGItemPrivate::get(m_shaderSource)->sceneGraphContext();
+    Q_ASSERT(QSGItemPrivate::get(m_shaderSource)->sceneGraphContext() == m_context);
 
     if (!m_renderer) {
-        m_renderer = context->createRenderer();
+        m_renderer = m_context->createRenderer();
         connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture()), Qt::DirectConnection);
     }
     m_renderer->setRootNode(static_cast<QSGRootNode *>(root));
@@ -293,7 +307,7 @@ void QSGShaderEffectTexture::grab()
 #ifdef QSG_DEBUG_FBO_OVERLAY
     if (qmlFboOverlay()) {
         if (!m_debugOverlay)
-            m_debugOverlay = context->createRectangleNode();
+            m_debugOverlay = m_context->createRectangleNode();
         m_debugOverlay->setRect(QRectF(0, 0, m_size.width(), m_size.height()));
         m_debugOverlay->setColor(QColor(0xff, 0x00, 0x80, 0x40));
         m_debugOverlay->setPenColor(QColor());
@@ -306,7 +320,7 @@ void QSGShaderEffectTexture::grab()
 
     m_dirtyTexture = false;
 
-    const QGLContext *ctx = QGLContext::currentContext();
+    const QGLContext *ctx = m_context->glContext();
     m_renderer->setDeviceRect(m_size);
     m_renderer->setViewportRect(m_size);
     QRectF mirrored(m_rect.left(), m_rect.bottom(), m_rect.width(), -m_rect.height());
@@ -462,7 +476,8 @@ QSGShaderEffectSource::QSGShaderEffectSource(QSGItem *parent)
 
 QSGShaderEffectSource::~QSGShaderEffectSource()
 {
-    delete m_texture;
+    m_texture->scheduleForCleanup();
+
     if (m_sourceItem)
         QSGItemPrivate::get(m_sourceItem)->derefFromEffectItem(m_hideSource);
 }
index ac8fde5..1108e8c 100644 (file)
@@ -114,6 +114,8 @@ public:
 
     void scheduleUpdate();
 
+    void scheduleForCleanup();
+
 Q_SIGNALS:
     void textureChanged();
 
@@ -137,6 +139,8 @@ private:
     QSGRectangleNode *m_debugOverlay;
 #endif
 
+    QSGContext *m_context;
+
     uint m_mipmap : 1;
     uint m_live : 1;
     uint m_recursive : 1;
@@ -226,7 +230,7 @@ protected:
     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
 
 private:
-    QSGTexture *m_texture;
+    QSGShaderEffectTexture *m_texture;
     WrapMode m_wrapMode;
     QPointer<QSGItem> m_sourceItem;
     QRectF m_sourceRect;