summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl_p.h
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2010-10-29 11:37:43 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2010-10-29 12:09:41 (GMT)
commitc4d715260bd0ed5f3b6d38a63a2659715342c90a (patch)
tree2c5f6cb9fc396789e7a14bfe6946b0a03f710464 /src/opengl/qgl_p.h
parentbdc13bcc7b4d195d741142acce9b4e9b68c4d5e0 (diff)
downloadQt-c4d715260bd0ed5f3b6d38a63a2659715342c90a.zip
Qt-c4d715260bd0ed5f3b6d38a63a2659715342c90a.tar.gz
Qt-c4d715260bd0ed5f3b6d38a63a2659715342c90a.tar.bz2
Prevented threading related crash in OpenGL module.
If the last shallow copy of a QImage which is cached in the QGLTextureCache is destroyed in a thread at the same time as the QGLContext which the texture was initialized in is active in a different thread, the QImage thread incorrectly tries to make the context active in two threads at once. To prevent this from happening it's best to always do the texture clean-up in the main thread. Task-number: QT-4238 Reviewed-by: Eskil Abrahamsen Blomfeldt
Diffstat (limited to 'src/opengl/qgl_p.h')
-rw-r--r--src/opengl/qgl_p.h68
1 files changed, 45 insertions, 23 deletions
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index f86c77f..18b2765 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -434,20 +434,6 @@ public:
static void setCurrentContext(QGLContext *context);
};
-// ### make QGLContext a QObject in 5.0 and remove the proxy stuff
-class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
-{
- Q_OBJECT
-public:
- QGLSignalProxy() : QObject() {}
- void emitAboutToDestroyContext(const QGLContext *context) {
- emit aboutToDestroyContext(context);
- }
- static QGLSignalProxy *instance();
-Q_SIGNALS:
- void aboutToDestroyContext(const QGLContext *context);
-};
-
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions)
// Temporarily make a context current if not already current or
@@ -490,6 +476,48 @@ private:
QGLContext *m_ctx;
};
+// ### make QGLContext a QObject in 5.0 and remove the proxy stuff
+class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
+{
+ Q_OBJECT
+public:
+ QGLSignalProxy() : QObject() {
+ qRegisterMetaType<GLuint>("GLuint");
+ connect(this, SIGNAL(freeTexture(QGLContext *, QPixmapData *, GLuint)),
+ this, SLOT(freeTexture_slot(QGLContext *, QPixmapData *, GLuint)));
+ }
+ void emitAboutToDestroyContext(const QGLContext *context) {
+ emit aboutToDestroyContext(context);
+ }
+ void emitFreeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id) {
+ emit freeTexture(context, boundPixmap, id);
+ }
+ static QGLSignalProxy *instance();
+Q_SIGNALS:
+ void aboutToDestroyContext(const QGLContext *context);
+ void freeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id);
+
+private slots:
+ void freeTexture_slot(QGLContext *context, QPixmapData *boundPixmap, GLuint id) {
+#if defined(Q_WS_X11)
+ if (boundPixmap) {
+ QGLContext *oldContext = const_cast<QGLContext *>(QGLContext::currentContext());
+ context->makeCurrent();
+ // Although glXReleaseTexImage is a glX call, it must be called while there
+ // is a current context - the context the pixmap was bound to a texture in.
+ // Otherwise the release doesn't do anything and you get BadDrawable errors
+ // when you come to delete the context.
+ QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
+ glDeleteTextures(1, &id);
+ oldContext->makeCurrent();
+ return;
+ }
+#endif
+ QGLShareContextScope scope(context);
+ glDeleteTextures(1, &id);
+ }
+};
+
class QGLTexture {
public:
QGLTexture(QGLContext *ctx = 0, GLuint tx_id = 0, GLenum tx_target = GL_TEXTURE_2D,
@@ -506,16 +534,10 @@ public:
~QGLTexture() {
if (options & QGLContext::MemoryManagedBindOption) {
Q_ASSERT(context);
- QGLShareContextScope scope(context);
-#if defined(Q_WS_X11)
- // Although glXReleaseTexImage is a glX call, it must be called while there
- // is a current context - the context the pixmap was bound to a texture in.
- // Otherwise the release doesn't do anything and you get BadDrawable errors
- // when you come to delete the context.
- if (boundPixmap)
- QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
+#if !defined(Q_WS_X11)
+ QPixmapData *boundPixmap = 0;
#endif
- glDeleteTextures(1, &id);
+ QGLSignalProxy::instance()->emitFreeTexture(context, boundPixmap, id);
}
}