summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl.cpp
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-10-04 23:40:37 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-10-04 23:40:37 (GMT)
commita3add3d6ab1b7a3e4dbb2df81fd51625b834fe45 (patch)
tree2f6cd04d4b7d03ae98f64fd1c5c7f703c1f226c0 /src/opengl/qgl.cpp
parent5f34e11676002953fe5e9f94fbcd08739d46aba8 (diff)
downloadQt-a3add3d6ab1b7a3e4dbb2df81fd51625b834fe45.zip
Qt-a3add3d6ab1b7a3e4dbb2df81fd51625b834fe45.tar.gz
Qt-a3add3d6ab1b7a3e4dbb2df81fd51625b834fe45.tar.bz2
Merge QGLContextReference into QGLContextGroup
Reviewed-by: trustme
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r--src/opengl/qgl.cpp64
1 files changed, 42 insertions, 22 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 72dd184..7dbe642 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -1393,11 +1393,39 @@ bool operator!=(const QGLFormat& a, const QGLFormat& b)
/*****************************************************************************
QGLContext implementation
*****************************************************************************/
-QGLContextPrivate::~QGLContextPrivate()
+
+QGLContextGroup::~QGLContextGroup()
+{
+ // Clear any remaining QGLSharedResourceGuard objects on the group.
+ QGLSharedResourceGuard *guard = m_guards;
+ while (guard != 0) {
+ guard->m_group = 0;
+ guard->m_id = 0;
+ guard = guard->m_next;
+ }
+}
+
+void QGLContextGroup::addGuard(QGLSharedResourceGuard *guard)
+{
+ if (m_guards)
+ m_guards->m_prev = guard;
+ guard->m_next = m_guards;
+ guard->m_prev = 0;
+ m_guards = guard;
+}
+
+void QGLContextGroup::removeGuard(QGLSharedResourceGuard *guard)
{
- if (!reference->deref())
- delete reference;
+ if (guard->m_next)
+ guard->m_next->m_prev = guard->m_prev;
+ if (guard->m_prev)
+ guard->m_prev->m_next = guard->m_next;
+ else
+ m_guards = guard->m_next;
+}
+QGLContextPrivate::~QGLContextPrivate()
+{
if (!group->m_refs.deref()) {
Q_ASSERT(group->context() == q_ptr);
delete group;
@@ -4959,30 +4987,22 @@ void QGLContextGroup::cleanupResources(const QGLContext *ctx)
it.key()->cleanup(ctx, it.value());
}
-QGLContextReference::QGLContextReference(const QGLContext *ctx)
- : m_ref(1), m_ctx(ctx)
+QGLSharedResourceGuard::~QGLSharedResourceGuard()
{
- connect(QGLSignalProxy::instance(),
- SIGNAL(aboutToDestroyContext(const QGLContext *)),
- this, SLOT(aboutToDestroyContext(const QGLContext *)));
+ if (m_group)
+ m_group->removeGuard(this);
}
-void QGLContextReference::aboutToDestroyContext(const QGLContext *ctx)
+void QGLSharedResourceGuard::setContext(const QGLContext *context)
{
- // Bail out if our context is not being destroyed.
- if (ctx != m_ctx || !m_ctx)
- return;
-
- // Find some other context that this one is shared with to take over.
- QList<const QGLContext *> shares = qgl_share_reg()->shares(m_ctx);
- shares.removeAll(m_ctx);
- if (!shares.isEmpty()) {
- m_ctx = shares[0];
- return;
+ if (m_group)
+ m_group->removeGuard(this);
+ if (context) {
+ m_group = QGLContextPrivate::contextGroup(context);
+ m_group->addGuard(this);
+ } else {
+ m_group = 0;
}
-
- // No more contexts sharing with this one, so the reference is now invalid.
- m_ctx = 0;
}
QT_END_NAMESPACE