From 9b6869b35dedbbe412342c6d7d9c450ee1c5f45d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 27 Jan 2021 08:34:44 -0600 Subject: Do less work when there are no active ImageParticle particles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't mark geometry and material as dirty if there is nothing to change. Task-number: QTBUG-41867 Change-Id: I016d2d76f4ebf731f5bfc931ba616ee5d074bc65 Reviewed-by: Tomi Korpipää Reviewed-by: Laszlo Agocs (cherry picked from commit e3cb305a6a19bf394c1068a7e483e1c95e11c22b) Reviewed-by: Qt Cherry-pick Bot --- src/particles/qquickimageparticle.cpp | 32 +++++++++++++++++++++++++------- src/particles/qquickimageparticle_p.h | 3 ++- src/particles/qquickparticlesystem_p.h | 2 ++ 3 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src/particles') diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp index 643194c8d5..884edc3390 100644 --- a/src/particles/qquickimageparticle.cpp +++ b/src/particles/qquickimageparticle.cpp @@ -743,6 +743,7 @@ QQuickImageParticle::QQuickImageParticle(QQuickItem* parent) , m_rhi(nullptr) , m_apiChecked(false) , m_dpr(1.0) + , m_previousActive(false) { setFlag(ItemHasContents); } @@ -1569,11 +1570,13 @@ QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *node, UpdatePaintNodeData } if (m_system && m_system->isRunning() && !m_system->isPaused()){ - prepareNextFrame(&node); + bool dirty = prepareNextFrame(&node); if (node) { update(); - foreach (QSGGeometryNode* n, m_nodes) - n->markDirty(QSGNode::DirtyGeometry); + if (dirty) { + foreach (QSGGeometryNode* n, m_nodes) + n->markDirty(QSGNode::DirtyGeometry); + } } else if (m_startedImageLoading < 2) { update();//To call prepareNextFrame() again from the renderThread } @@ -1587,7 +1590,7 @@ QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *node, UpdatePaintNodeData return node; } -void QQuickImageParticle::prepareNextFrame(QSGNode **node) +bool QQuickImageParticle::prepareNextFrame(QSGNode **node) { if (*node == nullptr){//TODO: Staggered loading (as emitted) buildParticleNodes(node); @@ -1603,7 +1606,7 @@ void QQuickImageParticle::prepareNextFrame(QSGNode **node) qDebug() << "Total count: " << count; } if (*node == nullptr) - return; + return false; } qint64 timeStamp = m_system->systemSync(this); @@ -1625,8 +1628,23 @@ void QQuickImageParticle::prepareNextFrame(QSGNode **node) getState(m_material)->timestamp = time; break; } - foreach (QSGGeometryNode* node, m_nodes) - node->markDirty(QSGNode::DirtyMaterial); + + bool active = false; + for (auto groupId : groupIds()) { + if (m_system->groupData[groupId]->isActive()) { + active = true; + break; + } + } + + const bool dirty = active || m_previousActive; + if (dirty) { + foreach (QSGGeometryNode* node, m_nodes) + node->markDirty(QSGNode::DirtyMaterial); + } + + m_previousActive = active; + return dirty; } void QQuickImageParticle::spritesUpdate(qreal time) diff --git a/src/particles/qquickimageparticle_p.h b/src/particles/qquickimageparticle_p.h index 320534ca0b..19000f6c9b 100644 --- a/src/particles/qquickimageparticle_p.h +++ b/src/particles/qquickimageparticle_p.h @@ -383,7 +383,7 @@ protected: void commit(int gIdx, int pIdx) override; QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; - void prepareNextFrame(QSGNode**); + bool prepareNextFrame(QSGNode**); void buildParticleNodes(QSGNode**); void sceneGraphInvalidated() override; @@ -483,6 +483,7 @@ private: QRhi *m_rhi; bool m_apiChecked; qreal m_dpr; + bool m_previousActive; }; QT_END_NAMESPACE diff --git a/src/particles/qquickparticlesystem_p.h b/src/particles/qquickparticlesystem_p.h index d991257452..2f2e10d264 100644 --- a/src/particles/qquickparticlesystem_p.h +++ b/src/particles/qquickparticlesystem_p.h @@ -205,6 +205,8 @@ public: return m_size; } + bool isActive() { return freeList.count() > 0; } + QString name() const; void setSize(int newSize); -- cgit v1.2.3