From kde-commits Fri Apr 04 19:07:03 2008 From: Maks Orlovich Date: Fri, 04 Apr 2008 19:07:03 +0000 To: kde-commits Subject: branches/KDE/4.0/kdelibs/kdeui/widgets Message-Id: <1207336023.376751.15781.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120733603418169 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 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(); }