This singleton is based on the same pattern as VlcManager or VoutManager.
It is intended to load and cache art for the whole skin.
Caching makes sense because 1/ several controls within a skin can display
the current art, and 2/ art is likely to be reused by successive inputs
(music album, repeat). Yet, caching is limited to two art for memory reason.
src/dialogs.hpp \
src/file_bitmap.cpp \
src/file_bitmap.hpp \
- src/art_bitmap.cpp \
- src/art_bitmap.hpp \
+ src/art_manager.cpp \
+ src/art_manager.hpp \
src/ft2_bitmap.cpp \
src/ft2_bitmap.hpp \
src/ft2_font.cpp \
#include "../src/os_graphics.hpp"
#include "../src/vlcproc.hpp"
#include "../src/scaled_bitmap.hpp"
-#include "../src/art_bitmap.hpp"
+#include "../src/art_manager.hpp"
#include "../utils/position.hpp"
{
VlcProc *pVlcProc = VlcProc::instance( getIntf() );
pVlcProc->getStreamArtVar().addObserver( this );
-
- ArtBitmap::initArtBitmap( getIntf() );
}
}
{
VlcProc *pVlcProc = VlcProc::instance( getIntf() );
pVlcProc->getStreamArtVar().delObserver( this );
-
- ArtBitmap::freeArtBitmap( );
}
}
if( &rVariable == &pVlcProc->getStreamArtVar() )
{
string str = ((VarString&)rVariable).get();
- GenericBitmap* pArt = (GenericBitmap*) ArtBitmap::getArtBitmap( str );
+ ArtManager* pArtManager = ArtManager::instance( getIntf() );
+ GenericBitmap* pArt = (GenericBitmap*) pArtManager->getArtBitmap( str );
m_pBitmap = pArt ? pArt : m_pOriginalBitmap;
/*****************************************************************************
- * art_bitmap.cpp
+ * art_manager.cpp
*****************************************************************************
* Copyright (C) 2010 the VideoLAN team
* $Id$
# include "config.h"
#endif
-#include "art_bitmap.hpp"
+#include "art_manager.hpp"
#include <vlc_image.h>
+#define MAX_ART_CACHED 2
-// static variables
-intf_thread_t* ArtBitmap::m_pIntf = NULL;
-image_handler_t* ArtBitmap::m_pImageHandler = NULL;
-list<ArtBitmap*> ArtBitmap::m_listBitmap;
-ArtBitmap::ArtBitmap( string uriName ):
- FileBitmap( m_pIntf, m_pImageHandler, uriName, -1 ), m_uriName( uriName )
+ArtManager *ArtManager::instance( intf_thread_t *pIntf )
{
+ if( pIntf->p_sys->p_artManager == NULL )
+ {
+ pIntf->p_sys->p_artManager = new ArtManager( pIntf );
+ }
+
+ return pIntf->p_sys->p_artManager;
}
-void ArtBitmap::initArtBitmap( intf_thread_t* pIntf )
+
+void ArtManager::destroy( intf_thread_t *pIntf )
{
- if( m_pIntf )
- return;
+ delete pIntf->p_sys->p_artManager;
+ pIntf->p_sys->p_artManager = NULL;
+}
- // retain reference to skins interface
- m_pIntf = pIntf;
+ArtManager::ArtManager( intf_thread_t* pIntf ) : SkinObject( pIntf )
+{
// initialize handler
m_pImageHandler = image_HandlerCreate( pIntf );
if( !m_pImageHandler )
- msg_Err( m_pIntf, "initialization of art bitmaps failed" );
+ msg_Err( getIntf(), "initialization of art manager failed" );
+}
+
+
+ArtManager::~ArtManager( )
+{
+ if( m_pImageHandler )
+ {
+ image_HandlerDelete( m_pImageHandler );
+ m_pImageHandler = NULL;
+ }
+
+ list<ArtBitmap*>::const_iterator it;
+ for( it = m_listBitmap.begin(); it != m_listBitmap.end(); ++it )
+ delete *it;
+ m_listBitmap.clear();
}
-ArtBitmap* ArtBitmap::getArtBitmap( string uriName )
+ArtBitmap* ArtManager::getArtBitmap( string uriName )
{
+ if( !uriName.size() )
+ return NULL;
+
if( !m_pImageHandler )
return NULL;
return *it;
}
- // create and retain a new ArtBitmap since uri if not yet known
- ArtBitmap* pArt = new ArtBitmap( uriName );
+ // create and retain a new ArtBitmap since uri is not yet known
+ ArtBitmap* pArt = new ArtBitmap( getIntf(), m_pImageHandler, uriName );
if( pArt && pArt->getWidth() && pArt->getHeight() )
{
+ if( m_listBitmap.size() == MAX_ART_CACHED )
+ {
+ ArtBitmap* pOldest = *(m_listBitmap.begin());
+ delete pOldest;
+ m_listBitmap.pop_front();
+ }
m_listBitmap.push_back( pArt );
return pArt;
}
return NULL;
}
}
-
-void ArtBitmap::freeArtBitmap( )
-{
- m_pIntf = NULL;
-
- if( m_pImageHandler )
- {
- image_HandlerDelete( m_pImageHandler );
- m_pImageHandler = NULL;
- }
-
- m_listBitmap.clear();
-}
/*****************************************************************************
- * art_bitmap.hpp
+ * art_manager.hpp
*****************************************************************************
* Copyright (C) 2010 the VideoLAN team
* $Id$
* 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#ifndef ART_BITMAP_HPP
-#define ART_BITMAP_HPP
+#ifndef ART_MANAGER_HPP
+#define ART_MANAGER_HPP
#include "file_bitmap.hpp"
#include <string>
{
public:
- static ArtBitmap* getArtBitmap( string uriName );
- static void initArtBitmap( intf_thread_t* pIntf );
- static void freeArtBitmap( );
-
string getUriName() { return m_uriName; }
-protected:
-
/// Constructor/destructor
- ArtBitmap( string uriName );
+ ArtBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
+ string uriName ) :
+ FileBitmap( pIntf, pImageHandler, uriName, -1 ),
+ m_uriName( uriName ) {}
virtual ~ArtBitmap() {}
- /// skins2 interface
- static intf_thread_t *m_pIntf;
+private:
+ /// uriName
+ string m_uriName;
+};
- /// Image handler (used to load art files)
- static image_handler_t *m_pImageHandler;
- // keep a cache of art already open
- static list<ArtBitmap*> m_listBitmap;
+/// Singleton object for handling art
+class ArtManager: public SkinObject
+{
+public:
+ /// Get the instance of ArtManager
+ /// Returns NULL if the initialization of the object failed
+ static ArtManager *instance( intf_thread_t *pIntf );
-private:
+ /// Delete the instance of ArtManager
+ static void destroy( intf_thread_t *pIntf );
- // uriName
- string m_uriName;
+ /// Retrieve for the art file from uri name
+ ArtBitmap* getArtBitmap( string uriName );
-};
+protected:
+ // Protected because it is a singleton
+ ArtManager( intf_thread_t *pIntf );
+ virtual ~ArtManager();
+private:
+ /// Image handler (used to load art files)
+ image_handler_t *m_pImageHandler;
+
+ // keep a cache of art already open
+ list<ArtBitmap*> m_listBitmap;
+};
#endif
class VarManager;
class VlcProc;
class VoutManager;
+class ArtManager;
class Theme;
class ThemeRepository;
VlcProc *p_vlcProc;
/// Vout manager
VoutManager *p_voutManager;
+ /// Art manager
+ ArtManager *p_artManager;
/// Theme repository
ThemeRepository *p_repository;
#include "theme_repository.hpp"
#include "vout_window.hpp"
#include "vout_manager.hpp"
+#include "art_manager.hpp"
#include "../parser/interpreter.hpp"
#include "../commands/async_queue.hpp"
#include "../commands/cmd_quit.hpp"
}
if( Interpreter::instance( p_intf ) == NULL )
{
- msg_Err( p_intf, "cannot instanciate Interpreter" );
+ msg_Err( p_intf, "cannot instantiate Interpreter" );
b_error = true;
goto end;
}
if( VarManager::instance( p_intf ) == NULL )
{
- msg_Err( p_intf, "cannot instanciate VarManager" );
+ msg_Err( p_intf, "cannot instantiate VarManager" );
b_error = true;
goto end;
}
}
if( VoutManager::instance( p_intf ) == NULL )
{
- msg_Err( p_intf, "cannot instanciate VoutManager" );
+ msg_Err( p_intf, "cannot instantiate VoutManager" );
+ b_error = true;
+ goto end;
+ }
+ if( ArtManager::instance( p_intf ) == NULL )
+ {
+ msg_Err( p_intf, "cannot instantiate ArtManager" );
b_error = true;
goto end;
}
if( ThemeRepository::instance( p_intf ) == NULL )
{
- msg_Err( p_intf, "cannot instanciate ThemeRepository" );
+ msg_Err( p_intf, "cannot instantiate ThemeRepository" );
b_error = true;
goto end;
}
if( Dialogs::instance( p_intf ) == NULL )
{
- msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
+ msg_Err( p_intf, "cannot instantiate qt4 dialogs provider" );
b_error = true;
goto end;
}
// Destroy "singleton" objects
Dialogs::destroy( p_intf );
ThemeRepository::destroy( p_intf );
+ ArtManager::destroy( p_intf );
VoutManager::destroy( p_intf );
VlcProc::destroy( p_intf );
VarManager::destroy( p_intf );