Ensure FrameSvg uses lastModified timestamp when using cache

This, I suspect, is the true source of bug 426674. FrameSvg would
request items from the cache without specifying any modification time
stamp, so we end up always retrieving the cached version. Since
lastModified is now a required parameter, we need to ensure this does
not happen anymore.

BUG: 426674
This commit is contained in:
Arjen Hiemstra 2020-09-22 15:03:27 +02:00
parent 7b42e5b45d
commit 16f852ea4c
2 changed files with 11 additions and 8 deletions

View File

@ -61,7 +61,7 @@ void FrameSvg::setImagePath(const QString &path)
setContainsMultipleImages(true);
Svg::d->setImagePath(path);
if (!d->repaintBlocked) {
d->updateFrameData();
d->updateFrameData(Svg::d->lastModified);
}
}
@ -74,7 +74,7 @@ void FrameSvg::setEnabledBorders(const EnabledBorders borders)
d->enabledBorders = borders;
if (!d->repaintBlocked) {
d->updateFrameData();
d->updateFrameData(Svg::d->lastModified);
}
}
@ -121,7 +121,7 @@ void FrameSvg::setElementPrefix(const QString &prefix)
d->location = Types::Floating;
if (!d->repaintBlocked) {
d->updateFrameData();
d->updateFrameData(Svg::d->lastModified);
}
}
@ -437,6 +437,7 @@ QSharedPointer<FrameData> FrameSvgPrivate::lookupOrCreateMaskFrame(const QShared
mask->enabledBorders = frame->enabledBorders;
mask->frameSize = frameSize(frame).toSize();
mask->cacheId = key;
mask->lastModified = frame->lastModified;
s_sharedFrames[q->theme()->d].insert(key, mask);
return mask;
@ -455,10 +456,10 @@ void FrameSvgPrivate::generateBackground(const QSharedPointer<FrameData> &frame)
const bool overlayAvailable = !frame->prefix.startsWith(QLatin1String("mask-")) && q->hasElement(frame->prefix % QLatin1String("overlay"));
QPixmap overlay;
if (q->isUsingRenderingCache()) {
frameCached = q->theme()->findInCache(id, frame->cachedBackground) && !frame->cachedBackground.isNull();
frameCached = q->theme()->findInCache(id, frame->cachedBackground, frame->lastModified) && !frame->cachedBackground.isNull();
if (overlayAvailable) {
overlayCached = q->theme()->findInCache(QLatin1String("overlay_") % id, overlay) && !overlay.isNull();
overlayCached = q->theme()->findInCache(QLatin1String("overlay_") % id, overlay, frame->lastModified) && !overlay.isNull();
}
}
@ -579,7 +580,7 @@ QRect FrameSvgPrivate::contentGeometry(const QSharedPointer<FrameData> &frame, c
return contentRect;
}
void FrameSvgPrivate::updateFrameData(UpdateType updateType)
void FrameSvgPrivate::updateFrameData(uint lastModified, UpdateType updateType)
{
auto fd = frame;
QString newKey;
@ -629,6 +630,7 @@ void FrameSvgPrivate::updateFrameData(UpdateType updateType)
fd->enabledBorders = enabledBorders;
fd->frameSize = pendingFrameSize;
fd->imagePath = q->imagePath();
fd->lastModified = lastModified;
//was fd just created empty now?
if (newKey.isEmpty()) {
newKey = cacheId(fd.data(), prefix);
@ -875,7 +877,7 @@ void FrameSvg::setRepaintBlocked(bool blocked)
d->repaintBlocked = blocked;
if (!blocked) {
d->updateFrameData();
d->updateFrameData(Svg::d->lastModified);
}
}

View File

@ -75,6 +75,7 @@ public:
QPixmap cachedBackground;
QCache<QString, QRegion> cachedMasks;
static const int MAX_CACHED_MASKS = 10;
uint lastModified = 0;
QSize frameSize;
QString cacheId;
@ -150,7 +151,7 @@ public:
void paintCorner(QPainter& p, const QSharedPointer<FrameData> &frame, Plasma::FrameSvg::EnabledBorders border, const QRect& output) const;
void paintCenter(QPainter& p, const QSharedPointer<FrameData> &frame, const QRect& contentRect, const QSize& fullSize);
QRect contentGeometry(const QSharedPointer<FrameData> &frame, const QSize& size) const;
void updateFrameData(UpdateType updateType = UpdateFrameAndMargins);
void updateFrameData(uint lastModified, UpdateType updateType = UpdateFrameAndMargins);
QSharedPointer<FrameData> lookupOrCreateMaskFrame(const QSharedPointer<FrameData> &frame, const QString &maskPrefix, const QString &maskRequestedPrefix);
Types::Location location = Types::Floating;