From a69a7c6f7cd83c559593161c86fec70fd125198e Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Tue, 15 Nov 2011 09:44:40 +0100 Subject: [PATCH] Use QQuickChangeListener for better performance Change-Id: Ia959cf905fd0a03f7f69b6b65b2eeed8e4a62153 Reviewed-by: Kim M. Kalland --- src/declarative/items/qquickshadereffectsource.cpp | 26 +++++++++++++++------- src/declarative/items/qquickshadereffectsource_p.h | 5 ++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/declarative/items/qquickshadereffectsource.cpp b/src/declarative/items/qquickshadereffectsource.cpp index 92e2072..e0aa9ed 100644 --- a/src/declarative/items/qquickshadereffectsource.cpp +++ b/src/declarative/items/qquickshadereffectsource.cpp @@ -500,8 +500,11 @@ QQuickShaderEffectSource::~QQuickShaderEffectSource() if (m_provider) m_provider->deleteLater(); - if (m_sourceItem) - QQuickItemPrivate::get(m_sourceItem)->derefFromEffectItem(m_hideSource); + if (m_sourceItem) { + QQuickItemPrivate *sd = QQuickItemPrivate::get(m_sourceItem); + sd->removeItemChangeListener(this, QQuickItemPrivate::Geometry); + sd->derefFromEffectItem(m_hideSource); + } } void QQuickShaderEffectSource::ensureTexture() @@ -580,14 +583,21 @@ QQuickItem *QQuickShaderEffectSource::sourceItem() const return m_sourceItem; } +void QQuickShaderEffectSource::itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect) +{ + Q_ASSERT(item == m_sourceItem); + if (newRect.size() != oldRect.size()) + update(); +} + void QQuickShaderEffectSource::setSourceItem(QQuickItem *item) { if (item == m_sourceItem) return; if (m_sourceItem) { - QQuickItemPrivate::get(m_sourceItem)->derefFromEffectItem(m_hideSource); - disconnect(m_sourceItem, SIGNAL(widthChanged()), this, SLOT(update())); - disconnect(m_sourceItem, SIGNAL(heightChanged()), this, SLOT(update())); + QQuickItemPrivate *d = QQuickItemPrivate::get(m_sourceItem); + d->derefFromEffectItem(m_hideSource); + d->removeItemChangeListener(this, QQuickItemPrivate::Geometry); } m_sourceItem = item; if (m_sourceItem) { @@ -599,9 +609,9 @@ void QQuickShaderEffectSource::setSourceItem(QQuickItem *item) m_sourceItem->setParentItem(this); m_sourceItem->setVisible(false); } - QQuickItemPrivate::get(m_sourceItem)->refFromEffectItem(m_hideSource); - connect(m_sourceItem, SIGNAL(widthChanged()), this, SLOT(update())); - connect(m_sourceItem, SIGNAL(heightChanged()), this, SLOT(update())); + QQuickItemPrivate *d = QQuickItemPrivate::get(m_sourceItem); + d->refFromEffectItem(m_hideSource); + d->addItemChangeListener(this, QQuickItemPrivate::Geometry); } update(); emit sourceItemChanged(); diff --git a/src/declarative/items/qquickshadereffectsource_p.h b/src/declarative/items/qquickshadereffectsource_p.h index b61170a..fee361c 100644 --- a/src/declarative/items/qquickshadereffectsource_p.h +++ b/src/declarative/items/qquickshadereffectsource_p.h @@ -47,6 +47,7 @@ #include #include #include +#include #include "qpointer.h" #include "qsize.h" @@ -153,7 +154,7 @@ private: uint m_grab : 1; }; -class Q_DECLARATIVE_EXPORT QQuickShaderEffectSource : public QQuickItem +class Q_DECLARATIVE_EXPORT QQuickShaderEffectSource : public QQuickItem, public QQuickItemChangeListener { Q_OBJECT Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) @@ -232,6 +233,8 @@ Q_SIGNALS: protected: virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect); + private: void ensureTexture(); -- 2.7.4