[Libreoffice-commits] online.git: 3 commits - loolwsd/MessageQueue.cpp loolwsd/MessageQueue.hpp loolwsd/test
Jan Holesovsky
kendy at collabora.com
Fri Sep 30 20:43:32 UTC 2016
loolwsd/MessageQueue.cpp | 26 +++++++++++++-------------
loolwsd/MessageQueue.hpp | 16 +++++++++-------
loolwsd/test/TileQueueTests.cpp | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 20 deletions(-)
New commits:
commit cbf9556b0a9fc7117471da8b43882fe186f75981
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri Sep 30 22:38:20 2016 +0200
Simplify the code around priorities and view ordering in TileQueue.
No functional change.
Change-Id: If34747a069032b13d7d9eb232b1bf10cef967afa
diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp
index 8a37e80..0a49051 100644
--- a/loolwsd/MessageQueue.cpp
+++ b/loolwsd/MessageQueue.cpp
@@ -163,7 +163,7 @@ int TileQueue::priority(const std::string& tileMsg)
{
auto tile = TileDesc::parse(tileMsg); //FIXME: Expensive, avoid.
- for (size_t i = 0; i < _viewOrder.size(); ++i)
+ for (int i = static_cast<int>(_viewOrder.size()) - 1; i >= 0; --i)
{
auto& cursor = _cursorPositions[_viewOrder[i]];
if (tile.intersectsWithRect(cursor.X, cursor.Y, cursor.Width, cursor.Height))
@@ -205,10 +205,8 @@ MessageQueue::Payload TileQueue::get_impl()
break;
int p = priority(prio);
- if (p == -1)
- continue;
- if (prioritySoFar == -1 || p < prioritySoFar)
+ if (p > prioritySoFar)
{
prioritySoFar = p;
prioritized = i;
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 3bf778c..2a13484 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -108,7 +108,7 @@ public:
_viewOrder.erase(view);
}
- _viewOrder.push_front(viewId);
+ _viewOrder.push_back(viewId);
}
void removeCursorPosition(int viewId)
@@ -132,16 +132,16 @@ private:
void removeDuplicate(const std::string& tileMsg);
/// Priority of the given tile message.
- /// 0 is the highest prio, the bigger is the value, the lower is the prio.
- /// -1 means the lowest prio (the tile does not intersect any of the cursors).
+ /// -1 means the lowest prio (the tile does not intersect any of the cursors),
+ /// the higher the number, the bigger is priority [up to _viewOrder.size()-1].
int priority(const std::string& tileMsg);
private:
std::map<int, CursorPosition> _cursorPositions;
/// Check the views in the order of how the editing (cursor movement) has
- /// been happening.
- std::deque<int> _viewOrder;
+ /// been happening (0 == oldest, size() - 1 == newest).
+ std::vector<int> _viewOrder;
};
#endif
commit f101b2b7cbbec2392109b6e8d5a095b2a0214216
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri Sep 30 22:02:22 2016 +0200
Check we get views prioritized according to when the cursor was updated.
Fails with any of e5adf272b876b0d6afd8aa989c005d8a4bed5f96,
d9c90e30fd9f02a7287183d2b58195f547fb92da or
4e7ba53a2b0c91c35d93f11e114a9e56dc467555 reverted.
Change-Id: I5a9384f20ae1f64e29509ec568670e29c3c4eb94
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 33edeeb..3bf778c 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -21,8 +21,6 @@
*/
class MessageQueue
{
- friend class TileQueueTests;
-
public:
typedef std::vector<char> Payload;
@@ -73,6 +71,8 @@ protected:
*/
class TileQueue : public MessageQueue
{
+ friend class TileQueueTests;
+
private:
class CursorPosition
diff --git a/loolwsd/test/TileQueueTests.cpp b/loolwsd/test/TileQueueTests.cpp
index 49a45c2..efe13cf 100644
--- a/loolwsd/test/TileQueueTests.cpp
+++ b/loolwsd/test/TileQueueTests.cpp
@@ -42,12 +42,14 @@ class TileQueueTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testTileQueuePriority);
CPPUNIT_TEST(testTileCombinedRendering);
CPPUNIT_TEST(testTileRecombining);
+ CPPUNIT_TEST(testViewOrder);
CPPUNIT_TEST_SUITE_END();
void testTileQueuePriority();
void testTileCombinedRendering();
void testTileRecombining();
+ void testViewOrder();
};
void TileQueueTests::testTileQueuePriority()
@@ -149,6 +151,43 @@ void TileQueueTests::testTileRecombining()
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue._queue.size()));
}
+void TileQueueTests::testViewOrder()
+{
+ TileQueue queue;
+
+ // should result in the 3, 2, 1, 0 order of the views
+ queue.updateCursorPosition(0, 0, 0, 0, 10, 100);
+ queue.updateCursorPosition(2, 0, 0, 0, 10, 100);
+ queue.updateCursorPosition(1, 0, 0, 7680, 10, 100);
+ queue.updateCursorPosition(3, 0, 0, 0, 10, 100);
+ queue.updateCursorPosition(2, 0, 0, 15360, 10, 100);
+ queue.updateCursorPosition(3, 0, 0, 23040, 10, 100);
+
+ const std::vector<std::string> tiles =
+ {
+ "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 ver=-1",
+ "tile part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 ver=-1",
+ "tile part=0 width=256 height=256 tileposx=0 tileposy=15360 tilewidth=3840 tileheight=3840 ver=-1",
+ "tile part=0 width=256 height=256 tileposx=0 tileposy=23040 tilewidth=3840 tileheight=3840 ver=-1"
+ };
+
+ for (auto &tile : tiles)
+ queue.put(tile);
+
+ CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(tiles.size()));
+
+ // should result in the 3, 2, 1, 0 order of the tiles thanks to the cursor
+ // positions
+ for (size_t i = 0; i < tiles.size(); ++i)
+ {
+ MessageQueue::Payload payload(queue.get());
+ std::string message(payload.data(), payload.size());
+
+ CPPUNIT_ASSERT_EQUAL(tiles[3 - i], message);
+ }
+
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(TileQueueTests);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit e5adf272b876b0d6afd8aa989c005d8a4bed5f96
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri Sep 30 22:00:20 2016 +0200
Search harder for the highest priority tile.
Without this, any cursor intersecting with the tile was treated as the
priority.
Change-Id: I6bc4629620d368ce383900386a00c535255ee133
diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp
index b9059cb..8a37e80 100644
--- a/loolwsd/MessageQueue.cpp
+++ b/loolwsd/MessageQueue.cpp
@@ -159,18 +159,18 @@ void TileQueue::removeDuplicate(const std::string& tileMsg)
}
}
-bool TileQueue::priority(const std::string& tileMsg)
+int TileQueue::priority(const std::string& tileMsg)
{
auto tile = TileDesc::parse(tileMsg); //FIXME: Expensive, avoid.
- for (int view : _viewOrder)
+ for (size_t i = 0; i < _viewOrder.size(); ++i)
{
- auto& cursor = _cursorPositions[view];
+ auto& cursor = _cursorPositions[_viewOrder[i]];
if (tile.intersectsWithRect(cursor.X, cursor.Y, cursor.Width, cursor.Height))
- return true;
+ return i;
}
- return false;
+ return -1;
}
MessageQueue::Payload TileQueue::get_impl()
@@ -191,7 +191,8 @@ MessageQueue::Payload TileQueue::get_impl()
// We are handling a tile; first try to find one that is at the cursor's
// position, otherwise handle the one that is at the front
- bool foundPrioritized = false;
+ int prioritized = 0;
+ int prioritySoFar = -1;
for (size_t i = 0; i < _queue.size(); ++i)
{
auto& it = _queue[i];
@@ -203,18 +204,19 @@ MessageQueue::Payload TileQueue::get_impl()
if (LOOLProtocol::getFirstToken(prio) != "tile")
break;
- if (priority(prio))
+ int p = priority(prio);
+ if (p == -1)
+ continue;
+
+ if (prioritySoFar == -1 || p < prioritySoFar)
{
- Log::debug() << "Handling a priority message: " << prio << Log::end;
- _queue.erase(_queue.begin() + i);
+ prioritySoFar = p;
+ prioritized = i;
msg = prio;
- foundPrioritized = true;
- break;
}
}
- if (!foundPrioritized)
- _queue.pop_front();
+ _queue.erase(_queue.begin() + prioritized);
tiles.emplace_back(TileDesc::parse(msg));
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 284f847..33edeeb 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -131,8 +131,10 @@ private:
/// Search the queue for a duplicate tile and remove it (if present).
void removeDuplicate(const std::string& tileMsg);
- /// Check if the given tile msg underlies a cursor.
- bool priority(const std::string& tileMsg);
+ /// Priority of the given tile message.
+ /// 0 is the highest prio, the bigger is the value, the lower is the prio.
+ /// -1 means the lowest prio (the tile does not intersect any of the cursors).
+ int priority(const std::string& tileMsg);
private:
std::map<int, CursorPosition> _cursorPositions;
More information about the Libreoffice-commits
mailing list