aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2018-10-11 15:36:29 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-10-18 13:46:47 +0000
commitdbca08fcd7ca70392420b2181aa6b7985ddb5c08 (patch)
tree28dc988f61f118133043ff5c2af8403b497d732e /src
parentc39b6a4a44b852ee7219466f46022dec8b76eae4 (diff)
Optimize QQuickWindowPrivate::grabTouchPoints()
It's given a list of touchpoint IDs, which normally are from the same event, so we should not need to find the corresponding device and its event repeatedly. Change-Id: I65ce120c50251d23b1300b79b9372e8e54e53741 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickwindow.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 059886f41c..d27ee54c89 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -774,6 +774,7 @@ bool QQuickWindowPrivate::deliverTouchAsMouse(QQuickItem *item, QQuickPointerEve
void QQuickWindowPrivate::grabTouchPoints(QObject *grabber, const QVector<int> &ids)
{
+ QQuickPointerEvent *ev = nullptr;
for (int i = 0; i < ids.count(); ++i) {
int id = ids.at(i);
if (Q_UNLIKELY(id < 0)) {
@@ -793,15 +794,26 @@ void QQuickWindowPrivate::grabTouchPoints(QObject *grabber, const QVector<int> &
qCDebug(DBG_MOUSE_TARGET) << "grabTouchPoints: mouse grabber changed due to grabTouchPoints:" << touchMouseGrabber << "-> null";
}
+ // optimization to avoid the loop over devices below:
+ // all ids are probably from the same event, so we don't have to search
+ if (ev) {
+ auto point = ev->pointById(id);
+ if (point && point->exclusiveGrabber() != grabber) {
+ point->setExclusiveGrabber(grabber);
+ continue; // next id in the ids loop
+ }
+ }
+ // search all devices for a QQuickPointerEvent instance that is delivering the point with id
const auto touchDevices = QQuickPointerDevice::touchDevices();
for (auto device : touchDevices) {
- auto point = pointerEventInstance(device)->pointById(id);
- if (!point)
- continue;
- QObject *oldGrabber = point->exclusiveGrabber();
- if (oldGrabber == grabber)
- continue;
- point->setExclusiveGrabber(grabber);
+ QQuickPointerEvent *pev = pointerEventInstance(device);
+ auto point = pev->pointById(id);
+ if (point) {
+ ev = pev;
+ if (point->exclusiveGrabber() != grabber)
+ point->setExclusiveGrabber(grabber);
+ break; // out of touchDevices loop
+ }
}
}
}