author | simon <simon> | 2002-12-11 17:18:17 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 17:18:17 (UTC) |
commit | 75f0ed4978579eb4b27cdece64c597741ed24b79 (patch) (side-by-side diff) | |
tree | 6443323e08a9639ad0db7b5b1852d3804172e70a /noncore/multimedia/opieplayer2/skin.cpp | |
parent | 94461696cfdcf8cdbaabec1400300e546edc447e (diff) | |
download | opie-75f0ed4978579eb4b27cdece64c597741ed24b79.zip opie-75f0ed4978579eb4b27cdece64c597741ed24b79.tar.gz opie-75f0ed4978579eb4b27cdece64c597741ed24b79.tar.bz2 |
- added a skin cache and a threaded skin loader. looks like the latter
we have to disable though, because pure image loading with qt is
anything but threadsafe :(
Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 8281b20..0de3023 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp @@ -6,2 +6,4 @@ +#include <assert.h> + Skin::Skin( const QString &name, const QString &fileNameInfix ) @@ -34,3 +36,3 @@ QImage Skin::backgroundImage() const if ( m_backgroundImage.isNull() ) - m_backgroundImage = QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); + m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); return m_backgroundImage; @@ -41,3 +43,3 @@ QImage Skin::buttonUpImage() const if ( m_buttonUpImage.isNull() ) - m_buttonUpImage = QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); + m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); return m_buttonUpImage; @@ -48,3 +50,3 @@ QImage Skin::buttonDownImage() const if ( m_buttonDownImage.isNull() ) - m_buttonDownImage = QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); + m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); return m_buttonDownImage; @@ -88,3 +90,3 @@ QImage Skin::buttonMaskImage( const QString &fileName ) const QString path = prefix + fileName + ".png"; - it = m_buttonMasks.insert( fileName, QImage( Resource::findPixmap( path ) ) ); + it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); } @@ -100,2 +102,50 @@ QString Skin::defaultSkinName() +SkinCache::SkinCache() +{ + m_cache.setAutoDelete( true ); +} + +QImage SkinCache::loadImage( const QString &name ) +{ + ThreadUtil::AutoLock lock( m_cacheGuard ); + + QImage *image = m_cache.find( name ); + if ( image ) { + qDebug( "cache hit for %s", name.ascii() ); + return *image; + } + + image = new QImage( Resource::findPixmap( name ) ); + m_cache.insert( name, image ); + return *image; +} + +SkinLoader::SkinLoader() +{ +} + +void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, + const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) +{ + assert( isRunning() == false ); + + pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); +} + +void SkinLoader::run() +{ + qDebug( "SkinLoader::run()" ); + for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) + load( *it ); + qDebug( "SkinLoader is done." ); +} + +void SkinLoader::load( const Info &nfo ) +{ + qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); + + Skin skin( nfo.skinName, nfo.fileNameInfix ); + skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); +} + /* vim: et sw=4 ts=4 |