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

List:       kde-commits
Subject:    branches/KDE/4.0/kdelibs/kdeui/widgets
From:       Maks Orlovich <maksim () kde ! org>
Date:       2008-04-04 19:07:03
Message-ID: 1207336023.376751.15781.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 793672 by orlovich:

Cache and reuse pixmaps for each frame. Before, new ones were created, 
and Qt would stick every single one of them into the pixmap cache,
potentially keeping as many as ~1000 X pixmaps pointlessly, which 
could slow down things such as EXA (though FredrikH made the latest 
devel X handle that better..)


 M  +14 -3     kanimatedbutton.cpp  


--- branches/KDE/4.0/kdelibs/kdeui/widgets/kanimatedbutton.cpp #793671:793672
@@ -48,6 +48,9 @@
   QPixmap                pixmap;
   QTimer                 timer;
   QString                icon_name;
+  QVector<QPixmap*>      framesCache; // We keep copies of each frame so that
+                                      // the icon code can properly cache them in QPixmapCache,
+                                      // and not fill it up with dead copies
 };
 
 KAnimatedButton::KAnimatedButton( QWidget *parent )
@@ -59,6 +62,7 @@
 KAnimatedButton::~KAnimatedButton()
 {
   d->timer.stop();
+  qDeleteAll(d->framesCache);
 
   delete d;
 }
@@ -110,14 +114,18 @@
   int w = pixmap.width();
   int h = w;
 
-  QPixmap pix(w, h);
 
+  QPixmap* frame = framesCache[current_frame];
+  if (!frame)
   {
-    QPainter p(&pix);
+    frame = new QPixmap(w, h);
+    QPainter p(frame);
     p.drawPixmap(QPoint(0,0), pixmap, QRect(0, current_frame * h, w, h));
+    p.end();
+    framesCache[current_frame] = frame;
   }
 
-  q->setIcon(QIcon(pix));
+  q->setIcon(QIcon(*frame));
 }
 
 void KAnimatedButton::updateIcons()
@@ -136,6 +144,9 @@
   }
   d->pixmap = QPixmap::fromImage(img);
 
+  qDeleteAll(d->framesCache);
+  d->framesCache.resize(d->frames);
+
   d->updateCurrentIcon();
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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