diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-10-15 08:43:23 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-10-24 01:40:45 +0200 |
commit | 273a25c796fca9afa0dfadac57dc3f336831221c (patch) | |
tree | 3efb1e505e27164bcdb2c164c59a48c814221ffe /sfx2 | |
parent | 667c2499d861cfcd26935fc0512cb5aaf602c4c5 (diff) |
change some LOK internal updates to be pull model instead of push
Some LOK messages may get called very often, such as updates about
cursor position. And since only the last one matters, they get
generated every time, which costs some time, and then later except
for one they get all discard again from CallbackFlushHandler queue,
which again costs time.
Change the model to instead only set an 'updated' flag, and
CallbackFlushHandler will request the actual message payload only
before flushing.
This commit changes LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR and
LOK_CALLBACK_INVALIDATE_VIEW_CURSOR to work this way.
Change-Id: I376be63176c0b4b5cb492fbf529c21ed01b35481
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124083
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 69 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 33 |
2 files changed, 91 insertions, 11 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 35b61798c272..cd93f9b4dd55 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -357,15 +357,21 @@ static OString lcl_generateJSON(const SfxViewShell* pView, const boost::property return OString(aString.c_str(), aString.size()).trim(); } -static inline OString lcl_generateJSON(const SfxViewShell* pView, std::string_view rKey, +static inline OString lcl_generateJSON(const SfxViewShell* pView, int nViewId, std::string_view rKey, const OString& rPayload) { assert(pView != nullptr && "pView must be valid"); - return OString::Concat("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView(pView)) + return OString::Concat("{ \"viewId\": \"") + OString::number(nViewId) + "\", \"part\": \"" + OString::number(pView->getPart()) + "\", \"" + rKey + "\": \"" + lcl_sanitizeJSONAsValue(rPayload) + "\" }"; } +static inline OString lcl_generateJSON(const SfxViewShell* pView, std::string_view rKey, + const OString& rPayload) +{ + return lcl_generateJSON(pView, SfxLokHelper::getView(pView), rKey, rPayload); +} + void SfxLokHelper::notifyOtherView(const SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, std::string_view rKey, const OString& rPayload) { @@ -451,6 +457,11 @@ void SfxLokHelper::notifyOtherViews(const SfxViewShell* pThisView, int nType, } } +OString SfxLokHelper::makePayloadJSON(const SfxViewShell* pThisView, int nViewId, std::string_view rKey, const OString& rPayload) +{ + return lcl_generateJSON(pThisView, nViewId, rKey, rPayload); +} + namespace { OUString lcl_getNameForSlot(const SfxViewShell* pShell, sal_uInt16 nWhich) { @@ -565,25 +576,20 @@ void SfxLokHelper::notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc } } -void SfxLokHelper::notifyVisCursorInvalidation(OutlinerViewShell const* pThisView, const OString& rRectangle, bool bMispelledWord, const OString& rHyperlink) +OString SfxLokHelper::makeVisCursorInvalidation(int nViewId, const OString& rRectangle, + bool bMispelledWord, const OString& rHyperlink) { - if (DisableCallbacks::disabled()) - return; - if (comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation()) { OString sHyperlink = rHyperlink.isEmpty() ? "{}" : rHyperlink; - OString sPayload = OString::Concat("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView()) + + return OString::Concat("{ \"viewId\": \"") + OString::number(nViewId) + "\", \"rectangle\": \"" + rRectangle + "\", \"mispelledWord\": \"" + OString::number(bMispelledWord ? 1 : 0) + "\", \"hyperlink\": " + sHyperlink + " }"; - const int viewId = SfxLokHelper::getView(); - pThisView->libreOfficeKitViewCallbackWithViewId(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sPayload.getStr(), viewId); } else { - OString sPayload = rRectangle; - pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sPayload.getStr()); + return rRectangle; } } @@ -615,6 +621,47 @@ void SfxLokHelper::notifyContextChange(SfxViewShell const* pViewShell, const OUS pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_CHANGED, aBuffer.getStr()); } +void SfxLokHelper::notifyUpdate(SfxViewShell const* pThisView, int nType) +{ + if (DisableCallbacks::disabled()) + return; + + pThisView->libreOfficeKitViewUpdatedCallback(nType); +} + +void SfxLokHelper::notifyUpdatePerViewId(SfxViewShell const* pThisView, int nType) +{ + notifyUpdatePerViewId(pThisView, pThisView, pThisView, nType); +} + +void SfxLokHelper::notifyUpdatePerViewId(SfxViewShell const* pTargetShell, SfxViewShell const* pViewShell, + SfxViewShell const* pSourceShell, int nType) +{ + if (DisableCallbacks::disabled()) + return; + + int viewId = SfxLokHelper::getView(pViewShell); + int sourceViewId = SfxLokHelper::getView(pSourceShell); + pTargetShell->libreOfficeKitViewUpdatedCallbackPerViewId(nType, viewId, sourceViewId); +} + +void SfxLokHelper::notifyOtherViewsUpdatePerViewId(SfxViewShell const* pThisView, int nType) +{ + assert(pThisView != nullptr && "pThisView must be valid"); + if (DisableCallbacks::disabled()) + return; + + int viewId = SfxLokHelper::getView(pThisView); + const ViewShellDocId nCurrentDocId = pThisView->GetDocId(); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + if (pViewShell != pThisView && nCurrentDocId == pViewShell->GetDocId()) + pViewShell->libreOfficeKitViewUpdatedCallbackPerViewId(nType, viewId, viewId); + + pViewShell = SfxViewShell::GetNext(*pViewShell); + } +} namespace { diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 5766fb48205c..ecfd3f97bba4 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1522,6 +1522,32 @@ void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) c << lokCallbackTypeToString(nType) << ": [" << pPayload << ']'); } +void SfxViewShell::libreOfficeKitViewUpdatedCallback(int nType) const +{ + if (ignoreLibreOfficeKitViewCallback(nType, pImpl.get())) + return; + if (pImpl->m_pLibreOfficeKitViewCallback) + pImpl->m_pLibreOfficeKitViewCallback->libreOfficeKitViewUpdatedCallback(nType); + else + SAL_INFO( + "sfx.view", + "SfxViewShell::libreOfficeKitViewUpdatedCallback no callback set! Dropped payload of type " + << lokCallbackTypeToString(nType)); +} + +void SfxViewShell::libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId, int nSourceViewId) const +{ + if (ignoreLibreOfficeKitViewCallback(nType, pImpl.get())) + return; + if (pImpl->m_pLibreOfficeKitViewCallback) + pImpl->m_pLibreOfficeKitViewCallback->libreOfficeKitViewUpdatedCallbackPerViewId(nType, nViewId, nSourceViewId); + else + SAL_INFO( + "sfx.view", + "SfxViewShell::libreOfficeKitViewUpdatedCallbackPerViewId no callback set! Dropped payload of type " + << lokCallbackTypeToString(nType)); +} + void SfxViewShell::afterCallbackRegistered() { } @@ -1531,6 +1557,13 @@ void SfxViewShell::flushPendingLOKInvalidateTiles() // SfxViewShell itself does not delay any tile invalidations. } +OString SfxViewShell::getLOKPayload(int nType, int /*nViewId*/) const +{ + // SfxViewShell itself currently doesn't handle any updated-payload types. + SAL_WARN("sfx.view", "SfxViewShell::getLOKPayload unhandled type " << lokCallbackTypeToString(nType)); + abort(); +} + vcl::Window* SfxViewShell::GetEditWindowForActiveOLEObj() const { vcl::Window* pEditWin = nullptr; |