summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl.cpp
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2010-03-11 14:52:37 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2010-03-11 14:53:26 (GMT)
commit82fa80a6b28ea5a4d3e245f531fea22a689c7ad3 (patch)
treebabf61d5c0bef983f4c5ad2a5dc1a4e66d8583f9 /src/opengl/qgl.cpp
parentc5cb91a714f3fa38aeab41c6e793a5a3d071dcef (diff)
downloadQt-82fa80a6b28ea5a4d3e245f531fea22a689c7ad3.zip
Qt-82fa80a6b28ea5a4d3e245f531fea22a689c7ad3.tar.gz
Qt-82fa80a6b28ea5a4d3e245f531fea22a689c7ad3.tar.bz2
Made QGLTextureCache::instance() threadsafe.
Reviewed-by: Tom Cooksey
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r--src/opengl/qgl.cpp27
1 files changed, 7 insertions, 20 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 7839191..c6ecef6 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -1688,14 +1688,12 @@ typedef void (*_qt_image_cleanup_hook_64)(qint64);
extern Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64;
extern Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64;
-static QGLTextureCache *qt_gl_texture_cache = 0;
+
+Q_GLOBAL_STATIC(QGLTextureCache, qt_gl_texture_cache)
QGLTextureCache::QGLTextureCache()
: m_cache(64*1024) // cache ~64 MB worth of textures - this is not accurate though
{
- Q_ASSERT(qt_gl_texture_cache == 0);
- qt_gl_texture_cache = this;
-
QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTexturesForPixampData);
QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction);
QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey);
@@ -1703,8 +1701,7 @@ QGLTextureCache::QGLTextureCache()
QGLTextureCache::~QGLTextureCache()
{
- qt_gl_texture_cache = 0;
-
+ Q_ASSERT(size() == 0);
QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTexturesForPixampData);
QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction);
QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey);
@@ -1754,22 +1751,14 @@ void QGLTextureCache::removeContextTextures(QGLContext* ctx)
}
}
-QGLTextureCache* QGLTextureCache::instance()
-{
- if (!qt_gl_texture_cache)
- qt_gl_texture_cache = new QGLTextureCache;
-
- return qt_gl_texture_cache;
-}
-
/*
a hook that removes textures from the cache when a pixmap/image
is deref'ed
*/
void QGLTextureCache::cleanupTexturesForCacheKey(qint64 cacheKey)
{
- instance()->remove(cacheKey);
- Q_ASSERT(instance()->getTexture(cacheKey) == 0);
+ qt_gl_texture_cache()->remove(cacheKey);
+ Q_ASSERT(qt_gl_texture_cache()->getTexture(cacheKey) == 0);
}
@@ -1791,10 +1780,9 @@ void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd)
#endif
}
-void QGLTextureCache::deleteIfEmpty()
+QGLTextureCache *QGLTextureCache::instance()
{
- if (instance()->size() == 0)
- delete instance();
+ return qt_gl_texture_cache();
}
// DDS format structure
@@ -1960,7 +1948,6 @@ QGLContext::~QGLContext()
{
// remove any textures cached in this context
QGLTextureCache::instance()->removeContextTextures(this);
- QGLTextureCache::deleteIfEmpty(); // ### thread safety
d_ptr->group->cleanupResources(this);