summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qopenglcontext.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-08-29 12:45:39 +0200
committerGunnar Sletta <gunnar.sletta@nokia.com>2011-09-01 07:44:01 +0200
commita3b026475483f9377248b2a00e55da28d17258d1 (patch)
tree33f458aa3a65b09e3d87f71953fd355381fd4983 /src/gui/kernel/qopenglcontext.cpp
parent9cdf9973c60f6974fe9b405b10ef9cffef7ae4f2 (diff)
Clean up shared resources immediately as the last context is destroyed.
By not waiting until deleteLater() kicks in it's easier to auto-test. We can now add a test case for what happens when a shared resource is still valid while the last context is destroyed. Change-Id: I72963928e6a921e49ed59a79e2579b497ba37ccf Reviewed-on: http://codereview.qt.nokia.com/3732 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/gui/kernel/qopenglcontext.cpp')
-rw-r--r--src/gui/kernel/qopenglcontext.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index e61c117bfa..d5b34c2f9b 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -360,17 +360,7 @@ QOpenGLContextGroup::QOpenGLContextGroup()
QOpenGLContextGroup::~QOpenGLContextGroup()
{
Q_D(QOpenGLContextGroup);
-
- QList<QOpenGLSharedResource *>::iterator it = d->m_sharedResources.begin();
- QList<QOpenGLSharedResource *>::iterator end = d->m_sharedResources.end();
-
- while (it != end) {
- (*it)->invalidateResource();
- (*it)->m_group = 0;
- ++it;
- }
-
- qDeleteAll(d->m_pendingDeletion.begin(), d->m_pendingDeletion.end());
+ d->cleanup();
}
QList<QOpenGLContext *> QOpenGLContextGroup::shares() const
@@ -402,8 +392,27 @@ void QOpenGLContextGroupPrivate::removeContext(QOpenGLContext *ctx)
if (ctx == m_context && !m_shares.isEmpty())
m_context = m_shares.first();
- if (!m_refs.deref())
+ if (!m_refs.deref()) {
+ cleanup();
q->deleteLater();
+ }
+}
+
+void QOpenGLContextGroupPrivate::cleanup()
+{
+ QList<QOpenGLSharedResource *>::iterator it = m_sharedResources.begin();
+ QList<QOpenGLSharedResource *>::iterator end = m_sharedResources.end();
+
+ while (it != end) {
+ (*it)->invalidateResource();
+ (*it)->m_group = 0;
+ ++it;
+ }
+
+ m_sharedResources.clear();
+
+ qDeleteAll(m_pendingDeletion.begin(), m_pendingDeletion.end());
+ m_pendingDeletion.clear();
}
void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx)