Avoid repainting if node is not changed

This commit is contained in:
David Edmundson 2014-02-19 18:19:43 +01:00
parent 9851f8c789
commit 318560c8c2
2 changed files with 11 additions and 3 deletions

View File

@ -33,7 +33,8 @@ namespace Plasma
SvgItem::SvgItem(QQuickItem *parent) SvgItem::SvgItem(QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_smooth(false) m_smooth(false),
m_dirty(false)
{ {
setFlag(QQuickItem::ItemHasContents, true); setFlag(QQuickItem::ItemHasContents, true);
} }
@ -59,7 +60,7 @@ void SvgItem::setElementId(const QString &elementID)
m_elementID = elementID; m_elementID = elementID;
emit elementIdChanged(); emit elementIdChanged();
emit naturalSizeChanged(); emit naturalSizeChanged();
update(); updateNeeded();
} }
QString SvgItem::elementId() const QString SvgItem::elementId() const
@ -124,6 +125,10 @@ bool SvgItem::smooth() const
QSGNode* SvgItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData) QSGNode* SvgItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData)
{ {
Q_UNUSED(updatePaintNodeData); Q_UNUSED(updatePaintNodeData);
if (!m_dirty) {
return oldNode;
}
QSGSimpleTextureNode *textureNode = static_cast<QSGSimpleTextureNode*>(oldNode); QSGSimpleTextureNode *textureNode = static_cast<QSGSimpleTextureNode*>(oldNode);
if (!textureNode) { if (!textureNode) {
textureNode = new QSGSimpleTextureNode; textureNode = new QSGSimpleTextureNode;
@ -131,11 +136,12 @@ QSGNode* SvgItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updateP
if (window() && m_svg) { if (window() && m_svg) {
m_svg.data()->resize(width(), height()); 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(); //TODO make m_svg return a QImage so that we can avoid the deep copy in toImage();
const QPixmap pixmap = m_svg.data()->pixmap(); const QPixmap pixmap = m_svg.data()->pixmap();
textureNode->setRect(0,0, pixmap.width(), pixmap.height()); textureNode->setRect(0,0, pixmap.width(), pixmap.height());
textureNode->setTexture(window()->createTextureFromImage(pixmap.toImage())); textureNode->setTexture(window()->createTextureFromImage(pixmap.toImage()));
m_dirty = false;
} }
return textureNode; return textureNode;
} }
@ -149,6 +155,7 @@ void SvgItem::updateNeeded()
setImplicitHeight(naturalSize().height()); setImplicitHeight(naturalSize().height());
} }
m_dirty = true;
update(); update();
} }

View File

@ -105,6 +105,7 @@ private:
QWeakPointer<Plasma::Svg> m_svg; QWeakPointer<Plasma::Svg> m_svg;
QString m_elementID; QString m_elementID;
bool m_smooth; bool m_smooth;
bool m_dirty;
}; };
} }