desktop/Executable_soffice_bin.mk                   |    3 +
 instsetoo_native/CustomTarget_emscripten-install.mk |    8 +++--
 vcl/headless/svpinst.cxx                            |   32 ++++++++++++++++++++
 vcl/inc/headless/svpinst.hxx                        |    8 ++++-
 4 files changed, 46 insertions(+), 5 deletions(-)

New commits:
commit 858fed2a98ad5a04ca65dc504722e2db52746e64
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Wed Aug 28 16:30:10 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Wed Aug 28 23:02:51 2024 +0200

    Emscripten: Support --disable-gui
    
    Change-Id: Iab28ee0bb533b0cdabb374c982fbb898bf04aac5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172537
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/desktop/Executable_soffice_bin.mk 
b/desktop/Executable_soffice_bin.mk
index f50cfb17633e..fcf16e041fb9 100644
--- a/desktop/Executable_soffice_bin.mk
+++ b/desktop/Executable_soffice_bin.mk
@@ -63,7 +63,8 @@ $(call gb_Executable_get_linktarget_target,soffice_bin): \
 
 $(eval $(call gb_Executable_add_ldflags,soffice_bin,\
        -s 
EXPORTED_FUNCTIONS=@$(gb_CustomTarget_workdir)/desktop/soffice_bin-emscripten-exports/exports
 -Wl$(COMMA)--whole-archive $(call gb_StaticLibrary_get_target,unoembind) 
-Wl$(COMMA)--no-whole-archive \
-       -sPROXY_TO_PTHREAD=1 -sOFFSCREENCANVAS_SUPPORT=1 
-sOFFSCREENCANVASES_TO_PTHREAD=\#qtcanvas \
+       -sPROXY_TO_PTHREAD=1 \
+       $(if $(DISABLE_GUI),,-sOFFSCREENCANVAS_SUPPORT=1 
-sOFFSCREENCANVASES_TO_PTHREAD=\#qtcanvas) \
 ))
 ifeq ($(ENABLE_QT6),TRUE)
 $(eval $(call gb_Executable_add_ldflags,soffice_bin, \
diff --git a/instsetoo_native/CustomTarget_emscripten-install.mk 
b/instsetoo_native/CustomTarget_emscripten-install.mk
index 23a5ee81885b..f4e63f729ab6 100644
--- a/instsetoo_native/CustomTarget_emscripten-install.mk
+++ b/instsetoo_native/CustomTarget_emscripten-install.mk
@@ -14,15 +14,17 @@ $(if $(or $(gb_not $(filter 
emscripten,$(PKGFORMAT))),$(filter-out emscripten,$(
 
 emscripten_install_files := \
     favicon.ico \
-    qt_soffice.html \
-    qtloader.js \
-    qtlogo.svg \
     soffice.data \
     soffice.data.js.metadata \
     soffice.js \
     soffice.wasm \
     soffice.worker.js \
     $(if $(ENABLE_SYMBOLS_FOR),soffice.wasm.dwp) \
+    $(if $(DISABLE_GUI), \
+        soffice.html, \
+        qt_soffice.html \
+        qtloader.js \
+        qtlogo.svg) \
 
 .PHONY: $(call gb_CustomTarget_get_target,instsetoo_native/emscripten-install)
 $(call gb_CustomTarget_get_target,instsetoo_native/emscripten-install): \
diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 82c24771027a..0b65626947aa 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -50,6 +50,11 @@
 #include <unx/salunxtime.h>
 #include <tools/debug.hxx>
 #include <comphelper/lok.hxx>
+#include <o3tl/unreachable.hxx>
+
+#if defined EMSCRIPTEN
+#include <emscripten.h>
+#endif
 
 SvpSalInstance* SvpSalInstance::s_pDefaultInstance = nullptr;
 
@@ -95,6 +100,9 @@ SvpSalInstance::SvpSalInstance( 
std::unique_ptr<SalYieldMutex> pMutex )
 #if !defined(ANDROID) && !defined(IOS) && !defined(EMSCRIPTEN)
     pthread_atfork(nullptr, nullptr, atfork_child);
 #endif
+#if defined EMSCRIPTEN
+    ImplGetSVData()->maAppData.m_bUseSystemLoop = true;
+#endif
 }
 
 SvpSalInstance::~SvpSalInstance()
@@ -272,6 +280,30 @@ void SvpSalInstance::ProcessEvent( SalUserEvent aEvent )
     pMutex->m_NonMainWaitingYieldCond.set();
 }
 
+#if defined EMSCRIPTEN
+
+static void loop(void * arg) {
+    SolarMutexGuard g;
+    static_cast<SvpSalInstance *>(arg)->ImplYield(false, false);
+}
+
+bool SvpSalInstance::DoExecute(int &) {
+    assert(Application::IsOnSystemEventLoop());
+    // emscripten_set_main_loop will unwind the stack by throwing a JavaScript 
exception, so we need
+    // to manually undo the call of AcquireYieldMutex() done in InitVCL:
+    ReleaseYieldMutex(false);
+    // Somewhat randomly use an fps=100 argument so the loop callback is 
called 100 times per
+    // second:
+    emscripten_set_main_loop_arg(loop, this, 100, 1);
+    O3TL_UNREACHABLE;
+}
+
+void SvpSalInstance::DoQuit() {
+    assert(Application::IsOnSystemEventLoop());
+}
+
+#endif
+
 SvpSalYieldMutex::SvpSalYieldMutex()
 {
 }
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index 34f3019c7b70..f3d9205a8981 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -100,7 +100,11 @@ class VCL_DLLPUBLIC SvpSalInstance : public 
SalGenericInstance, public SalUserEv
 
     virtual void            TriggerUserEventProcessing() override;
     virtual void            ProcessEvent( SalUserEvent aEvent ) override;
-    SAL_DLLPRIVATE bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
+
+#if defined EMSCRIPTEN
+    bool DoExecute(int &nExitCode) override;
+    void DoQuit() override;
+#endif
 
 public:
     static SvpSalInstance*  s_pDefaultInstance;
@@ -108,6 +112,8 @@ public:
     SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex );
     virtual ~SvpSalInstance() override;
 
+    SAL_DLLPRIVATE bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
+
     SAL_DLLPRIVATE void     CloseWakeupPipe();
     SAL_DLLPRIVATE void     Wakeup(SvpRequest request = SvpRequest::NONE);
 

Reply via email to