summaryrefslogtreecommitdiffstats
path: root/src/opengl
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
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')
-rw-r--r--src/opengl/qgl.cpp64
-rw-r--r--src/opengl/qgl_p.h71
2 files changed, 62 insertions, 73 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
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index fd7f544..38a1845 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -220,6 +220,7 @@ public:
};
class QGLContextResource;
+class QGLSharedResourceGuard;
// QGLContextPrivate has the responsibility of creating context groups.
// QGLContextPrivate and QGLShareRegister will both maintain the reference counter and destroy
@@ -228,15 +229,21 @@ class QGLContextResource;
class QGLContextGroup
{
public:
+ ~QGLContextGroup();
+
QGLExtensionFuncs &extensionFuncs() {return m_extensionFuncs;}
const QGLContext *context() const {return m_context;}
+
+ void addGuard(QGLSharedResourceGuard *guard);
+ void removeGuard(QGLSharedResourceGuard *guard);
private:
- QGLContextGroup(const QGLContext *context) : m_context(context), m_refs(1) { }
+ QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }
QGLExtensionFuncs m_extensionFuncs;
const QGLContext *m_context; // context group's representative
QList<const QGLContext *> m_shares;
QHash<QGLContextResource *, void *> m_resources;
+ QGLSharedResourceGuard *m_guards; // double-linked list of active guards.
QAtomicInt m_refs;
void cleanupResources(const QGLContext *ctx);
@@ -247,37 +254,13 @@ private:
friend class QGLContextResource;
};
-// Reference to a QGLContext which automatically switches to another
-// shared context when the main one is destroyed. If there is no
-// shared context to switch to, the context pointer is set to null.
-// Note: should be merged into QGLContextGroup at some point.
-class QGLContextReference : public QObject
-{
- Q_OBJECT
-public:
- QGLContextReference(const QGLContext *ctx);
- ~QGLContextReference() {}
-
- const QGLContext *context() const { return m_ctx; }
-
- void ref() { m_ref.ref(); }
- bool deref() { return m_ref.deref(); }
-
-private slots:
- void aboutToDestroyContext(const QGLContext *ctx);
-
-private:
- QAtomicInt m_ref;
- const QGLContext *m_ctx;
-};
-
class QGLTexture;
class QGLContextPrivate
{
Q_DECLARE_PUBLIC(QGLContext)
public:
- explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {reference = new QGLContextReference(context); group = new QGLContextGroup(context);}
+ explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
~QGLContextPrivate();
QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
QGLContext::BindOptions options);
@@ -340,7 +323,6 @@ public:
QGLContext *q_ptr;
QGLFormat::OpenGLVersionFlags version_flags;
- QGLContextReference *reference;
QGLContextGroup *group;
GLint max_texture_size;
@@ -579,44 +561,27 @@ class Q_OPENGL_EXPORT QGLSharedResourceGuard
{
public:
QGLSharedResourceGuard(const QGLContext *context)
- : m_ctxref(0), m_id(0)
+ : m_group(0), m_id(0), m_next(0), m_prev(0)
{
setContext(context);
}
QGLSharedResourceGuard(const QGLContext *context, GLuint id)
- : m_ctxref(0), m_id(id)
+ : m_group(0), m_id(id), m_next(0), m_prev(0)
{
setContext(context);
}
- ~QGLSharedResourceGuard()
- {
- if (m_ctxref && !m_ctxref->deref())
- delete m_ctxref;
- }
+ ~QGLSharedResourceGuard();
const QGLContext *context() const
{
- return m_ctxref ? m_ctxref->context() : 0;
+ return m_group ? m_group->context() : 0;
}
- void setContext(const QGLContext *context)
- {
- if (m_ctxref && !m_ctxref->deref())
- delete m_ctxref;
- if (context) {
- m_ctxref = context->d_ptr->reference;
- m_ctxref->ref();
- } else {
- m_ctxref = 0;
- }
- }
+ void setContext(const QGLContext *context);
GLuint id() const
{
- if (m_ctxref && m_ctxref->context())
- return m_id;
- else
- return 0;
+ return m_id;
}
void setId(GLuint id)
@@ -625,8 +590,12 @@ public:
}
private:
- QGLContextReference *m_ctxref;
+ QGLContextGroup *m_group;
GLuint m_id;
+ QGLSharedResourceGuard *m_next;
+ QGLSharedResourceGuard *m_prev;
+
+ friend class QGLContextGroup;
};
QT_END_NAMESPACE