diff options
author | Michael Brasser <michael.brasser@live.com> | 2013-03-26 10:52:34 -0500 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-04-02 10:25:14 +0200 |
commit | 2e8c125a9e72fe2cba5328fe8cd4f22548d26444 (patch) | |
tree | b7a950a054d9481d1af212f1fb4e206b83cb0fa7 /customcontext | |
parent | 2a37b55beed47d904093f420adc4eec103e56efd (diff) |
Introduce 'nonpreservedtexture'
Provide a texture factory that does not keep a reference to the
QImage. This is intended to lower memory usage in the case of an
embedded system with only a single window that is never hidden or
re-exposed.
See also 8b50a9f00f6f5b693d18c59ff15968e2b902ebf8 in qtdeclarative.
Change-Id: If0a11f6bb37f4fb3b409a577609ebdfce73789b2
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'customcontext')
-rw-r--r-- | customcontext/context.cpp | 16 | ||||
-rw-r--r-- | customcontext/context.h | 4 | ||||
-rw-r--r-- | customcontext/customcontext.pro | 10 | ||||
-rw-r--r-- | customcontext/texture/nonpreservedtexture.cpp | 32 | ||||
-rw-r--r-- | customcontext/texture/nonpreservedtexture.h | 29 |
5 files changed, 91 insertions, 0 deletions
diff --git a/customcontext/context.cpp b/customcontext/context.cpp index 8ab0a4f..f349213 100644 --- a/customcontext/context.cpp +++ b/customcontext/context.cpp @@ -71,6 +71,10 @@ #include "mactexture.h" #endif +#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE +#include "nonpreservedtexture.h" +#endif + namespace CustomContext @@ -126,6 +130,10 @@ Context::Context(QObject *parent) connect(this, SIGNAL(invalidated()), &m_threadUploadManager, SLOT(invalidated()), Qt::DirectConnection); #endif +#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE + m_nonPreservedTexture = qgetenv("CUSTOMCONTEXT_NO_NONPRESERVEDTEXTURE").isEmpty(); +#endif + #ifdef CUSTOMCONTEXT_DEBUG @@ -154,6 +162,9 @@ Context::Context(QObject *parent) #ifdef CUSTOMCONTEXT_MACTEXTURE qDebug(" - mac textures: %s", m_macTexture ? "yes" : "no"); #endif +#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE + qDebug(" - non preserved textures: %s", m_nonPreservedTexture ? "yes" : "no"); +#endif #ifdef CUSTOMCONTEXT_DITHER qDebug(" - ordered 2x2 dither: %s", m_dither ? "yes" : "no"); @@ -317,6 +328,11 @@ QQuickTextureFactory *Context::createTextureFactory(const QImage &image) return m_threadUploadManager.create(image); #endif +#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE + if (m_nonPreservedTexture) + return new NonPreservedTextureFactory(image); +#endif + return 0; } diff --git a/customcontext/context.h b/customcontext/context.h index a02d0d6..fff2a56 100644 --- a/customcontext/context.h +++ b/customcontext/context.h @@ -121,6 +121,10 @@ private: bool m_threadUploadTexture; #endif +#ifdef CUSTOMCONTEXT_NONPRESERVEDTEXTURE + bool m_nonPreservedTexture; +#endif + }; diff --git a/customcontext/customcontext.pro b/customcontext/customcontext.pro index 62bb5ab..2443360 100644 --- a/customcontext/customcontext.pro +++ b/customcontext/customcontext.pro @@ -67,6 +67,16 @@ mactexture:{ message("mactexture ...............: no") } +nonpreservedtexture:{ + message("nonpreservedtexture ......: yes") + DEFINES += CUSTOMCONTEXT_NONPRESERVEDTEXTURE + SOURCES += texture/nonpreservedtexture.cpp + HEADERS += texture/nonpreservedtexture.h + INCLUDEPATH += texture +} else { + message("nonpreservedtexture ......: no") +} + ############################################################ diff --git a/customcontext/texture/nonpreservedtexture.cpp b/customcontext/texture/nonpreservedtexture.cpp new file mode 100644 index 0000000..dbfb4d1 --- /dev/null +++ b/customcontext/texture/nonpreservedtexture.cpp @@ -0,0 +1,32 @@ +#include "nonpreservedtexture.h" + +#include <private/qsgtexture_p.h> + +namespace CustomContext { + +/* + Typically a texture factory will keep a reference to the + QImage so that it can be reused when QQuickWindow::setPersistentSceneGraph(false) + is set and the window is hidden and then re-exposed. + + This texture factory does not keep a reference, and is + intended to lower memory usage in the case of an embedded + system with only a single window that is never hidden or re-exposed. +*/ + +NonPreservedTextureFactory::NonPreservedTextureFactory(const QImage &image) + : m_image(image) +{ + m_size = m_image.size(); + m_byteCount = m_image.byteCount(); +} + +QSGTexture *NonPreservedTextureFactory::createTexture(QQuickWindow *) const +{ + QSGPlainTexture *t = new QSGPlainTexture(); + t->setImage(m_image); + m_image = QImage(); + return t; +} + +} // end of namespace diff --git a/customcontext/texture/nonpreservedtexture.h b/customcontext/texture/nonpreservedtexture.h new file mode 100644 index 0000000..65f89a2 --- /dev/null +++ b/customcontext/texture/nonpreservedtexture.h @@ -0,0 +1,29 @@ +#ifndef NONPRESERVEDTEXTURE_H +#define NONPRESERVEDTEXTURE_H + +#include <QSize> +#include <QImage> +#include <QQuickTextureFactory> + +namespace CustomContext { + +class NonPreservedTextureFactory : public QQuickTextureFactory +{ + Q_OBJECT +public: + NonPreservedTextureFactory(const QImage &image); + + QSGTexture *createTexture(QQuickWindow *window) const; + QSize textureSize() const { return m_size; } + int textureByteCount() const { return m_byteCount; } + QImage image() const { return m_image; } + +private: + mutable QImage m_image; + QSize m_size; + int m_byteCount; +}; + +} + +#endif // NONPRESERVEDTEXTURE_H |