diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-01-16 14:37:24 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-01-17 12:44:39 +0100 |
commit | 5da906d07bf88bb9c56325d03272006d5a0662c4 (patch) | |
tree | 16763a743098db8f184bcd7cc9060ddeb8815a6f | |
parent | 6985f81b528b0e06bd3b11160c35ed2d4a999845 (diff) |
iOS+SVP convert remaining VCL plugins to salplug
While this makes the preprocessor usage even larger, the code in
salplug.cxx is now hopefully easier to follow. I added a comment
about the main code structure at the beginning.
It also includes changes to the generic plugin list to include
gtk3_kde5 before gen, qt5 and qt6 after gen, but still skips the
headless / svp plugin.
And I explicitly excluded salplug.cxx from the externandnotdefined
compiler plugin. I could have added a dummy, but that seemed not
worth the effort. My try on a non-dummy with correct includes and
defines made the code in salplug.cxx much harder to follow.
FWIW, the iOS VCL plugin actually seems to use the osx SalData, so
I think these changes to iosinst.cxx are more correct then commit
7d990aafdc363b2a12b5db78637d7f3bef7780bd ("VCL drop m_pInstance
from *nix SalData"). But hard to tell without a compiler.
Change-Id: I0e2944d4221ca5910fb2120cc8b24def5c5b3f33
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128477
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
-rw-r--r-- | compilerplugins/clang/externandnotdefined.cxx | 4 | ||||
-rw-r--r-- | vcl/Library_vcl.mk | 5 | ||||
-rw-r--r-- | vcl/android/androidinst.cxx | 2 | ||||
-rw-r--r-- | vcl/headless/headlessinst.cxx | 29 | ||||
-rw-r--r-- | vcl/headless/svpdata.cxx | 21 | ||||
-rw-r--r-- | vcl/inc/headless/svpinst.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/salinst.hxx | 4 | ||||
-rw-r--r-- | vcl/ios/iosinst.cxx | 41 | ||||
-rw-r--r-- | vcl/source/app/salplug.cxx | 176 |
9 files changed, 124 insertions, 160 deletions
diff --git a/compilerplugins/clang/externandnotdefined.cxx b/compilerplugins/clang/externandnotdefined.cxx index 5d65579a6af1..a45c5c9f9a9d 100644 --- a/compilerplugins/clang/externandnotdefined.cxx +++ b/compilerplugins/clang/externandnotdefined.cxx @@ -64,6 +64,10 @@ bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) { if (loplugin::hasPathnamePrefix(fileName, SRCDIR "/filter/qa/")) { return true; } + // keeps the code structure of salplug.cxx easier to follow + if (fileName == SRCDIR "/vcl/source/app/salplug.cxx") { + return true; + } report( DiagnosticsEngine::Warning, "extern prototype in main file without definition", diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 4712da2f716f..42282268b8ce 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -391,6 +391,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/app/help \ vcl/source/app/i18nhelp \ vcl/source/app/idle \ + vcl/source/app/salplug \ vcl/source/app/salusereventlist \ vcl/source/app/salvtables \ vcl/source/app/scheduler \ @@ -529,7 +530,6 @@ vcl_headless_code= \ vcl/headless/SvpGraphicsBackend \ vcl/headless/CairoCommon \ vcl/headless/BitmapHelper \ - $(if $(ENABLE_HEADLESS),vcl/headless/svpdata) \ ) \ vcl/headless/svpdummies \ vcl/headless/svpinst \ @@ -621,9 +621,6 @@ endif # !DISABLE_GUI # * select headless code and corresponding libraries # $(eval $(call gb_Library_add_exception_objects,vcl,\ - $(if $(filter-out iOS,$(OS)), \ - vcl/source/app/salplug \ - ) \ $(if $(USE_HEADLESS_CODE), \ $(if $(ENABLE_CUPS), \ vcl/unx/generic/printer/cupsmgr \ diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx index 8e83dae0a8dd..ca130fb1b19f 100644 --- a/vcl/android/androidinst.cxx +++ b/vcl/android/androidinst.cxx @@ -156,7 +156,7 @@ SalFrame *AndroidSalInstance::CreateFrame( SalFrame* pParent, SalFrameStyleFlags // This is our main entry point: extern "C" SalInstance *create_SalInstance() { - LOGI("Android: CreateSalInstance!"); + LOGI("Android: create_SalInstance!"); AndroidSalInstance* pInstance = new AndroidSalInstance( std::make_unique<SvpSalYieldMutex>() ); new SvpSalData(); return pInstance; diff --git a/vcl/headless/headlessinst.cxx b/vcl/headless/headlessinst.cxx index 3c47e82333e8..abe3e1cf92c7 100644 --- a/vcl/headless/headlessinst.cxx +++ b/vcl/headless/headlessinst.cxx @@ -45,38 +45,11 @@ SalSystem *HeadlessSalInstance::CreateSalSystem() return new HeadlessSalSystem(); } -void SalAbort( const OUString& rErrorText, bool bDumpCore ) -{ - OUString aError( rErrorText ); - if( aError.isEmpty() ) - aError = "Unknown application error"; - - SAL_WARN("vcl.headless", rErrorText); - SAL_INFO("vcl.headless", "SalAbort: '" << aError << "'."); - - if( bDumpCore ) - abort(); - else - _exit(1); -} - -const OUString& SalGetDesktopEnvironment() -{ - static OUString aEnv( "headless" ); - return aEnv; -} - -// This is our main entry point: -SalInstance *CreateSalInstance() +extern "C" SalInstance *create_SalInstance() { HeadlessSalInstance* pInstance = new HeadlessSalInstance(std::make_unique<SvpSalYieldMutex>()); new SvpSalData(); return pInstance; } -void DestroySalInstance( SalInstance *pInst ) -{ - delete pInst; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/headless/svpdata.cxx b/vcl/headless/svpdata.cxx deleted file mode 100644 index a5d17b007115..000000000000 --- a/vcl/headless/svpdata.cxx +++ /dev/null @@ -1,21 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include <headless/svpdata.hxx> -#include <headless/svpinst.hxx> - -// plugin factory function -SalInstance* svp_create_SalInstance() -{ - SvpSalInstance* pInstance = new SvpSalInstance( std::make_unique<SvpSalYieldMutex>() ); - new SvpSalData(); - return pInstance; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx index 06c6e432ffed..874ce672d97a 100644 --- a/vcl/inc/headless/svpinst.hxx +++ b/vcl/inc/headless/svpinst.hxx @@ -88,8 +88,6 @@ public: virtual bool IsCurrentThread() const override; }; -SalInstance* svp_create_SalInstance(); - // NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of // SvpSalYieldMutex; if a subclass uses something else it must override these // (Wakeup is only called by SvpSalTimer and SvpSalFrame) diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx index a807d5c263f3..9dcee57bc2e6 100644 --- a/vcl/inc/salinst.hxx +++ b/vcl/inc/salinst.hxx @@ -224,10 +224,6 @@ 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/ios/iosinst.cxx b/vcl/ios/iosinst.cxx index 416b53912fec..a9fa27e5ea82 100644 --- a/vcl/ios/iosinst.cxx +++ b/vcl/ios/iosinst.cxx @@ -23,7 +23,7 @@ #include "ios/iosinst.hxx" #include "headless/svpdummies.hxx" -#include "unx/gendata.hxx" +#include <osx/saldata.hxx> #include "quartz/utils.h" #include <vcl/layout.hxx> #include <vcl/settings.hxx> @@ -31,17 +31,6 @@ // Totally wrong of course but doesn't seem to harm much in the iOS app. static int viewWidth = 1, viewHeight = 1; -class SalData -{ - SystemFontList* mpFontList; - CGColorSpaceRef mxRGBSpace; - CGColorSpaceRef mxGraySpace; - - static void ensureThreadAutoreleasePool() {}; - - explicit SalData(); -}; - void IosSalInstance::GetWorkArea( tools::Rectangle& rRect ) { rRect = tools::Rectangle( Point( 0, 0 ), @@ -140,19 +129,6 @@ SalFrame *IosSalInstance::CreateFrame( SalFrame* pParent, SalFrameStyleFlags nSt return new IosSalFrame( this, pParent, nStyle ); } -void SalAbort( const OUString& rErrorText, bool bDumpCore ) -{ - (void) bDumpCore; - - NSLog(@"SalAbort: %s", OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() ); -} - -const OUString& SalGetDesktopEnvironment() -{ - static OUString aEnv( "iOS" ); - return aEnv; -} - SalData::SalData() : mpFontList( 0 ), mxRGBSpace( CGColorSpaceCreateDeviceRGB() ), @@ -160,20 +136,21 @@ SalData::SalData() : { } +SalData::~SalData() +{ + CGColorSpaceRelease(mxRGBSpace); + CGColorSpaceRelease(mxGraySpace); +} -// This is our main entry point: -SalInstance *CreateSalInstance() +void SalData::ensureThreadAutoreleasePool() {} + +extern "C" SalInstance *create_SalInstance() { IosSalInstance* pInstance = new IosSalInstance( std::make_unique<SvpSalYieldMutex>() ); new SvpSalData(pInstance); return pInstance; } -void DestroySalInstance( SalInstance *pInst ) -{ - delete pInst; -} - int IosSalSystem::ShowNativeDialog( const OUString& rTitle, const OUString& rMessage, const std::vector< OUString >& rButtons ) diff --git a/vcl/source/app/salplug.cxx b/vcl/source/app/salplug.cxx index e56c6dcffb3d..1c7ef02d373b 100644 --- a/vcl/source/app/salplug.cxx +++ b/vcl/source/app/salplug.cxx @@ -17,63 +17,91 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <osl/module.hxx> +// Th current high-level preprocessor structure is: +// +// if !HAVE_FEATURE_UI +// => STATIC_SAL_INSTANCE +// else +// ? !STATIC_SAL_INSTANCE +// ? UNIX_DESKTOP_DETECT +// endif +// +// ENABLE_HEADLESS just signifies the use of the SVP plugin! + +#include <config_features.h> +#include <config_vclplug.h> +#include <cstdio> +#include <desktop/crashreport.hxx> #include <rtl/bootstrap.hxx> #include <rtl/process.h> -#include <sal/log.hxx> - -#include <salframe.hxx> #include <salinst.hxx> -#include <config_vclplug.h> -#include <desktop/crashreport.hxx> +#include <sal/log.hxx> +#include <svdata.hxx> +#include <vcl/svapp.hxx> -#ifndef _WIN32 -#include <headless/svpinst.hxx> -#include <printerinfomanager.hxx> +#if USING_X11 +#define UNIX_DESKTOP_DETECT 1 #include <unx/desktops.hxx> +#else +#define UNIX_DESKTOP_DETECT 0 +#endif -#include <unistd.h> +#if defined(DISABLE_DYNLOADING) || !HAVE_FEATURE_UI +#define STATIC_SAL_INSTANCE 1 +extern "C" SalInstance* create_SalInstance(); #else -#include <svdata.hxx> -#include <o3tl/char16_t2wchar_t.hxx> -#include <Windows.h> +#define STATIC_SAL_INSTANCE 0 +#include <osl/module.hxx> #endif -#include <cstdio> +#if defined(iOS) +#include <premac.h> +#include <UIKit/UIKit.h> +#include <postmac.h> -#ifdef ANDROID +#elif defined(ANDROID) #include <android/androidinst.hxx> #endif -#if USING_X11 -#define DESKTOPDETECT +#if defined(_WIN32) +#include <svdata.hxx> +#include <o3tl/char16_t2wchar_t.hxx> +#include <Windows.h> +#else +#include <unistd.h> #endif + #if ENABLE_HEADLESS -#define HEADLESS_VCLPLUG +#include <headless/svpdata.hxx> +#include <headless/svpinst.hxx> #endif -extern "C" { -typedef SalInstance*(*salFactoryProc)(); +namespace { + +#if ENABLE_HEADLESS +SalInstance* svp_create_SalInstance() +{ + SvpSalInstance* pInstance = new SvpSalInstance(std::make_unique<SvpSalYieldMutex>()); + new SvpSalData(); + return pInstance; } +#endif -namespace { +#if HAVE_FEATURE_UI -#ifndef DISABLE_DYNLOADING +#if !STATIC_SAL_INSTANCE oslModule pCloseModule = nullptr; -#endif + +extern "C" typedef SalInstance* (*salFactoryProc)(); SalInstance* tryInstance( const OUString& rModuleBase, bool bForce = false ) { -#ifdef HEADLESS_VCLPLUG +#if ENABLE_HEADLESS if (rModuleBase == "svp") return svp_create_SalInstance(); #endif -#ifdef DISABLE_DYNLOADING - (void)rModuleBase; - (void)bForce; - return create_SalInstance(); -#else // !DISABLE_DYNLOADING + SalInstance* pInst = nullptr; OUString aUsedModuleBase(rModuleBase); if (aUsedModuleBase == "kde5") @@ -133,10 +161,10 @@ SalInstance* tryInstance( const OUString& rModuleBase, bool bForce = false ) // coverity[leaked_storage] - this is on purpose return pInst; -#endif // !DISABLE_DYNLOADING } +#endif // !STATIC_SAL_INSTANCE -#ifdef DESKTOPDETECT +#if UNIX_DESKTOP_DETECT #ifndef DISABLE_DYNLOADING extern "C" typedef DesktopType Fn_get_desktop_environment(); #else @@ -166,11 +194,9 @@ DesktopType lcl_get_desktop_environment() return ret; } -SalInstance* autodetect_plugin() +#if !STATIC_SAL_INSTANCE +const char* const* autodetect_plugin_list() { -#ifdef DISABLE_DYNLOADING - return nullptr; -#else // !DISABLE_DYNLOADING static const char* const pKDEFallbackList[] = { #if ENABLE_KF5 @@ -199,7 +225,7 @@ SalInstance* autodetect_plugin() nullptr }; -#ifdef HEADLESS_VCLPLUG +#if ENABLE_HEADLESS static const char* const pHeadlessFallbackList[] = { "svp", @@ -207,11 +233,10 @@ SalInstance* autodetect_plugin() }; #endif - SalInstance* pInst = nullptr; DesktopType desktop = lcl_get_desktop_environment(); const char * const * pList = pStandardFallbackList; -#ifdef HEADLESS_VCLPLUG +#if ENABLE_HEADLESS // no server at all: dummy plugin if ( desktop == DESKTOP_NONE ) pList = pHeadlessFallbackList; @@ -225,18 +250,13 @@ SalInstance* autodetect_plugin() else if (desktop == DESKTOP_PLASMA5 || desktop == DESKTOP_LXQT) pList = pKDEFallbackList; - for (int i = 0; !pInst && pList[i]; ++i) - { - OUString aTry(OUString::createFromAscii(pList[i])); - pInst = tryInstance( aTry ); - SAL_INFO_IF(pInst, "vcl.plugadapt", "plugin autodetection: " << pList[i]); - } - return pInst; -#endif // !DISABLE_DYNLOADING + return pList; } -#endif // DESKTOPDETECT +#endif // !STATIC_SAL_INSTANCE +#endif // UNIX_DESKTOP_DETECT + +#endif // HAVE_FEATURE_UI -#ifdef HEADLESS_VCLPLUG // HACK to obtain Application::IsHeadlessModeEnabled early on, before // Application::EnableHeadlessMode has potentially been called: bool IsHeadlessModeRequested() @@ -254,41 +274,46 @@ bool IsHeadlessModeRequested() } return false; } -#endif } // anonymous namespace SalInstance *CreateSalInstance() { - SalInstance *pInst = nullptr; OUString aUsePlugin; rtl::Bootstrap::get("SAL_USE_VCLPLUGIN", aUsePlugin); - SAL_INFO_IF(!aUsePlugin.isEmpty(), "vcl", "Requested VCL plugin: " << aUsePlugin); -#ifdef HEADLESS_VCLPLUG + SAL_INFO_IF(!aUsePlugin.isEmpty(), "vcl.plugadapt", "Requested VCL plugin: " << aUsePlugin); + if (Application::IsBitmapRendering() || (aUsePlugin.isEmpty() && IsHeadlessModeRequested())) aUsePlugin = "svp"; -#endif if (aUsePlugin == "svp") { Application::EnableBitmapRendering(); -#ifndef HEADLESS_VCLPLUG +#if ENABLE_HEADLESS + return svp_create_SalInstance(); +#else aUsePlugin.clear(); #endif } +#if STATIC_SAL_INSTANCE + return create_SalInstance(); + +#else // !STATIC_SAL_INSTANCE + SalInstance *pInst = nullptr; + if( !aUsePlugin.isEmpty() ) pInst = tryInstance( aUsePlugin, true ); -#ifdef DESKTOPDETECT - if( ! pInst ) - pInst = autodetect_plugin(); +#if UNIX_DESKTOP_DETECT + const char* const* pPluginList = pInst ? nullptr : autodetect_plugin_list(); + for (int i = 0; !pInst && pPluginList[i]; ++i) + { + pInst = tryInstance(OUString::createFromAscii(pPluginList[i])); + SAL_INFO_IF(pInst, "vcl.plugadapt", "plugin autodetection: " << pPluginList[i]); + } #endif -#ifdef DISABLE_DYNLOADING - if (!pInst) - pInst = tryInstance(""); -#else // fallback, try everything static const char* const pPlugin[] = { #ifdef _WIN32 @@ -302,16 +327,24 @@ SalInstance *CreateSalInstance() #if ENABLE_KF5 "kf5", #endif +#if ENABLE_GTK3_KDE5 + "gtk3_kde5", +#endif #if ENABLE_GEN "gen", #endif +#if ENABLE_QT5 + "qt5", +#endif +#if ENABLE_QT6 + "qt6", +#endif #endif // !_WIN32 && !MACOSX nullptr - }; + }; for (int i = 0; !pInst && pPlugin[i]; ++i) pInst = tryInstance( OUString::createFromAscii( pPlugin[ i ] ) ); -#endif // !DISABLE_DYNLOADING if( ! pInst ) { @@ -320,12 +353,13 @@ SalInstance *CreateSalInstance() } return pInst; +#endif // !STATIC_SAL_INSTANCE } void DestroySalInstance( SalInstance *pInst ) { delete pInst; -#ifndef DISABLE_DYNLOADING +#if !STATIC_SAL_INSTANCE if( pCloseModule ) osl_unloadModule( pCloseModule ); #endif @@ -350,10 +384,12 @@ void SalAbort( const OUString& rErrorText, bool bDumpCore ) RaiseException( 0, EXCEPTION_NONCONTINUABLE, 0, nullptr ); FatalAppExitW( 0, o3tl::toW(rErrorText.getStr()) ); } -#else +#else // !_WIN32 #if defined ANDROID OUString aError(rErrorText.isEmpty() ? "Unspecified application error" : rErrorText); LOGE("SalAbort: '%s'", OUStringToOString(aError, osl_getThreadTextEncoding()).getStr()); +#elif defined(iOS) + NSLog(@"SalAbort: %s", OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr()); #else if( rErrorText.isEmpty() ) std::fprintf( stderr, "Unspecified Application Error\n" ); @@ -367,12 +403,14 @@ void SalAbort( const OUString& rErrorText, bool bDumpCore ) abort(); else _exit(1); -#endif +#endif // !_WIN32 } const OUString& SalGetDesktopEnvironment() { -#ifdef _WIN32 +#if !HAVE_FEATURE_UI + static OUString aDesktopEnvironment("headless"); +#elif defined(_WIN32) static OUString aDesktopEnvironment( "Windows" ); #elif defined(MACOSX) static OUString aDesktopEnvironment( "MacOSX" ); @@ -380,7 +418,9 @@ const OUString& SalGetDesktopEnvironment() static OUString aDesktopEnvironment("WASM"); #elif defined(ANDROID) static OUString aDesktopEnvironment("android"); -#elif USING_X11 +#elif defined(iOS) + static OUString aDesktopEnvironment("iOS"); +#elif UNIX_DESKTOP_DETECT // Order to match desktops.hxx' DesktopType static const char * const desktop_strings[] = { "none", "unknown", "GNOME", "UNITY", |