Commit 4cd590ad authored by Erwan Tulou's avatar Erwan Tulou

skins2: implement a ArtManager singleton

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.
parent ab848324
......@@ -107,8 +107,8 @@ SOURCES_skins2 = \
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 \
......
......@@ -29,7 +29,7 @@
#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"
......@@ -51,8 +51,6 @@ CtrlImage::CtrlImage( intf_thread_t *pIntf, GenericBitmap &rBitmap,
{
VlcProc *pVlcProc = VlcProc::instance( getIntf() );
pVlcProc->getStreamArtVar().addObserver( this );
ArtBitmap::initArtBitmap( getIntf() );
}
}
......@@ -66,8 +64,6 @@ CtrlImage::~CtrlImage()
{
VlcProc *pVlcProc = VlcProc::instance( getIntf() );
pVlcProc->getStreamArtVar().delObserver( this );
ArtBitmap::freeArtBitmap( );
}
}
......@@ -218,7 +214,8 @@ void CtrlImage::onUpdate( Subject<VarString> &rVariable, void* arg )
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$
......@@ -25,38 +25,60 @@
# 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;
......@@ -68,10 +90,16 @@ ArtBitmap* ArtBitmap::getArtBitmap( string uriName )
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;
}
......@@ -81,16 +109,3 @@ ArtBitmap* ArtBitmap::getArtBitmap( string uriName )
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$
......@@ -21,8 +21,8 @@
* 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>
......@@ -34,33 +34,46 @@ class ArtBitmap: public FileBitmap
{
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
......@@ -46,6 +46,7 @@ class OSLoop;
class VarManager;
class VlcProc;
class VoutManager;
class ArtManager;
class Theme;
class ThemeRepository;
......@@ -124,6 +125,8 @@ struct intf_sys_t
VlcProc *p_vlcProc;
/// Vout manager
VoutManager *p_voutManager;
/// Art manager
ArtManager *p_artManager;
/// Theme repository
ThemeRepository *p_repository;
......
......@@ -43,6 +43,7 @@
#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"
......@@ -212,13 +213,13 @@ static void *Run( void * p_obj )
}
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;
}
......@@ -230,19 +231,25 @@ static void *Run( void * p_obj )
}
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;
}
......@@ -295,6 +302,7 @@ 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 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment