Emscripten: Support --disable-gui

Change-Id: Iab28ee0bb533b0cdabb374c982fbb898bf04aac5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172537
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
This commit is contained in:
Stephan Bergmann 2024-08-28 16:30:10 +02:00
parent 599b1711ea
commit 858fed2a98
4 changed files with 46 additions and 5 deletions

View file

@ -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, \

View file

@ -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): \

View file

@ -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()
{
}

View file

@ -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);