diff --git a/framesvg.cpp b/framesvg.cpp index abde25a52..afb609f6c 100644 --- a/framesvg.cpp +++ b/framesvg.cpp @@ -621,13 +621,13 @@ void FrameSvgPrivate::cacheFrame(const QString &prefixToSave) //kDebug()<<"Saving to cache frame"<insertIntoCache(id, frame->cachedBackground); + Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground, QString::number((int)q)+prefixToSave); //insert overlay id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_"). arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(size.width()).arg(size.height()).arg(prefixToSave).arg(q->imagePath()); - Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground); + Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground, QString::number((int)q)+prefixToSave+"overlay"); } void FrameSvgPrivate::updateSizes() diff --git a/svg.cpp b/svg.cpp index 5c8c068dd..dee9cbfd8 100644 --- a/svg.cpp +++ b/svg.cpp @@ -238,7 +238,7 @@ class SvgPrivate } if (cacheRendering) { - actualTheme()->insertIntoCache(id, p); + actualTheme()->insertIntoCache(id, p, QString::number((int)q)+elementId); } return p; diff --git a/theme.cpp b/theme.cpp index fc1849030..e65e32534 100644 --- a/theme.cpp +++ b/theme.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef Q_WS_X11 #include #endif @@ -152,6 +153,8 @@ public: KSharedConfigPtr svgElementsCache; QHash > invalidElements; QHash pixmapsToCache; + QHash keysToCache; + QHash idsToCache; QTimer *saveTimer; #ifdef Q_WS_X11 @@ -238,16 +241,15 @@ void ThemePrivate::discardCache(bool recreateElementsCache) void ThemePrivate::scheduledCacheUpdate() { - //kDebug()<< "Saving to cache:"; - QHash::const_iterator it = pixmapsToCache.constBegin(); - - while (it != pixmapsToCache.constEnd()) { - //kDebug()<< "Saving item to cache: " << it.key(); - pixmapCache->insert(it.key(), it.value()); - ++it; + QHashIterator it(pixmapsToCache); + while (it.hasNext()) { + it.next(); + pixmapCache->insert(idsToCache[it.key()], it.value()); } pixmapsToCache.clear(); + keysToCache.clear(); + idsToCache.clear(); } void ThemePrivate::colorsChanged() @@ -672,8 +674,13 @@ bool Theme::useNativeWidgetStyle() const bool Theme::findInCache(const QString &key, QPixmap &pix) { if (d->useCache()) { - if (d->pixmapsToCache.contains(key)) { - pix = d->pixmapsToCache.value(key); + if (!d->keysToCache.contains(key)) { + return false; + } + + const QString id = d->keysToCache[key]; + if (d->pixmapsToCache.contains(id)) { + pix = d->pixmapsToCache.value(id); return true; } @@ -696,8 +703,22 @@ bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModif void Theme::insertIntoCache(const QString& key, const QPixmap& pix) { if (d->useCache()) { - d->pixmapsToCache.insert(key, pix); - d->saveTimer->start(500); + d->pixmapCache->insert(key, pix); + } +} + +void Theme::insertIntoCache(const QString& key, const QPixmap& pix, const QString& id) +{ + if (d->useCache()) { + d->pixmapsToCache.insert(id, pix); + + if (d->idsToCache.contains(id)) { + d->keysToCache.remove(d->idsToCache[id]); + } + + d->keysToCache.insert(key, id); + d->idsToCache.insert(id, key); + d->saveTimer->start(600); } } diff --git a/theme.h b/theme.h index 4bd6fed22..66de1c847 100644 --- a/theme.h +++ b/theme.h @@ -240,6 +240,23 @@ class PLASMA_EXPORT Theme : public QObject **/ void insertIntoCache(const QString& key, const QPixmap& pix); + /** + * Insert specified pixmap into the cache. + * If the cache already contains pixmap with the specified key then it is + * overwritten. + * The actual insert is delayed for optimization reasons and the id + * parameter is used to discard repeated inserts in the delay time, useful + * when for instance the graphics to inser comes from a quickly resizing + * object: the frames between the start and destination sizes aren't + * useful in the cache and just cause overhead. + * + * @param key the name to use in the cache for this pixmap + * @param pix the pixmap data to store in the cache + * @param id a name that identifies the caller class of this function in an unique fashion + * @since 4.3 + **/ + void insertIntoCache(const QString& key, const QPixmap& pix, const QString& id); + /** * Sets the maximum size of the cache (in kilobytes). If cache gets bigger * the limit then some entries are removed