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];
|
FrameData *frame = d->frames[d->prefix];
|
||||||
QString id = d->cacheId(frame, QString());
|
QString id = d->cacheId(frame, QString());
|
||||||
if (!frame->cachedMasks.contains(id)) {
|
|
||||||
//TODO: Implement a better way to cap the number of cached masks
|
QRegion* obj = frame->cachedMasks.object(id);
|
||||||
if (frame->cachedMasks.count() > frame->MAX_CACHED_MASKS) {
|
|
||||||
frame->cachedMasks.clear();
|
if (!obj) {
|
||||||
|
obj = new QRegion(QBitmap(d->alphaMask().alphaChannel().createMaskFromColor(Qt::black)));
|
||||||
|
frame->cachedMasks.insert(id, obj);
|
||||||
}
|
}
|
||||||
frame->cachedMasks.insert(id, QRegion(QBitmap(d->alphaMask().alphaChannel().createMaskFromColor(Qt::black))));
|
return *obj;
|
||||||
}
|
|
||||||
return frame->cachedMasks[id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameSvg::setCacheAllRenderedFrames(bool cache)
|
void FrameSvg::setCacheAllRenderedFrames(bool cache)
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define PLASMA_FRAMESVG_P_H
|
#define PLASMA_FRAMESVG_P_H
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QCache>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -57,6 +58,7 @@ public:
|
|||||||
FrameData(const FrameData &other, FrameSvg *svg)
|
FrameData(const FrameData &other, FrameSvg *svg)
|
||||||
: prefix(other.prefix),
|
: prefix(other.prefix),
|
||||||
enabledBorders(other.enabledBorders),
|
enabledBorders(other.enabledBorders),
|
||||||
|
cachedMasks(MAX_CACHED_MASKS),
|
||||||
frameSize(other.frameSize),
|
frameSize(other.frameSize),
|
||||||
topHeight(0),
|
topHeight(0),
|
||||||
leftWidth(0),
|
leftWidth(0),
|
||||||
@ -85,7 +87,7 @@ public:
|
|||||||
QString prefix;
|
QString prefix;
|
||||||
FrameSvg::EnabledBorders enabledBorders;
|
FrameSvg::EnabledBorders enabledBorders;
|
||||||
QPixmap cachedBackground;
|
QPixmap cachedBackground;
|
||||||
QHash<QString, QRegion> cachedMasks;
|
QCache<QString, QRegion> cachedMasks;
|
||||||
static const int MAX_CACHED_MASKS = 10;
|
static const int MAX_CACHED_MASKS = 10;
|
||||||
|
|
||||||
QSize frameSize;
|
QSize frameSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user