[Libreoffice-commits] core.git: config_host/config_vclplug.h.in configure.ac vcl/android vcl/inc vcl/Library_vcl.mk vcl/source vcl/win

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Sat May 29 14:33:01 UTC 2021


 config_host/config_vclplug.h.in |    5 ++
 configure.ac                    |    4 ++
 vcl/Library_vcl.mk              |    1 
 vcl/android/androidinst.cxx     |   45 -----------------------
 vcl/inc/android/androidinst.hxx |    5 ++
 vcl/inc/salinst.hxx             |    6 +++
 vcl/inc/win/salinst.h           |    1 
 vcl/source/app/salplug.cxx      |   77 +++++++++++++++++++++++++++-------------
 vcl/win/app/salinst.cxx         |    5 ++
 9 files changed, 80 insertions(+), 69 deletions(-)

New commits:
commit b6518bebc5fc82c88a455c6b22023e6392483e14
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sat May 29 13:35:23 2021 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Sat May 29 16:32:24 2021 +0200

    vcl: Implement static vclplug usage
    
    .. and convert Android to it. Will also be used by WASM.
    
    It's also kind of a followup on commit
    f5af2104fc490b90510e36bbf1d2adec8017c594.
    
    Change-Id: I3a1b5bc2eae2692e706da10c6352534433c61e57
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116385
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/config_host/config_vclplug.h.in b/config_host/config_vclplug.h.in
index 488140b9ee4d..1a44907fb087 100644
--- a/config_host/config_vclplug.h.in
+++ b/config_host/config_vclplug.h.in
@@ -7,6 +7,11 @@ Settings about which desktops have support enabled.
 #ifndef CONFIG_VCLPLUG_H
 #define CONFIG_VCLPLUG_H
 
+/**
+ * Set, if the platform uses X11 code.
+ */
+#define USING_X11 0
+
 #define ENABLE_GTK3 0
 #define ENABLE_GTK3_KDE5 0
 #define ENABLE_KF5 0
diff --git a/configure.ac b/configure.ac
index 670d118c7644..4175aae4aa41 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5185,6 +5185,10 @@ if test "$enable_gui" = "no"; then
 fi
 AC_SUBST(DISABLE_GUI)
 
+if test "$USING_X11" = TRUE; then
+    AC_DEFINE(USING_X11)
+fi
+
 WORKDIR="${BUILDDIR}/workdir"
 INSTDIR="${BUILDDIR}/instdir"
 INSTROOTBASE=${INSTDIR}${INSTROOTBASESUFFIX}
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 530df12019a1..45861cf2271c 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -665,6 +665,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/unx/generic/printer/ppdparser \
     vcl/null/printerinfomanager \
     vcl/android/androidinst \
+    vcl/source/app/salplug \
     $(vcl_headless_code) \
     $(vcl_headless_freetype_code) \
 ))
diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx
index dafd43f7aad8..8febcd23a729 100644
--- a/vcl/android/androidinst.cxx
+++ b/vcl/android/androidinst.cxx
@@ -9,7 +9,6 @@
 
 #include <jni.h>
 
-#include <android/log.h>
 #include <android/looper.h>
 #include <android/bitmap.h>
 
@@ -24,10 +23,6 @@
 #include <memory>
 #include <unistd.h>
 
-#define LOGTAG "LibreOffice/androidinst"
-#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
-#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOGTAG, __VA_ARGS__))
-
 // Horrible hack
 static int viewWidth = 1, viewHeight = 1;
 
@@ -169,53 +164,15 @@ SalFrame *AndroidSalInstance::CreateFrame( SalFrame* pParent, SalFrameStyleFlags
     return new AndroidSalFrame( this, pParent, nStyle );
 }
 
