1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010 the VideoLAN team
7 * Author: Erwan Tulou <erwan10@vidoelan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "art_manager.hpp"
29 #include <vlc_image.h>
31 #define MAX_ART_CACHED 2
34 ArtManager *ArtManager::instance( intf_thread_t *pIntf )
36 if( pIntf->p_sys->p_artManager == NULL )
38 pIntf->p_sys->p_artManager = new ArtManager( pIntf );
41 return pIntf->p_sys->p_artManager;
45 void ArtManager::destroy( intf_thread_t *pIntf )
47 delete pIntf->p_sys->p_artManager;
48 pIntf->p_sys->p_artManager = NULL;
52 ArtManager::ArtManager( intf_thread_t* pIntf ) : SkinObject( pIntf )
55 m_pImageHandler = image_HandlerCreate( pIntf );
57 if( !m_pImageHandler )
58 msg_Err( getIntf(), "initialization of art manager failed" );
62 ArtManager::~ArtManager( )
66 image_HandlerDelete( m_pImageHandler );
67 m_pImageHandler = NULL;
70 list<ArtBitmap*>::const_iterator it;
71 for( it = m_listBitmap.begin(); it != m_listBitmap.end(); ++it )
77 ArtBitmap* ArtManager::getArtBitmap( string uriName )
82 if( !m_pImageHandler )
85 // check whether art is already loaded
86 list<ArtBitmap*>::const_iterator it;
87 for( it = m_listBitmap.begin(); it != m_listBitmap.end(); ++it )
89 if( (*it)->getUriName() == uriName )
93 // create and retain a new ArtBitmap since uri is not yet known
94 ArtBitmap* pArt = new ArtBitmap( getIntf(), m_pImageHandler, uriName );
95 if( pArt && pArt->getWidth() && pArt->getHeight() )
97 if( m_listBitmap.size() == MAX_ART_CACHED )
99 ArtBitmap* pOldest = *(m_listBitmap.begin());
101 m_listBitmap.pop_front();
103 m_listBitmap.push_back( pArt );