From 05a61de622917ba67986afff6288c05a34ff5a90 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 28 Feb 2013 14:07:04 +0100 Subject: Allow flushing window system events from other thread For platform plugins such as the Android plugin, we need to make sure an event is delivered and handled before continuing execution (e.g. when doing an expose event to report that the EGL surface has been destroyed when the app goes into the background.) Change-Id: Ibd381baafa93f111dbc887d4cf9d9ca37429b186 Reviewed-by: Gunnar Sletta --- src/gui/kernel/qguiapplication.cpp | 3 +++ src/gui/kernel/qwindowsysteminterface.cpp | 20 +++++++++++++++++++- src/gui/kernel/qwindowsysteminterface.h | 1 + src/gui/kernel/qwindowsysteminterface_p.h | 14 +++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index b8c6e4db20..1763624b83 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1279,6 +1279,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv case QWindowSystemInterfacePrivate::ApplicationStateChanged: QGuiApplicationPrivate::processApplicationStateChangedEvent(static_cast(e)); break; + case QWindowSystemInterfacePrivate::FlushEvents: + QWindowSystemInterface::deferredFlushWindowSystemEvents(); + break; case QWindowSystemInterfacePrivate::Close: QGuiApplicationPrivate::processCloseEvent( static_cast(e)); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 01100d8555..8c5a3bc215 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE QElapsedTimer QWindowSystemInterfacePrivate::eventTime; bool QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = false; +QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed; +QMutex QWindowSystemInterfacePrivate::flushEventMutex; //------------------------------------------------------------ // @@ -514,9 +516,25 @@ void QWindowSystemInterface::handleExposeEvent(QWindow *tlw, const QRegion ®i QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } +void QWindowSystemInterface::deferredFlushWindowSystemEvents() +{ + Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread()); + + QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); + flushWindowSystemEvents(); + QWindowSystemInterfacePrivate::eventsFlushed.wakeOne(); +} + void QWindowSystemInterface::flushWindowSystemEvents() { - sendWindowSystemEventsImplementation(QEventLoop::AllEvents); + if (QThread::currentThread() != QGuiApplication::instance()->thread()) { + QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); + QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(); + QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); + QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex); + } else { + sendWindowSystemEventsImplementation(QEventLoop::AllEvents); + } } bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 5668f3c0cf..22e5983a07 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -186,6 +186,7 @@ public: static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); static void setSynchronousWindowsSystemEvents(bool enable); static void flushWindowSystemEvents(); + static void deferredFlushWindowSystemEvents(); static int windowSystemEventsQueued(); private: diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 8336c3d63c..431b2cbe1e 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -58,6 +58,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -89,7 +90,8 @@ public: TabletLeaveProximity = UserInputEvent | 0x16, PlatformPanel = UserInputEvent | 0x17, ContextMenu = UserInputEvent | 0x18, - ApplicationStateChanged = 0x19 + ApplicationStateChanged = 0x19, + FlushEvents = 0x20 }; class WindowSystemEvent { @@ -162,6 +164,13 @@ public: Qt::ApplicationState newState; }; + class FlushEventsEvent : public WindowSystemEvent { + public: + FlushEventsEvent() + : WindowSystemEvent(FlushEvents) + { } + }; + class UserEvent : public WindowSystemEvent { public: UserEvent(QWindow * w, ulong time, EventType t) @@ -432,6 +441,9 @@ public: static QElapsedTimer eventTime; static bool synchronousWindowsSystemEvents; + static QWaitCondition eventsFlushed; + static QMutex flushEventMutex; + static QList convertTouchPoints(const QList &points, QEvent::Type *type); }; -- cgit v1.2.3