-void SalAbort( const OUString& rErrorText, bool bDumpCore )
-{
-    OUString aError( rErrorText );
-    if( aError.isEmpty() )
-        aError = "Unknown application error";
-    LOGI("%s", OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
-
-    LOGI("SalAbort: '%s'",
-         OUStringToOString(aError, RTL_TEXTENCODING_ASCII_US).getStr());
-    if( bDumpCore )
-        abort();
-    else
-        _exit(1);
-}
-
-const OUString& SalGetDesktopEnvironment()
-{
-    static OUString aEnv( "android" );
-    return aEnv;
-}
-
-SalData::SalData() :
-    m_pInstance( 0 ),
-    m_pPIManager(0 )
-{
-}
-
-SalData::~SalData()
-{
-}
-
 // This is our main entry point:
-SalInstance *CreateSalInstance()
+extern "C" SalInstance *create_SalInstance()
 {
     LOGI("Android: CreateSalInstance!");
     AndroidSalInstance* pInstance = new AndroidSalInstance( std::make_unique<SvpSalYieldMutex>() );
     new AndroidSalData( pInstance );
-    pInstance->AcquireYieldMutex();
     return pInstance;
 }
 
-void DestroySalInstance( SalInstance *pInst )
-{
-    pInst->ReleaseYieldMutexAll();
-    delete pInst;
-}
-
 int AndroidSalSystem::ShowNativeDialog( const OUString& rTitle,
                                         const OUString& rMessage,
                                         const std::vector< OUString >& rButtons )
diff --git a/vcl/inc/android/androidinst.hxx b/vcl/inc/android/androidinst.hxx
index 46adea903e09..c157b0fd3128 100644
--- a/vcl/inc/android/androidinst.hxx
+++ b/vcl/inc/android/androidinst.hxx
@@ -12,10 +12,15 @@
 
 #include <jni.h>
 #include <android/input.h>
+#include <android/log.h>
 #include <android/native_window.h>
 #include <headless/svpinst.hxx>
 #include <headless/svpframe.hxx>
 
+#define LOGTAG "LibreOffice/androidinst"
+#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
+#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOGTAG, __VA_ARGS__))
+
 class AndroidSalFrame;
 class AndroidSalInstance : public SvpSalInstance
 {
diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx
index 6ce6a3d2743d..f38d6f45e44c 100644
--- a/vcl/inc/salinst.hxx
+++ b/vcl/inc/salinst.hxx
@@ -205,6 +205,8 @@ public:
     virtual const cairo_font_options_t* GetCairoFontOptions() { return nullptr; }
 
     virtual void* CreateGStreamerSink(const SystemChildWindow*) { return nullptr; }
+
+    virtual void BeforeAbort(const OUString& /* rErrorText */, bool /* bDumpCore */) {}
 };
 
 // called from SVMain
@@ -215,6 +217,10 @@ void SalAbort( const OUString& rErrorText, bool bDumpCore );
 
 const OUString& SalGetDesktopEnvironment();
 
+#ifdef DISABLE_DYNLOADING
+extern "C" SalInstance *create_SalInstance();
+#endif
+
 #endif // INCLUDED_VCL_INC_SALINST_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/win/salinst.h b/vcl/inc/win/salinst.h
index 975baff282ec..cd98a0231288 100644
--- a/vcl/inc/win/salinst.h
+++ b/vcl/inc/win/salinst.h
@@ -74,6 +74,7 @@ public:
 
     virtual OUString            getOSVersion() override;
     virtual std::shared_ptr<vcl::BackendCapabilities> GetBackendCapabilities() override;
+    virtual void BeforeAbort(const OUString&, bool) override;
 
     static int WorkaroundExceptionHandlingInUSER32Lib(int nExcept, LPEXCEPTION_POINTERS pExceptionInfo);
 };
diff --git a/vcl/source/app/salplug.cxx b/vcl/source/app/salplug.cxx
index c3e4e666e9d3..8179e0c95097 100644
--- a/vcl/source/app/salplug.cxx
+++ b/vcl/source/app/salplug.cxx
@@ -43,11 +43,13 @@
 #include <cstdio>
 
 #ifdef ANDROID
