From ce4bddf30723ccff2bbea8015e738339c207003c Mon Sep 17 00:00:00 2001
From: Erwan Tulou <erwan10@videolan.org>
Date: Sat, 26 Dec 2009 21:31:06 +0100
Subject: [PATCH] skins2: optimize refresh

skins2 manages a cache for building layouts. Yet, on each redraw/expose,
it rebuilds the whole layout. This patch avoids these unnecessary rebuilds.
It results in dramatic improvement, especially on Linux, where refresh was a real issue.
---
 modules/gui/skins2/src/generic_layout.cpp | 31 ++++++++++++++---------
 modules/gui/skins2/src/top_window.cpp     |  8 +++---
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/modules/gui/skins2/src/generic_layout.cpp b/modules/gui/skins2/src/generic_layout.cpp
index ff695aec0dba..97bb03ce4d26 100644
--- a/modules/gui/skins2/src/generic_layout.cpp
+++ b/modules/gui/skins2/src/generic_layout.cpp
@@ -234,17 +234,7 @@ void GenericLayout::refreshRect( int x, int y, int width, int height )
         if( y + height > m_rect.getHeight() )
             height = m_rect.getHeight() - y;
 
-        // Refresh the window... but do not paint on a visible video control!
-        if( !m_pVideoCtrlSet.size() )
-        {
-            // No video control, we can safely repaint the rectangle
-            pWindow->refresh( x, y, width, height );
-        }
-        else
-        {
-            // video control(s) present, we need more calculations
-            computeRefresh( x, y, width, height );
-        }
+        computeRefresh( x, y, width, height );
     }
 }
 
@@ -280,9 +270,23 @@ public:
 
 void GenericLayout::computeRefresh( int x, int y, int width, int height )
 {
+    TopWindow *pWindow = getWindow();
+
+#ifndef WIN32
+
+    pWindow->refresh( x, y, width, height );
+
+#else
+
+    if( !m_pVideoCtrlSet.size() )
+    {
+        // No video control, we can safely repaint the rectangle
+        pWindow->refresh( x, y, width, height );
+        return;
+    }
+
     int w = width;
     int h = height;
-    TopWindow *pWindow = getWindow();
 
     set<int> x_set;
     set<int> y_set;
@@ -355,6 +359,9 @@ void GenericLayout::computeRefresh( int x, int y, int width, int height )
                 pWindow->refresh( x0, y0, w0 ,h0 );
         }
     }
+
+#endif
+
 }
 
 
diff --git a/modules/gui/skins2/src/top_window.cpp b/modules/gui/skins2/src/top_window.cpp
index b7f791b62770..1b355ebf0fa8 100644
--- a/modules/gui/skins2/src/top_window.cpp
+++ b/modules/gui/skins2/src/top_window.cpp
@@ -82,10 +82,10 @@ void TopWindow::processEvent( EvtRefresh &rEvtRefresh )
     }
     else
     {
-        m_pActiveLayout->refreshRect( rEvtRefresh.getXStart(),
-                                      rEvtRefresh.getYStart(),
-                                      rEvtRefresh.getWidth(),
-                                      rEvtRefresh.getHeight() );
+        m_pActiveLayout->computeRefresh( rEvtRefresh.getXStart(),
+                                         rEvtRefresh.getYStart(),
+                                         rEvtRefresh.getWidth(),
+                                         rEvtRefresh.getHeight() );
     }
 }
 
-- 
GitLab