summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-12-08 06:34:41 +0100
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-12-08 06:34:41 +0100
commita2e244eb4a958d3f8adc42d364def21ff8ea7f20 (patch)
tree37f4a6ccce85bc74285ed75f26bff26e53a2053f
parentf639ecdb28a281a2b2d2f5d27dfa03f3c8bcba9c (diff)
cache the QSGTexture, so that we only return one pr QImage
-rw-r--r--src/scenegraph/coreapi/qsgtexturemanager.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/scenegraph/coreapi/qsgtexturemanager.cpp b/src/scenegraph/coreapi/qsgtexturemanager.cpp
index d8ce090..89cbe19 100644
--- a/src/scenegraph/coreapi/qsgtexturemanager.cpp
+++ b/src/scenegraph/coreapi/qsgtexturemanager.cpp
@@ -44,6 +44,7 @@
#include <QImage>
#include <qgl.h>
+#include <qhash.h>
QSGTexture::QSGTexture()
: m_status(Null)
@@ -74,7 +75,30 @@ void QSGTexture::setStatus(Status s)
+struct QSGTextureCacheKey {
+ quint64 cacheKey;
+
+ bool operator==(const QSGTextureCacheKey &other) const {
+ return other.cacheKey == cacheKey;
+ }
+};
+
+
+uint qHash(const QSGTextureCacheKey &key)
+{
+ return (key.cacheKey >> 32) ^ uint(key.cacheKey);
+}
+
+class QSGTextureManagerPrivate
+{
+public:
+ QHash<QSGTextureCacheKey, QSGTexture *> cache;
+};
+
+
+
QSGTextureManager::QSGTextureManager()
+ : d(new QSGTextureManagerPrivate)
{
}
@@ -97,6 +121,11 @@ QImage QSGTextureManager::swizzleBGGRAToRGBA(const QImage &image)
QSGTextureRef QSGTextureManager::upload(const QImage &image)
{
+ QSGTextureCacheKey key = { image.cacheKey() };
+ QSGTexture *texture = d->cache.value(key);
+ if (texture)
+ return QSGTextureRef(texture);
+
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
@@ -108,12 +137,14 @@ QSGTextureRef QSGTextureManager::upload(const QImage &image)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, image.constBits());
#endif
- QSGTexture *texture = new QSGTexture;
+ texture = new QSGTexture;
texture->setTextureId(id);
texture->setTextureSize(image.size());
texture->setAlphaChannel(image.hasAlphaChannel());
texture->setStatus(QSGTexture::Ready);
+ d->cache.insert(key, texture);
+
QSGTextureRef ref(texture);
return ref;
}