summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/qgl_p.h')
-rw-r--r--src/opengl/qgl_p.h71
1 files changed, 20 insertions, 51 deletions
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