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>
This commit is contained in:
Erik Verbruggen 2016-09-21 12:29:50 +02:00 committed by Erik Verbruggen
parent e05fbf5c8b
commit f5e2783ace
2 changed files with 21 additions and 12 deletions

View File

@ -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();

View File

@ -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();