put the delayed write-to-cache in theme rather than svg; this means that there is one collection per theme instead of one per svg, one timer per theme rather that one per svg and one write out to cache for the theme. win!

svn path=/trunk/KDE/kdelibs/; revision=975389
This commit is contained in:
Aaron J. Seigo 2009-05-30 03:08:33 +00:00
parent d2dbbdae33
commit 214c0348a3
4 changed files with 39 additions and 31 deletions

29
svg.cpp
View File

@ -23,7 +23,6 @@
#include <QMatrix>
#include <QPainter>
#include <QSharedData>
#include <QTimer>
#include <kcolorscheme.h>
#include <kconfiggroup.h>
@ -69,7 +68,6 @@ class SvgPrivate
SvgPrivate(Svg *svg)
: q(svg),
theme(0),
saveTimer(0),
renderer(0),
lastModified(0),
multipleImages(false),
@ -77,9 +75,6 @@ class SvgPrivate
applyColors(false),
cacheRendering(true)
{
saveTimer = new QTimer(q);
saveTimer->setSingleShot(true);
QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate()));
}
~SvgPrivate()
@ -233,27 +228,13 @@ class SvgPrivate
p = p.fromImage(itmp);
}
if (cacheRendering && !itemsToSave.contains(id)) {
itemsToSave.insert(id, p);
saveTimer->start(300);
if (cacheRendering) {
actualTheme()->insertIntoCache(id, p);
}
return p;
}
void scheduledCacheUpdate()
{
QHash<QString, QPixmap>::const_iterator i = itemsToSave.constBegin();
while (i != itemsToSave.constEnd()) {
//kDebug()<<"Saving item to cache: " << i.key();
actualTheme()->insertIntoCache(i.key(), i.value());
++i;
}
itemsToSave.clear();
}
void createRenderer()
{
if (renderer) {
@ -395,8 +376,6 @@ class SvgPrivate
eraseRenderer();
localRectCache.clear();
itemsToSave.clear();
saveTimer->stop();
//kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed";
emit q->repaintNeeded();
@ -409,8 +388,6 @@ class SvgPrivate
}
eraseRenderer();
itemsToSave.clear();
saveTimer->stop();
emit q->repaintNeeded();
}
@ -419,8 +396,6 @@ class SvgPrivate
Svg *q;
QPointer<Theme> theme;
QHash<QString, QRectF> localRectCache;
QHash<QString, QPixmap> itemsToSave;
QTimer *saveTimer;
SharedSvgRenderer::Ptr renderer;
QString themePath;
QString path;

1
svg.h
View File

@ -261,7 +261,6 @@ class PLASMA_EXPORT Svg : public QObject
Q_PRIVATE_SLOT(d, void themeChanged())
Q_PRIVATE_SLOT(d, void colorsChanged())
Q_PRIVATE_SLOT(d, void scheduledCacheUpdate())
friend class SvgPrivate;
friend class FrameSvgPrivate;

View File

@ -22,6 +22,7 @@
#include <QApplication>
#include <QFile>
#include <QFileInfo>
#include <QTimer>
#ifdef Q_WS_X11
#include <QX11Info>
#endif
@ -84,6 +85,10 @@ public:
QObject::connect(compositeWatch, SIGNAL(lostOwner()), q, SLOT(compositingChanged()));
}
#endif
saveTimer = new QTimer(q);
saveTimer->setSingleShot(true);
QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate()));
}
~ThemePrivate()
@ -120,6 +125,7 @@ public:
void compositingChanged();
void discardCache();
void discardCache(bool recreateElementsCache);
void scheduledCacheUpdate();
void colorsChanged();
bool useCache();
void settingsFileChanged(const QString &);
@ -143,6 +149,8 @@ public:
KPixmapCache *pixmapCache;
KSharedConfigPtr svgElementsCache;
QHash<QString, QSet<QString> > invalidElements;
QHash<QString, QPixmap> pixmapsToCache;
QTimer *saveTimer;
#ifdef Q_WS_X11
KSelectionWatcher *compositeWatch;
@ -216,9 +224,10 @@ void ThemePrivate::discardCache(bool recreateElementsCache)
delete pixmapCache;
pixmapCache = 0;
invalidElements.clear();
pixmapsToCache.clear();
saveTimer->stop();
svgElementsCache = 0;
QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
if (!svgElementsFile.isEmpty()) {
QFile f(svgElementsFile);
@ -230,6 +239,20 @@ void ThemePrivate::discardCache(bool recreateElementsCache)
}
}
void ThemePrivate::scheduledCacheUpdate()
{
//kDebug()<< "Saving to cache:";
QHash<QString, QPixmap>::const_iterator it = pixmapsToCache.constBegin();
while (it != pixmapsToCache.constEnd()) {
//kDebug()<< "Saving item to cache: " << it.key();
pixmapCache->insert(it.key(), it.value());
++it;
}
pixmapsToCache.clear();
}
void ThemePrivate::colorsChanged()
{
discardCache(true);
@ -618,7 +641,16 @@ bool Theme::useNativeWidgetStyle() const
bool Theme::findInCache(const QString &key, QPixmap &pix)
{
return d->useCache() && d->pixmapCache->find(key, pix);
if (d->useCache()) {
if (d->pixmapsToCache.contains(key)) {
pix = d->pixmapsToCache.value(key);
return true;
}
return d->pixmapCache->find(key, pix);
}
return false;
}
// BIC FIXME: Should be merged with the other findInCache method above when we break BC
@ -634,7 +666,8 @@ bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModif
void Theme::insertIntoCache(const QString& key, const QPixmap& pix)
{
if (d->useCache()) {
d->pixmapCache->insert(key, pix);
d->pixmapsToCache.insert(key, pix);
d->saveTimer->start(500);
}
}

View File

@ -307,6 +307,7 @@ class PLASMA_EXPORT Theme : public QObject
Q_PRIVATE_SLOT(d, void discardCache())
Q_PRIVATE_SLOT(d, void colorsChanged())
Q_PRIVATE_SLOT(d, void settingsFileChanged(const QString &))
Q_PRIVATE_SLOT(d, void scheduledCacheUpdate())
};
} // Plasma namespace