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:
parent
d2dbbdae33
commit
214c0348a3
29
svg.cpp
29
svg.cpp
@ -23,7 +23,6 @@
|
|||||||
#include <QMatrix>
|
#include <QMatrix>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSharedData>
|
#include <QSharedData>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <kcolorscheme.h>
|
#include <kcolorscheme.h>
|
||||||
#include <kconfiggroup.h>
|
#include <kconfiggroup.h>
|
||||||
@ -69,7 +68,6 @@ class SvgPrivate
|
|||||||
SvgPrivate(Svg *svg)
|
SvgPrivate(Svg *svg)
|
||||||
: q(svg),
|
: q(svg),
|
||||||
theme(0),
|
theme(0),
|
||||||
saveTimer(0),
|
|
||||||
renderer(0),
|
renderer(0),
|
||||||
lastModified(0),
|
lastModified(0),
|
||||||
multipleImages(false),
|
multipleImages(false),
|
||||||
@ -77,9 +75,6 @@ class SvgPrivate
|
|||||||
applyColors(false),
|
applyColors(false),
|
||||||
cacheRendering(true)
|
cacheRendering(true)
|
||||||
{
|
{
|
||||||
saveTimer = new QTimer(q);
|
|
||||||
saveTimer->setSingleShot(true);
|
|
||||||
QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~SvgPrivate()
|
~SvgPrivate()
|
||||||
@ -233,27 +228,13 @@ class SvgPrivate
|
|||||||
p = p.fromImage(itmp);
|
p = p.fromImage(itmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cacheRendering && !itemsToSave.contains(id)) {
|
if (cacheRendering) {
|
||||||
itemsToSave.insert(id, p);
|
actualTheme()->insertIntoCache(id, p);
|
||||||
saveTimer->start(300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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()
|
void createRenderer()
|
||||||
{
|
{
|
||||||
if (renderer) {
|
if (renderer) {
|
||||||
@ -395,8 +376,6 @@ class SvgPrivate
|
|||||||
eraseRenderer();
|
eraseRenderer();
|
||||||
|
|
||||||
localRectCache.clear();
|
localRectCache.clear();
|
||||||
itemsToSave.clear();
|
|
||||||
saveTimer->stop();
|
|
||||||
|
|
||||||
//kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed";
|
//kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed";
|
||||||
emit q->repaintNeeded();
|
emit q->repaintNeeded();
|
||||||
@ -409,8 +388,6 @@ class SvgPrivate
|
|||||||
}
|
}
|
||||||
|
|
||||||
eraseRenderer();
|
eraseRenderer();
|
||||||
itemsToSave.clear();
|
|
||||||
saveTimer->stop();
|
|
||||||
emit q->repaintNeeded();
|
emit q->repaintNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,8 +396,6 @@ class SvgPrivate
|
|||||||
Svg *q;
|
Svg *q;
|
||||||
QPointer<Theme> theme;
|
QPointer<Theme> theme;
|
||||||
QHash<QString, QRectF> localRectCache;
|
QHash<QString, QRectF> localRectCache;
|
||||||
QHash<QString, QPixmap> itemsToSave;
|
|
||||||
QTimer *saveTimer;
|
|
||||||
SharedSvgRenderer::Ptr renderer;
|
SharedSvgRenderer::Ptr renderer;
|
||||||
QString themePath;
|
QString themePath;
|
||||||
QString path;
|
QString path;
|
||||||
|
1
svg.h
1
svg.h
@ -261,7 +261,6 @@ class PLASMA_EXPORT Svg : public QObject
|
|||||||
|
|
||||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||||
Q_PRIVATE_SLOT(d, void colorsChanged())
|
Q_PRIVATE_SLOT(d, void colorsChanged())
|
||||||
Q_PRIVATE_SLOT(d, void scheduledCacheUpdate())
|
|
||||||
|
|
||||||
friend class SvgPrivate;
|
friend class SvgPrivate;
|
||||||
friend class FrameSvgPrivate;
|
friend class FrameSvgPrivate;
|
||||||
|
39
theme.cpp
39
theme.cpp
@ -22,6 +22,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QTimer>
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
#endif
|
#endif
|
||||||
@ -84,6 +85,10 @@ public:
|
|||||||
QObject::connect(compositeWatch, SIGNAL(lostOwner()), q, SLOT(compositingChanged()));
|
QObject::connect(compositeWatch, SIGNAL(lostOwner()), q, SLOT(compositingChanged()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
saveTimer = new QTimer(q);
|
||||||
|
saveTimer->setSingleShot(true);
|
||||||
|
QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
~ThemePrivate()
|
~ThemePrivate()
|
||||||
@ -120,6 +125,7 @@ public:
|
|||||||
void compositingChanged();
|
void compositingChanged();
|
||||||
void discardCache();
|
void discardCache();
|
||||||
void discardCache(bool recreateElementsCache);
|
void discardCache(bool recreateElementsCache);
|
||||||
|
void scheduledCacheUpdate();
|
||||||
void colorsChanged();
|
void colorsChanged();
|
||||||
bool useCache();
|
bool useCache();
|
||||||
void settingsFileChanged(const QString &);
|
void settingsFileChanged(const QString &);
|
||||||
@ -143,6 +149,8 @@ public:
|
|||||||
KPixmapCache *pixmapCache;
|
KPixmapCache *pixmapCache;
|
||||||
KSharedConfigPtr svgElementsCache;
|
KSharedConfigPtr svgElementsCache;
|
||||||
QHash<QString, QSet<QString> > invalidElements;
|
QHash<QString, QSet<QString> > invalidElements;
|
||||||
|
QHash<QString, QPixmap> pixmapsToCache;
|
||||||
|
QTimer *saveTimer;
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
KSelectionWatcher *compositeWatch;
|
KSelectionWatcher *compositeWatch;
|
||||||
@ -216,9 +224,10 @@ void ThemePrivate::discardCache(bool recreateElementsCache)
|
|||||||
delete pixmapCache;
|
delete pixmapCache;
|
||||||
pixmapCache = 0;
|
pixmapCache = 0;
|
||||||
invalidElements.clear();
|
invalidElements.clear();
|
||||||
|
pixmapsToCache.clear();
|
||||||
|
saveTimer->stop();
|
||||||
|
|
||||||
svgElementsCache = 0;
|
svgElementsCache = 0;
|
||||||
|
|
||||||
QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
|
QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
|
||||||
if (!svgElementsFile.isEmpty()) {
|
if (!svgElementsFile.isEmpty()) {
|
||||||
QFile f(svgElementsFile);
|
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()
|
void ThemePrivate::colorsChanged()
|
||||||
{
|
{
|
||||||
discardCache(true);
|
discardCache(true);
|
||||||
@ -618,7 +641,16 @@ bool Theme::useNativeWidgetStyle() const
|
|||||||
|
|
||||||
bool Theme::findInCache(const QString &key, QPixmap &pix)
|
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
|
// 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)
|
void Theme::insertIntoCache(const QString& key, const QPixmap& pix)
|
||||||
{
|
{
|
||||||
if (d->useCache()) {
|
if (d->useCache()) {
|
||||||
d->pixmapCache->insert(key, pix);
|
d->pixmapsToCache.insert(key, pix);
|
||||||
|
d->saveTimer->start(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
theme.h
1
theme.h
@ -307,6 +307,7 @@ class PLASMA_EXPORT Theme : public QObject
|
|||||||
Q_PRIVATE_SLOT(d, void discardCache())
|
Q_PRIVATE_SLOT(d, void discardCache())
|
||||||
Q_PRIVATE_SLOT(d, void colorsChanged())
|
Q_PRIVATE_SLOT(d, void colorsChanged())
|
||||||
Q_PRIVATE_SLOT(d, void settingsFileChanged(const QString &))
|
Q_PRIVATE_SLOT(d, void settingsFileChanged(const QString &))
|
||||||
|
Q_PRIVATE_SLOT(d, void scheduledCacheUpdate())
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user