From 088b364e4b220ffe3acf28842444c6a80601f2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 13 Sep 2021 11:09:48 +0200 Subject: [PATCH] QEventDispatcherWasm: handle EventLoopExec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call emscripten_set_main_loop like the old GUI event dispatcher did, with one difference that requestAnimationFrame updates are now no longer handled by the event dispatcher. Change-Id: If02d90ae9c45d7b38999567d733a237af842cded Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 18 ++++++++++++++++++ src/corelib/kernel/qeventdispatcher_wasm_p.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 61b49fdc551..7632b2ca55b 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -208,6 +208,8 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) if (flags & QEventLoop::DialogExec) handleDialogExec(); + else if (flags & QEventLoop::EventLoopExec) + handleEventLoopExec(); if (!(flags & QEventLoop::ExcludeUserInputEvents)) pollForNativeEvents(); @@ -364,6 +366,22 @@ void QEventDispatcherWasm::wakeUp() emscripten_async_call(&QEventDispatcherWasm::callProcessEvents, this, 0); } +void QEventDispatcherWasm::handleEventLoopExec() +{ + // Start the main loop, and then stop it on the first callback. This + // is done for the "simulateInfiniteLoop" functionality where + // emscripten_set_main_loop() throws a JS exception which returns + // control to the browser while preserving the C++ stack. + // + // Note that we don't use asyncify here: Emscripten supports one level of + // asyncify only and we want to reserve that for dialog exec() instead of + // using it for the one qApp exec(). + const bool simulateInfiniteLoop = true; + emscripten_set_main_loop([](){ + emscripten_pause_main_loop(); + }, 0, simulateInfiniteLoop); +} + void QEventDispatcherWasm::handleDialogExec() { #if !QT_HAVE_EMSCRIPTEN_ASYNCIFY diff --git a/src/corelib/kernel/qeventdispatcher_wasm_p.h b/src/corelib/kernel/qeventdispatcher_wasm_p.h index 75db11723c4..7eea28b0523 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm_p.h +++ b/src/corelib/kernel/qeventdispatcher_wasm_p.h @@ -90,6 +90,7 @@ private: bool isMainThreadEventDispatcher(); bool isSecondaryThreadEventDispatcher(); + void handleEventLoopExec(); void handleDialogExec(); void pollForNativeEvents(); bool waitForForEvents();