-#error "Android has no plugin infrastructure!"
+#include <android/androidinst.hxx>
 #endif
 
 #if !(defined _WIN32 || defined MACOSX)
+#if USING_X11
 #define DESKTOPDETECT
+#endif
 #define HEADLESS_VCLPLUG
 #endif
 
@@ -57,10 +59,17 @@ typedef SalInstance*(*salFactoryProc)();
 
 namespace {
 
+#ifndef DISABLE_DYNLOADING
 oslModule pCloseModule = nullptr;
+#endif
 
 SalInstance* tryInstance( const OUString& rModuleBase, bool bForce = false )
 {
+#ifdef DISABLE_DYNLOADING
+    (void)rModuleBase;
+    (void)bForce;
+    return create_SalInstance();
+#else // !DISABLE_DYNLOADING
 #ifdef HEADLESS_VCLPLUG
     if (rModuleBase == "svp")
         return svp_create_SalInstance();
@@ -122,18 +131,24 @@ SalInstance* tryInstance( const OUString& rModuleBase, bool bForce = false )
 
     // coverity[leaked_storage] - this is on purpose
     return pInst;
+#endif // !DISABLE_DYNLOADING
 }
 
 #ifdef DESKTOPDETECT
+#ifndef DISABLE_DYNLOADING
 extern "C" typedef DesktopType Fn_get_desktop_environment();
+#endif
 
-DesktopType get_desktop_environment()
+DesktopType lcl_get_desktop_environment()
 {
+    DesktopType ret = DESKTOP_UNKNOWN;
+#ifdef DISABLE_DYNLOADING
+    ret = get_desktop_environment();
+#else
     OUString aModule(DESKTOP_DETECTOR_DLL_NAME);
     oslModule aMod = osl_loadModuleRelative(
         reinterpret_cast< oslGenericFunction >( &tryInstance ), aModule.pData,
         SAL_LOADMODULE_DEFAULT );
-    DesktopType ret = DESKTOP_UNKNOWN;
     if( aMod )
     {
         Fn_get_desktop_environment * pSym
@@ -143,11 +158,15 @@ DesktopType get_desktop_environment()
             ret = pSym();
     }
     osl_unloadModule( aMod );
+#endif
     return ret;
 }
 
 SalInstance* autodetect_plugin()
 {
+#ifdef DISABLE_DYNLOADING
+    return nullptr;
+#else // !DISABLE_DYNLOADING
     static const char* const pKDEFallbackList[] =
     {
 #if ENABLE_KF5
@@ -171,7 +190,8 @@ SalInstance* autodetect_plugin()
     };
 #endif
 
-    DesktopType desktop = get_desktop_environment();
+    SalInstance* pInst = nullptr;
+    DesktopType desktop = lcl_get_desktop_environment();
     const char * const * pList = pStandardFallbackList;
     int nListEntry = 0;
 
@@ -189,7 +209,6 @@ SalInstance* autodetect_plugin()
     else if (desktop == DESKTOP_PLASMA5 || desktop == DESKTOP_LXQT)
         pList = pKDEFallbackList;
 
-    SalInstance* pInst = nullptr;
     while( pList[nListEntry] && pInst == nullptr )
     {
         OUString aTry( OUString::createFromAscii( pList[nListEntry] ) );
@@ -199,8 +218,8 @@ SalInstance* autodetect_plugin()
             "plugin autodetection: " << pList[nListEntry]);
         nListEntry++;
     }
-
     return pInst;
+#endif // !DISABLE_DYNLOADING
 }
 #endif // DESKTOPDETECT
 
@@ -229,7 +248,6 @@ bool IsHeadlessModeRequested()
 SalInstance *CreateSalInstance()
 {
     SalInstance *pInst = nullptr;
-
     OUString aUsePlugin;
     rtl::Bootstrap::get("SAL_USE_VCLPLUGIN", aUsePlugin);
     SAL_INFO_IF(!aUsePlugin.isEmpty(), "vcl", "Requested VCL plugin: " << aUsePlugin);
@@ -245,6 +263,7 @@ SalInstance *CreateSalInstance()
         aUsePlugin.clear();
 #endif
     }
