summaryrefslogtreecommitdiff
path: root/sd
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:41:04 +0200
commitabb8d6e97029b1e344de04db31e3f616360e52aa (patch)
tree514a28b9b4b152f9ba1901668026f2274e7205b2 /sd
parente10b8707d01ff2a31f0d62641eb45adc9f7fde92 (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/+/123627 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/qa/unit/tiledrendering/CallbackRecorder.hxx26
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx82
2 files changed, 54 insertions, 54 deletions
diff --git a/sd/qa/unit/tiledrendering/CallbackRecorder.hxx b/sd/qa/unit/tiledrendering/CallbackRecorder.hxx
index 7e6c8a42d07d..6c4faf81edae 100644
--- a/sd/qa/unit/tiledrendering/CallbackRecorder.hxx
+++ b/sd/qa/unit/tiledrendering/CallbackRecorder.hxx
@@ -14,6 +14,7 @@
#include <comphelper/string.hxx>
#include <osl/conditn.hxx>
#include <sfx2/viewsh.hxx>
+#include <sfx2/lokcallback.hxx>
namespace
{
@@ -44,7 +45,7 @@ void lcl_convertRectangle(const OUString& rString, tools::Rectangle& rRectangle)
}
}
-struct CallbackRecorder
+struct CallbackRecorder : public SfxLokCallbackInterface
{
CallbackRecorder()
: m_bFound(true)
@@ -67,22 +68,16 @@ struct CallbackRecorder
/// For document size changed callback.
osl::Condition m_aDocumentSizeCondition;
- static void callback(int nType, const char* pPayload, void* pData)
+ void libreOfficeKitViewCallback(int nType, const char* pPayload) override
{
- static_cast<CallbackRecorder*>(pData)->processCallback(nType, pPayload);
+ libreOfficeKitViewCallback(nType, pPayload, -1);
}
-
- void processCallback(int nType, const char* pPayload)
+ void libreOfficeKitViewCallback(int nType, const char* pPayload, int /*nViewId*/) override
{
switch (nType)
{
case LOK_CALLBACK_INVALIDATE_TILES:
- {
- OUString aPayload = OUString::createFromAscii(pPayload);
- if (aPayload != "EMPTY" && m_aInvalidation.IsEmpty())
- lcl_convertRectangle(aPayload, m_aInvalidation);
- }
- break;
+ abort();
case LOK_CALLBACK_TEXT_SELECTION:
{
OUString aPayload = OUString::createFromAscii(pPayload);
@@ -136,9 +131,16 @@ struct CallbackRecorder
}
}
+ virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect,
+ int /*nPart*/) override
+ {
+ if (pRect != nullptr && m_aInvalidation.IsEmpty())
+ m_aInvalidation = *pRect;
+ }
+
void registerCallbacksFor(SfxViewShell& rViewShell)
{
- rViewShell.registerLibreOfficeKitViewCallback(&CallbackRecorder::callback, this);
+ rViewShell.setLibreOfficeKitViewCallback(this);
}
};
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 5c852d854c90..211622a795bf 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -15,6 +15,7 @@
#include <boost/property_tree/json_parser.hpp>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <sfx2/lokhelper.hxx>
+#include <sfx2/lokcallback.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include <comphelper/dispatchcommand.hxx>
#include <comphelper/processfactory.hxx>
@@ -71,7 +72,7 @@ static std::ostream& operator<<(std::ostream& os, ViewShellId id)
return os;
}
-class SdTiledRenderingTest : public SdModelTestBase, public XmlTestTools
+class SdTiledRenderingTest : public SdModelTestBase, public XmlTestTools, public SfxLokCallbackInterface
{
public:
SdTiledRenderingTest();
@@ -193,10 +194,13 @@ public:
CPPUNIT_TEST_SUITE_END();
+ virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override;
+ virtual void libreOfficeKitViewCallback(int nType, const char* pPayload, int nViewId) override;
+ virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect,
+ int nPart) override;
+
private:
SdXImpressDocument* createDoc(const char* pName, const uno::Sequence<beans::PropertyValue>& rArguments = uno::Sequence<beans::PropertyValue>());
- static void callback(int nType, const char* pPayload, void* pData);
- void callbackImpl(int nType, const char* pPayload);
xmlDocUniquePtr parseXmlDump();
uno::Reference<lang::XComponent> mxComponent;
@@ -258,11 +262,6 @@ SdXImpressDocument* SdTiledRenderingTest::createDoc(const char* pName, const uno
return pImpressDocument;
}
-void SdTiledRenderingTest::callback(int nType, const char* pPayload, void* pData)
-{
- static_cast<SdTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload);
-}
-
namespace
{
@@ -295,17 +294,17 @@ void lcl_convertRectangle(const OUString& rString, ::tools::Rectangle& rRectangl
} // end anonymous namespace
-void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
+void SdTiledRenderingTest::libreOfficeKitViewCallback(int nType, const char* pPayload, int /*nViewId*/)
+{
+ libreOfficeKitViewCallback(nType, pPayload); // the view id is also included in payload
+}
+
+void SdTiledRenderingTest::libreOfficeKitViewCallback(int nType, const char* pPayload)
{
switch (nType)
{
case LOK_CALLBACK_INVALIDATE_TILES:
- {
- OUString aPayload = OUString::createFromAscii(pPayload);
- if (aPayload != "EMPTY" && m_aInvalidation.IsEmpty())
- lcl_convertRectangle(aPayload, m_aInvalidation);
- }
- break;
+ abort();
case LOK_CALLBACK_TEXT_SELECTION:
{
OUString aPayload = OUString::createFromAscii(pPayload);
@@ -355,6 +354,13 @@ void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
}
}
+void SdTiledRenderingTest::libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect,
+ int /*nPart*/)
+{
+ if (pRect != nullptr && m_aInvalidation.IsEmpty())
+ m_aInvalidation = *pRect;
+}
+
xmlDocUniquePtr SdTiledRenderingTest::parseXmlDump()
{
if (m_pXmlBuffer)
@@ -394,7 +400,7 @@ void SdTiledRenderingTest::testRegisterCallback()
{
SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
- pViewShell->GetViewShellBase().registerLibreOfficeKitViewCallback(&SdTiledRenderingTest::callback, this);
+ pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(this);
// Start text edit of the empty title shape.
SdPage* pActualPage = pViewShell->GetActualPage();
@@ -624,7 +630,7 @@ void SdTiledRenderingTest::testInsertDeletePage()
{
SdXImpressDocument* pXImpressDocument = createDoc("insert-delete.odp");
sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
- pViewShell->GetViewShellBase().registerLibreOfficeKitViewCallback(&SdTiledRenderingTest::callback, this);
+ pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(this);
SdDrawDocument* pDoc = pXImpressDocument->GetDocShell()->GetDoc();
CPPUNIT_ASSERT(pDoc);
@@ -876,7 +882,7 @@ void SdTiledRenderingTest::testResizeTableColumn()
namespace {
/// A view callback tracks callbacks invoked on one specific view.
-class ViewCallback final
+class ViewCallback final : public SfxLokCallbackInterface
{
SfxViewShell* mpViewShell;
int mnView;
@@ -907,42 +913,27 @@ public:
m_bViewSelectionSet(false)
{
mpViewShell = SfxViewShell::Current();
- mpViewShell->registerLibreOfficeKitViewCallback(&ViewCallback::callback, this);
+ mpViewShell->setLibreOfficeKitViewCallback(this);
mnView = SfxLokHelper::getView();
}
~ViewCallback()
{
SfxLokHelper::setView(mnView);
- mpViewShell->registerLibreOfficeKitViewCallback(nullptr, nullptr);
+ mpViewShell->setLibreOfficeKitViewCallback(nullptr);
}
- static void callback(int nType, const char* pPayload, void* pData)
+ virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override
{
- static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
+ libreOfficeKitViewCallback(nType, pPayload, -1);
}
- void callbackImpl(int nType, const char* pPayload)
+ virtual void libreOfficeKitViewCallback(int nType, const char* pPayload, int nViewId) override
{
switch (nType)
{
case LOK_CALLBACK_INVALIDATE_TILES:
- {
- m_bTilesInvalidated = true;
- OString text(pPayload);
- if (!text.startsWith("EMPTY"))
- {
- uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload));
- CPPUNIT_ASSERT(aSeq.getLength() == 4 || aSeq.getLength() == 5);
- tools::Rectangle aInvalidationRect;
- aInvalidationRect.setX(aSeq[0].toInt32());
- aInvalidationRect.setY(aSeq[1].toInt32());
- aInvalidationRect.setWidth(aSeq[2].toInt32());
- aInvalidationRect.setHeight(aSeq[3].toInt32());
- m_aInvalidations.push_back(aInvalidationRect);
- }
- }
- break;
+ abort();
case LOK_CALLBACK_GRAPHIC_SELECTION:
{
m_bGraphicSelectionInvalidated = true;
@@ -978,7 +969,7 @@ public:
std::stringstream aStream(pPayload);
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
- int nViewId = aTree.get_child("viewId").get_value<int>();
+ nViewId = aTree.get_child("viewId").get_value<int>();
m_aViewCursorInvalidations[nViewId] = true;
}
break;
@@ -987,7 +978,7 @@ public:
std::stringstream aStream(pPayload);
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
- const int nViewId = aTree.get_child("viewId").get_value<int>();
+ nViewId = aTree.get_child("viewId").get_value<int>();
m_aViewCursorVisibilities[nViewId] = OString("true") == pPayload;
}
break;
@@ -1006,6 +997,13 @@ public:
break;
}
}
+ virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect,
+ int /*nPart*/) override
+ {
+ m_bTilesInvalidated = true;
+ if (pRect != nullptr)
+ m_aInvalidations.push_back(*pRect);
+ }
};
}
@@ -2455,7 +2453,7 @@ void SdTiledRenderingTest::testCutSelectionChange()
CPPUNIT_ASSERT(pXImpressDocument);
sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
- pViewShell->GetViewShellBase().registerLibreOfficeKitViewCallback(&SdTiledRenderingTest::callback, this);
+ pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(this);
Scheduler::ProcessEventsToIdle();
// Select first text object