[vlc-commits] skins2: implement a caching mechanism for graphics

Erwan Tulou git at videolan.org
Sat Apr 6 14:50:09 CEST 2013


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Apr  6 14:18:26 2013 +0200| [3a3c9918c57545822440b681b3378a1d5d68b5ff] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3a3c9918c57545822440b681b3378a1d5d68b5ff
---

 modules/gui/skins2/src/generic_bitmap.cpp |   23 ++++++++++++++++++++++-
 modules/gui/skins2/src/generic_bitmap.hpp |    9 ++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/modules/gui/skins2/src/generic_bitmap.cpp b/modules/gui/skins2/src/generic_bitmap.cpp
index 37818df..66abaf1 100644
--- a/modules/gui/skins2/src/generic_bitmap.cpp
+++ b/modules/gui/skins2/src/generic_bitmap.cpp
@@ -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 ):
diff --git a/modules/gui/skins2/src/generic_bitmap.hpp b/modules/gui/skins2/src/generic_bitmap.hpp
index 800a8a0..690c902 100644
--- a/modules/gui/skins2/src/generic_bitmap.hpp
+++ b/modules/gui/skins2/src/generic_bitmap.hpp
@@ -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;
 };
 
 



More information about the vlc-commits mailing list