include/svtools/colorcfg.hxx | 5 -- svtools/source/config/colorcfg.cxx | 67 ++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 39 deletions(-)
New commits: commit d4a314fcc66fade6c761cc7c7106336c1fd0e672 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Mar 25 15:16:49 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Mar 27 09:17:14 2025 +0100 tdf#150623 reduce cost of ColorCfg when switching tabs on this document, we end up in the ScChildrenShapes performance sinkhole, which constructs and destructs ColorCfg a ton of times. Which should normally be free, but a bunch of logic has crept into the outer class, and now we spend a lot of time unnecessarily adding and removing an application event listener. So push that logic down into ColorCfg_Impl, where it belongs, and now tab switching goes from 2 seconds to under 1 second. Change-Id: I4c7a508da0064a11bd4fa0b9251a91a6cda50c71 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183301 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/include/svtools/colorcfg.hxx b/include/svtools/colorcfg.hxx index 86fdcb94d636..7030abc21c3a 100644 --- a/include/svtools/colorcfg.hxx +++ b/include/svtools/colorcfg.hxx @@ -291,11 +291,6 @@ public: // 1 gets the default color on dark mod. static Color GetDefaultColor(ColorConfigEntry eEntry, int nMod = -1); static const OUString& GetCurrentSchemeName(); - - void LoadThemeColorsFromRegistry(); - void SetupTheme(); - - DECL_LINK(DataChangedHdl, VclSimpleEvent&, void); }; class SVT_DLLPUBLIC EditableColorConfig diff --git a/svtools/source/config/colorcfg.cxx b/svtools/source/config/colorcfg.cxx index c1a973af27a4..b3e40141fc43 100644 --- a/svtools/source/config/colorcfg.cxx +++ b/svtools/source/config/colorcfg.cxx @@ -98,6 +98,12 @@ public: using ConfigItem::SetModified; using ConfigItem::ClearModified; void SettingsChanged(); + void SetupTheme(); + const OUString& GetCurrentSchemeName(); + void LoadThemeColorsFromRegistry(); + // get the configured value - if bSmart is set the default color setting is provided + // instead of the automatic color + ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart = true) const; DECL_LINK( DataChangedEventListener, VclSimpleEvent&, void ); }; @@ -149,8 +155,9 @@ ColorConfig_Impl::ColorConfig_Impl() : if (!comphelper::IsFuzzing()) Load(OUString()); - ::Application::AddEventListener( LINK(this, ColorConfig_Impl, DataChangedEventListener) ); + SetupTheme(); + ::Application::AddEventListener( LINK(this, ColorConfig_Impl, DataChangedEventListener) ); } ColorConfig_Impl::~ColorConfig_Impl() @@ -419,6 +426,8 @@ IMPL_LINK( ColorConfig_Impl, DataChangedEventListener, VclSimpleEvent&, rEvent, (pData->GetFlags() & AllSettingsFlags::STYLE) ) { SettingsChanged(); + ThemeColors::SetThemeCached(false); + SetupTheme(); } } } @@ -426,7 +435,7 @@ IMPL_LINK( ColorConfig_Impl, DataChangedEventListener, VclSimpleEvent&, rEvent, // caches registry colors into the static ThemeColors::m_aThemeColors object. if the color // value is set to COL_AUTO, the ColorConfig::GetColorValue function calls ColorConfig::GetDefaultColor() // which returns some hard coded colors for the document, and StyleSettings colors for the UI (lcl_GetDefaultUIColor). -void ColorConfig::LoadThemeColorsFromRegistry() +void ColorConfig_Impl::LoadThemeColorsFromRegistry() { ThemeColors& rThemeColors = ThemeColors::GetThemeColors(); @@ -463,16 +472,16 @@ void ColorConfig::LoadThemeColorsFromRegistry() // as more controls support it, we might want to have ColorConfigValue entries in ThemeColors // instead of just colors. for now that seems overkill for just one control. rThemeColors.SetAppBackBitmapFileName( - m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).sBitmapFileName); + GetColorConfigValue(svtools::APPBACKGROUND).sBitmapFileName); rThemeColors.SetAppBackUseBitmap( - m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bUseBitmapBackground); + GetColorConfigValue(svtools::APPBACKGROUND).bUseBitmapBackground); rThemeColors.SetAppBackBitmapStretched( - m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bIsBitmapStretched); + GetColorConfigValue(svtools::APPBACKGROUND).bIsBitmapStretched); ThemeColors::SetThemeCached(true); } -void ColorConfig::SetupTheme() +void ColorConfig_Impl::SetupTheme() { if (ThemeColors::IsThemeDisabled()) { @@ -496,8 +505,8 @@ void ColorConfig::SetupTheme() if (!ThemeColors::IsThemeCached()) { // registry to ColorConfig::m_pImpl - m_pImpl->Load(GetCurrentSchemeName()); - m_pImpl->CommitCurrentSchemeName(); + Load(GetCurrentSchemeName()); + CommitCurrentSchemeName(); // ColorConfig::m_pImpl to static ThemeColors::m_aThemeColors LoadThemeColorsFromRegistry(); @@ -517,15 +526,10 @@ ColorConfig::ColorConfig() } ++nColorRefCount_Impl; m_pImpl->AddListener(this); - SetupTheme(); - - ::Application::AddEventListener( LINK(this, ColorConfig, DataChangedHdl) ); } ColorConfig::~ColorConfig() { - ::Application::RemoveEventListener( LINK(this, ColorConfig, DataChangedHdl) ); - if (comphelper::IsFuzzing()) return; std::unique_lock aGuard( ColorMutex_Impl() ); @@ -738,10 +742,14 @@ Color ColorConfig::GetDefaultColor(ColorConfigEntry eEntry, int nMod) ColorConfigValue ColorConfig::GetColorValue(ColorConfigEntry eEntry, bool bSmart) const { - ColorConfigValue aRet; - if (m_pImpl) - aRet = m_pImpl->GetColorConfigValue(eEntry); + return m_pImpl->GetColorValue(eEntry, bSmart); + return ColorConfigValue(); +} + +ColorConfigValue ColorConfig_Impl::GetColorValue(ColorConfigEntry eEntry, bool bSmart) const +{ + ColorConfigValue aRet = GetColorConfigValue(eEntry); if (bSmart && aRet.nColor == COL_AUTO) aRet.nColor = ColorConfig::GetDefaultColor(eEntry); @@ -751,34 +759,25 @@ ColorConfigValue ColorConfig::GetColorValue(ColorConfigEntry eEntry, bool bSmart const OUString& ColorConfig::GetCurrentSchemeName() { - uno::Sequence<OUString> aNames = m_pImpl->GetSchemeNames(); + return m_pImpl->GetCurrentSchemeName(); +} + +const OUString& ColorConfig_Impl::GetCurrentSchemeName() +{ + uno::Sequence<OUString> aNames = GetSchemeNames(); OUString aCurrentSchemeName = officecfg::Office::UI::ColorScheme::CurrentColorScheme::get().value(); for (const OUString& rSchemeName : aNames) if (rSchemeName == aCurrentSchemeName) - return m_pImpl->GetLoadedScheme(); + return GetLoadedScheme(); // Use "Automatic" as fallback auto pChange(comphelper::ConfigurationChanges::create()); officecfg::Office::UI::ColorScheme::CurrentColorScheme::set(AUTOMATIC_COLOR_SCHEME, pChange); pChange->commit(); - m_pImpl->SetCurrentSchemeName(AUTOMATIC_COLOR_SCHEME); - return m_pImpl->GetLoadedScheme(); -} - -IMPL_LINK( ColorConfig, DataChangedHdl, VclSimpleEvent&, rEvent, void ) -{ - if (rEvent.GetId() == VclEventId::ApplicationDataChanged) - { - DataChangedEvent* pData = static_cast<DataChangedEvent*>(static_cast<VclWindowEvent&>(rEvent).GetData()); - if (pData->GetType() == DataChangedEventType::SETTINGS && - pData->GetFlags() & AllSettingsFlags::STYLE) - { - ThemeColors::SetThemeCached(false); - SetupTheme(); - } - } + SetCurrentSchemeName(AUTOMATIC_COLOR_SCHEME); + return GetLoadedScheme(); } EditableColorConfig::EditableColorConfig() :