diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-12-10 16:30:18 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-14 13:17:19 +0100 |
commit | 3064c1bc8cc04a40f6e468033d73823987687d40 (patch) | |
tree | c24b66cb19bc9419de86bc355f71793bb4f80da8 /src/gui/kernel | |
parent | 14d9a2b06c58f544f0db13267091cf94ed0d2e97 (diff) |
Remove redundant touch processing in QtGui and widgets.
The duplicated hash tables in QGuiApplicationPrivate and
QApplicationPrivate are now unified into one single hash table in
QGuiApplicationPrivate. This also reduced the number of lookups.
The extra processing needed to keep the touch points' first/lastPos
values in sync is now done only once, in QGuiApplication. This
eliminates the performance penalty (for widget-based apps) that was
introduced during the QPA migration.
As an added bonus the patch adds support for touch events arriving
simultaenously from multiple devices. This was broken before: As there
is no guarantee that two devices/drivers will not send touch points
with the same ID, using structures with only the ID as key is
wrong. The proper key is composed of the device ID (that is, a
QTouchDevice pointer) and the touch point ID.
The exported internal function qt_translateRawTouchEvent() has been
removed. This function cannot work properly in the QPA world: It
injected touches into the widget subsystem (QApplication) only which
is wrong, and would result in half-filled touch events due to not
routing the injected data through QGuiApplication. Autotests using
this function are migrated to
QWindowSystemInterface::handleTouchEvent().
Change-Id: I7632781d77f9e0ac4626fd7c9933511c94492156
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 46 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 20 |
2 files changed, 53 insertions, 13 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index dc8e5edb56..312d8f50fb 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -823,6 +823,18 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl QGuiApplication::sendSpontaneousEvent(e->window.data(), &event); } +Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k) +{ + return qHash(k.device) + k.touchPointId; +} + +Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a, + const QGuiApplicationPrivate::ActiveTouchPointsKey &b) +{ + return a.device == b.device + && a.touchPointId == b.touchPointId; +} + void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e) { QWindow *window = e->window.data(); @@ -840,13 +852,15 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To // update state QWeakPointer<QWindow> w; QTouchEvent::TouchPoint previousTouchPoint; + ActiveTouchPointsKey touchInfoKey(e->device, touchPoint.id()); + ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey]; switch (touchPoint.state()) { case Qt::TouchPointPressed: if (e->device->type() == QTouchDevice::TouchPad) { // on touch-pads, send all touch points to the same widget - w = d->windowForTouchPointId.isEmpty() + w = d->activeTouchPoints.isEmpty() ? QWeakPointer<QWindow>() - : d->windowForTouchPointId.constBegin().value(); + : d->activeTouchPoints.constBegin().value().window; } if (!w) { @@ -858,7 +872,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To w = window; } - d->windowForTouchPointId[touchPoint.id()] = w; + touchInfo.window = w; touchPoint.d->startScreenPos = touchPoint.screenPos(); touchPoint.d->lastScreenPos = touchPoint.screenPos(); touchPoint.d->startNormalizedPos = touchPoint.normalizedPos(); @@ -866,14 +880,15 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To if (touchPoint.pressure() < qreal(0.)) touchPoint.d->pressure = qreal(1.); - d->appCurrentTouchPoints.insert(touchPoint.id(), touchPoint); + touchInfo.touchPoint = touchPoint; break; case Qt::TouchPointReleased: - w = d->windowForTouchPointId.take(touchPoint.id()); + w = touchInfo.window; if (!w) continue; - previousTouchPoint = d->appCurrentTouchPoints.take(touchPoint.id()); + + previousTouchPoint = touchInfo.touchPoint; touchPoint.d->startScreenPos = previousTouchPoint.startScreenPos(); touchPoint.d->lastScreenPos = previousTouchPoint.screenPos(); touchPoint.d->startPos = previousTouchPoint.startPos(); @@ -882,14 +897,15 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos(); if (touchPoint.pressure() < qreal(0.)) touchPoint.d->pressure = qreal(0.); + break; default: - w = d->windowForTouchPointId.value(touchPoint.id()); + w = touchInfo.window; if (!w) continue; - Q_ASSERT(d->appCurrentTouchPoints.contains(touchPoint.id())); - previousTouchPoint = d->appCurrentTouchPoints.value(touchPoint.id()); + + previousTouchPoint = touchInfo.touchPoint; touchPoint.d->startScreenPos = previousTouchPoint.startScreenPos(); touchPoint.d->lastScreenPos = previousTouchPoint.screenPos(); touchPoint.d->startPos = previousTouchPoint.startPos(); @@ -902,7 +918,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To // Stationary points might not be delivered down to the receiving item // and get their position transformed, keep the old values instead. if (touchPoint.state() != Qt::TouchPointStationary) - d->appCurrentTouchPoints[touchPoint.id()] = touchPoint; + touchInfo.touchPoint = touchPoint; break; } @@ -969,6 +985,16 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QGuiApplication::sendSpontaneousEvent(w, &touchEvent); } + + // Remove released points from the hash table only after the event is + // delivered. When the receiver is a widget, QApplication will access + // activeTouchPoints during delivery and therefore nothing can be removed + // before sending the event. + for (int i = 0; i < e->points.count(); ++i) { + QTouchEvent::TouchPoint touchPoint = e->points.at(i); + if (touchPoint.state() == Qt::TouchPointReleased) + d->activeTouchPoints.remove(ActiveTouchPointsKey(e->device, touchPoint.id())); + } } void QGuiApplicationPrivate::reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 9c8a2ca642..2d13127487 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -189,15 +189,29 @@ public: QShortcutMap shortcutMap; #endif + struct ActiveTouchPointsKey { + ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { } + QTouchDevice *device; + int touchPointId; + }; + struct ActiveTouchPointsValue { + QWeakPointer<QWindow> window; + QWeakPointer<QObject> target; + QTouchEvent::TouchPoint touchPoint; + }; + QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints; + private: void init(); static QGuiApplicationPrivate *self; - - QMap<int, QWeakPointer<QWindow> > windowForTouchPointId; - QMap<int, QTouchEvent::TouchPoint> appCurrentTouchPoints; }; +Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k); + +Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a, + const QGuiApplicationPrivate::ActiveTouchPointsKey &b); + QT_END_NAMESPACE QT_END_HEADER |