summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-09-24 11:25:27 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-10-15 13:39:43 +0200
commit3b729db05553c1a6d461fb41c89a05702f407448 (patch)
tree42a0195fe2dd40a97126b5e0fd4c4d55b737ed10 /sfx2
parentaf908d9f18fbb83a5c393f856026cebefd821f18 (diff)
do not use text-based LOK callback internally
CallbackFlushHandler post-processes LOK messages, but for things like dropping useless invalidations it needs to know the rectangle or the view id, and since the only data it gets are string messages, it needs to convert those back to binary form. Which is slow with large numbers of messages. Add internal LOK callback variant that allows also passing specific data in the original binary form. And then use directly the binary data in CallbackFlushHandler. Change-Id: I8dd30d2ff9c09feadebc31a44d8e6a8ccc306504 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123589 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/view/lokhelper.cxx43
-rw-r--r--sfx2/source/view/viewimp.hxx3
-rw-r--r--sfx2/source/view/viewsh.cxx51
3 files changed, 65 insertions, 32 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index a6c7d207865c..f62497f5ae81 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -374,7 +374,8 @@ void SfxLokHelper::notifyOtherView(const SfxViewShell* pThisView, SfxViewShell c
return;
const OString aPayload = lcl_generateJSON(pThisView, rKey, rPayload);
- pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr());
+ const int viewId = SfxLokHelper::getView(pThisView);
+ pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr(), viewId);
}
void SfxLokHelper::notifyOtherView(const SfxViewShell* pThisView, SfxViewShell const* pOtherView,
@@ -384,7 +385,8 @@ void SfxLokHelper::notifyOtherView(const SfxViewShell* pThisView, SfxViewShell c
if (DisableCallbacks::disabled())
return;
- pOtherView->libreOfficeKitViewCallback(nType, lcl_generateJSON(pThisView, rTree).getStr());
+ const int viewId = SfxLokHelper::getView(pThisView);
+ pOtherView->libreOfficeKitViewCallback(nType, lcl_generateJSON(pThisView, rTree).getStr(), viewId);
}
void SfxLokHelper::notifyOtherViews(const SfxViewShell* pThisView, int nType, std::string_view rKey,
@@ -396,6 +398,7 @@ void SfxLokHelper::notifyOtherViews(const SfxViewShell* pThisView, int nType, st
// Cache the payload so we only have to generate it once, at most.
OString aPayload;
+ int viewId = -1;
const ViewShellDocId nCurrentDocId = pThisView->GetDocId();
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
@@ -405,9 +408,12 @@ void SfxLokHelper::notifyOtherViews(const SfxViewShell* pThisView, int nType, st
{
// Payload is only dependent on pThisView.
if (aPayload.isEmpty())
+ {
aPayload = lcl_generateJSON(pThisView, rKey, rPayload);
+ viewId = SfxLokHelper::getView(pThisView);
+ }
- pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr());
+ pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr(), viewId);
}
pViewShell = SfxViewShell::GetNext(*pViewShell);
@@ -423,6 +429,7 @@ void SfxLokHelper::notifyOtherViews(const SfxViewShell* pThisView, int nType,
// Cache the payload so we only have to generate it once, at most.
OString aPayload;
+ int viewId = -1;
const ViewShellDocId nCurrentDocId = pThisView->GetDocId();
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
@@ -432,9 +439,12 @@ void SfxLokHelper::notifyOtherViews(const SfxViewShell* pThisView, int nType,
{
// Payload is only dependent on pThisView.
if (aPayload.isEmpty())
+ {
aPayload = lcl_generateJSON(pThisView, rTree);
+ viewId = SfxLokHelper::getView(pThisView);
+ }
- pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr());
+ pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr(), viewId);
}
pViewShell = SfxViewShell::GetNext(*pViewShell);
@@ -513,17 +523,8 @@ void SfxLokHelper::notifyInvalidation(SfxViewShell const* pThisView, tools::Rect
if (DisableCallbacks::disabled())
return;
- OStringBuffer aBuf(64);
- if (pRect)
- aBuf.append(pRect->toString());
- else
- aBuf.append("EMPTY");
- if (comphelper::LibreOfficeKit::isPartInInvalidation())
- {
- aBuf.append(", ");
- aBuf.append(static_cast<sal_Int32>(pThisView->getPart()));
- }
- pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_TILES, aBuf.makeStringAndClear().getStr());
+ const int nPart = comphelper::LibreOfficeKit::isPartInInvalidation() ? pThisView->getPart() : INT_MIN;
+ pThisView->libreOfficeKitViewInvalidateTilesCallback(pRect, nPart);
}
void SfxLokHelper::notifyDocumentSizeChanged(SfxViewShell const* pThisView, const OString& rPayload, vcl::ITiledRenderable* pDoc, bool bInvalidateAll)
@@ -536,8 +537,7 @@ void SfxLokHelper::notifyDocumentSizeChanged(SfxViewShell const* pThisView, cons
for (int i = 0; i < pDoc->getParts(); ++i)
{
tools::Rectangle aRectangle(0, 0, 1000000000, 1000000000);
- OString sPayload = aRectangle.toString() + ", " + OString::number(i);
- pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_TILES, sPayload.getStr());
+ pThisView->libreOfficeKitViewInvalidateTilesCallback(&aRectangle, i);
}
}
pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, rPayload.getStr());
@@ -570,20 +570,21 @@ void SfxLokHelper::notifyVisCursorInvalidation(OutlinerViewShell const* pThisVie
if (DisableCallbacks::disabled())
return;
- OString sPayload;
if (comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation())
{
OString sHyperlink = rHyperlink.isEmpty() ? "{}" : rHyperlink;
- sPayload = OString::Concat("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView()) +
+ OString sPayload = OString::Concat("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView()) +
"\", \"rectangle\": \"" + rRectangle +
"\", \"mispelledWord\": \"" + OString::number(bMispelledWord ? 1 : 0) +
"\", \"hyperlink\": " + sHyperlink + " }";
+ const int viewId = SfxLokHelper::getView();
+ pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sPayload.getStr(), viewId);
}
else
{
- sPayload = rRectangle;
+ OString sPayload = rRectangle;
+ pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sPayload.getStr());
}
- pThisView->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sPayload.getStr());
}
void SfxLokHelper::notifyAllViews(int nType, const OString& rPayload)
diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx
index cf6892dec4e9..54e8267be658 100644
--- a/sfx2/source/view/viewimp.hxx
+++ b/sfx2/source/view/viewimp.hxx
@@ -50,8 +50,7 @@ struct SfxViewShell_Impl
mutable std::vector<SfxInPlaceClient*> maIPClients;
- LibreOfficeKitCallback m_pLibreOfficeKitViewCallback;
- void* m_pLibreOfficeKitViewData;
+ SfxLokCallbackInterface* m_pLibreOfficeKitViewCallback;
/// Set if we are in the middle of a tiled search.
bool m_bTiledSearching;
static sal_uInt32 m_nLastViewShellId;
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 009c16f9feb4..9f5ff0e1ff85 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -20,6 +20,7 @@
#include <config_features.h>
#include <sal/log.hxx>
+#include <rtl/strbuf.hxx>
#include <svl/stritem.hxx>
#include <svl/eitem.hxx>
#include <svl/whiter.hxx>
@@ -82,6 +83,7 @@
#include <sfx2/sfxsids.hrc>
#include <sfx2/objface.hxx>
#include <sfx2/lokhelper.hxx>
+#include <sfx2/lokcallback.hxx>
#include <openuriexternally.hxx>
#include <vector>
@@ -221,7 +223,6 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags, ViewShellDo
: m_bHasPrintOptions(nFlags & SfxViewShellFlags::HAS_PRINTOPTIONS)
, m_nFamily(0xFFFF) // undefined, default set by TemplateDialog
, m_pLibreOfficeKitViewCallback(nullptr)
-, m_pLibreOfficeKitViewData(nullptr)
, m_bTiledSearching(false)
, m_nViewShellId(SfxViewShell_Impl::m_nLastViewShellId++)
, m_nDocId(nDocId)
@@ -1429,14 +1430,14 @@ bool SfxViewShell::ExecKey_Impl(const KeyEvent& aKey)
return pImpl->m_xAccExec->execute(aKey.GetKeyCode());
}
-void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCallback, void* pData)
+void SfxViewShell::setLibreOfficeKitViewCallback(SfxLokCallbackInterface* pCallback)
{
+ pImpl->m_pLibreOfficeKitViewCallback = nullptr;
pImpl->m_pLibreOfficeKitViewCallback = pCallback;
- pImpl->m_pLibreOfficeKitViewData = pData;
afterCallbackRegistered();
- if (!pCallback)
+ if (!pImpl->m_pLibreOfficeKitViewCallback)
return;
// Ask other views to tell us about their cursors.
@@ -1449,10 +1450,10 @@ void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCa
}
}
-void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) const
+static bool ignoreLibreOfficeKitViewCallback(int nType, const SfxViewShell_Impl* pImpl)
{
if (!comphelper::LibreOfficeKit::isActive())
- return;
+ return true;
if (comphelper::LibreOfficeKit::isTiledPainting())
{
@@ -1463,7 +1464,7 @@ void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) c
break;
default:
// Reject e.g. invalidate during paint.
- return;
+ return true;
}
}
@@ -1477,12 +1478,44 @@ void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) c
case LOK_CALLBACK_TEXT_SELECTION_END:
case LOK_CALLBACK_GRAPHIC_SELECTION:
case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION:
- return;
+ return true;
}
}
+ return false;
+}
+
+void SfxViewShell::libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart) const
+{
+ if (ignoreLibreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_TILES, pImpl.get()))
+ return;
+ if (pImpl->m_pLibreOfficeKitViewCallback)
+ pImpl->m_pLibreOfficeKitViewCallback->libreOfficeKitViewInvalidateTilesCallback(pRect, nPart);
+ else
+ SAL_INFO(
+ "sfx.view",
+ "SfxViewShell::libreOfficeKitViewInvalidateTilesCallback no callback set!");
+}
+
+void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload, int nViewId) const
+{
+ if (ignoreLibreOfficeKitViewCallback(nType, pImpl.get()))
+ return;
+ if (pImpl->m_pLibreOfficeKitViewCallback)
+ pImpl->m_pLibreOfficeKitViewCallback->libreOfficeKitViewCallback(nType, pPayload, nViewId);
+ else
+ SAL_INFO(
+ "sfx.view",
+ "SfxViewShell::libreOfficeKitViewCallback no callback set! Dropped payload of type "
+ << lokCallbackTypeToString(nType) << ": [" << pPayload << ']');
+}
+
+void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) const
+{
+ if (ignoreLibreOfficeKitViewCallback(nType, pImpl.get()))
+ return;
if (pImpl->m_pLibreOfficeKitViewCallback)
- pImpl->m_pLibreOfficeKitViewCallback(nType, pPayload, pImpl->m_pLibreOfficeKitViewData);
+ pImpl->m_pLibreOfficeKitViewCallback->libreOfficeKitViewCallback(nType, pPayload);
else
SAL_INFO(
"sfx.view",