+
     if( !aUsePlugin.isEmpty() )
         pInst = tryInstance( aUsePlugin, true );
 
@@ -287,40 +306,45 @@ void DestroySalInstance( SalInstance *pInst )
     pInst->ReleaseYieldMutexAll();
 
     delete pInst;
+#ifndef DISABLE_DYNLOADING
     if( pCloseModule )
         osl_unloadModule( pCloseModule );
+#endif
 }
 
 void SalAbort( const OUString& rErrorText, bool bDumpCore )
 {
-#if defined _WIN32
-    //TODO: ImplFreeSalGDI();
-#endif
+    if (GetSalData()->m_pInstance)
+        GetSalData()->m_pInstance->BeforeAbort(rErrorText, bDumpCore);
 
+#if defined _WIN32
+    (void) bDumpCore;
     if( rErrorText.isEmpty() )
     {
-#if defined _WIN32
         // make sure crash reporter is triggered
         RaiseException( 0, EXCEPTION_NONCONTINUABLE, 0, nullptr );
         FatalAppExitW( 0, L"Application Error" );
-#else
-        std::fprintf( stderr, "Application Error\n" );
-#endif
     }
     else
     {
         CrashReporter::addKeyValue("AbortMessage", rErrorText, CrashReporter::Write);
-#if defined _WIN32
         // make sure crash reporter is triggered
         RaiseException( 0, EXCEPTION_NONCONTINUABLE, 0, nullptr );
         FatalAppExitW( 0, o3tl::toW(rErrorText.getStr()) );
+    }
 #else
+#if defined ANDROID
+    OUString aError(rErrorText.isEmpty() ? "Unspecified application error" : rErrorText);
+    LOGE("SalAbort: '%s'", OUStringToOString(aError, osl_getThreadTextEncoding()).getStr());
+#else
+    if( rErrorText.isEmpty() )
+        std::fprintf( stderr, "Unspecified Application Error\n" );
+    else
+    {
+        CrashReporter::addKeyValue("AbortMessage", rErrorText, CrashReporter::Write);
         std::fprintf( stderr, "%s\n", OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
-#endif
     }
-#if defined _WIN32
-    (void) bDumpCore;
-#else
+#endif
     if( bDumpCore )
         abort();
     else
@@ -332,11 +356,13 @@ const OUString& SalGetDesktopEnvironment()
 {
 #ifdef _WIN32
     static OUString aDesktopEnvironment( "Windows" );
-
-#else
-#ifdef MACOSX
+#elif defined(MACOSX)
     static OUString aDesktopEnvironment( "MacOSX" );
-#else
+#elif defined(EMSCRIPTEN)
+    static OUString aDesktopEnvironment("WASM");
+#elif defined(ANDROID)
+    static OUString aDesktopEnvironment("android");
+#elif USING_X11
     // Order to match desktops.hxx' DesktopType
     static const char * const desktop_strings[] = {
         "none", "unknown", "GNOME", "UNITY",
@@ -345,9 +371,10 @@ const OUString& SalGetDesktopEnvironment()
     if( aDesktopEnvironment.isEmpty())
     {
         aDesktopEnvironment = OUString::createFromAscii(
-            desktop_strings[get_desktop_environment()]);
+            desktop_strings[lcl_get_desktop_environment()]);
     }
-#endif
+#else
+    static OUString aDesktopEnvironment("unknown");
 #endif
     return aDesktopEnvironment;
 }
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index 1771120e42c8..50f48b076679 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -931,4 +931,9 @@ std::shared_ptr<vcl::BackendCapabilities> WinSalInstance::GetBackendCapabilities
     return pBackendCapabilities;
 }
 
+void WinSalInstance::BeforeAbort(const OUString&, bool)
+{
+    ImplFreeSalGDI();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list