diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2009-10-16 07:55:28 (GMT) |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2009-10-22 16:44:05 (GMT) |
commit | 5de213210ef4f14e698c3fd970cf7e6c5b27c72d (patch) | |
tree | da5d692ff2dec2ed835cc698ee7770d93351830d /src/gui/effects | |
parent | a392366b164081fe3b75c806dbf2030e64754eaf (diff) | |
download | Qt-5de213210ef4f14e698c3fd970cf7e6c5b27c72d.zip Qt-5de213210ef4f14e698c3fd970cf7e6c5b27c72d.tar.gz Qt-5de213210ef4f14e698c3fd970cf7e6c5b27c72d.tar.bz2 |
Added caching of graphics effect source pixmaps to speed up effects.
If an effect is applied repeatedly on the same source, just with
varying parameters, we can save a lot by caching the source pixmaps.
Reviewed-by: Bjørn Erik Nilsen
Diffstat (limited to 'src/gui/effects')
-rw-r--r-- | src/gui/effects/qgraphicseffect.cpp | 19 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect.h | 1 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect_p.h | 12 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 91641b0..96d35b0 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -253,7 +253,24 @@ bool QGraphicsEffectSource::isPixmap() const */ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset) const { - return d_func()->pixmap(system, offset); + Q_D(const QGraphicsEffectSource); + + QPixmap pm; + if (d->m_cachedSystem == system) + QPixmapCache::find(d->m_cacheKey, &pm); + + if (pm.isNull()) { + pm = d->pixmap(system, &d->m_cachedOffset); + d->m_cachedSystem = system; + + d->invalidateCache(); + d->m_cacheKey = QPixmapCache::insert(pm); + } + + if (offset) + *offset = d->m_cachedOffset; + + return pm; } /*! diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h index c5d3ede..c89851e 100644 --- a/src/gui/effects/qgraphicseffect.h +++ b/src/gui/effects/qgraphicseffect.h @@ -87,6 +87,7 @@ private: friend class QGraphicsEffectPrivate; friend class QGraphicsScenePrivate; friend class QGraphicsItem; + friend class QGraphicsItemPrivate; friend class QWidget; friend class QWidgetPrivate; }; diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h index ff2fb85..8fb55d8 100644 --- a/src/gui/effects/qgraphicseffect_p.h +++ b/src/gui/effects/qgraphicseffect_p.h @@ -55,6 +55,8 @@ #include "qgraphicseffect.h" +#include <QPixmapCache> + #include <private/qobject_p.h> #include <private/qpixmapfilter_p.h> @@ -65,7 +67,7 @@ class QGraphicsEffectSourcePrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QGraphicsEffectSource) public: QGraphicsEffectSourcePrivate() : QObjectPrivate() {} - virtual ~QGraphicsEffectSourcePrivate() {} + virtual ~QGraphicsEffectSourcePrivate() { invalidateCache(); } virtual void detach() = 0; virtual QRectF boundingRect(Qt::CoordinateSystem system) const = 0; virtual QRect deviceRect() const = 0; @@ -77,9 +79,16 @@ public: virtual bool isPixmap() const = 0; virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0) const = 0; virtual void effectBoundingRectChanged() = 0; + void invalidateCache() const { QPixmapCache::remove(m_cacheKey); } + friend class QGraphicsScenePrivate; friend class QGraphicsItem; friend class QGraphicsItemPrivate; + +private: + mutable Qt::CoordinateSystem m_cachedSystem; + mutable QPoint m_cachedOffset; + mutable QPixmapCache::Key m_cacheKey; }; class Q_GUI_EXPORT QGraphicsEffectPrivate : public QObjectPrivate @@ -94,6 +103,7 @@ public: if (source) { flags |= QGraphicsEffect::SourceDetached; source->d_func()->detach(); + source->d_func()->invalidateCache(); delete source; } source = newSource; |