Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increased pixmapCache size limit and made it dependent on devicePixelRatio (for HiDPI/Retina displays) #12416

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/library/coverartcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ namespace {

mixxx::Logger kLogger("CoverArtCache");

// The initial QPixmapCache limit is 10MB.
// But it is not used just by the coverArt stuff,
// it is also used by Qt to handle other things behind the scenes.
// Consequently coverArt cache will always have less than those
// 10MB available to store the pixmaps.
// So, we must increase this size a bit more,
// in order to allow CoverCache handle more covers (performance gain).
constexpr int kPixmapCacheLimit = 20480;

QString pixmapCacheKey(mixxx::cache_key_t hash, int width) {
return QString("CoverArtCache_%1_%2")
.arg(QString::number(hash), QString::number(width));
Expand All @@ -39,7 +30,6 @@ inline QImage resizeImageWidth(const QImage& image, int width) {
} // anonymous namespace

CoverArtCache::CoverArtCache() {
QPixmapCache::setCacheLimit(kPixmapCacheLimit);
}

//static
Expand Down
17 changes: 17 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <QApplication>
#include <QDir>
#include <QPixmapCache>
#include <QString>
#include <QStringList>
#include <QTextCodec>
Expand Down Expand Up @@ -40,6 +41,16 @@ constexpr char kScaleFactorEnvVar[] = "QT_SCALE_FACTOR";
const QString kConfigGroup = QStringLiteral("[Config]");
const QString kScaleFactorKey = QStringLiteral("ScaleFactor");

// The default initial QPixmapCache limit is 10MB.
// But this is used for all CoverArts in all used sizes and
// as rendering cache for all SVG icons by Qt behind the scenes.
// Consequently coverArt cache will always have less than those
// 10MB available to store the pixmaps.
// Profiling at 100% HiDPI zoom on Windows, that with 20MByte,
// the SVG rendering happens sometimes during normal operation.
// An indicator that the QPixmapCache was too small.
constexpr int kPixmapCacheLimitAt100PercentZoom = 32 * 1024; // 32 MByte

int runMixxx(MixxxApplication* pApp, const CmdlineArgs& args) {
const auto pCoreServices = std::make_shared<mixxx::CoreServices>(args, pApp);

Expand Down Expand Up @@ -67,6 +78,12 @@ int runMixxx(MixxxApplication* pApp, const CmdlineArgs& args) {
&mixxx::CoreServices::initializationProgressUpdate,
&mainWindow,
&MixxxMainWindow::initializationProgressUpdate);

// The size of cached pixmaps increases with the square of devicePixelRatio
// (this covers both, operating system scaling and Mixxx preferences scaling)
QPixmapCache::setCacheLimit(static_cast<int>(kPixmapCacheLimitAt100PercentZoom *
pow(pApp->devicePixelRatio(), 2.0f)));

pCoreServices->initialize(pApp);

#ifdef MIXXX_USE_QOPENGL
Expand Down