diff options
author | Andrew Knight <andrew.knight@digia.com> | 2014-01-06 22:51:49 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-07 10:55:28 +0100 |
commit | 153f82390dd977436000de5aae2fe8eb4a5d9936 (patch) | |
tree | c173028ef970d94dd638215c4a9a24c13132592a /src/plugins/platforms/winrt/qwinrteventdispatcher.cpp | |
parent | ae56140b50bccde9e6cfdc6757f345c989ccd755 (diff) |
WinRT: Improve event dispatcher
- Sleep when there are no events to process. Otherwise, CPU usage remains
high all the time.
- Reorder processing so window events are processed after being collected
by the native event loop.
- Provide basic interrupt and WaitForMoreEvents flag support.
Task-number: QTBUG-35327
Change-Id: I8a5545cba5f3e65eafd0bb40695bf6ffde68bb04
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'src/plugins/platforms/winrt/qwinrteventdispatcher.cpp')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrteventdispatcher.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp b/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp index 3fada75b25..baa8b5c636 100644 --- a/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp +++ b/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp @@ -52,12 +52,14 @@ using namespace ABI::Windows::ApplicationModel::Core; using namespace ABI::Windows::UI::Core; using namespace ABI::Windows::Foundation; +using namespace Microsoft::WRL; QT_BEGIN_NAMESPACE QWinRTEventDispatcher::QWinRTEventDispatcher(ICoreDispatcher *dispatcher, QObject *parent) : QEventDispatcherWinRT(parent) , m_dispatcher(dispatcher) + , m_interrupt(false) { } @@ -66,14 +68,38 @@ bool QWinRTEventDispatcher::hasPendingEvents() return QEventDispatcherWinRT::hasPendingEvents() || QWindowSystemInterface::windowSystemEventsQueued(); } +void QWinRTEventDispatcher::interrupt() +{ + m_interrupt = true; +} + bool QWinRTEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) { - if (m_dispatcher) - m_dispatcher->ProcessEvents(CoreProcessEventsOption_ProcessAllIfPresent); + bool canWait = flags & QEventLoop::WaitForMoreEvents; + bool didProcess; + m_interrupt = false; + do { + // Send Qt events + didProcess = QEventDispatcherWinRT::processEvents(flags); + + // Process system events + emit aboutToBlock(); + if (m_dispatcher) + m_dispatcher->ProcessEvents(CoreProcessEventsOption_ProcessAllIfPresent); + emit awake(); - const bool didProcess = QWindowSystemInterface::sendWindowSystemEvents(flags); + // Dispatch accumulated user events + didProcess |= QWindowSystemInterface::sendWindowSystemEvents(flags); + canWait = canWait && !didProcess && !m_interrupt; - return QEventDispatcherWinRT::processEvents(flags & ~QEventLoop::WaitForMoreEvents) || didProcess; + // Short sleep if there is nothing to do + if (canWait) { + emit aboutToBlock(); + WaitForSingleObjectEx(GetCurrentThread(), 1, true); + emit awake(); + } + } while (canWait); + return didProcess; } QT_END_NAMESPACE |