From 26ff8f9029107877bfbfdc2f099f9b11861183ed Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 22 Mar 2016 07:24:47 -0500 Subject: Allow more control over memory/speed tradeoff in the atlas. QSG_ATLAS_TRANSIENT_IMAGE_THRESHOLD can be used to define a threshold for retaining the QImage associated with an atlas texture. This gives more control to the developer on platforms where removing a texture from the atlas (e.g. for use in a ShaderEffect) can be prohibitively expensive. Change-Id: I13fd01ebbe94dd960fdcb3ee20b4ff40dcc5694f Reviewed-by: Laszlo Agocs Reviewed-by: Brett Stottlemyer Reviewed-by: Robin Burchell Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/util/qsgatlastexture.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/quick/scenegraph/util/qsgatlastexture.cpp') diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 8e8e870505..832510148c 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -121,6 +121,7 @@ Atlas::Atlas(const QSize &size) : m_allocator(size) , m_texture_id(0) , m_size(size) + , m_atlas_transient_image_threshold(0) , m_allocated(false) { @@ -170,6 +171,11 @@ Atlas::Atlas(const QSize &size) m_use_bgra_fallback = qEnvironmentVariableIsSet("QSG_ATLAS_USE_BGRA_FALLBACK"); m_debug_overlay = qEnvironmentVariableIsSet("QSG_ATLAS_OVERLAY"); + + // images smaller than this will retain their QImage. + // by default no images are retained (favoring memory) + // set to a very large value to retain all images (allowing quick removal from the atlas) + m_atlas_transient_image_threshold = qt_sg_envInt("QSG_ATLAS_TRANSIENT_IMAGE_THRESHOLD", 0); } Atlas::~Atlas() @@ -392,7 +398,10 @@ void Atlas::bind(QSGTexture::Filtering filtering) } else { upload(t); } - t->releaseImage(); + const QSize textureSize = t->textureSize(); + if (textureSize.width() > m_atlas_transient_image_threshold || + textureSize.height() > m_atlas_transient_image_threshold) + t->releaseImage(); qCDebug(QSG_LOG_TIME_TEXTURE).nospace() << "atlastexture uploaded in: " << qsg_renderer_timer.elapsed() << "ms (" << t->textureSize().width() << "x" -- cgit v1.2.3