[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/utils/kpager
From:       Pino Toscano <pino () kde ! org>
Date:       2015-11-19 8:31:51
Message-ID: E1ZzKdD-0007eN-Kg () scm ! kde ! org
[Download RAW message or body]

SVN commit 1444578 by pino:

use QCache for the window pixmaps cache

place this new cache in KPager, passing it to all the desktop created
(so we can avoid static data all around)

furthermore, get rid of m_windowPixmapsDirty: if the (possibly cached)
pixmap window is considered dirty, then it is better to just remove it
from the cache


 M  +10 -14    desktop.cpp  
 M  +3 -7      desktop.h  
 M  +3 -3      kpager.cpp  
 M  +3 -0      kpager.h  


--- trunk/extragear/utils/kpager/desktop.cpp #1444577:1444578
@@ -49,7 +49,7 @@
 #include <QX11Info>
 #include <settings.h>
 
-Desktop::Desktop(int desk, QWidget *parent): QWidget(parent)
+Desktop::Desktop(int desk, QCache<WId, QPixmap> &winPixCache, QWidget *parent): \
QWidget(parent), m_windowPixmapsCache(winPixCache)  {
   m_desk = desk;
   m_name = KWindowSystem::desktopName(m_desk);
@@ -117,7 +117,7 @@
 	KWindowSystem::forceActiveWindow(info->win());
 
 	//	    if ( static_cast<WindowDrawMode>( KPagerConfigDialog::m_windowDrawMode ) == \
                Pixmap )
-	//		m_windowPixmapsDirty.insert(info->win());
+	//		m_windowPixmapsCache.remove(info->win());
       }
     }
   }
@@ -562,9 +562,8 @@
   rSmall = QRect( r.x() * width() / dw, 2 + r.y() * height() / dh,
       r.width() * width() / dw, r.height() * height() / dh );
 
-  QPixmap pixmap = m_windowPixmaps.value(info->win());
-  const bool isDirty = m_windowPixmapsDirty.contains(info->win());
-  if ( !pixmap.isNull() || isDirty || m_grabWindows )
+  QPixmap *pixmap = m_windowPixmapsCache.object(info->win());
+  if ( !pixmap || m_grabWindows )
   {
     if ( isCurrent() )
     {
@@ -583,14 +582,13 @@
 		nWd = rSmall.width();
 		nHg = rSmall.height();
 	}
-	pixmap = fastScalePixmap(tmp, nWd, nHg);
-	m_windowPixmaps[info->win()] = pixmap;
-	m_windowPixmapsDirty.remove(info->win());
+	pixmap = new QPixmap(fastScalePixmap(tmp, nWd, nHg));
+	m_windowPixmapsCache.insert(info->win(), pixmap);
       }
     }
 
     // It was impossible to get the pixmap, let's fallback to the icon mode.
-    if ( pixmap.isNull() )
+    if ( !pixmap )
     {
       paintWindowIcon(p, info, onDesktop);
       return;
@@ -601,14 +599,14 @@
   if ( !onDesktop )
     rSmall.moveTopLeft(QPoint(0,0));
 
-  if (rSmall.width() != pixmap.width() || rSmall.height() != pixmap.height())
+  if (rSmall.width() != pixmap->width() || rSmall.height() != pixmap->height())
 	{
-		QPixmap pixmapSmall(fastScalePixmap(pixmap,rSmall.width(),rSmall.height()));
+		QPixmap pixmapSmall(fastScalePixmap(*pixmap,rSmall.width(),rSmall.height()));
 		p.drawPixmap( rSmall.topLeft(), pixmapSmall );
 	}
 	else
 	{
-		p.drawPixmap( rSmall.topLeft(), pixmap);
+		p.drawPixmap( rSmall.topLeft(), *pixmap);
 	}
 
 }
@@ -681,7 +679,5 @@
 
 QPixmap *Desktop::m_bgCommonSmallPixmap=0L;
 bool Desktop::m_isCommon=false;
-QHash<WId, QPixmap> Desktop::m_windowPixmaps;
-QSet<WId> Desktop::m_windowPixmapsDirty;
 
 #include "desktop.moc"
--- trunk/extragear/utils/kpager/desktop.h #1444577:1444578
@@ -28,8 +28,7 @@
 
 #include <QWidget>
 #include <QPixmap>
-#include <QHash>
-#include <QSet>
+#include <QCache>
 
 class KSharedPixmap;
 
@@ -41,7 +40,7 @@
     Q_OBJECT
 
 public:
-  Desktop( int desk, QWidget *parent=0 );
+  Desktop( int desk, QCache<WId, QPixmap> &winPixCache, QWidget *parent=0 );
   ~Desktop();
 
   int id() const { return m_desk; }
@@ -66,8 +65,6 @@
   void convertRectS2P(QRect &r) const;
   void convertCoordP2S(int &x, int &y) const;
 
-  static void removeCachedPixmap(WId nWin) { m_windowPixmaps.remove(nWin); }
-
   QSize sizeHint() const;
 
   /**
@@ -102,8 +99,6 @@
   QPixmap *m_bgSmallPixmap;
   static QPixmap *m_bgCommonSmallPixmap;
   static bool m_isCommon;
-  static QHash<WId, QPixmap> m_windowPixmaps;
-  static QSet<WId> m_windowPixmapsDirty;
   WindowTransparentMode m_transparentMode;
 
   QPixmap paintNewWindow(const KWindowInfo *info) const;
@@ -120,6 +115,7 @@
 private:
   class KPager* pager() const;
     QPoint pressPos;
+    QCache<WId, QPixmap> &m_windowPixmapsCache;
 
 };
 
--- trunk/extragear/utils/kpager/kpager.cpp #1444577:1444578
@@ -220,7 +220,7 @@
     int numberOfDesktops=KWindowSystem::numberOfDesktops();
     for (int i=0;i<numberOfDesktops;i++)
     {
-        Desktop *dsk=new Desktop(i+1,this);
+        Desktop *dsk=new Desktop(i+1,m_windowPixmapsCache,this);
         m_desktops.append(dsk);
     }
 
@@ -458,7 +458,7 @@
     if (inf)
     {
         m_windows.remove( win );
-        Desktop::removeCachedPixmap(win);
+        m_windowPixmapsCache.remove(win);
         updateDesktop(inf->desktop());
         delete inf;
     }
@@ -542,7 +542,7 @@
 
         for (int d=m_desktops.count()+1;d<=nDesktops; d++)
         {
-            Desktop *dsk=new Desktop(d,this);
+            Desktop *dsk=new Desktop(d,m_windowPixmapsCache,this);
             m_desktops.append(dsk);
             dsk->show();
         }
--- trunk/extragear/utils/kpager/kpager.h #1444577:1444578
@@ -26,6 +26,7 @@
 #ifndef __KPAGER_H
 #define __KPAGER_H
 
+#include <QCache>
 #include <QHash>
 #include <kmainwindow.h>
 #include <kwindowinfo.h>
@@ -143,6 +144,8 @@
 
     QTimer *m_grabWinTimer;
     int     m_currentDesktop;
+
+    QCache<WId, QPixmap> m_windowPixmapsCache;
 };
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic