summaryrefslogtreecommitdiff
path: root/desktop/inc
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 /desktop/inc
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 'desktop/inc')
-rw-r--r--desktop/inc/lib/init.hxx59
1 files changed, 47 insertions, 12 deletions
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 291dbff069bb..b31b52eabaa0 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -26,6 +26,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <tools/gen.hxx>
+#include <sfx2/lokcallback.hxx>
#include <sfx2/lokhelper.hxx>
#include <desktop/dllapi.h>
@@ -45,6 +46,12 @@ namespace desktop {
{
}
+ RectangleAndPart(const tools::Rectangle* pRect, int nPart)
+ : m_aRectangle( pRect ? *pRect : tools::Rectangle(0, 0, SfxLokHelper::MaxTwips, SfxLokHelper::MaxTwips))
+ , m_nPart(nPart)
+ {
+ }
+
OString toString() const
{
if (m_nPart >= -1)
@@ -70,13 +77,13 @@ namespace desktop {
static RectangleAndPart Create(const std::string& rPayload);
};
- class DESKTOP_DLLPUBLIC CallbackFlushHandler final : public Idle
+ class DESKTOP_DLLPUBLIC CallbackFlushHandler final : public Idle, public SfxLokCallbackInterface
{
public:
explicit CallbackFlushHandler(LibreOfficeKitDocument* pDocument, LibreOfficeKitCallback pCallback, void* pData);
virtual ~CallbackFlushHandler() override;
virtual void Invoke() override;
- static void callback(const int type, const char* payload, void* data);
+ // TODO This should be dropped and the binary libreOfficeKitViewCallback() variants should be called?
void queue(const int type, const char* data);
/// Disables callbacks on this handler. Must match with identical count
@@ -91,17 +98,33 @@ namespace desktop {
void addViewStates(int viewId);
void removeViewStates(int viewId);
+ // SfxLockCallbackInterface
+ 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:
struct CallbackData
{
- CallbackData(const std::string& payload)
- : PayloadString(payload)
+ CallbackData(const char* payload)
+ : PayloadString(payload ? payload : "(nil)")
{
}
- /// Parse and set the RectangleAndPart object and return it. Clobbers PayloadString.
- RectangleAndPart& setRectangleAndPart(const std::string& payload);
- /// Set a RectangleAndPart object and update PayloadString.
- void setRectangleAndPart(const RectangleAndPart& rRectAndPart);
+ CallbackData(const char* payload, int viewId)
+ : PayloadString(payload ? payload : "(nil)")
+ , PayloadObject(viewId)
+ {
+ }
+
+ CallbackData(const tools::Rectangle* pRect, int viewId)
+ : PayloadObject(RectangleAndPart(pRect, viewId))
+ { // PayloadString will be done on demand
+ }
+
+ const std::string& getPayload() const;
+ /// Update a RectangleAndPart object and update PayloadString if necessary.
+ void updateRectangleAndPart(const RectangleAndPart& rRectAndPart);
/// Return the parsed RectangleAndPart instance.
const RectangleAndPart& getRectangleAndPart() const;
/// Parse and set the JSON object and return it. Clobbers PayloadString.
@@ -111,29 +134,41 @@ namespace desktop {
/// Return the parsed JSON instance.
const boost::property_tree::ptree& getJson() const;
+ int getViewId() const;
+
+ bool isEmpty() const
+ {
+ return PayloadString.empty() && PayloadObject.which() == 0;
+ }
+ void clear()
+ {
+ PayloadString.clear();
+ PayloadObject = boost::blank();
+ }
+
/// Validate that the payload and parsed object match.
bool validate() const;
/// Returns true iff there is cached data.
bool isCached() const { return PayloadObject.which() != 0; }
- std::string PayloadString;
-
private:
+ mutable std::string PayloadString;
+
/// The parsed payload cache. Update validate() when changing this.
- boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree> PayloadObject;
+ mutable boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree, int> PayloadObject;
};
typedef std::vector<int> queue_type1;
typedef std::vector<CallbackData> queue_type2;
- private:
bool removeAll(int type);
bool removeAll(int type, const std::function<bool (const CallbackData&)>& rTestFunc);
bool processInvalidateTilesEvent(int type, CallbackData& aCallbackData);
bool processWindowEvent(int type, CallbackData& aCallbackData);
queue_type2::iterator toQueue2(queue_type1::iterator);
queue_type2::reverse_iterator toQueue2(queue_type1::reverse_iterator);
+ void queue(const int type, CallbackData& data);
/** we frequently want to scan the queue, and mostly when we do so, we only care about the element type
so we split the queue in 2 to make the scanning cache friendly. */