From fa78127622424fba161f5f42e9e76c72e653828a Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 29 Jan 2015 19:09:39 +0100 Subject: Introduce QSG_TRANSIENT_IMAGES. This feature enables the same feature that we already have in the 'nonpreservedtexture' in the scene graph playground. This change also cleans up some leftover logic from the early Qt 5.2 days when we had to manually extract the image from the default texture factory rather than going through QQuickWindow::createTexture(). This cleanup is required for the logic to work. Change-Id: I7cdf15d981ba8af94f8d51781fc01e2b834b77c6 Reviewed-by: Robin Burchell --- src/quick/scenegraph/qsgcontext.cpp | 5 +---- src/quick/util/qquickpixmapcache.cpp | 10 +++++++--- src/quick/util/qquickpixmapcache_p.h | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp index 95388d82e0..096f53b94c 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -806,10 +806,7 @@ QSGTexture *QSGRenderContext::textureForFactory(QQuickTextureFactory *factory, Q m_mutex.unlock(); if (!texture) { - if (QQuickDefaultTextureFactory *dtf = qobject_cast(factory)) - texture = createTexture(dtf->image()); - else - texture = factory->createTexture(window); + texture = factory->createTexture(window); m_mutex.lock(); m_textures.insert(factory, texture); diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index a2a8ef03c7..7daf6756ad 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -101,13 +102,16 @@ QQuickDefaultTextureFactory::QQuickDefaultTextureFactory(const QImage &image) } else { im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); } + size = im.size(); } -QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickWindow *) const +QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickWindow *window) const { - QSGPlainTexture *t = new QSGPlainTexture(); - t->setImage(im); + QSGTexture *t = window->createTextureFromImage(im, QQuickWindow::TextureCanUseAtlas); + static bool transient = qEnvironmentVariableIsSet("QSG_TRANSIENT_IMAGES"); + if (transient) + const_cast(this)->im = QImage(); return t; } diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h index df56ee3a10..f7a76a69f8 100644 --- a/src/quick/util/qquickpixmapcache_p.h +++ b/src/quick/util/qquickpixmapcache_p.h @@ -55,12 +55,13 @@ class QQuickDefaultTextureFactory : public QQuickTextureFactory public: QQuickDefaultTextureFactory(const QImage &i); QSGTexture *createTexture(QQuickWindow *window) const; - QSize textureSize() const { return im.size(); } - int textureByteCount() const { return im.byteCount(); } + QSize textureSize() const { return size; } + int textureByteCount() const { return size.width() * size.height() * 4; } QImage image() const { return im; } private: QImage im; + QSize size; }; class Q_QUICK_PRIVATE_EXPORT QQuickPixmap -- cgit v1.2.3