Fix cache implementation

It was weird.

Reviewed by the Handa-man.
This commit is contained in:
Aleix Pol 2014-07-11 18:37:43 +02:00
parent 100b60a7fb
commit 804a0d34da
2 changed files with 10 additions and 8 deletions

View File

@ -497,14 +497,14 @@ QRegion FrameSvg::mask() const
{
FrameData *frame = d->frames[d->prefix];
QString id = d->cacheId(frame, QString());
if (!frame->cachedMasks.contains(id)) {
//TODO: Implement a better way to cap the number of cached masks
if (frame->cachedMasks.count() > frame->MAX_CACHED_MASKS) {
frame->cachedMasks.clear();
}
frame->cachedMasks.insert(id, QRegion(QBitmap(d->alphaMask().alphaChannel().createMaskFromColor(Qt::black))));
QRegion* obj = frame->cachedMasks.object(id);
if (!obj) {
obj = new QRegion(QBitmap(d->alphaMask().alphaChannel().createMaskFromColor(Qt::black)));
frame->cachedMasks.insert(id, obj);
}
return frame->cachedMasks[id];
return *obj;
}
void FrameSvg::setCacheAllRenderedFrames(bool cache)

View File

@ -22,6 +22,7 @@
#define PLASMA_FRAMESVG_P_H
#include <QHash>
#include <QCache>
#include <QStringBuilder>
#include <QDebug>
@ -57,6 +58,7 @@ public:
FrameData(const FrameData &other, FrameSvg *svg)
: prefix(other.prefix),
enabledBorders(other.enabledBorders),
cachedMasks(MAX_CACHED_MASKS),
frameSize(other.frameSize),
topHeight(0),
leftWidth(0),
@ -85,7 +87,7 @@ public:
QString prefix;
FrameSvg::EnabledBorders enabledBorders;
QPixmap cachedBackground;
QHash<QString, QRegion> cachedMasks;
QCache<QString, QRegion> cachedMasks;
static const int MAX_CACHED_MASKS = 10;
QSize frameSize;