include/svx/svdpagv.hxx                               |   10 +++--
 sc/qa/unit/tiledrendering/data/invalidate-on-save.ods |binary
 sc/qa/unit/tiledrendering/tiledrendering.cxx          |   32 ++++++++++++++++++
 svx/source/svdraw/svdpagv.cxx                         |   17 ++++++---
 svx/source/svdraw/svdpntv.cxx                         |   15 ++------
 5 files changed, 55 insertions(+), 19 deletions(-)

New commits:
commit 916fc836f19b5c63da501acdb6221945b13c6d81
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Jan 18 09:31:17 2024 +0000
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Jan 19 14:05:34 2024 +0100

    cool#7769 Reduce unnecessary invalidations on calc save
    
    https://github.com/CollaboraOnline/online/issues/7769
    
    Reduce unnecessary invalidations. Don't invalidate windows
    if layer visibility didn't really change.
    
    Change-Id: Ic2abd78d60aea2e8676c8e56608cf51e941f5918
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162303
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/svx/svdpagv.hxx b/include/svx/svdpagv.hxx
index 2f77dfa6692a..a59f1669b09e 100644
--- a/include/svx/svdpagv.hxx
+++ b/include/svx/svdpagv.hxx
@@ -102,7 +102,8 @@ public:
 private:
     void ImpInvalidateHelpLineArea(sal_uInt16 nNum) const;
 
-    void SetLayer(const OUString& rName, SdrLayerIDSet& rBS, bool bJa);
+    // return true if changed, false if unchanged
+    bool SetLayer(const OUString& rName, SdrLayerIDSet& rBS, bool bJa);
     bool IsLayer(const OUString& rName, const SdrLayerIDSet& rBS) const;
 
     /// Let's see if the current Group (pCurrentGroup) is still inserted
@@ -182,10 +183,13 @@ public:
     tools::Rectangle& MarkBound() { return aMarkBound; }
     tools::Rectangle& MarkSnap() { return aMarkSnap; }
 
-    void SetLayerVisible(const OUString& rName, bool bShow) {
-        SetLayer(rName, aLayerVisi, bShow);
+    bool SetLayerVisible(const OUString& rName, bool bShow) {
+        const bool bChanged = SetLayer(rName, aLayerVisi, bShow);
+        if (!bChanged)
+            return false;
         if(!bShow) AdjHdl();
         InvalidateAllWin();
+        return true;
     }
     bool IsLayerVisible(const OUString& rName) const { return IsLayer(rName, 
aLayerVisi); }
 
diff --git a/sc/qa/unit/tiledrendering/data/invalidate-on-save.ods 
b/sc/qa/unit/tiledrendering/data/invalidate-on-save.ods
new file mode 100644
index 000000000000..efe2c225a410
Binary files /dev/null and 
b/sc/qa/unit/tiledrendering/data/invalidate-on-save.ods differ
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index fbd5beba3b71..b3813aa1c85c 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -164,6 +164,7 @@ public:
     void testStatusBarLocale();
     void testLongFirstColumnMouseClick();
     void testSidebarLocale();
+    void testNoInvalidateOnSave();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnHeaders);
@@ -238,6 +239,7 @@ public:
     CPPUNIT_TEST(testStatusBarLocale);
     CPPUNIT_TEST(testLongFirstColumnMouseClick);
     CPPUNIT_TEST(testSidebarLocale);
+    CPPUNIT_TEST(testNoInvalidateOnSave);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3656,6 +3658,36 @@ void ScTiledRenderingTest::testSidebarLocale()
     CPPUNIT_ASSERT_EQUAL(std::string("de-DE"), aLocale);
 }
 
+// Saving shouldn't trigger an invalidation
+void ScTiledRenderingTest::testNoInvalidateOnSave()
+{
+    comphelper::LibreOfficeKit::setCompatFlag(
+        comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
+
+    loadFromURL(u"invalidate-on-save.ods");
+
+    // .uno:Save modifies the original file, make a copy first
+    saveAndReload("calc8");
+    ScModelObj* pModelObj = 
comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
+    CPPUNIT_ASSERT(pModelObj);
+    
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+
+    ScTabViewShell* pView = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pView);
+
+    Scheduler::ProcessEventsToIdle();
+
+    // track invalidations
+    ViewCallback aView;
+
+    uno::Sequence<beans::PropertyValue> aArgs;
+    dispatchCommand(mxComponent, ".uno:Save", aArgs);
+
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT(!aView.m_bInvalidateTiles);
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx
index 60cd8cfe8ca0..c399c4339d66 100644
--- a/svx/source/svdraw/svdpagv.cxx
+++ b/svx/source/svdraw/svdpagv.cxx
@@ -557,15 +557,22 @@ void SdrPageView::AdjHdl()
     GetView().AdjustMarkHdl();
 }
 
-void SdrPageView::SetLayer(const OUString& rName, SdrLayerIDSet& rBS, bool bJa)
+// return true if changed, false if unchanged
+bool SdrPageView::SetLayer(const OUString& rName, SdrLayerIDSet& rBS, bool bJa)
 {
-    if(!GetPage())
-        return;
+    if (!GetPage())
+        return false;
 
     SdrLayerID nID = GetPage()->GetLayerAdmin().GetLayerID(rName);
 
-    if(SDRLAYER_NOTFOUND != nID)
-        rBS.Set(nID, bJa);
+    if (SDRLAYER_NOTFOUND == nID)
+        return false;
+
+    if (rBS.IsSet(nID) == bJa)
+        return false;
+
+    rBS.Set(nID, bJa);
+    return true;
 }
 
 bool SdrPageView::IsLayer(const OUString& rName, const SdrLayerIDSet& rBS) 
const
diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx
index 566e07b2d853..1cb47c6aee3e 100644
--- a/svx/source/svdraw/svdpntv.cxx
+++ b/svx/source/svdraw/svdpntv.cxx
@@ -415,22 +415,15 @@ void 
SdrPaintView::DeleteDeviceFromPaintView(OutputDevice& rOldDev)
 
 void SdrPaintView::SetLayerVisible(const OUString& rName, bool bShow)
 {
-    if(mpPageView)
-    {
-        mpPageView->SetLayerVisible(rName, bShow);
-    }
-
+    const bool bChanged = mpPageView && mpPageView->SetLayerVisible(rName, 
bShow);
+    if (!bChanged)
+        return;
     InvalidateAllWin();
 }
 
 bool SdrPaintView::IsLayerVisible(const OUString& rName) const
 {
-    if(mpPageView)
-    {
-        return mpPageView->IsLayerVisible(rName);
-    }
-
-    return false;
+    return mpPageView && mpPageView->IsLayerVisible(rName);
 }
 
 void SdrPaintView::SetLayerLocked(const OUString& rName, bool bLock)

Reply via email to