summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2016-04-30 14:29:37 -0400
committerJan Holesovsky <kendy@collabora.com>2016-05-09 13:58:29 +0200
commitbc990b011a928ab55b42361415c6eeb5cb9d172c (patch)
treef8e1cb980630e9696a3abf951944b84f0655722f /desktop
parentfda7a716a782f95f89d8b2b980e0b67058d7fec8 (diff)
Some LOK notifications are dropped if they are superseeded by later ones
Change-Id: I323e46a2a6c60b200b182b89199945f99a7f384a Reviewed-on: https://gerrit.libreoffice.org/24567 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com> (cherry picked from commit cf98799fff7ae999bd62cec6486c986bf44000cc)
Diffstat (limited to 'desktop')
-rw-r--r--desktop/inc/lib/init.hxx51
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx108
2 files changed, 98 insertions, 61 deletions
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 66811e40a51c..315f566b0568 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -109,6 +109,35 @@ namespace desktop {
m_queue.emplace_back(type, payload);
+ // These are safe to use the latest state and ignore previous
+ // ones (if any) since the last overrides previous ones.
+ switch (type)
+ {
+ case LOK_CALLBACK_TEXT_SELECTION_START:
+ case LOK_CALLBACK_TEXT_SELECTION_END:
+ case LOK_CALLBACK_TEXT_SELECTION:
+ case LOK_CALLBACK_MOUSE_POINTER:
+ case LOK_CALLBACK_CELL_CURSOR:
+ case LOK_CALLBACK_CELL_FORMULA:
+ case LOK_CALLBACK_CURSOR_VISIBLE:
+ case LOK_CALLBACK_SET_PART:
+ case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
+ removeAllButLast(type);
+ break;
+
+ // These come with rects, so drop earlier
+ // only when the latter includes former ones.
+ case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+ case LOK_CALLBACK_INVALIDATE_TILES:
+ if (payload.empty())
+ {
+ // Invalidating everything means previous
+ // invalidated tiles can be dropped.
+ removeAllButLast(type);
+ }
+ break;
+ }
+
lock.unlock();
if (!IsActive())
{
@@ -131,6 +160,28 @@ namespace desktop {
}
}
+ void removeAllButLast(const int type)
+ {
+ int i = m_queue.size() - 1;
+ for (; i >= 0; --i)
+ {
+ if (m_queue[i].first == type)
+ {
+ SAL_WARN("idle", "Found [" + std::to_string(type) + "] at " + std::to_string(i));
+ break;
+ }
+ }
+
+ for (--i; i >= 0; --i)
+ {
+ if (m_queue[i].first == type)
+ {
+ SAL_WARN("idle", "Removing [" + std::to_string(type) + "] at " + std::to_string(i));
+ m_queue.erase(m_queue.begin() + i);
+ }
+ }
+ }
+
private:
std::vector<std::pair<int, std::string>> m_queue;
std::map<int, std::string> m_states;
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 7f1d97ba73e7..f20835db5472 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -1277,95 +1277,81 @@ void DesktopLOKTest::testNotificationCompression()
std::unique_ptr<CallbackFlushHandler> handler(new CallbackFlushHandler(callbackCompressionTest, &notifs));
handler->queue(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, ""); // 0
- handler->queue(LOK_CALLBACK_TEXT_SELECTION, "15 25 15 10"); // 1
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION, "15 25 15 10"); // Superseeded.
handler->queue(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, ""); // Should be dropped.
- handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "15 25 15 10"); // 2
+ handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "15 25 15 10"); // 1
handler->queue(LOK_CALLBACK_TEXT_SELECTION, "15 25 15 10"); // Should be dropped.
- handler->queue(LOK_CALLBACK_TEXT_SELECTION, ""); // 3
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION, ""); // Superseeded.
+ handler->queue(LOK_CALLBACK_STATE_CHANGED, ""); // 2
+ handler->queue(LOK_CALLBACK_STATE_CHANGED, ".uno:Bold"); // 3
handler->queue(LOK_CALLBACK_STATE_CHANGED, ""); // 4
- handler->queue(LOK_CALLBACK_STATE_CHANGED, ".uno:Bold"); // 5
- handler->queue(LOK_CALLBACK_STATE_CHANGED, ""); // 6
- handler->queue(LOK_CALLBACK_MOUSE_POINTER, "text"); // 7
- handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "15 25 15 10"); // 8
+ handler->queue(LOK_CALLBACK_MOUSE_POINTER, "text"); // 5
+ handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "15 25 15 10"); // 6
handler->queue(LOK_CALLBACK_INVALIDATE_TILES, "15 25 15 10"); // Should be dropped.
handler->queue(LOK_CALLBACK_MOUSE_POINTER, "text"); // Should be dropped.
- handler->queue(LOK_CALLBACK_TEXT_SELECTION_START, "15 25 15 10"); // 9
- handler->queue(LOK_CALLBACK_TEXT_SELECTION_END, "15 25 15 10"); // 10
- handler->queue(LOK_CALLBACK_TEXT_SELECTION, "15 25 15 10"); // 11
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION_START, "15 25 15 10"); // Superseeded.
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION_END, "15 25 15 10"); // Superseeded.
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION, "15 25 15 10"); // Superseedd.
handler->queue(LOK_CALLBACK_TEXT_SELECTION_START, "15 25 15 10"); // Should be dropped.
handler->queue(LOK_CALLBACK_TEXT_SELECTION_END, "15 25 15 10"); // Should be dropped.
- handler->queue(LOK_CALLBACK_TEXT_SELECTION, ""); // 12
- handler->queue(LOK_CALLBACK_TEXT_SELECTION_START, "15 25 15 10"); // 13
- handler->queue(LOK_CALLBACK_TEXT_SELECTION_END, "15 25 15 10"); // 14
- handler->queue(LOK_CALLBACK_CELL_CURSOR, "15 25 15 10"); // 15
- handler->queue(LOK_CALLBACK_CURSOR_VISIBLE, ""); // 16
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION, ""); // 7
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION_START, "15 25 15 10"); // 8
+ handler->queue(LOK_CALLBACK_TEXT_SELECTION_END, "15 25 15 10"); // 9
+ handler->queue(LOK_CALLBACK_CELL_CURSOR, "15 25 15 10"); // 10
+ handler->queue(LOK_CALLBACK_CURSOR_VISIBLE, ""); // 11
handler->queue(LOK_CALLBACK_CELL_CURSOR, "15 25 15 10"); // Should be dropped.
- handler->queue(LOK_CALLBACK_CELL_FORMULA, "blah"); // 17
- handler->queue(LOK_CALLBACK_SET_PART, "1"); // 18
+ handler->queue(LOK_CALLBACK_CELL_FORMULA, "blah"); // 12
+ handler->queue(LOK_CALLBACK_SET_PART, "1"); // 13
handler->queue(LOK_CALLBACK_CURSOR_VISIBLE, ""); // Should be dropped.
handler->queue(LOK_CALLBACK_CELL_FORMULA, "blah"); // Should be dropped.
handler->queue(LOK_CALLBACK_SET_PART, "1"); // Should be dropped.
Scheduler::ProcessEventsToIdle();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(19), notifs.size());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(14), notifs.size());
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, (int)std::get<0>(notifs[0]));
- CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[0]));
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION, (int)std::get<0>(notifs[1]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[1]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_TILES, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_TILES, (int)std::get<0>(notifs[2]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[2]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_STATE_CHANGED, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION, (int)std::get<0>(notifs[3]));
- CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[3]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_STATE_CHANGED, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string(".uno:Bold"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_STATE_CHANGED, (int)std::get<0>(notifs[4]));
- CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[4]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_STATE_CHANGED, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_STATE_CHANGED, (int)std::get<0>(notifs[5]));
- CPPUNIT_ASSERT_EQUAL(std::string(".uno:Bold"), std::get<1>(notifs[5]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_MOUSE_POINTER, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("text"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_STATE_CHANGED, (int)std::get<0>(notifs[6]));
- CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[6]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_TILES, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_MOUSE_POINTER, (int)std::get<0>(notifs[7]));
- CPPUNIT_ASSERT_EQUAL(std::string("text"), std::get<1>(notifs[7]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_INVALIDATE_TILES, (int)std::get<0>(notifs[8]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[8]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION_START, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION_START, (int)std::get<0>(notifs[9]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[9]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION_END, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION_END, (int)std::get<0>(notifs[10]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[10]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_CELL_CURSOR, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION, (int)std::get<0>(notifs[11]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[11]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_CURSOR_VISIBLE, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION, (int)std::get<0>(notifs[12]));
- CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[12]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_CELL_FORMULA, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("blah"), std::get<1>(notifs[i++]));
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION_START, (int)std::get<0>(notifs[13]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[13]));
-
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_TEXT_SELECTION_END, (int)std::get<0>(notifs[14]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[14]));
-
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_CELL_CURSOR, (int)std::get<0>(notifs[15]));
- CPPUNIT_ASSERT_EQUAL(std::string("15 25 15 10"), std::get<1>(notifs[15]));
-
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_CURSOR_VISIBLE, (int)std::get<0>(notifs[16]));
- CPPUNIT_ASSERT_EQUAL(std::string(""), std::get<1>(notifs[16]));
-
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_CELL_FORMULA, (int)std::get<0>(notifs[17]));
- CPPUNIT_ASSERT_EQUAL(std::string("blah"), std::get<1>(notifs[17]));
-
- CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_SET_PART, (int)std::get<0>(notifs[18]));
- CPPUNIT_ASSERT_EQUAL(std::string("1"), std::get<1>(notifs[18]));
+ CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_SET_PART, (int)std::get<0>(notifs[i]));
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), std::get<1>(notifs[i++]));
}
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);