From c5f4865ee62e6efc1e3d7258a41cea442c96af0e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 30 Dec 2021 06:10:19 +0100 Subject: [PATCH] Try to reduce CPU overhead of animated images a bit --- src/ui/MxcAnimatedImage.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ui/MxcAnimatedImage.cpp b/src/ui/MxcAnimatedImage.cpp index 3c82c614..f88f820d 100644 --- a/src/ui/MxcAnimatedImage.cpp +++ b/src/ui/MxcAnimatedImage.cpp @@ -91,6 +91,10 @@ MxcAnimatedImage::startDownload() "Playing movie with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen()); movie.setFormat(mimeType); movie.setDevice(&buffer); + movie.setScaledSize(this->size().toSize()); + if (buffer.bytesAvailable() < + 4LL * 1024 * 1024 * 1024) // cache images smaller than 4MB in RAM + movie.setCacheMode(QMovie::CacheAll); if (play_) movie.start(); else @@ -158,17 +162,17 @@ MxcAnimatedImage::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeD // n->setTexture(nullptr); auto img = movie.currentImage(); + n->setSourceRect(img.rect()); if (!img.isNull()) - n->setTexture(window()->createTextureFromImage(img)); + n->setTexture(window()->createTextureFromImage(std::move(img))); else { delete n; return nullptr; } - n->setSourceRect(img.rect()); n->setRect(QRect(0, 0, width(), height())); - n->setFiltering(QSGTexture::Linear); - n->setMipmapFiltering(QSGTexture::Linear); + n->setFiltering(QSGTexture::Nearest); + n->setMipmapFiltering(QSGTexture::None); return n; }