From 73d9a446d3db1e2a951d37076836583dc3a80cb4 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 21 Sep 2022 11:40:40 +0200 Subject: [PATCH 1/2] changed: move complete ReloadSkin handling into CApplicationSkinHandling --- xbmc/application/Application.cpp | 15 ++++-------- xbmc/application/Application.h | 1 - xbmc/application/ApplicationSkinHandling.cpp | 25 +++++++++++--------- xbmc/application/ApplicationSkinHandling.h | 14 ++++++++--- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/xbmc/application/Application.cpp b/xbmc/application/Application.cpp index 8bdbf7a2ff8d7..311b9a16a9bf4 100644 --- a/xbmc/application/Application.cpp +++ b/xbmc/application/Application.cpp @@ -218,7 +218,8 @@ using namespace std::chrono_literals; CApplication::CApplication(void) : CApplicationPlayerCallback(m_stackHelper), - CApplicationSettingsHandling(*this, *this) + CApplicationSettingsHandling(*this, *this), + CApplicationSkinHandling(this, this, m_bInitializing) #ifdef HAS_DVD_DRIVE , m_Autorun(new CAutorun()) @@ -736,12 +737,12 @@ bool CApplication::Initialize() CServiceBroker::RegisterTextureCache(std::make_shared()); std::string skinId = settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN); - if (!CApplicationSkinHandling::LoadSkin(skinId, this, this)) + if (!CApplicationSkinHandling::LoadSkin(skinId)) { CLog::Log(LOGERROR, "Failed to load skin '{}'", skinId); std::string defaultSkin = std::static_pointer_cast(setting)->GetDefault(); - if (!CApplicationSkinHandling::LoadSkin(defaultSkin, this, this)) + if (!CApplicationSkinHandling::LoadSkin(defaultSkin)) { CLog::Log(LOGFATAL, "Default skin '{}' could not be loaded! Terminating..", defaultSkin); return false; @@ -842,14 +843,6 @@ bool CApplication::OnSettingsSaving() const return !m_bStop; } -void CApplication::ReloadSkin(bool confirm/*=false*/) -{ - if (!g_SkinInfo || m_bInitializing) - return; // Don't allow reload before skin is loaded by system - - CApplicationSkinHandling::ReloadSkin(confirm, this, this); -} - void CApplication::Render() { // do not render if we are stopped or in background diff --git a/xbmc/application/Application.h b/xbmc/application/Application.h index df0f359e19c20..ff969c9339468 100644 --- a/xbmc/application/Application.h +++ b/xbmc/application/Application.h @@ -119,7 +119,6 @@ friend class CAppInboundProtocol; bool InitWindow(RESOLUTION res = RES_INVALID); bool Stop(int exitCode); - void ReloadSkin(bool confirm = false); const std::string& CurrentFile(); CFileItem& CurrentFileItem(); std::shared_ptr CurrentFileItemPtr(); diff --git a/xbmc/application/ApplicationSkinHandling.cpp b/xbmc/application/ApplicationSkinHandling.cpp index 442dc5ca221b9..9b095a786a295 100644 --- a/xbmc/application/ApplicationSkinHandling.cpp +++ b/xbmc/application/ApplicationSkinHandling.cpp @@ -44,9 +44,14 @@ using namespace KODI::MESSAGING; -bool CApplicationSkinHandling::LoadSkin(const std::string& skinID, - IMsgTargetCallback* msgCb, - IWindowManagerCallback* wCb) +CApplicationSkinHandling::CApplicationSkinHandling(IMsgTargetCallback* msgCb, + IWindowManagerCallback* wCb, + bool& bInitializing) + : m_msgCb(msgCb), m_wCb(wCb), m_bInitializing(bInitializing) +{ +} + +bool CApplicationSkinHandling::LoadSkin(const std::string& skinID) { ADDON::SkinPtr skin; { @@ -151,12 +156,12 @@ bool CApplicationSkinHandling::LoadSkin(const std::string& skinID, CLog::Log(LOGDEBUG, "Load Skin XML: {:.2f} ms", duration.count()); CLog::Log(LOGINFO, " initialize new skin..."); - CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(msgCb); + CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(m_msgCb); CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(&CServiceBroker::GetPlaylistPlayer()); CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget(&g_fontManager); CServiceBroker::GetGUI()->GetWindowManager().AddMsgTarget( &CServiceBroker::GetGUI()->GetStereoscopicsManager()); - CServiceBroker::GetGUI()->GetWindowManager().SetCallback(*wCb); + CServiceBroker::GetGUI()->GetWindowManager().SetCallback(*m_wCb); //@todo should be done by GUIComponents CServiceBroker::GetGUI()->GetWindowManager().Initialize(); @@ -366,12 +371,10 @@ bool CApplicationSkinHandling::LoadCustomWindows() return true; } -void CApplicationSkinHandling::ReloadSkin(bool confirm, - IMsgTargetCallback* msgCb, - IWindowManagerCallback* wCb) +void CApplicationSkinHandling::ReloadSkin(bool confirm) { - // if (!g_SkinInfo || m_bInitializing) - // return; // Don't allow reload before skin is loaded by system + if (!g_SkinInfo || m_bInitializing) + return; // Don't allow reload before skin is loaded by system std::string oldSkin = g_SkinInfo->ID(); @@ -381,7 +384,7 @@ void CApplicationSkinHandling::ReloadSkin(bool confirm, const std::shared_ptr settings = CServiceBroker::GetSettingsComponent()->GetSettings(); std::string newSkin = settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN); - if (LoadSkin(newSkin, msgCb, wCb)) + if (LoadSkin(newSkin)) { /* The Reset() or SetString() below will cause recursion, so the m_confirmSkinChange boolean is set so as to not prompt the user as to whether they want to keep the current skin. */ diff --git a/xbmc/application/ApplicationSkinHandling.h b/xbmc/application/ApplicationSkinHandling.h index 70be4a06efd83..5d9721232ad40 100644 --- a/xbmc/application/ApplicationSkinHandling.h +++ b/xbmc/application/ApplicationSkinHandling.h @@ -20,21 +20,29 @@ class IWindowManagerCallback; class CApplicationSkinHandling { public: + CApplicationSkinHandling(IMsgTargetCallback* msgCb, + IWindowManagerCallback* wCb, + bool& bInitializing); + void UnloadSkin(); bool OnSettingChanged(const CSetting& setting); + void ReloadSkin(bool confirm = false); protected: - bool LoadSkin(const std::string& skinID, IMsgTargetCallback* msgCb, IWindowManagerCallback* wCb); + bool LoadSkin(const std::string& skinID); bool LoadCustomWindows(); - void ReloadSkin(bool confirm, IMsgTargetCallback* msgCb, IWindowManagerCallback* wCb); /*! - * \brief Called by the application main/render thread for processing operations belonging to the skin + * \brief Called by the application main/render thread for processing + * operations belonging to the skin. */ void ProcessSkin() const; bool m_saveSkinOnUnloading = true; bool m_confirmSkinChange = true; bool m_ignoreSkinSettingChanges = false; + IMsgTargetCallback* m_msgCb; + IWindowManagerCallback* m_wCb; + bool& m_bInitializing; }; From aa856b4dca70faccdbe4ce55fc84c5fdde800f6b Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 20 Sep 2022 22:02:53 +0200 Subject: [PATCH 2/2] ApplicationSkinHandling: move to ApplicationComponents --- xbmc/application/Application.cpp | 26 +++++++++++-------- xbmc/application/Application.h | 2 -- .../ApplicationSettingsHandling.cpp | 16 ++++++------ .../application/ApplicationSettingsHandling.h | 5 +--- xbmc/application/ApplicationSkinHandling.h | 7 ++++- xbmc/interfaces/builtins/SkinBuiltins.cpp | 16 ++++++++---- xbmc/windowing/X11/WinSystemX11GLContext.cpp | 25 ++++++++++++++---- .../windowing/X11/WinSystemX11GLESContext.cpp | 21 ++++++++++++--- 8 files changed, 78 insertions(+), 40 deletions(-) diff --git a/xbmc/application/Application.cpp b/xbmc/application/Application.cpp index 311b9a16a9bf4..16fc9a476ed86 100644 --- a/xbmc/application/Application.cpp +++ b/xbmc/application/Application.cpp @@ -28,6 +28,7 @@ #include "application/ApplicationActionListeners.h" #include "application/ApplicationPlayer.h" #include "application/ApplicationPowerHandling.h" +#include "application/ApplicationSkinHandling.h" #include "cores/AudioEngine/Engines/ActiveAE/ActiveAE.h" #include "cores/IPlayer.h" #include "cores/playercorefactory/PlayerCoreFactory.h" @@ -218,8 +219,7 @@ using namespace std::chrono_literals; CApplication::CApplication(void) : CApplicationPlayerCallback(m_stackHelper), - CApplicationSettingsHandling(*this, *this), - CApplicationSkinHandling(this, this, m_bInitializing) + CApplicationSettingsHandling(static_cast(*this)) #ifdef HAS_DVD_DRIVE , m_Autorun(new CAutorun()) @@ -238,10 +238,12 @@ CApplication::CApplication(void) RegisterComponent(std::make_shared(m_critSection)); RegisterComponent(std::make_shared()); RegisterComponent(std::make_shared()); + RegisterComponent(std::make_shared(this, this, m_bInitializing)); } CApplication::~CApplication(void) { + DeregisterComponent(typeid(CApplicationSkinHandling)); DeregisterComponent(typeid(CApplicationPowerHandling)); DeregisterComponent(typeid(CApplicationPlayer)); DeregisterComponent(typeid(CApplicationActionListeners)); @@ -675,15 +677,17 @@ bool CApplication::Initialize() // GUI depends on seek handler GetComponent()->GetSeekHandler().Configure(); + const auto skinHandling = GetComponent(); + bool uiInitializationFinished = false; if (CServiceBroker::GetGUI()->GetWindowManager().Initialized()) { - const std::shared_ptr settings = CServiceBroker::GetSettingsComponent()->GetSettings(); + const auto settings = CServiceBroker::GetSettingsComponent()->GetSettings(); CServiceBroker::GetGUI()->GetWindowManager().CreateWindows(); - m_confirmSkinChange = false; + skinHandling->m_confirmSkinChange = false; std::vector incompatibleAddons; event.Reset(); @@ -725,7 +729,7 @@ bool CApplication::Initialize() // Start splashscreen and load skin CServiceBroker::GetRenderSystem()->ShowSplash(""); - m_confirmSkinChange = true; + skinHandling->m_confirmSkinChange = true; auto setting = settings->GetSetting(CSettings::SETTING_LOOKANDFEEL_SKIN); if (!setting) @@ -737,12 +741,12 @@ bool CApplication::Initialize() CServiceBroker::RegisterTextureCache(std::make_shared()); std::string skinId = settings->GetString(CSettings::SETTING_LOOKANDFEEL_SKIN); - if (!CApplicationSkinHandling::LoadSkin(skinId)) + if (!skinHandling->LoadSkin(skinId)) { CLog::Log(LOGERROR, "Failed to load skin '{}'", skinId); std::string defaultSkin = std::static_pointer_cast(setting)->GetDefault(); - if (!CApplicationSkinHandling::LoadSkin(defaultSkin)) + if (!skinHandling->LoadSkin(defaultSkin)) { CLog::Log(LOGFATAL, "Default skin '{}' could not be loaded! Terminating..", defaultSkin); return false; @@ -1913,7 +1917,7 @@ bool CApplication::Cleanup() CServiceBroker::UnregisterSpeechRecognition(); CLog::Log(LOGINFO, "unload skin"); - UnloadSkin(); + GetComponent()->UnloadSkin(); CServiceBroker::UnregisterTextureCache(); @@ -2680,7 +2684,7 @@ bool CApplication::OnMessage(CGUIMessage& message) m_bInitializing = false; if (message.GetSenderId() == WINDOW_SETTINGS_PROFILES) - g_application.ReloadSkin(false); + GetComponent()->ReloadSkin(false); } else if (message.GetParam1() == GUI_MSG_UPDATE_ITEM && message.GetItem()) { @@ -3090,7 +3094,7 @@ void CApplication::Process() void CApplication::ProcessSlow() { // process skin resources (skin timers) - ProcessSkin(); + GetComponent()->ProcessSkin(); CServiceBroker::GetPowerManager().ProcessEvents(); @@ -3517,7 +3521,7 @@ void CApplication::SetLoggingIn(bool switchingProfiles) // because in that case we have already loaded the new profile and // would therefore write the previous skin's settings into the new profile // instead of into the previous one - m_saveSkinOnUnloading = !switchingProfiles; + GetComponent()->m_saveSkinOnUnloading = !switchingProfiles; } void CApplication::PrintStartupLog() diff --git a/xbmc/application/Application.h b/xbmc/application/Application.h index ff969c9339468..08f3c8f25aa9a 100644 --- a/xbmc/application/Application.h +++ b/xbmc/application/Application.h @@ -12,7 +12,6 @@ #include "application/ApplicationEnums.h" #include "application/ApplicationPlayerCallback.h" #include "application/ApplicationSettingsHandling.h" -#include "application/ApplicationSkinHandling.h" #include "application/ApplicationStackHelper.h" #include "application/ApplicationVolumeHandling.h" #include "guilib/IMsgTargetCallback.h" @@ -90,7 +89,6 @@ class CApplication : public IWindowManagerCallback, public CApplicationComponents, public CApplicationPlayerCallback, public CApplicationSettingsHandling, - public CApplicationSkinHandling, public CApplicationVolumeHandling { friend class CAppInboundProtocol; diff --git a/xbmc/application/ApplicationSettingsHandling.cpp b/xbmc/application/ApplicationSettingsHandling.cpp index cd8319a6a3597..a6d78c468b24f 100644 --- a/xbmc/application/ApplicationSettingsHandling.cpp +++ b/xbmc/application/ApplicationSettingsHandling.cpp @@ -39,8 +39,8 @@ bool IsPlaying(const std::string& condition, } // namespace CApplicationSettingsHandling::CApplicationSettingsHandling( - CApplicationSkinHandling& skinHandling, CApplicationVolumeHandling& volumeHandling) - : m_skinHandling(skinHandling), m_volumeHandling(volumeHandling) + CApplicationVolumeHandling& volumeHandling) + : m_volumeHandling(volumeHandling) { } @@ -113,18 +113,18 @@ void CApplicationSettingsHandling::OnSettingChanged(const std::shared_ptr(); - - if (appPower->OnSettingChanged(*setting)) + const auto appSkin = components.GetComponent(); + if (appSkin->OnSettingChanged(*setting)) return; if (m_volumeHandling.OnSettingChanged(*setting)) return; + const auto appPower = components.GetComponent(); + if (appPower->OnSettingChanged(*setting)) + return; + const std::string& settingId = setting->GetId(); if (settingId == CSettings::SETTING_VIDEOSCREEN_FAKEFULLSCREEN) diff --git a/xbmc/application/ApplicationSettingsHandling.h b/xbmc/application/ApplicationSettingsHandling.h index ceb4131e5bf3d..fa71fd47b9ede 100644 --- a/xbmc/application/ApplicationSettingsHandling.h +++ b/xbmc/application/ApplicationSettingsHandling.h @@ -13,7 +13,6 @@ #include "settings/lib/ISettingsHandler.h" class CApplicationVolumeHandling; -class CApplicationSkinHandling; /*! * \brief Class handling application support for settings. @@ -24,8 +23,7 @@ class CApplicationSettingsHandling : public ISettingCallback, public ISubSettings { public: - CApplicationSettingsHandling(CApplicationSkinHandling& skinHandling, - CApplicationVolumeHandling& volumeHandling); + explicit CApplicationSettingsHandling(CApplicationVolumeHandling& volumeHandling); protected: void RegisterSettings(); @@ -39,6 +37,5 @@ class CApplicationSettingsHandling : public ISettingCallback, const char* oldSettingId, const TiXmlNode* oldSettingNode) override; - CApplicationSkinHandling& m_skinHandling; CApplicationVolumeHandling& m_volumeHandling; }; diff --git a/xbmc/application/ApplicationSkinHandling.h b/xbmc/application/ApplicationSkinHandling.h index 5d9721232ad40..fc5c3d0df5b2e 100644 --- a/xbmc/application/ApplicationSkinHandling.h +++ b/xbmc/application/ApplicationSkinHandling.h @@ -8,8 +8,11 @@ #pragma once +#include "application/IApplicationComponent.h" + #include +class CApplication; class CSetting; class IMsgTargetCallback; class IWindowManagerCallback; @@ -17,8 +20,10 @@ class IWindowManagerCallback; /*! * \brief Class handling application support for skin management. */ -class CApplicationSkinHandling +class CApplicationSkinHandling : public IApplicationComponent { + friend class CApplication; + public: CApplicationSkinHandling(IMsgTargetCallback* msgCb, IWindowManagerCallback* wCb, diff --git a/xbmc/interfaces/builtins/SkinBuiltins.cpp b/xbmc/interfaces/builtins/SkinBuiltins.cpp index c39d87ef05294..ef708d5b5dae8 100644 --- a/xbmc/interfaces/builtins/SkinBuiltins.cpp +++ b/xbmc/interfaces/builtins/SkinBuiltins.cpp @@ -14,7 +14,8 @@ #include "Util.h" #include "addons/addoninfo/AddonInfo.h" #include "addons/gui/GUIWindowAddonBrowser.h" -#include "application/Application.h" +#include "application/ApplicationComponents.h" +#include "application/ApplicationSkinHandling.h" #include "dialogs/GUIDialogColorPicker.h" #include "dialogs/GUIDialogFileBrowser.h" #include "dialogs/GUIDialogNumeric.h" @@ -39,8 +40,9 @@ using namespace ADDON; static int ReloadSkin(const std::vector& params) { // Reload the skin - g_application.ReloadSkin(!params.empty() && - StringUtils::EqualsNoCase(params[0], "confirm")); + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(!params.empty() && StringUtils::EqualsNoCase(params[0], "confirm")); return 0; } @@ -50,7 +52,9 @@ static int ReloadSkin(const std::vector& params) */ static int UnloadSkin(const std::vector& params) { - g_application.UnloadSkin(); + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->UnloadSkin(); return 0; } @@ -421,7 +425,9 @@ static int SetTheme(const std::vector& params) if (StringUtils::EqualsNoCase(colorTheme, "Textures.xml")) colorTheme = "defaults.xml"; settings->SetString(CSettings::SETTING_LOOKANDFEEL_SKINCOLORS, colorTheme); - g_application.ReloadSkin(); + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); return 0; } diff --git a/xbmc/windowing/X11/WinSystemX11GLContext.cpp b/xbmc/windowing/X11/WinSystemX11GLContext.cpp index cbfd72d7d8047..ad27acaed3c05 100644 --- a/xbmc/windowing/X11/WinSystemX11GLContext.cpp +++ b/xbmc/windowing/X11/WinSystemX11GLContext.cpp @@ -12,7 +12,8 @@ #include "OptionalsReg.h" #include "VideoSyncOML.h" #include "X11DPMSSupport.h" -#include "application/Application.h" +#include "application/ApplicationComponents.h" +#include "application/ApplicationSkinHandling.h" #include "cores/RetroPlayer/process/X11/RPProcessInfoX11.h" #include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGL.h" #include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h" @@ -150,7 +151,11 @@ bool CWinSystemX11GLContext::ResizeWindow(int newWidth, int newHeight, int newLe CRenderSystemGL::ResetRenderSystem(newWidth, newHeight); if (m_newGlContext) - g_application.ReloadSkin(); + { + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); + } return true; } @@ -162,7 +167,11 @@ void CWinSystemX11GLContext::FinishWindowResize(int newWidth, int newHeight) CRenderSystemGL::ResetRenderSystem(newWidth, newHeight); if (m_newGlContext) - g_application.ReloadSkin(); + { + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); + } } bool CWinSystemX11GLContext::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) @@ -172,7 +181,11 @@ bool CWinSystemX11GLContext::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res CRenderSystemGL::ResetRenderSystem(res.iWidth, res.iHeight); if (m_newGlContext) - g_application.ReloadSkin(); + { + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); + } return true; } @@ -221,7 +234,9 @@ bool CWinSystemX11GLContext::RefreshGLContext(bool force) { if (force) { - g_application.UnloadSkin(); + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->UnloadSkin(); CRenderSystemGL::DestroyRenderSystem(); } success = m_pGLContext->Refresh(force, m_screen, m_glWindow, m_newGlContext); diff --git a/xbmc/windowing/X11/WinSystemX11GLESContext.cpp b/xbmc/windowing/X11/WinSystemX11GLESContext.cpp index 0c1f6af30d7bc..e2367d3e646e1 100644 --- a/xbmc/windowing/X11/WinSystemX11GLESContext.cpp +++ b/xbmc/windowing/X11/WinSystemX11GLESContext.cpp @@ -11,7 +11,8 @@ #include "GLContextEGL.h" #include "OptionalsReg.h" #include "X11DPMSSupport.h" -#include "application/Application.h" +#include "application/ApplicationComponents.h" +#include "application/ApplicationSkinHandling.h" #include "cores/RetroPlayer/process/X11/RPProcessInfoX11.h" #include "cores/RetroPlayer/rendering/VideoRenderers/RPRendererOpenGLES.h" #include "cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h" @@ -135,7 +136,11 @@ bool CWinSystemX11GLESContext::ResizeWindow(int newWidth, int newHeight, int new CRenderSystemGLES::ResetRenderSystem(newWidth, newHeight); if (m_newGlContext) - g_application.ReloadSkin(); + { + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); + } return true; } @@ -147,7 +152,11 @@ void CWinSystemX11GLESContext::FinishWindowResize(int newWidth, int newHeight) CRenderSystemGLES::ResetRenderSystem(newWidth, newHeight); if (m_newGlContext) - g_application.ReloadSkin(); + { + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); + } } bool CWinSystemX11GLESContext::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays) @@ -157,7 +166,11 @@ bool CWinSystemX11GLESContext::SetFullScreen(bool fullScreen, RESOLUTION_INFO& r CRenderSystemGLES::ResetRenderSystem(res.iWidth, res.iHeight); if (m_newGlContext) - g_application.ReloadSkin(); + { + auto& components = CServiceBroker::GetAppComponents(); + const auto appSkin = components.GetComponent(); + appSkin->ReloadSkin(); + } return true; }