summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 17:50:15 (UTC)
committer simon <simon>2002-12-11 17:50:15 (UTC)
commit7c897dfbee81f0fabce4b1a8de4ebab70f3783ee (patch) (unidiff)
treeec8571ae41c07f78ec697b57f42ebb2d3af947b2
parent483e550c75f935706fde4e0ca29c4486aeca09a0 (diff)
downloadopie-7c897dfbee81f0fabce4b1a8de4ebab70f3783ee.zip
opie-7c897dfbee81f0fabce4b1a8de4ebab70f3783ee.tar.gz
opie-7c897dfbee81f0fabce4b1a8de4ebab70f3783ee.tar.bz2
- restructing a bit the skin data storage, in preparation for cache
improvements
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp57
-rw-r--r--noncore/multimedia/opieplayer2/skin.h11
2 files changed, 41 insertions, 27 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index cef3259..9ad5f3f 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -1,173 +1,190 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <simon@lst.de> 2 Copyright (C) 2002 Simon Hausmann <simon@lst.de>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include "skin.h" 23#include "skin.h"
24 24
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27 27
28#include <assert.h> 28#include <assert.h>
29 29
30struct SkinData
31{
32 typedef QMap<QString, QImage> ButtonMaskImageMap;
33
34 QImage backgroundImage;
35 QImage buttonUpImage;
36 QImage buttonDownImage;
37 QImage buttonMask;
38 ButtonMaskImageMap buttonMasks;
39};
40
30Skin::Skin( const QString &name, const QString &fileNameInfix ) 41Skin::Skin( const QString &name, const QString &fileNameInfix )
31 : m_fileNameInfix( fileNameInfix ) 42 : m_fileNameInfix( fileNameInfix )
32{ 43{
33 init( name ); 44 init( name );
34} 45}
35 46
36Skin::Skin( const QString &fileNameInfix ) 47Skin::Skin( const QString &fileNameInfix )
37 : m_fileNameInfix( fileNameInfix ) 48 : m_fileNameInfix( fileNameInfix )
38{ 49{
39 init( defaultSkinName() ); 50 init( defaultSkinName() );
40} 51}
41 52
53Skin::~Skin()
54{
55 delete d;
56}
57
42void Skin::init( const QString &name ) 58void Skin::init( const QString &name )
43{ 59{
44 m_skinPath = "opieplayer2/skins/" + name; 60 m_skinPath = "opieplayer2/skins/" + name;
61 d = new SkinData;
45} 62}
46 63
47void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) 64void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount )
48{ 65{
49 backgroundImage(); 66 backgroundImage();
50 buttonUpImage(); 67 buttonUpImage();
51 buttonDownImage(); 68 buttonDownImage();
52 ( void )buttonMask( skinButtonInfo, buttonCount ); 69 ( void )buttonMask( skinButtonInfo, buttonCount );
53} 70}
54 71
55QImage Skin::backgroundImage() const 72QImage Skin::backgroundImage() const
56{ 73{
57 if ( m_backgroundImage.isNull() ) 74 if ( d->backgroundImage.isNull() )
58 m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); 75 d->backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) );
59 return m_backgroundImage; 76 return d->backgroundImage;
60} 77}
61 78
62QImage Skin::buttonUpImage() const 79QImage Skin::buttonUpImage() const
63{ 80{
64 if ( m_buttonUpImage.isNull() ) 81 if ( d->buttonUpImage.isNull() )
65 m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 82 d->buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
66 return m_buttonUpImage; 83 return d->buttonUpImage;
67} 84}
68 85
69QImage Skin::buttonDownImage() const 86QImage Skin::buttonDownImage() const
70{ 87{
71 if ( m_buttonDownImage.isNull() ) 88 if ( d->buttonDownImage.isNull() )
72 m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 89 d->buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
73 return m_buttonDownImage; 90 return d->buttonDownImage;
74} 91}
75 92
76QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const 93QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const
77{ 94{
78 if ( !m_buttonMask.isNull() ) 95 if ( !d->buttonMask.isNull() )
79 return m_buttonMask; 96 return d->buttonMask;
80 97
81 QSize buttonAreaSize = buttonUpImage().size(); 98 QSize buttonAreaSize = buttonUpImage().size();
82 99
83 m_buttonMask = QImage( buttonAreaSize, 8, 255 ); 100 d->buttonMask = QImage( buttonAreaSize, 8, 255 );
84 m_buttonMask.fill( 0 ); 101 d->buttonMask.fill( 0 );
85 102
86 for ( uint i = 0; i < buttonCount; ++i ) 103 for ( uint i = 0; i < buttonCount; ++i )
87 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); 104 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) );
88 105
89 return m_buttonMask; 106 return d->buttonMask;
90} 107}
91 108
92void Skin::addButtonToMask( int tag, const QImage &maskImage ) const 109void Skin::addButtonToMask( int tag, const QImage &maskImage ) const
93{ 110{
94 if ( maskImage.isNull() ) 111 if ( maskImage.isNull() )
95 return; 112 return;
96 113
97 uchar **dest = m_buttonMask.jumpTable(); 114 uchar **dest = d->buttonMask.jumpTable();
98 for ( int y = 0; y < m_buttonMask.height(); y++ ) { 115 for ( int y = 0; y < d->buttonMask.height(); y++ ) {
99 uchar *line = dest[y]; 116 uchar *line = dest[y];
100 for ( int x = 0; x < m_buttonMask.width(); x++ ) 117 for ( int x = 0; x < d->buttonMask.width(); x++ )
101 if ( !qRed( maskImage.pixel( x, y ) ) ) 118 if ( !qRed( maskImage.pixel( x, y ) ) )
102 line[x] = tag; 119 line[x] = tag;
103 } 120 }
104} 121}
105 122
106QImage Skin::buttonMaskImage( const QString &fileName ) const 123QImage Skin::buttonMaskImage( const QString &fileName ) const
107{ 124{
108 ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); 125 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName );
109 if ( it == m_buttonMasks.end() ) { 126 if ( it == d->buttonMasks.end() ) {
110 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); 127 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
111 QString path = prefix + fileName + ".png"; 128 QString path = prefix + fileName + ".png";
112 it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); 129 it = d->buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) );
113 } 130 }
114 return *it; 131 return *it;
115} 132}
116 133
117QString Skin::defaultSkinName() 134QString Skin::defaultSkinName()
118{ 135{
119 Config cfg( "OpiePlayer" ); 136 Config cfg( "OpiePlayer" );
120 cfg.setGroup( "Options" ); 137 cfg.setGroup( "Options" );
121 return cfg.readEntry( "Skin", "default" ); 138 return cfg.readEntry( "Skin", "default" );
122} 139}
123 140
124SkinCache::SkinCache() 141SkinCache::SkinCache()
125{ 142{
126 m_cache.setAutoDelete( true ); 143 m_cache.setAutoDelete( true );
127} 144}
128 145
129QImage SkinCache::loadImage( const QString &name ) 146QImage SkinCache::loadImage( const QString &name )
130{ 147{
131 ThreadUtil::AutoLock lock( m_cacheGuard ); 148 ThreadUtil::AutoLock lock( m_cacheGuard );
132 149
133 QImage *image = m_cache.find( name ); 150 QImage *image = m_cache.find( name );
134 if ( image ) { 151 if ( image ) {
135 qDebug( "cache hit for %s", name.ascii() ); 152 qDebug( "cache hit for %s", name.ascii() );
136 return *image; 153 return *image;
137 } 154 }
138 155
139 image = new QImage( Resource::findPixmap( name ) ); 156 image = new QImage( Resource::findPixmap( name ) );
140 m_cache.insert( name, image ); 157 m_cache.insert( name, image );
141 return *image; 158 return *image;
142} 159}
143 160
144SkinLoader::SkinLoader() 161SkinLoader::SkinLoader()
145{ 162{
146} 163}
147 164
148void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, 165void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix,
149 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) 166 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount )
150{ 167{
151 assert( isRunning() == false ); 168 assert( isRunning() == false );
152 169
153 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); 170 pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount );
154} 171}
155 172
156void SkinLoader::run() 173void SkinLoader::run()
157{ 174{
158 qDebug( "SkinLoader::run()" ); 175 qDebug( "SkinLoader::run()" );
159 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) 176 for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it )
160 load( *it ); 177 load( *it );
161 qDebug( "SkinLoader is done." ); 178 qDebug( "SkinLoader is done." );
162} 179}
163 180
164void SkinLoader::load( const Info &nfo ) 181void SkinLoader::load( const Info &nfo )
165{ 182{
166 qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); 183 qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() );
167 184
168 Skin skin( nfo.skinName, nfo.fileNameInfix ); 185 Skin skin( nfo.skinName, nfo.fileNameInfix );
169 skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); 186 skin.preload( nfo.skinButtonInfo, nfo.buttonCount );
170} 187}
171 188
172/* vim: et sw=4 ts=4 189/* vim: et sw=4 ts=4
173 */ 190 */
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index 9f7326e..5ab6574 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -1,124 +1,121 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <simon@lst.de> 2 Copyright (C) 2002 Simon Hausmann <simon@lst.de>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef SKIN_H 23#ifndef SKIN_H
24#define SKIN_H 24#define SKIN_H
25 25
26#include <qstring.h> 26#include <qstring.h>
27#include <qimage.h> 27#include <qimage.h>
28#include <qmap.h> 28#include <qmap.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "mediawidget.h" 31#include "mediawidget.h"
32#include "threadutil.h" 32#include "threadutil.h"
33#include "singleton.h" 33#include "singleton.h"
34 34
35struct SkinData;
36
35class Skin 37class Skin
36{ 38{
37public: 39public:
38 Skin( const QString &name, const QString &fileNameInfix ); 40 Skin( const QString &name, const QString &fileNameInfix );
39 Skin( const QString &fileNameInfix ); 41 Skin( const QString &fileNameInfix );
42 ~Skin();
40 43
41 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); 44 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount );
42 45
43 QImage backgroundImage() const; 46 QImage backgroundImage() const;
44 QImage buttonUpImage() const; 47 QImage buttonUpImage() const;
45 QImage buttonDownImage() const; 48 QImage buttonDownImage() const;
46 49
47 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; 50 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const;
48 51
49 QImage buttonMaskImage( const QString &fileName ) const; 52 QImage buttonMaskImage( const QString &fileName ) const;
50 53
51 static QString defaultSkinName(); 54 static QString defaultSkinName();
52 55
53private: 56private:
54 void init( const QString &name ); 57 void init( const QString &name );
55 58
56 void addButtonToMask( int tag, const QImage &maskImage ) const; 59 void addButtonToMask( int tag, const QImage &maskImage ) const;
57 60
58 QString m_fileNameInfix; 61 QString m_fileNameInfix;
59 QString m_skinPath; 62 QString m_skinPath;
60 63
61 typedef QMap<QString, QImage> ButtonMaskImageMap; 64 SkinData *d;
62
63 mutable QImage m_backgroundImage;
64 mutable QImage m_buttonUpImage;
65 mutable QImage m_buttonDownImage;
66 mutable QImage m_buttonMask;
67 mutable ButtonMaskImageMap m_buttonMasks;
68 65
69 Skin( const Skin & ); 66 Skin( const Skin & );
70 Skin &operator=( const Skin & ); 67 Skin &operator=( const Skin & );
71}; 68};
72 69
73class SkinCache : public Singleton<SkinCache> 70class SkinCache : public Singleton<SkinCache>
74{ 71{
75public: 72public:
76 SkinCache(); 73 SkinCache();
77 74
78 QImage loadImage( const QString &name ); 75 QImage loadImage( const QString &name );
79 76
80private: 77private:
81 typedef QDict<QImage> ImageCache; 78 typedef QDict<QImage> ImageCache;
82 79
83 ImageCache m_cache; 80 ImageCache m_cache;
84 81
85 ThreadUtil::Mutex m_cacheGuard; 82 ThreadUtil::Mutex m_cacheGuard;
86}; 83};
87 84
88class SkinLoader : public ThreadUtil::Thread 85class SkinLoader : public ThreadUtil::Thread
89{ 86{
90public: 87public:
91 SkinLoader(); 88 SkinLoader();
92 89
93 void schedule( const QString &skinName, const QString &fileNameInfix, 90 void schedule( const QString &skinName, const QString &fileNameInfix,
94 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); 91 const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount );
95 92
96protected: 93protected:
97 virtual void run(); 94 virtual void run();
98 95
99private: 96private:
100 struct Info 97 struct Info
101 { 98 {
102 Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} 99 Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {}
103 Info( const QString &_skinName, const QString &_fileNameInfix, 100 Info( const QString &_skinName, const QString &_fileNameInfix,
104 const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) 101 const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount )
105 : skinName( _skinName ), fileNameInfix( _fileNameInfix ), 102 : skinName( _skinName ), fileNameInfix( _fileNameInfix ),
106 skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount ) 103 skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount )
107 {} 104 {}
108 105
109 const QString skinName; 106 const QString skinName;
110 const QString fileNameInfix; 107 const QString fileNameInfix;
111 const MediaWidget::SkinButtonInfo *skinButtonInfo; 108 const MediaWidget::SkinButtonInfo *skinButtonInfo;
112 const uint buttonCount; 109 const uint buttonCount;
113 }; 110 };
114 typedef QValueList<Info> InfoList; 111 typedef QValueList<Info> InfoList;
115 112
116 void load( const Info &nfo ); 113 void load( const Info &nfo );
117 114
118 InfoList pendingSkins; 115 InfoList pendingSkins;
119 ThreadUtil::Mutex guard; 116 ThreadUtil::Mutex guard;
120}; 117};
121 118
122#endif // SKIN_H 119#endif // SKIN_H
123/* vim: et sw=4 ts=4 120/* vim: et sw=4 ts=4
124 */ 121 */