summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpixmapcache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image/qpixmapcache.cpp')
-rw-r--r--src/gui/image/qpixmapcache.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 7a6a73f436..ca21a0c688 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -196,9 +196,10 @@ public:
static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);
QList< QPair<QString,QPixmap> > allPixmaps() const;
- void flushDetachedPixmaps(bool nt);
+ bool flushDetachedPixmaps(bool nt);
private:
+ enum { soon_time = 10000, flush_time = 30000 };
int *keyArray;
int theid;
int ps;
@@ -236,38 +237,44 @@ QPMCache::~QPMCache()
cleaning-up, and to not cut down the size of the cache while the
cache is in active use.
- When the last pixmap has been deleted from the cache, kill the
- timer so Qt won't keep the CPU from going into sleep mode.
+ When the last detached pixmap has been deleted from the cache, kill the
+ timer so Qt won't keep the CPU from going into sleep mode. Currently
+ the timer is not restarted when the pixmap becomes unused, but it does
+ restart once something else is added (i.e. the cache space is actually needed).
+
+ Returns true if any were removed.
*/
-void QPMCache::flushDetachedPixmaps(bool nt)
+bool QPMCache::flushDetachedPixmaps(bool nt)
{
int mc = maxCost();
setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
setMaxCost(mc);
ps = totalCost();
+ bool any = false;
QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();
while (it != cacheKeys.end()) {
if (!contains(it.value())) {
releaseKey(it.value());
it = cacheKeys.erase(it);
+ any = true;
} else {
++it;
}
}
+
+ return any;
}
void QPMCache::timerEvent(QTimerEvent *)
{
bool nt = totalCost() == ps;
- flushDetachedPixmaps(nt);
-
- if (!size()) {
+ if (!flushDetachedPixmaps(nt)) {
killTimer(theid);
theid = 0;
} else if (nt != t) {
killTimer(theid);
- theid = startTimer(nt ? 10000 : 30000);
+ theid = startTimer(nt ? soon_time : flush_time);
t = nt;
}
}
@@ -315,7 +322,7 @@ bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
if (success) {
cacheKeys.insert(key, cacheKey);
if (!theid) {
- theid = startTimer(30000);
+ theid = startTimer(flush_time);
t = false;
}
} else {
@@ -331,7 +338,7 @@ QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)
bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
if (success) {
if (!theid) {
- theid = startTimer(30000);
+ theid = startTimer(flush_time);
t = false;
}
} else {
@@ -352,7 +359,7 @@ bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int
bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
if (success) {
if(!theid) {
- theid = startTimer(30000);
+ theid = startTimer(flush_time);
t = false;
}
const_cast<QPixmapCache::Key&>(key) = cacheKey;