mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
* Use QPixmapCache for scaled covers to reduce memory footprint.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -282,15 +283,16 @@ Album::cover( const QSize& size, bool forceLoad ) const
|
|||||||
|
|
||||||
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
||||||
{
|
{
|
||||||
if ( m_coverCache.contains( size.width() ) )
|
const QString cacheKey = infoid() + "_" + size.width();
|
||||||
{
|
QPixmap cover;
|
||||||
return m_coverCache.value( size.width() );
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap scaledCover;
|
if ( !QPixmapCache::find( cacheKey, cover ) )
|
||||||
scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
{
|
||||||
m_coverCache.insert( size.width(), scaledCover );
|
cover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
return scaledCover;
|
QPixmapCache::insert( cacheKey, cover );
|
||||||
|
return cover;
|
||||||
|
}
|
||||||
|
return cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_cover )
|
if ( m_cover )
|
||||||
|
@@ -102,7 +102,6 @@ private:
|
|||||||
mutable QByteArray m_coverBuffer;
|
mutable QByteArray m_coverBuffer;
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
mutable QPixmap* m_cover;
|
mutable QPixmap* m_cover;
|
||||||
mutable QHash< int, QPixmap > m_coverCache;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
|
QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -585,15 +586,16 @@ Artist::cover( const QSize& size, bool forceLoad ) const
|
|||||||
|
|
||||||
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
||||||
{
|
{
|
||||||
if ( m_coverCache.contains( size.width() ) )
|
const QString cacheKey = infoid() + "_" + size.width();
|
||||||
{
|
QPixmap cover;
|
||||||
return m_coverCache.value( size.width() );
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap scaledCover;
|
if ( !QPixmapCache::find( cacheKey, cover ) )
|
||||||
scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
{
|
||||||
m_coverCache.insert( size.width(), scaledCover );
|
cover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
return scaledCover;
|
QPixmapCache::insert( cacheKey, cover );
|
||||||
|
return cover;
|
||||||
|
}
|
||||||
|
return cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_cover )
|
if ( m_cover )
|
||||||
|
@@ -131,7 +131,6 @@ private:
|
|||||||
mutable QByteArray m_coverBuffer;
|
mutable QByteArray m_coverBuffer;
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
mutable QPixmap* m_cover;
|
mutable QPixmap* m_cover;
|
||||||
mutable QHash< int, QPixmap > m_coverCache;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
|
QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
|
||||||
|
Reference in New Issue
Block a user