From 318560c8c25524d81ad311ce08ab6b4a962717f4 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 19 Feb 2014 18:19:43 +0100 Subject: [PATCH] Avoid repainting if node is not changed --- src/declarativeimports/core/svgitem.cpp | 13 ++++++++++--- src/declarativeimports/core/svgitem.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/declarativeimports/core/svgitem.cpp b/src/declarativeimports/core/svgitem.cpp index 796e04283..3f9c3993d 100644 --- a/src/declarativeimports/core/svgitem.cpp +++ b/src/declarativeimports/core/svgitem.cpp @@ -33,7 +33,8 @@ namespace Plasma SvgItem::SvgItem(QQuickItem *parent) : QQuickItem(parent), - m_smooth(false) + m_smooth(false), + m_dirty(false) { setFlag(QQuickItem::ItemHasContents, true); } @@ -59,7 +60,7 @@ void SvgItem::setElementId(const QString &elementID) m_elementID = elementID; emit elementIdChanged(); emit naturalSizeChanged(); - update(); + updateNeeded(); } QString SvgItem::elementId() const @@ -124,6 +125,10 @@ bool SvgItem::smooth() const QSGNode* SvgItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData) { Q_UNUSED(updatePaintNodeData); + if (!m_dirty) { + return oldNode; + } + QSGSimpleTextureNode *textureNode = static_cast(oldNode); if (!textureNode) { textureNode = new QSGSimpleTextureNode; @@ -131,11 +136,12 @@ QSGNode* SvgItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updateP if (window() && m_svg) { m_svg.data()->resize(width(), height()); - + qDebug() << "called"; //TODO make m_svg return a QImage so that we can avoid the deep copy in toImage(); const QPixmap pixmap = m_svg.data()->pixmap(); textureNode->setRect(0,0, pixmap.width(), pixmap.height()); textureNode->setTexture(window()->createTextureFromImage(pixmap.toImage())); + m_dirty = false; } return textureNode; } @@ -149,6 +155,7 @@ void SvgItem::updateNeeded() setImplicitHeight(naturalSize().height()); } + m_dirty = true; update(); } diff --git a/src/declarativeimports/core/svgitem.h b/src/declarativeimports/core/svgitem.h index 9234fa62f..738b0630a 100644 --- a/src/declarativeimports/core/svgitem.h +++ b/src/declarativeimports/core/svgitem.h @@ -105,6 +105,7 @@ private: QWeakPointer m_svg; QString m_elementID; bool m_smooth; + bool m_dirty; }; }