diff options
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; |