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

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/plasma
From:       Fredrik Höglund <fredrik () kde ! org>
Date:       2008-06-29 19:23:08
Message-ID: 1214767388.530899.5411.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 826071 by fredrik:

Reimplement drawBackground() in DesktopView to work around a problem
with the QGraphicsView implementation that prevents it from hitting
accelerated code in the X server.  This dramatically improves
performance with the EXA drivers when drawing the desktop background.

This problem does need to be fixed in Qt, but fixing it properly is
non-trivial, so let's just work around it here for now.


 M  +40 -0     desktopview.cpp  
 M  +1 -0      desktopview.h  


--- trunk/KDE/kdebase/workspace/plasma/plasma/desktopview.cpp #826070:826071
@@ -309,6 +309,46 @@
     }
 }
 
+// This function is reimplemented from QGraphicsView to work around the problem
+// that QPainter::fillRect(QRectF/QRect, QBrush), which QGraphicsView uses, is
+// potentially slow when the anti-aliasing hint is set and as implemented won't
+// hit accelerated code at all when it isn't set.  This implementation avoids
+// the problem by using integer coordinates and by using drawTiledPixmap() in
+// the case of a texture brush, and fillRect(QRect, QColor) in the case of a
+// solid pattern.  As an additional optimization it draws the background with
+// CompositionMode_Source.
+void DesktopView::drawBackground(QPainter *painter, const QRectF &rect)
+{
+    const QPainter::CompositionMode savedMode = painter->compositionMode();
+    const QBrush brush = backgroundBrush();
+
+    switch (brush.style())
+    {
+    case Qt::TexturePattern:
+    {
+        // Note: this assumes that the brush origin is (0, 0), and that
+        //       the brush has an identity transformation matrix.
+        const QPixmap texture = brush.texture();
+        QRect r = rect.toAlignedRect();
+        r.setLeft(r.left() - (r.left() % texture.width()));
+        r.setTop(r.top() - (r.top() % texture.height()));
+        painter->setCompositionMode(QPainter::CompositionMode_Source);
+        painter->drawTiledPixmap(r, texture);
+        painter->setCompositionMode(savedMode);
+        return;
+    }
+
+    case Qt::SolidPattern:
+        painter->setCompositionMode(QPainter::CompositionMode_Source);
+        painter->fillRect(rect.toAlignedRect(), brush.color());
+        painter->setCompositionMode(savedMode);
+        return;
+
+    default:
+        QGraphicsView::drawBackground(painter, rect);
+    }
+}
+
 void DesktopView::screenOwnerChanged(int wasScreen, int isScreen, Plasma::Containment* containment)
 {
     kDebug() << "was, is, containment:" << wasScreen << isScreen << (QObject*)containment;
--- trunk/KDE/kdebase/workspace/plasma/plasma/desktopview.h #826070:826071
@@ -98,6 +98,7 @@
 
 protected:
     void wheelEvent(QWheelEvent *event);
+    void drawBackground(QPainter *painter, const QRectF &rect);
 
 private:
     Plasma::ZoomLevel m_zoomLevel;
[prev in list] [next in list] [prev in thread] [next in thread] 

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