Fix cache implementation
It was weird. Reviewed by the Handa-man.
This commit is contained in:
parent
100b60a7fb
commit
804a0d34da
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user