From e3ed95dd44b95b6e9361b562807e711d7ce5a58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 3 Nov 2016 17:08:02 +0100 Subject: QPA: Move (post|process)WindowSystemEvent into their templated counterparts No need for the templates to just forward. Reduces the call stack during event delivery. Change-Id: I93f7eb5fa331cc7e86e5bdb5985bcad1eb8b2a4a Reviewed-by: Maurice Kalinowski Reviewed-by: Lars Knoll --- src/gui/kernel/qwindowsysteminterface.cpp | 79 ++++++++++--------------------- src/gui/kernel/qwindowsysteminterface_p.h | 4 -- 2 files changed, 25 insertions(+), 58 deletions(-) diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 86d9aae46a..6a9a68f68b 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -69,28 +69,47 @@ extern QPointer qt_last_mouse_receiver; /*! Handles a window system event asynchronously by posting the event to Qt Gui. - \sa postWindowSystemEvent() + This function posts the event on the window system event queue and wakes the + Gui event dispatcher. Qt Gui will then handle the event asynchonously at a + later point. */ template<> bool QWindowSystemInterfacePrivate::handleWindowSystemEvent(WindowSystemEvent *ev) { - QWindowSystemInterfacePrivate::postWindowSystemEvent(ev); + windowSystemEventQueue.append(ev); + if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher()) + dispatcher->wakeUp(); return true; } /*! Handles a window system event synchronously. + Qt Gui will process the event immediately. The return value indicates if Qt + accepted the event. + If the event is delivered from another thread than the Qt main thread the window system event queue is flushed, which may deliver other events as well. - - \sa processWindowSystemEvent() */ template<> bool QWindowSystemInterfacePrivate::handleWindowSystemEvent(WindowSystemEvent *ev) { - return QWindowSystemInterfacePrivate::processWindowSystemEvent(ev); + bool accepted = true; + if (QThread::currentThread() == QGuiApplication::instance()->thread()) { + // Process the event immediately on the current thread and return the accepted state. + QGuiApplicationPrivate::processWindowSystemEvent(ev); + accepted = ev->eventAccepted; + delete ev; + } else { + // Post the event on the Qt main thread queue and flush the queue. + // This will wake up the Gui thread which will process the event. + // Return the accepted state for the last event on the queue, + // which is the event posted by this function. + handleWindowSystemEvent(ev); + accepted = QWindowSystemInterface::flushWindowSystemEvents(); + } + return accepted; } /*! @@ -106,7 +125,7 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent bool QWindowSystemInterfacePrivate::handleWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *ev) @@ -142,54 +161,6 @@ void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *e windowSystemEventQueue.remove(event); } -/*! - Posts a window system event to be handled asynchronously by Qt Gui. - - This function posts the event on the window system event queue and wakes the - Gui event dispatcher. Qt Gui will then handle the event asynchonously at a - later point. - - \sa flushWindowSystemEvents(), processWindowSystemEvent(), handleWindowSystemEvent() -*/ -void QWindowSystemInterfacePrivate::postWindowSystemEvent(WindowSystemEvent *ev) -{ - windowSystemEventQueue.append(ev); - QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher(); - if (dispatcher) - dispatcher->wakeUp(); -} - -/*! - Processes a window system event synchronously. - - Qt Gui will process the event immediately. The return value indicates if Qt - accepted the event. - - If the event is delivered from another thread than the Qt main thread the - window system event queue is flushed, which may deliver other events as - well. - - \sa flushWindowSystemEvents(), postWindowSystemEvent(), handleWindowSystemEvent() -*/ -bool QWindowSystemInterfacePrivate::processWindowSystemEvent(WindowSystemEvent *ev) -{ - bool accepted = true; - if (QThread::currentThread() == QGuiApplication::instance()->thread()) { - // Process the event immediately on the current thread and return the accepted state. - QGuiApplicationPrivate::processWindowSystemEvent(ev); - accepted = ev->eventAccepted; - delete ev; - } else { - // Post the event on the Qt main thread queue and flush the queue. - // This will wake up the Gui thread which will process the event. - // Return the accepted state for the last event on the queue, - // which is the event posted by this function. - postWindowSystemEvent(ev); - accepted = QWindowSystemInterface::flushWindowSystemEvents(); - } - return accepted; -} - void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler) { if (!eventHandler) diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index ced2d01f73..c594369ae5 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -494,10 +494,6 @@ public: template static bool handleWindowSystemEvent(WindowSystemEvent *ev); -private: - static void postWindowSystemEvent(WindowSystemEvent *ev); - static bool processWindowSystemEvent(WindowSystemEvent *ev); - public: static QElapsedTimer eventTime; static bool synchronousWindowSystemEvents; -- cgit v1.2.3