mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Fix CPU usage from out of frame animated images
This commit is contained in:
parent
15b5712f9a
commit
b03bfa53e4
2 changed files with 16 additions and 4 deletions
|
@ -102,10 +102,12 @@ MxcAnimatedImage::startDownload()
|
||||||
if (buffer.bytesAvailable() <
|
if (buffer.bytesAvailable() <
|
||||||
4LL * 1024 * 1024 * 1024) // cache images smaller than 4MB in RAM
|
4LL * 1024 * 1024 * 1024) // cache images smaller than 4MB in RAM
|
||||||
movie.setCacheMode(QMovie::CacheAll);
|
movie.setCacheMode(QMovie::CacheAll);
|
||||||
if (play_)
|
if (play_ && movie.frameCount() > 1)
|
||||||
movie.start();
|
movie.start();
|
||||||
else
|
else {
|
||||||
movie.jumpToFrame(0);
|
movie.jumpToFrame(0);
|
||||||
|
movie.setPaused(true);
|
||||||
|
}
|
||||||
emit loadedChanged();
|
emit loadedChanged();
|
||||||
update();
|
update();
|
||||||
});
|
});
|
||||||
|
@ -173,6 +175,9 @@ MxcAnimatedImage::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeD
|
||||||
if (!imageDirty)
|
if (!imageDirty)
|
||||||
return oldNode;
|
return oldNode;
|
||||||
|
|
||||||
|
if (clipRect().isEmpty())
|
||||||
|
return oldNode;
|
||||||
|
|
||||||
imageDirty = false;
|
imageDirty = false;
|
||||||
QSGImageNode *n = static_cast<QSGImageNode *>(oldNode);
|
QSGImageNode *n = static_cast<QSGImageNode *>(oldNode);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
connect(this, &MxcAnimatedImage::roomChanged, &MxcAnimatedImage::startDownload);
|
connect(this, &MxcAnimatedImage::roomChanged, &MxcAnimatedImage::startDownload);
|
||||||
connect(&movie, &QMovie::frameChanged, this, &MxcAnimatedImage::newFrame);
|
connect(&movie, &QMovie::frameChanged, this, &MxcAnimatedImage::newFrame);
|
||||||
setFlag(QQuickItem::ItemHasContents);
|
setFlag(QQuickItem::ItemHasContents);
|
||||||
|
setFlag(QQuickItem::ItemObservesViewport);
|
||||||
// setAcceptHoverEvents(true);
|
// setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +56,12 @@ public:
|
||||||
{
|
{
|
||||||
if (play_ != newPlay) {
|
if (play_ != newPlay) {
|
||||||
play_ = newPlay;
|
play_ = newPlay;
|
||||||
movie.setPaused(!play_);
|
if (movie.frameCount() > 1)
|
||||||
|
movie.setPaused(!play_);
|
||||||
|
else {
|
||||||
|
movie.jumpToFrame(0);
|
||||||
|
movie.setPaused(true);
|
||||||
|
}
|
||||||
emit playChanged();
|
emit playChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +83,8 @@ private slots:
|
||||||
{
|
{
|
||||||
currentFrame = frame;
|
currentFrame = frame;
|
||||||
imageDirty = true;
|
imageDirty = true;
|
||||||
update();
|
if (!clipRect().isEmpty())
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue