aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod/ResourcePack.cpp
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-06-25 12:36:27 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-06-25 12:43:48 -0700
commitdf4fd7df7f98589c5dba85e4b5cdf0179a77faf5 (patch)
treeb382b0375a12d91305849f5dad41f4e0b04de8df /launcher/minecraft/mod/ResourcePack.cpp
parentc8ff812ab89044890d88779e33f3c6f86c4b8f74 (diff)
parent1bd778d0ae27b3e87b800f773d5bc35708060c19 (diff)
downloadPrismLauncher-df4fd7df7f98589c5dba85e4b5cdf0179a77faf5.tar.gz
PrismLauncher-df4fd7df7f98589c5dba85e4b5cdf0179a77faf5.tar.bz2
PrismLauncher-df4fd7df7f98589c5dba85e4b5cdf0179a77faf5.zip
Merge remote-tracking branch 'upstream/develop' into refactor/net-split-headers-to-proxy-class
Diffstat (limited to 'launcher/minecraft/mod/ResourcePack.cpp')
-rw-r--r--launcher/minecraft/mod/ResourcePack.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp
index 759d2b56..e06c1ac1 100644
--- a/launcher/minecraft/mod/ResourcePack.cpp
+++ b/launcher/minecraft/mod/ResourcePack.cpp
@@ -40,7 +40,7 @@ void ResourcePack::setDescription(QString new_description)
m_description = new_description;
}
-void ResourcePack::setImage(QImage new_image)
+void ResourcePack::setImage(QImage new_image) const
{
QMutexLocker locker(&m_data_lock);
@@ -49,7 +49,10 @@ void ResourcePack::setImage(QImage new_image)
if (m_pack_image_cache_key.key.isValid())
PixmapCache::instance().remove(m_pack_image_cache_key.key);
- m_pack_image_cache_key.key = PixmapCache::instance().insert(QPixmap::fromImage(new_image));
+ // scale the image to avoid flooding the pixmapcache
+ auto pixmap = QPixmap::fromImage(new_image.scaled({64, 64}, Qt::AspectRatioMode::KeepAspectRatioByExpanding));
+
+ m_pack_image_cache_key.key = PixmapCache::instance().insert(pixmap);
m_pack_image_cache_key.was_ever_used = true;
// This can happen if the pixmap is too big to fit in the cache :c
@@ -59,21 +62,25 @@ void ResourcePack::setImage(QImage new_image)
}
}
-QPixmap ResourcePack::image(QSize size)
+QPixmap ResourcePack::image(QSize size, Qt::AspectRatioMode mode) const
{
QPixmap cached_image;
if (PixmapCache::instance().find(m_pack_image_cache_key.key, &cached_image)) {
if (size.isNull())
return cached_image;
- return cached_image.scaled(size);
+ return cached_image.scaled(size, mode);
}
// No valid image we can get
- if (!m_pack_image_cache_key.was_ever_used)
+ if (!m_pack_image_cache_key.was_ever_used) {
return {};
+ } else {
+ qDebug() << "Resource Pack" << name() << "Had it's image evicted from the cache. reloading...";
+ PixmapCache::markCacheMissByEviciton();
+ }
// Imaged got evicted from the cache. Re-process it and retry.
- ResourcePackUtils::process(*this);
+ ResourcePackUtils::processPackPNG(*this);
return image(size);
}