summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2013-03-26 11:48:18 -0500
committerGunnar Sletta <gunnar.sletta@digia.com>2013-04-02 10:25:32 +0200
commit7a29e57ea8c466c16fd75af059fb22adb6ab72f5 (patch)
tree51510d16909a7c62e4a6d81a266dbb541bd991ef
parent2e8c125a9e72fe2cba5328fe8cd4f22548d26444 (diff)
Allow nonpreservedrtexture and atlastexture to be used together.
Small images will be atlased; large ones will not be preserved. Change-Id: Ia521e849e22068fef42ad3d0db7f57c22953818a Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
-rw-r--r--customcontext/context.cpp9
-rw-r--r--customcontext/context.h1
-rw-r--r--customcontext/texture/atlastexture.cpp6
-rw-r--r--customcontext/texture/nonpreservedtexture.cpp13
-rw-r--r--customcontext/texture/nonpreservedtexture.h5
5 files changed, 24 insertions, 10 deletions
diff --git a/customcontext/context.cpp b/customcontext/context.cpp
index f349213..27a6a81 100644
--- a/customcontext/context.cpp
+++ b/customcontext/context.cpp
@@ -278,8 +278,11 @@ QSurfaceFormat Context::defaultSurfaceFormat() const
QSGTexture *Context::createTexture(const QImage &image) const
{
#ifdef CUSTOMCONTEXT_ATLASTEXTURE
- if (m_atlasTexture)
- return const_cast<Context *>(this)->m_atlasManager.create(image);
+ if (m_atlasTexture) {
+ QSGTexture *t = const_cast<Context *>(this)->m_atlasManager.create(image);
+ if (t)
+ return t;
+ }
#endif
#ifdef CUSTOMCONTEXT_MACTEXTURE
@@ -330,7 +333,7 @@ QQuickTextureFactory *Context::createTextureFactory(const QImage &image)
#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE
if (m_nonPreservedTexture)
- return new NonPreservedTextureFactory(image);
+ return new NonPreservedTextureFactory(image, this);
#endif
return 0;
diff --git a/customcontext/context.h b/customcontext/context.h
index fff2a56..53bfb6f 100644
--- a/customcontext/context.h
+++ b/customcontext/context.h
@@ -123,6 +123,7 @@ private:
#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE
bool m_nonPreservedTexture;
+ friend class NonPreservedTextureFactory;
#endif
diff --git a/customcontext/texture/atlastexture.cpp b/customcontext/texture/atlastexture.cpp
index dee14fd..e85d2cd 100644
--- a/customcontext/texture/atlastexture.cpp
+++ b/customcontext/texture/atlastexture.cpp
@@ -105,8 +105,8 @@ void TextureAtlasManager::invalidate()
QSGTexture *TextureAtlasManager::create(const QImage &image)
{
+ QSGTexture *t = 0;
if (image.width() < m_atlas_size_limit && image.height() < m_atlas_size_limit) {
- QSGTexture *t = 0;
// If we have a larger atlas, try to allocate in that one, so we get as many
// images as possible batched together.
@@ -129,9 +129,7 @@ QSGTexture *TextureAtlasManager::create(const QImage &image)
return t;
}
- QSGPlainTexture *pt = new QSGPlainTexture();
- pt->setImage(image);
- return pt;
+ return t;
}
TextureAtlas::TextureAtlas(const QSize &size)
diff --git a/customcontext/texture/nonpreservedtexture.cpp b/customcontext/texture/nonpreservedtexture.cpp
index dbfb4d1..004e90b 100644
--- a/customcontext/texture/nonpreservedtexture.cpp
+++ b/customcontext/texture/nonpreservedtexture.cpp
@@ -1,5 +1,6 @@
#include "nonpreservedtexture.h"
+#include "context.h"
#include <private/qsgtexture_p.h>
namespace CustomContext {
@@ -14,8 +15,8 @@ namespace CustomContext {
system with only a single window that is never hidden or re-exposed.
*/
-NonPreservedTextureFactory::NonPreservedTextureFactory(const QImage &image)
- : m_image(image)
+NonPreservedTextureFactory::NonPreservedTextureFactory(const QImage &image, Context *context)
+ : m_image(image), m_context(context)
{
m_size = m_image.size();
m_byteCount = m_image.byteCount();
@@ -23,6 +24,14 @@ NonPreservedTextureFactory::NonPreservedTextureFactory(const QImage &image)
QSGTexture *NonPreservedTextureFactory::createTexture(QQuickWindow *) const
{
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ if (m_context->m_atlasTexture) {
+ QSGTexture *atlasedTexture = m_context->m_atlasManager.create(m_image);
+ if (atlasedTexture)
+ return atlasedTexture;
+ }
+#endif
+
QSGPlainTexture *t = new QSGPlainTexture();
t->setImage(m_image);
m_image = QImage();
diff --git a/customcontext/texture/nonpreservedtexture.h b/customcontext/texture/nonpreservedtexture.h
index 65f89a2..5fe6db3 100644
--- a/customcontext/texture/nonpreservedtexture.h
+++ b/customcontext/texture/nonpreservedtexture.h
@@ -7,11 +7,13 @@
namespace CustomContext {
+class Context;
+
class NonPreservedTextureFactory : public QQuickTextureFactory
{
Q_OBJECT
public:
- NonPreservedTextureFactory(const QImage &image);
+ NonPreservedTextureFactory(const QImage &image, Context *context);
QSGTexture *createTexture(QQuickWindow *window) const;
QSize textureSize() const { return m_size; }
@@ -22,6 +24,7 @@ private:
mutable QImage m_image;
QSize m_size;
int m_byteCount;
+ Context *m_context;
};
}