]> git.sesse.net Git - vlc/commitdiff
skins2: implement a caching mechanism for graphics
authorErwan Tulou <erwan10@videolan.org>
Sat, 6 Apr 2013 12:18:26 +0000 (14:18 +0200)
committerErwan Tulou <erwan10@videolan.org>
Sat, 6 Apr 2013 12:46:51 +0000 (14:46 +0200)
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.

modules/gui/skins2/src/generic_bitmap.cpp
modules/gui/skins2/src/generic_bitmap.hpp

index 37818df4cae1d0775ce79c166d62887bc2e4c221..66abaf1e6f6ec4fb63acdd03178b7911c4d8599c 100644 (file)
  *****************************************************************************/
 
 #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 ):
index 800a8a0828b9a2e72f43a42ba775fef0afa10726..690c9020703832dd49460501e25437ec4040b26d 100644 (file)
@@ -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"
 
 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;
 };