delay insertion into the pixmap cache of all prefix that is being

resized and save all of them at once at a timer event.
this way when a big number of scales is done in little time (e.g. applet
reszing) prevents too many disk writes and qimage conversions

svn path=/trunk/KDE/kdelibs/; revision=890663
This commit is contained in:
Marco Martin 2008-11-29 19:24:40 +00:00
parent f4cf4b189b
commit 8328875f4c
2 changed files with 33 additions and 2 deletions

View File

@ -23,6 +23,7 @@
#include <QPainter>
#include <QSize>
#include <QBitmap>
#include <QTimer>
#include <kdebug.h>
@ -79,7 +80,8 @@ class FrameSvgPrivate
public:
FrameSvgPrivate(FrameSvg *psvg)
: q(psvg),
cacheAll(false)
cacheAll(false),
saveTimer(0)
{
}
@ -90,6 +92,7 @@ public:
}
void generateBackground(FrameData *frame);
void scheduledCacheUpdate();
void updateSizes();
void updateNeeded();
void updateAndSignalSizes();
@ -100,6 +103,8 @@ public:
FrameSvg *q;
bool cacheAll : 1;
QStringList framesToSave;
QTimer *saveTimer;
QHash<QString, FrameData*> frames;
};
@ -110,6 +115,10 @@ FrameSvg::FrameSvg(QObject *parent)
{
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
d->frames.insert(QString(), new FrameData());
d->saveTimer = new QTimer(this);
d->saveTimer->setSingleShot(true);
connect(d->saveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate()));
}
FrameSvg::~FrameSvg()
@ -198,6 +207,7 @@ void FrameSvg::setElementPrefix(const QString & prefix)
if (!d->cacheAll) {
delete d->frames[oldPrefix];
d->framesToSave.removeAll(oldPrefix);
d->frames.remove(oldPrefix);
}
@ -419,6 +429,7 @@ void FrameSvgPrivate::generateBackground(FrameData *frame)
QString id = QString::fromLatin1("%5_%4_%3_%2_%1_").
arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
Theme *theme = Theme::defaultTheme();
if (theme->findInCache(id, frame->cachedBackground) && !frame->cachedBackground.isNull()) {
return;
@ -593,7 +604,26 @@ void FrameSvgPrivate::generateBackground(FrameData *frame)
}
}
theme->insertIntoCache(id, frame->cachedBackground);
if (!framesToSave.contains(prefix)) {
framesToSave.append(prefix);
}
saveTimer->start(300);
}
void FrameSvgPrivate::scheduledCacheUpdate()
{
foreach ( QString prefixToSave, framesToSave) {
FrameData *frame = frames[prefix];
framesToSave.removeAll(prefixToSave);
QString id = QString::fromLatin1("%5_%4_%3_%2_%1_").
arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
//kDebug()<<"Saving to cache frame"<<id;
Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
}
}
void FrameSvgPrivate::updateSizes()

View File

@ -254,6 +254,7 @@ class PLASMA_EXPORT FrameSvg : public Svg
Q_PRIVATE_SLOT(d, void updateSizes())
Q_PRIVATE_SLOT(d, void updateNeeded())
Q_PRIVATE_SLOT(d, void scheduledCacheUpdate())
};
} // Plasma namespace