summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2016-09-21 12:29:50 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2016-09-23 11:46:56 +0000
commitf5e2783acec1f46070330fc1ce90cb16901a5533 (patch)
tree0685880e6eb030208866d0ca90122c85d458896d
parente05fbf5c8bf636db5c500c3371d673de17de8c33 (diff)
Quick: Do not send SG updates when AnimatedSprite is not visible
Task-number: QTBUG-55935 Change-Id: I475c1bb3e7aae9499b1b07a52f3c10f54c8b3481 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp32
-rw-r--r--src/quick/items/qquickanimatedsprite_p.h1
2 files changed, 21 insertions, 12 deletions
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index 44b5ff1e45..7fd89e21a1 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -35,6 +35,7 @@
#include "qquicksprite_p.h"
#include "qquickspriteengine_p.h"
#include <QtQuick/private/qsgcontext_p.h>
+#include <QtQuick/private/qquickitem_p.h>
#include <private/qsgadaptationlayer_p.h>
#include <private/qqmlglobal_p.h>
#include <QtQuick/qsgnode.h>
@@ -362,7 +363,7 @@ void QQuickAnimatedSprite::start()
}
emit currentFrameChanged(0);
emit runningChanged(true);
- update();
+ maybeUpdate();
}
void QQuickAnimatedSprite::stop()
@@ -372,7 +373,7 @@ void QQuickAnimatedSprite::stop()
return;
m_pauseOffset = 0;
emit runningChanged(false);
- update();
+ maybeUpdate();
}
/*!
@@ -390,7 +391,15 @@ void QQuickAnimatedSprite::advance(int frames)
m_curFrame += m_spriteEngine->maxFrames();
m_curFrame = m_curFrame % m_spriteEngine->maxFrames();
emit currentFrameChanged(m_curFrame);
- update();
+ maybeUpdate();
+}
+
+void QQuickAnimatedSprite::maybeUpdate()
+{
+ QQuickItemPrivate *priv = QQuickItemPrivate::get(this);
+ const QLazilyAllocated<QQuickItemPrivate::ExtraData> &extraData = priv->extra;
+ if ((extraData.isAllocated() && extraData->effectRefCount > 0) || priv->effectiveVisible)
+ update();
}
/*!
@@ -408,7 +417,7 @@ void QQuickAnimatedSprite::pause()
m_pauseOffset = m_timestamp.elapsed();
m_paused = true;
emit pausedChanged(true);
- update();
+ maybeUpdate();
}
/*!
@@ -426,7 +435,7 @@ void QQuickAnimatedSprite::resume()
m_pauseOffset = m_pauseOffset - m_timestamp.elapsed();
m_paused = false;
emit pausedChanged(false);
- update();
+ maybeUpdate();
}
void QQuickAnimatedSprite::createEngine()
@@ -438,7 +447,6 @@ void QQuickAnimatedSprite::createEngine()
m_spriteEngine = new QQuickSpriteEngine(QList<QQuickSprite*>(spriteList), this);
m_spriteEngine->startAssemblingImage();
reset();
- update();
}
static QSGGeometry::Attribute AnimatedSprite_Attributes[] = {
@@ -476,10 +484,10 @@ QSGGeometryNode* QQuickAnimatedSprite::buildNode()
return 0;
} else if (m_spriteEngine->status() == QQuickPixmap::Null) {
m_spriteEngine->startAssemblingImage();
- update();//Schedule another update, where we will check again
+ maybeUpdate();//Schedule another update, where we will check again
return 0;
} else if (m_spriteEngine->status() == QQuickPixmap::Loading) {
- update();//Schedule another update, where we will check again
+ maybeUpdate();//Schedule another update, where we will check again
return 0;
}
@@ -541,7 +549,7 @@ QSGGeometryNode* QQuickAnimatedSprite::buildNode()
void QQuickAnimatedSprite::reset()
{
m_pleaseReset = true;
- update();
+ maybeUpdate();
}
QSGNode *QQuickAnimatedSprite::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
@@ -562,7 +570,7 @@ QSGNode *QQuickAnimatedSprite::updatePaintNode(QSGNode *oldNode, UpdatePaintNode
if (m_running) {
if (!m_paused)
- update();
+ maybeUpdate();
if (node) {
node->markDirty(QSGNode::DirtyMaterial);
@@ -618,7 +626,7 @@ void QQuickAnimatedSprite::prepareNextFrame(QSGGeometryNode *node)
frameAt = 0;
m_running = false;
emit runningChanged(false);
- update();
+ maybeUpdate();
}
} else {
frameAt = m_curFrame;
@@ -626,7 +634,7 @@ void QQuickAnimatedSprite::prepareNextFrame(QSGGeometryNode *node)
if (m_curFrame != lastFrame) {
if (isCurrentFrameChangedConnected())
emit currentFrameChanged(m_curFrame);
- update();
+ maybeUpdate();
}
qreal frameCount = m_spriteEngine->spriteFrames();
diff --git a/src/quick/items/qquickanimatedsprite_p.h b/src/quick/items/qquickanimatedsprite_p.h
index 5b181640f9..01c5c2d3bd 100644
--- a/src/quick/items/qquickanimatedsprite_p.h
+++ b/src/quick/items/qquickanimatedsprite_p.h
@@ -360,6 +360,7 @@ protected:
void componentComplete() Q_DECL_OVERRIDE;
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE;
private:
+ void maybeUpdate();
bool isCurrentFrameChangedConnected();
void prepareNextFrame(QSGGeometryNode *node);
void reloadImage();