From e969813b4a345a9982d1d15c1295f1df6110d042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Tue, 16 Mar 2010 16:34:39 +0000 Subject: [PATCH] Wait two seconds before deleting the scratch pixmap in the paint redirector in case we need it again. This should improve performance with drivers where creating pixmaps is expensive. svn path=/trunk/KDE/kdebase/workspace/; revision=1104069 --- paintredirector.cpp | 25 +++++++++++++++++++++---- paintredirector.h | 4 ++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/paintredirector.cpp b/paintredirector.cpp index dcea50af15..4113178e17 100644 --- a/paintredirector.cpp +++ b/paintredirector.cpp @@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE. #include #include #include +#include namespace KWin { @@ -43,15 +44,22 @@ PaintRedirector::PaintRedirector( QWidget* w ) QPixmap PaintRedirector::performPendingPaint() { //qDebug() << "### performing paint, pending:" << pending.boundingRect(); - QPixmap pixmap( pending.boundingRect().size()); - pixmap.fill( Qt::transparent ); + const QSize size = pending.boundingRect().size(); + if ( scratch.width() < size.width() || scratch.height() < size.height() ) + { + int w = qCeil( size.width() / 128. ) * 128; + int h = qCeil( size.height() / 128. ) * 128; + scratch = QPixmap( qMax( scratch.width(), w ), qMax( scratch.height(), h ) ); + } + scratch.fill( Qt::transparent ); recursionCheck = true; // do not use DrawWindowBackground, it's ok to be transparent - widget->render( &pixmap, QPoint(), pending.boundingRect(), QWidget::DrawChildren ); + widget->render( &scratch, QPoint(), pending.boundingRect(), QWidget::DrawChildren ); recursionCheck = false; pending = QRegion(); scheduled = QRegion(); - return pixmap; + cleanupTimer.start(2000, this); + return scratch; } bool PaintRedirector::isToolTip( QWidget *object ) const @@ -128,6 +136,15 @@ void PaintRedirector::removed( QWidget* w ) w->installEventFilter( this ); } +void PaintRedirector::timerEvent( QTimerEvent* event ) + { + if ( event->timerId() == cleanupTimer.timerId() ) + { + cleanupTimer.stop(); + scratch = QPixmap(); + } + } + } // namespace #include "paintredirector.moc" diff --git a/paintredirector.h b/paintredirector.h index ce11daa457..2964913f28 100644 --- a/paintredirector.h +++ b/paintredirector.h @@ -28,6 +28,7 @@ DEALINGS IN THE SOFTWARE. #include #include #include +#include namespace KWin { @@ -50,11 +51,14 @@ class PaintRedirector void added( QWidget* widget ); void removed( QWidget* widget ); bool isToolTip( QWidget* widget ) const; + void timerEvent( QTimerEvent* event ); QWidget* widget; QRegion pending; QRegion scheduled; + QPixmap scratch; bool recursionCheck; QTimer timer; + QBasicTimer cleanupTimer; }; } // namespace