summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-01-04 04:08:37 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-01-04 22:18:48 (GMT)
commit619392c059326c11c24c1092ab62dd091114a0ab (patch)
tree5e239e2660b8bc13ea509d3fc154b9930b82b059 /src
parentf019f3cf807e3c804bba3ef5598ea69adbb39e8b (diff)
downloadQt-619392c059326c11c24c1092ab62dd091114a0ab.zip
Qt-619392c059326c11c24c1092ab62dd091114a0ab.tar.gz
Qt-619392c059326c11c24c1092ab62dd091114a0ab.tar.bz2
Remove QGLShareRegister and transfer its functionality to QGLContextGroup
Task-number: QT-2600 Reviewed-by: Samuel
Diffstat (limited to 'src')
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp15
-rw-r--r--src/opengl/qgl.cpp28
-rw-r--r--src/opengl/qgl.h2
-rw-r--r--src/opengl/qgl_egl.cpp2
-rw-r--r--src/opengl/qgl_mac.mm2
-rw-r--r--src/opengl/qgl_p.h25
-rw-r--r--src/opengl/qgl_win.cpp2
-rw-r--r--src/opengl/qgl_x11.cpp2
-rw-r--r--src/opengl/qglpixelbuffer.cpp2
9 files changed, 39 insertions, 41 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index a41d439..7655971 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -124,17 +124,20 @@ public:
public Q_SLOTS:
void contextDestroyed(const QGLContext *context) {
if (context == ctx) {
- QList<const QGLContext *> shares = qgl_share_reg()->shares(ctx);
- if (shares.isEmpty()) {
- glDeleteFramebuffers(1, &m_fbo);
- if (m_width || m_height)
- glDeleteTextures(1, &m_texture);
+ const QGLContext *nextCtx = qt_gl_transfer_context(ctx);
+ if (!nextCtx) {
+ // the context may not be current, so we cannot directly
+ // destroy the fbo and texture here, but since the context
+ // is about to be destroyed, the GL server will do the
+ // clean up for us anyway
+ m_fbo = 0;
+ m_texture = 0;
ctx = 0;
} else {
// since the context holding the texture is shared, and
// about to be destroyed, we have to transfer ownership
// of the texture to one of the share contexts
- ctx = const_cast<QGLContext *>((ctx == shares.at(0)) ? shares.at(1) : shares.at(0));
+ ctx = const_cast<QGLContext *>(nextCtx);
}
}
}
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index f5e46de..c3e4a2e 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -1436,6 +1436,18 @@ void QGLContextGroup::removeGuard(QGLSharedResourceGuard *guard)
m_guards = guard->m_next;
}
+const QGLContext *qt_gl_transfer_context(const QGLContext *ctx)
+{
+ if (!ctx)
+ return 0;
+ QList<const QGLContext *> shares
+ (QGLContextPrivate::contextGroup(ctx)->shares());
+ if (shares.size() >= 2)
+ return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0);
+ else
+ return 0;
+}
+
QGLContextPrivate::~QGLContextPrivate()
{
if (!group->m_refs.deref()) {
@@ -1731,12 +1743,6 @@ struct DDSFormat {
#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
#endif
-Q_GLOBAL_STATIC(QGLShareRegister, _qgl_share_reg)
-Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg()
-{
- return _qgl_share_reg();
-}
-
/*!
\class QGLContext
\brief The QGLContext class encapsulates an OpenGL rendering context.
@@ -2985,7 +2991,7 @@ bool QGLContext::create(const QGLContext* shareContext)
wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer();
}
if (d->sharing) // ok, we managed to share
- qgl_share_reg()->addShare(this, shareContext);
+ QGLContextGroup::addShare(this, shareContext);
return d->valid;
}
@@ -4971,7 +4977,7 @@ Q_OPENGL_EXPORT const QString qt_gl_library_name()
}
#endif
-void QGLShareRegister::addShare(const QGLContext *context, const QGLContext *share) {
+void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) {
Q_ASSERT(context && share);
if (context->d_ptr->group == share->d_ptr->group)
return;
@@ -4992,11 +4998,7 @@ void QGLShareRegister::addShare(const QGLContext *context, const QGLContext *sha
group->m_shares.append(context);
}
-QList<const QGLContext *> QGLShareRegister::shares(const QGLContext *context) {
- return context->d_ptr->group->m_shares;
-}
-
-void QGLShareRegister::removeShare(const QGLContext *context) {
+void QGLContextGroup::removeShare(const QGLContext *context) {
// Remove the context from the group.
QGLContextGroup *group = context->d_ptr->group;
if (group->m_shares.isEmpty())
diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h
index b6cd128..932ea7e 100644
--- a/src/opengl/qgl.h
+++ b/src/opengl/qgl.h
@@ -398,7 +398,7 @@ private:
friend class QGLPixmapData;
friend class QGLPixmapFilterBase;
friend class QGLTextureGlyphCache;
- friend class QGLShareRegister;
+ friend class QGLContextGroup;
friend class QGLSharedResourceGuard;
friend class QGLPixmapBlurFilter;
friend QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags();
diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp
index 839e8eb..084db32 100644
--- a/src/opengl/qgl_egl.cpp
+++ b/src/opengl/qgl_egl.cpp
@@ -152,7 +152,7 @@ void QGLContext::reset()
d->valid = false;
d->transpColor = QColor();
d->initDone = false;
- qgl_share_reg()->removeShare(this);
+ QGLContextGroup::removeShare(this);
}
void QGLContext::makeCurrent()
diff --git a/src/opengl/qgl_mac.mm b/src/opengl/qgl_mac.mm
index 4dd822d..8ecc48b 100644
--- a/src/opengl/qgl_mac.mm
+++ b/src/opengl/qgl_mac.mm
@@ -476,7 +476,7 @@ void QGLContext::reset()
d->valid = false;
d->transpColor = QColor();
d->initDone = false;
- qgl_share_reg()->removeShare(this);
+ QGLContextGroup::removeShare(this);
}
void QGLContext::makeCurrent()
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 834ff96..fcfe791 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -222,9 +222,8 @@ class QGLSharedResourceGuard;
typedef QHash<QString, GLuint> QGLDDSCache;
// QGLContextPrivate has the responsibility of creating context groups.
-// QGLContextPrivate and QGLShareRegister will both maintain the reference counter and destroy
+// QGLContextPrivate maintains the reference counter and destroys
// context groups when needed.
-// QGLShareRegister has the responsibility of keeping the context pointer up to date.
class QGLContextGroup
{
public:
@@ -233,9 +232,13 @@ public:
QGLExtensionFuncs &extensionFuncs() {return m_extensionFuncs;}
const QGLContext *context() const {return m_context;}
bool isSharing() const { return m_shares.size() >= 2; }
+ QList<const QGLContext *> shares() const { return m_shares; }
void addGuard(QGLSharedResourceGuard *guard);
void removeGuard(QGLSharedResourceGuard *guard);
+
+ static void addShare(const QGLContext *context, const QGLContext *share);
+ static void removeShare(const QGLContext *context);
private:
QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }
@@ -249,12 +252,15 @@ private:
void cleanupResources(const QGLContext *ctx);
- friend class QGLShareRegister;
friend class QGLContext;
friend class QGLContextPrivate;
friend class QGLContextResource;
};
+// Get the context that resources for "ctx" will transfer to once
+// "ctx" is destroyed. Returns null if nothing is sharing with ctx.
+Q_OPENGL_EXPORT const QGLContext *qt_gl_transfer_context(const QGLContext *);
+
class QGLTexture;
// This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's
@@ -404,19 +410,6 @@ public:
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions)
-class Q_OPENGL_EXPORT QGLShareRegister
-{
-public:
- QGLShareRegister() {}
- ~QGLShareRegister() {}
-
- void addShare(const QGLContext *context, const QGLContext *share);
- QList<const QGLContext *> shares(const QGLContext *context);
- void removeShare(const QGLContext *context);
-};
-
-extern Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg();
-
// Temporarily make a context current if not already current or
// shared with the current contex. The previous context is made
// current when the object goes out of scope.
diff --git a/src/opengl/qgl_win.cpp b/src/opengl/qgl_win.cpp
index 5b5820a..f80025d 100644
--- a/src/opengl/qgl_win.cpp
+++ b/src/opengl/qgl_win.cpp
@@ -1145,7 +1145,7 @@ void QGLContext::reset()
delete d->cmap;
d->cmap = 0;
d->initDone = false;
- qgl_share_reg()->removeShare(this);
+ QGLContextGroup::removeShare(this);
}
//
diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp
index 9c3fc79..8173bec 100644
--- a/src/opengl/qgl_x11.cpp
+++ b/src/opengl/qgl_x11.cpp
@@ -825,7 +825,7 @@ void QGLContext::reset()
d->valid = false;
d->transpColor = QColor();
d->initDone = false;
- qgl_share_reg()->removeShare(this);
+ QGLContextGroup::removeShare(this);
}
diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp
index 7c97ebb..fab6efc 100644
--- a/src/opengl/qglpixelbuffer.cpp
+++ b/src/opengl/qglpixelbuffer.cpp
@@ -127,7 +127,7 @@ void QGLPixelBufferPrivate::common_init(const QSize &size, const QGLFormat &form
qctx = new QGLContext(format);
qctx->d_func()->sharing = (shareWidget != 0);
if (shareWidget != 0 && shareWidget->d_func()->glcx) {
- qgl_share_reg()->addShare(qctx, shareWidget->d_func()->glcx);
+ QGLContextGroup::addShare(qctx, shareWidget->d_func()->glcx);
shareWidget->d_func()->glcx->d_func()->sharing = true;
}