summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qeventdispatcher_wasm.cpp
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2024-01-26 11:46:26 +0100
committerMorten Sørvig <morten.sorvig@qt.io>2024-02-08 06:04:58 +0100
commit5e5e6240c2dcb7d228fc68075c263f668a9ee963 (patch)
tree91c3b224f61bd14b2cf493136e5b97058c946960 /src/corelib/kernel/qeventdispatcher_wasm.cpp
parent74dac559c060ee24242a625fc46a8c463d06055f (diff)
wasm: fix onLoaded delay functionality
onLoaded and the initial expose/paint should be sequenced such that onLoaded is fired first, followed by the expose. This makes sure that we don't spend any time on painting frames before Qt is completely initialized. Add a "requestUpdateHold" mode to QWasmCompositor (initially on) which disables requestUpdate calls, as well as releaseRequestUpdateHold() which enables requestUpdate calls again. This is a one-way transition; the mode can't be enabled again. This amends commit f2e22774 which implemented the concept of startup tasks, where onLoaded can be delayed until for instance font loading has been completed. After this commit the expose event and initial commit will be delayed as well. Change-Id: Icc784306726174fbabe8785d54485860e968745a Reviewed-by: Lorn Potter <lorn.potter@gmail.com> Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
Diffstat (limited to 'src/corelib/kernel/qeventdispatcher_wasm.cpp')
-rw-r--r--src/corelib/kernel/qeventdispatcher_wasm.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp
index 5f4c46c07f..f5061f35d7 100644
--- a/src/corelib/kernel/qeventdispatcher_wasm.cpp
+++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp
@@ -218,9 +218,12 @@ QEventDispatcherWasm::QEventDispatcherWasm()
#if QT_CONFIG(thread)
g_mainThread = pthread_self();
#endif
+
// Call the "onLoaded" JavaScript callback, unless startup tasks
- // have been registered which should complete first.
- checkCallQtLoaded();
+ // have been registered which should complete first. Run async
+ // to make sure event dispatcher construction (in particular any
+ // subclass construction) has completed first.
+ runAsync(callOnLoadedIfRequired);
} else {
#if QT_CONFIG(thread)
std::lock_guard<std::mutex> lock(g_staticDataMutex);
@@ -916,10 +919,10 @@ void QEventDispatcherWasm::registerStartupTask()
void QEventDispatcherWasm::completeStarupTask()
{
--g_startupTasks;
- checkCallQtLoaded();
+ callOnLoadedIfRequired();
}
-void QEventDispatcherWasm::checkCallQtLoaded()
+void QEventDispatcherWasm::callOnLoadedIfRequired()
{
if (g_startupTasks > 0)
return;
@@ -929,12 +932,16 @@ void QEventDispatcherWasm::checkCallQtLoaded()
return;
qtLoadedCalled = true;
- QTimer::singleShot(0, [](){
- emscripten::val qt = emscripten::val::module_property("qt");
- if (qt.isUndefined())
- return;
- qt.call<void>("onLoaded");
- });
+ Q_ASSERT(g_mainThreadEventDispatcher);
+ g_mainThreadEventDispatcher->onLoaded();
+}
+
+void QEventDispatcherWasm::onLoaded()
+{
+ emscripten::val qt = emscripten::val::module_property("qt");
+ if (qt.isUndefined())
+ return;
+ qt.call<void>("onLoaded");
}
namespace {