summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorTom Cooksey <thomas.cooksey@nokia.com>2009-07-27 14:44:27 (GMT)
committerTom Cooksey <thomas.cooksey@nokia.com>2009-07-28 14:17:45 (GMT)
commitf4978a5894212dd655a91dbb0db02a89070bb165 (patch)
tree2028648f9304274e21a4ee73f7d16cde7855b462 /src/opengl
parent8e9921c43ae0b896aee091e1031b4f42c332332b (diff)
downloadQt-f4978a5894212dd655a91dbb0db02a89070bb165.zip
Qt-f4978a5894212dd655a91dbb0db02a89070bb165.tar.gz
Qt-f4978a5894212dd655a91dbb0db02a89070bb165.tar.bz2
Refactor QImage/QPixmap cleanup hooks into a seperate class
The new class alows more than one hook to be installed at a time and, for QPixmaps, the hook is told which pixmap is getting deleted. Reviewed-By: Samuel
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qgl.cpp25
-rw-r--r--src/opengl/qgl_p.h3
2 files changed, 22 insertions, 6 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index edda6b6..8bb72d5 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -86,6 +86,7 @@
#include <private/qpixmapdata_gl_p.h>
#include <private/qglpixelbuffer_p.h>
#include <private/qwindowsurface_gl_p.h>
+#include <private/qimagepixmapcleanuphooks_p.h>
#include "qcolormap.h"
#include "qfile.h"
#include "qlibrary.h"
@@ -1407,15 +1408,17 @@ QGLTextureCache::QGLTextureCache()
{
Q_ASSERT(qt_gl_texture_cache == 0);
qt_gl_texture_cache = this;
- qt_pixmap_cleanup_hook_64 = cleanupHook;
- qt_image_cleanup_hook_64 = cleanupHook;
+
+ QImagePixmapCleanupHooks::instance()->addPixmapHook(pixmapCleanupHook);
+ QImagePixmapCleanupHooks::instance()->addImageHook(imageCleanupHook);
}
QGLTextureCache::~QGLTextureCache()
{
qt_gl_texture_cache = 0;
- qt_pixmap_cleanup_hook_64 = 0;
- qt_image_cleanup_hook_64 = 0;
+
+ QImagePixmapCleanupHooks::instance()->removePixmapHook(pixmapCleanupHook);
+ QImagePixmapCleanupHooks::instance()->removeImageHook(imageCleanupHook);
}
void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost)
@@ -1471,11 +1474,23 @@ QGLTextureCache* QGLTextureCache::instance()
a hook that removes textures from the cache when a pixmap/image
is deref'ed
*/
-void QGLTextureCache::cleanupHook(qint64 cacheKey)
+void QGLTextureCache::imageCleanupHook(qint64 cacheKey)
+{
+ // ### remove when the GL texture cache becomes thread-safe
+ if (qApp->thread() != QThread::currentThread())
+ return;
+ QGLTexture *texture = instance()->getTexture(cacheKey);
+ if (texture && texture->clean)
+ instance()->remove(cacheKey);
+}
+
+
+void QGLTextureCache::pixmapCleanupHook(QPixmap* pixmap)
{
// ### remove when the GL texture cache becomes thread-safe
if (qApp->thread() != QThread::currentThread())
return;
+ const qint64 cacheKey = pixmap->cacheKey();
QGLTexture *texture = instance()->getTexture(cacheKey);
if (texture && texture->clean)
instance()->remove(cacheKey);
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 85dae0d..a83cc63 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -458,7 +458,8 @@ public:
static QGLTextureCache *instance();
static void deleteIfEmpty();
- static void cleanupHook(qint64 cacheKey);
+ static void imageCleanupHook(qint64 cacheKey);
+ static void pixmapCleanupHook(QPixmap* pixmap);
private:
QCache<qint64, QGLTexture> m_cache;