From cb60edbc2c0725f0309a5b934f41e999a1fe0c5f Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Tue, 12 Oct 2021 14:24:44 +0200 Subject: delay, collect and compress LOK invalidations for Writer views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due the to way views are updated on any document change, invalidations are at least O(n^2), and since LOK may use a number of views and for each view the entire document is considered to be the view area, this can lead to a huge number of invalidations that are mostly the same repeated rectangles. Change-Id: I63682958d2fc388344641dcd19fa1d2b39054b51 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123617 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- desktop/inc/lib/init.hxx | 3 +++ desktop/source/lib/init.cxx | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'desktop') diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx index b31b52eabaa0..9f15377ba0ec 100644 --- a/desktop/inc/lib/init.hxx +++ b/desktop/inc/lib/init.hxx @@ -98,6 +98,8 @@ namespace desktop { void addViewStates(int viewId); void removeViewStates(int viewId); + void setViewId( int viewId ) { m_viewId = viewId; } + // SfxLockCallbackInterface virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override; virtual void libreOfficeKitViewCallback(int nType, const char* pPayload, int nViewId) override; @@ -177,6 +179,7 @@ namespace desktop { std::map m_states; std::unordered_map> m_viewStates; LibreOfficeKitDocument* m_pDocument; + int m_viewId = -1; // view id of the associated SfxViewShell LibreOfficeKitCallback m_pCallback; void *m_pData; int m_nDisableCallbacks; diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 521fe2a18be9..535cf9808d4d 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2039,6 +2039,14 @@ void CallbackFlushHandler::Invoke() if (!m_pCallback) return; + // Get any pending invalidate tile events. This will call our callbacks, + // so it must be done before taking the mutex. + if(SfxViewShell* viewShell = SfxViewShell::GetFirst( false, + [this](const SfxViewShell* shell) { return shell->GetViewShellId().get() == m_viewId; } )) + { + viewShell->flushPendingLOKInvalidateTiles(); + } + std::scoped_lock lock(m_mutex); SAL_INFO("lok", "Flushing " << m_queue1.size() << " elements."); @@ -3423,7 +3431,7 @@ static void doc_paintPartTile(LibreOfficeKitDocument* pThis, { if (pViewShell->getPart() == nPart) { - nViewId = static_cast(pViewShell->GetViewShellId()); + nViewId = pViewShell->GetViewShellId().get(); doc_setView(pThis, nViewId); break; } @@ -3556,6 +3564,7 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis, if (SfxViewShell* pViewShell = SfxViewShell::Current()) { + pDocument->mpCallbackFlushHandlers[nView]->setViewId(pViewShell->GetViewShellId().get()); pViewShell->setLibreOfficeKitViewCallback(pDocument->mpCallbackFlushHandlers[nView].get()); } } @@ -3564,6 +3573,7 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis, if (SfxViewShell* pViewShell = SfxViewShell::Current()) { pViewShell->setLibreOfficeKitViewCallback(nullptr); + pDocument->mpCallbackFlushHandlers[nView]->setViewId(-1); } } } -- cgit