Commit 3a3c9918 authored by Erwan Tulou's avatar Erwan Tulou

skins2: implement a caching mechanism for graphics

This patch will drastically reduce the multiple copies of the same
bitmap as graphics. It is now the GenericBitmap responsability
to create/delete one single read-only copy.
parent b8330f3a
......@@ -22,15 +22,36 @@
*****************************************************************************/
#include "generic_bitmap.hpp"
#include "os_factory.hpp"
GenericBitmap::GenericBitmap( intf_thread_t *pIntf,
int nbFrames, int fps, int nbLoops ):
SkinObject( pIntf ), m_nbFrames( nbFrames ),
m_frameRate( fps ), m_nbLoops( nbLoops )
m_frameRate( fps ), m_nbLoops( nbLoops ), m_pGraphics( NULL )
{
}
const OSGraphics *GenericBitmap::getGraphics() const
{
if( m_pGraphics )
return m_pGraphics;
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
int width = getWidth();
int height = getHeight();
if( width > 0 && height > 0 )
{
m_pGraphics = pOsFactory->createOSGraphics( width, height );
m_pGraphics->drawBitmap( *this, 0, 0 );
return m_pGraphics;
}
msg_Err( getIntf(), "failed to create a graphics, please report" );
return NULL;
}
BitmapImpl::BitmapImpl( intf_thread_t *pIntf, int width, int height,
int nbFrames, int fps, int nbLoops ):
......
......@@ -26,6 +26,7 @@
#define GENERIC_BITMAP_HPP
#include "skin_common.hpp"
#include "../src/os_graphics.hpp"
#include "../utils/pointer.hpp"
#include "../utils/position.hpp"
......@@ -34,12 +35,15 @@
class GenericBitmap: public SkinObject, public Box
{
public:
virtual ~GenericBitmap() { }
virtual ~GenericBitmap() { delete m_pGraphics; }
/// Get a linear buffer containing the image data.
/// Each pixel is stored in 4 bytes in the order B,G,R,A
virtual uint8_t *getData() const = 0;
/// Get the bitmap as a graphics
virtual const OSGraphics *getGraphics() const;
/// Get the number of frames in the bitmap
int getNbFrames() const { return m_nbFrames; }
......@@ -59,6 +63,9 @@ private:
int m_frameRate;
/// Number of Loops
int m_nbLoops;
/// graphics copy of the bitmap
mutable OSGraphics* m_pGraphics;
};
......
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