[vlc-commits] commit: skins2: some optimisation for playlist (Erwan Tulou )

git at videolan.org git at videolan.org
Sun Jan 16 23:05:51 CET 2011


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Jan 15 23:24:44 2011 +0100| [a714732f247bc149c58084c634bad51645d1e0d7] | committer: Erwan Tulou 

skins2: some optimisation for playlist

limit rebuilding the playlist control only when the notified item is
 expected to be visible. This improves responsiveness when playlists
are very large.

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

 modules/gui/skins2/controls/ctrl_tree.cpp |   32 +++++++++++++++++++---------
 modules/gui/skins2/controls/ctrl_tree.hpp |    3 ++
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/modules/gui/skins2/controls/ctrl_tree.cpp b/modules/gui/skins2/controls/ctrl_tree.cpp
index 4f538e1..2b07c9f 100644
--- a/modules/gui/skins2/controls/ctrl_tree.cpp
+++ b/modules/gui/skins2/controls/ctrl_tree.cpp
@@ -143,33 +143,36 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
     if( arg->i_type == 0 ) // Item update
     {
         if( arg->b_active_item )
-        {
             autoScroll();
-            ///\todo We should make image if we are visible in the view
-            makeImage();
-        }
+        makeImage();
+        notifyLayout();
     }
-    /// \todo handle delete in a more clever way
     else if ( arg->i_type == 1 ) // Global change or deletion
     {
         m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
 
         makeImage();
+        notifyLayout();
     }
     else if ( arg->i_type == 2 ) // Item-append
     {
         if( m_flat && m_firstPos->size() )
+        {
             m_firstPos = m_rTree.getNextLeaf( m_firstPos );
-        /// \todo Check if the item is really visible in the view
-        // (we only check if it in the document)
-        if( arg->b_visible == true )
+
+            makeImage();
+            notifyLayout();
+        }
+        else if( isItemVisible( arg->i_id ) )
         {
             makeImage();
+            notifyLayout();
         }
     }
     else if( arg->i_type == 3 ) // item-del
     {
         /* Make sure firstPos is valid */
+        VarTree::Iterator it_old = m_firstPos;
         while( m_firstPos->isDeleted() &&
                m_firstPos != (m_flat ? m_rTree.firstLeaf()
                                      : m_rTree.begin()) )
@@ -180,12 +183,12 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
         if( m_firstPos->isDeleted() )
             m_firstPos = m_rTree.begin();
 
-        if( arg->b_visible == true )
+        if( m_firstPos != it_old || isItemVisible( arg->i_id ) )
         {
             makeImage();
+            notifyLayout();
         }
     }
-    notifyLayout();
 }
 
 void CtrlTree::onUpdate( Subject<VarPercent> &rPercent, void* arg)
@@ -880,3 +883,12 @@ VarTree::Iterator CtrlTree::findItemAtPos( int pos )
 
     return it;
 }
+
+bool CtrlTree::isItemVisible( int id )
+{
+    VarTree::Iterator it = m_rTree.findById( id );
+
+    int rank1 = m_rTree.getRank( m_firstPos, m_flat );
+    int rank2 = m_rTree.getRank( it, m_flat );
+    return ( rank2 >= rank1 && rank2 <= rank1 + maxItems() -1 );
+}
diff --git a/modules/gui/skins2/controls/ctrl_tree.hpp b/modules/gui/skins2/controls/ctrl_tree.hpp
index 7465b97..28a646e 100644
--- a/modules/gui/skins2/controls/ctrl_tree.hpp
+++ b/modules/gui/skins2/controls/ctrl_tree.hpp
@@ -147,6 +147,9 @@ private:
      *  n too big)
      */
     VarTree::Iterator findItemAtPos( int n );
+
+    /// check if id is within the visible control
+    bool isItemVisible( int id );
 };
 
 #endif



More information about the vlc-commits mailing list