summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2011-01-24 14:44:48 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2011-01-24 14:44:48 (GMT)
commitf1262bdf81251d488c6fe8c1a00325a81654844e (patch)
treef40145704fb0d88d2e243902f787701388a4fdb4
parent673da830f6f83438e4b52296dbdc61a33112e4ec (diff)
downloadQt-f1262bdf81251d488c6fe8c1a00325a81654844e.zip
Qt-f1262bdf81251d488c6fe8c1a00325a81654844e.tar.gz
Qt-f1262bdf81251d488c6fe8c1a00325a81654844e.tar.bz2
Cocoa: add scroll optimization when scrolling both hor and ver
-rw-r--r--src/gui/kernel/qcocoaview_mac.mm6
-rw-r--r--src/gui/kernel/qt_cocoa_helpers_mac.mm6
-rw-r--r--src/gui/kernel/qt_cocoa_helpers_mac_p.h54
-rw-r--r--src/gui/kernel/qwidget_mac.mm4
4 files changed, 70 insertions, 0 deletions
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm
index 18a2be1..1b81699 100644
--- a/src/gui/kernel/qcocoaview_mac.mm
+++ b/src/gui/kernel/qcocoaview_mac.mm
@@ -579,6 +579,10 @@ static int qCocoaViewCount = 0;
}
#ifndef QT_NO_WHEELEVENT
+ // ### Qt 5: Send one QWheelEvent with dx, dy and dz
+
+ QMacScrollOptimization::initNewScroll();
+
if (deltaX != 0) {
QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal);
qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
@@ -595,6 +599,8 @@ static int qCocoaViewCount = 0;
QWheelEvent qwe(qlocal, qglobal, deltaZ, buttons, keyMods, (Qt::Orientation)3);
qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
}
+
+ QMacScrollOptimization::performDelayedScroll();
#endif //QT_NO_WHEELEVENT
}
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm
index 35b9d52..ddbf53f 100644
--- a/src/gui/kernel/qt_cocoa_helpers_mac.mm
+++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm
@@ -1724,6 +1724,12 @@ void qt_mac_post_retranslateAppMenu()
#endif
}
+QWidgetPrivate *QMacScrollOptimization::_target = 0;
+bool QMacScrollOptimization::_inWheelEvent = false;
+int QMacScrollOptimization::_dx = 0;
+int QMacScrollOptimization::_dy = 0;
+QRect QMacScrollOptimization::_scrollRect = QRect(0, 0, -1, -1);
+
#ifdef QT_MAC_USE_COCOA
// This method implements the magic for the drawRectSpecial method.
// We draw a line at the upper edge of the content view in order to
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h
index c30fdc0..eab8a86 100644
--- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h
+++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h
@@ -103,6 +103,7 @@
#include <qtimer.h>
#include <qtooltip.h>
#include <private/qeffects_p.h>
+#include <private/qwidget_p.h>
#include <qtextdocument.h>
#include <qdebug.h>
#include <qpoint.h>
@@ -245,6 +246,59 @@ void qt_cocoaPostMessageAfterEventLoopExit(id target, SEL selector, int argCount
#endif
+class QMacScrollOptimization {
+ // This class is made optimize for the case when the user
+ // scrolls both horizontally and vertically at the same
+ // time. This will result in two QWheelEvents (one for each
+ // direction), which will typically result in two calls to
+ // QWidget::_scroll_sys. Rather than copying pixels twize on
+ // screen because of this, we add this helper class to try to
+ // get away with only one blit.
+ static QWidgetPrivate *_target;
+ static bool _inWheelEvent;
+ static int _dx;
+ static int _dy;
+ static QRect _scrollRect;
+
+public:
+ static void initNewScroll()
+ {
+ _inWheelEvent = true;
+ }
+
+ static bool delayScroll(QWidgetPrivate *target, int dx, int dy, const QRect &scrollRect)
+ {
+ if (!_inWheelEvent)
+ return false;
+ if (_target && _target != target)
+ return false;
+ if (_scrollRect.width() != -1 && _scrollRect != scrollRect)
+ return false;
+
+ _target = target;
+ _dx += dx;
+ _dy += dy;
+ _scrollRect = scrollRect;
+ return true;
+ }
+
+ static void performDelayedScroll()
+ {
+ if (!_inWheelEvent)
+ return;
+ if (!_target)
+ return;
+
+ _inWheelEvent = false;
+ _target->scroll_sys(_dx, _dy, _scrollRect);
+
+ _target = 0;
+ _dx = 0;
+ _dy = 0;
+ _scrollRect = QRect(0, 0, -1, -1);
+ }
+};
+
void qt_mac_post_retranslateAppMenu();
void qt_mac_display(QWidget *widget);
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm
index 03f496e..f3fbaa7 100644
--- a/src/gui/kernel/qwidget_mac.mm
+++ b/src/gui/kernel/qwidget_mac.mm
@@ -4654,6 +4654,10 @@ void QWidgetPrivate::scroll_sys(int dx, int dy)
void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect)
{
Q_Q(QWidget);
+
+ if (QMacScrollOptimization::delayScroll(this, dx, dy, qscrollRect))
+ return;
+
if (QApplicationPrivate::graphicsSystem() && !paintOnScreen()) {
// INVARIANT: Alien paint engine
scrollRect(qscrollRect, dx, dy);