From 1eb0deb0dffd524f66a9c179331a1268e3404467 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 21 Feb 2014 00:44:42 +0100 Subject: [PATCH] Move QSGTexture memory management into QSGSimpleTextureNode subclass --- src/declarativeimports/core/svgitem.cpp | 30 ++++++++++++++++--------- src/declarativeimports/core/svgitem.h | 2 -- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/declarativeimports/core/svgitem.cpp b/src/declarativeimports/core/svgitem.cpp index b7f2d42fa..6234d6429 100644 --- a/src/declarativeimports/core/svgitem.cpp +++ b/src/declarativeimports/core/svgitem.cpp @@ -19,7 +19,6 @@ #include "svgitem.h" -#include #include #include #include @@ -31,9 +30,22 @@ namespace Plasma { +class SVGTextureNode : public QSGSimpleTextureNode +{ + public: + SVGTextureNode() {} + void setTexture(QSGTexture *texture); + private: + QScopedPointer m_texture; +}; + +void SVGTextureNode::setTexture(QSGTexture *texture) { + m_texture.reset(texture); + QSGSimpleTextureNode::setTexture(texture); +} + SvgItem::SvgItem(QQuickItem *parent) : QQuickItem(parent), - m_texture(0), m_smooth(false) { setFlag(QQuickItem::ItemHasContents, true); @@ -42,7 +54,6 @@ SvgItem::SvgItem(QQuickItem *parent) SvgItem::~SvgItem() { - delete m_texture; } void SvgItem::setElementId(const QString &elementID) @@ -125,30 +136,27 @@ bool SvgItem::smooth() const QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) { - Q_UNUSED(updatePaintNodeData) - if (!window() || !m_svg) { delete oldNode; return 0; } - QSGSimpleTextureNode *textureNode = static_cast(oldNode); + SVGTextureNode *textureNode = static_cast(oldNode); if (!textureNode) { - textureNode = new QSGSimpleTextureNode; + textureNode = new SVGTextureNode; } //TODO use a heuristic to work out when to redraw //if !m_smooth and size is approximate simply change the textureNode.rect without //updating the material - if (!m_texture || m_texture->textureSize() != QSize(width(), height())) { + if (!textureNode->texture() || textureNode->texture()->textureSize() != QSize(width(), height())) { m_svg.data()->resize(width(), height()); m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty()); const QImage image = m_svg.data()->image(m_elementID); - delete m_texture; - m_texture = window()->createTextureFromImage(image); - textureNode->setTexture(m_texture); + QSGTexture *texture = window()->createTextureFromImage(image); + textureNode->setTexture(texture); textureNode->setRect(0, 0, width(), height()); } diff --git a/src/declarativeimports/core/svgitem.h b/src/declarativeimports/core/svgitem.h index 1d658e165..9234fa62f 100644 --- a/src/declarativeimports/core/svgitem.h +++ b/src/declarativeimports/core/svgitem.h @@ -22,7 +22,6 @@ #include class QImage; -class QSGTexture; namespace Plasma { class Svg; @@ -105,7 +104,6 @@ protected Q_SLOTS: private: QWeakPointer m_svg; QString m_elementID; - QSGTexture *m_texture; bool m_smooth; }; }