[Libreoffice-commits] online.git: Branch 'feature/latency' - 3 commits - loleaflet/src wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/TestStubs.cpp wsd/TileCache.cpp
Tamás Zolnai
tamas.zolnai at collabora.com
Fri Jul 6 10:39:13 UTC 2018
loleaflet/src/layer/tile/TileLayer.js | 6 ----
wsd/ClientSession.cpp | 49 ++++++++++++++++++++++++++++++----
wsd/ClientSession.hpp | 15 +++++++++-
wsd/DocumentBroker.cpp | 16 +++++------
wsd/TestStubs.cpp | 5 +++
wsd/TileCache.cpp | 4 ++
6 files changed, 74 insertions(+), 21 deletions(-)
New commits:
commit 63e4dd94ef8065755ef59c839a29a54f30fddea3
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
Date: Fri Jul 6 12:38:31 2018 +0200
Store wiredIDs on the server side
So we can use this information in tile requests.
Change-Id: I87ba420ec0fd699353d48a228268e546ace21921
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index f7d4901ea..48339850b 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1395,17 +1395,11 @@ L.TileLayer = L.GridLayer.extend({
}
ctx.putImageData(imgData, 0, 0);
-
- tile.oldWireId = tile.wireId;
- tile.wireId = command.wireId;
tile.el.src = canvas.toDataURL('image/png');
console.log('set new image');
}
else if (tile) {
- if (command.wireId != undefined) {
- tile.oldWireId = command.wireId;
- }
if (this._tiles[key]._invalidCount > 0) {
this._tiles[key]._invalidCount -= 1;
}
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 1acc06155..0923c4294 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -285,6 +285,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
else
{
_clientVisibleArea = Util::Rectangle(x, y, width, height);
+ resetWireIdMap();
return forwardToChild(std::string(buffer, length), docBroker);
}
}
@@ -302,6 +303,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
else
{
_clientSelectedPart = temp;
+ resetWireIdMap();
return forwardToChild(std::string(buffer, length), docBroker);
}
}
@@ -324,6 +326,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
_tileHeightPixel = tilePixelHeight;
_tileWidthTwips = tileTwipWidth;
_tileHeightTwips = tileTwipHeight;
+ resetWireIdMap();
return forwardToChild(std::string(buffer, length), docBroker);
}
}
@@ -860,6 +863,7 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
if(getTokenInteger(token, "current", part))
{
_clientSelectedPart = part;
+ resetWireIdMap();
}
// Get document type too
@@ -996,10 +1000,7 @@ Authorization ClientSession::getAuthorization() const
void ClientSession::addTileOnFly(const TileDesc& tile)
{
- std::ostringstream tileID;
- tileID << tile.getPart() << ":" << tile.getTilePosX() << ":" << tile.getTilePosY() << ":"
- << tile.getTileWidth() << ":" << tile.getTileHeight();
- _tilesOnFly.push_back(tileID.str());
+ _tilesOnFly.push_back(generateTileID(tile));
}
void ClientSession::clearTilesOnFly()
@@ -1124,7 +1125,13 @@ void ClientSession::handleTileInvalidation(const std::string& message,
j <= std::ceil(intersection._y2 / _tileHeightTwips); ++j)
{
invalidTiles.emplace_back(TileDesc(part, _tileWidthPixel, _tileHeightPixel, i * _tileWidthTwips, j * _tileHeightTwips, _tileWidthTwips, _tileHeightTwips, -1, 0, -1, false));
- invalidTiles.back().setOldWireId(0);
+
+ TileWireId oldWireId = 0;
+ auto iter = _oldWireIds.find(generateTileID(invalidTiles.back()));
+ if(iter != _oldWireIds.end())
+ oldWireId = iter->second;
+
+ invalidTiles.back().setOldWireId(oldWireId);
invalidTiles.back().setWireId(0);
}
}
@@ -1138,4 +1145,36 @@ void ClientSession::handleTileInvalidation(const std::string& message,
}
}
+void ClientSession::resetWireIdMap()
+{
+ _oldWireIds.clear();
+}
+
+void ClientSession::traceTileBySend(const TileDesc& tile)
+{
+ const std::string tileID = generateTileID(tile);
+
+ // Store wireId first
+ auto iter = _oldWireIds.find(tileID);
+ if(iter != _oldWireIds.end())
+ {
+ iter->second = tile.getWireId();
+ }
+ else
+ {
+ _oldWireIds.insert(std::pair<std::string, TileWireId>(tileID, tile.getWireId()));
+ }
+
+ // Record that the tile is sent
+ addTileOnFly(tile);
+}
+
+std::string ClientSession::generateTileID(const TileDesc& tile)
+{
+ std::ostringstream tileID;
+ tileID << tile.getPart() << ":" << tile.getTilePosX() << ":" << tile.getTilePosY() << ":"
+ << tile.getTileWidth() << ":" << tile.getTileHeight();
+ return tileID.str();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 92589ea6b..a4e473d8f 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -19,6 +19,7 @@
#include <Rectangle.hpp>
#include <boost/optional.hpp>
#include <list>
+#include <map>
class DocumentBroker;
@@ -118,7 +119,9 @@ public:
int getTileWidthInTwips() const { return _tileWidthTwips; }
int getTileHeightInTwips() const { return _tileHeightTwips; }
-
+ /// This method updates internal data related to sent tiles (wireID and tiles-on-fly)
+ /// Call this method anytime when a new tile is sent to the client
+ void traceTileBySend(const TileDesc& tile);
private:
/// SocketHandler: disconnection event.
@@ -159,6 +162,11 @@ private:
void handleTileInvalidation(const std::string& message,
const std::shared_ptr<DocumentBroker>& docBroker);
+ /// Clear wireId map anytime when client visible area changes (visible area, zoom, part number)
+ void resetWireIdMap();
+
+ std::string generateTileID(const TileDesc& tile);
+
private:
std::weak_ptr<DocumentBroker> _docBroker;
@@ -197,12 +205,15 @@ private:
int _tileWidthTwips;
int _tileHeightTwips;
- // Type of the docuemnt, extracter from status message
+ /// Client is using a text document?
bool _isTextDocument;
std::list<std::string> _tilesOnFly;
boost::optional<std::list<TileDesc>> _requestedTiles;
+
+ /// Store wireID's of the sent tiles for the actual visible area
+ std::map<std::string, TileWireId> _oldWireIds;
};
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8f4ccc792..c072d3bdd 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1384,7 +1384,6 @@ void DocumentBroker::sendRequestedTiles(const std::shared_ptr<ClientSession>& se
while(session->getTilesOnFlyCount() < tilesOnFlyUpperLimit && !requestedTiles.get().empty())
{
TileDesc& tile = *(requestedTiles.get().begin());
- session->addTileOnFly(tile);
// Satisfy as many tiles from the cache.
std::unique_ptr<std::fstream> cachedTile = _tileCache->lookupTile(tile);
@@ -1411,6 +1410,7 @@ void DocumentBroker::sendRequestedTiles(const std::shared_ptr<ClientSession>& se
cachedTile->read(output.data() + pos, size);
cachedTile->close();
+ session->traceTileBySend(tile);
session->sendBinaryFrame(output.data(), output.size());
}
else
diff --git a/wsd/TestStubs.cpp b/wsd/TestStubs.cpp
index 963bf9618..0a1f7524b 100644
--- a/wsd/TestStubs.cpp
+++ b/wsd/TestStubs.cpp
@@ -15,6 +15,11 @@
#include "DocumentBroker.hpp"
+#include "ClientSession.hpp"
+
void DocumentBroker::assertCorrectThread() const {}
+
+void ClientSession::traceTileBySend(const TileDesc& /*tile*/) {}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index b2d8ca793..84dd5b3bd 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -189,7 +189,10 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
auto& firstSubscriber = tileBeingRendered->_subscribers[0];
std::shared_ptr<ClientSession> firstSession = firstSubscriber.lock();
if (firstSession)
+ {
+ firstSession->traceTileBySend(tile);
firstSession->enqueueSendMessage(payload);
+ }
if (subscriberCount > 1)
{
@@ -209,6 +212,7 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
std::shared_ptr<ClientSession> session = subscriber.lock();
if (session)
{
+ session->traceTileBySend(tile);
session->enqueueSendMessage(payload);
}
}
commit eff2c956d7d36a348872fd0afee54969e2fb2b98
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
Date: Thu Jul 5 16:10:47 2018 +0200
Fix cast to use the actualy type we have in the declaration
Change-Id: Ib2048be1e642cac26802ae41968153202d94f7c7
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c5e0b5256..8f4ccc792 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1367,10 +1367,10 @@ void DocumentBroker::sendRequestedTiles(const std::shared_ptr<ClientSession>& se
std::unique_lock<std::mutex> lock(_mutex);
// How many tiles we have on the visible area, set the upper limit accordingly
- const unsigned tilesFitOnWidth = static_cast<int>(std::ceil(static_cast<float>(session->getVisibleArea().getWidth()) /
- static_cast<float>(session->getTileWidthInTwips())));
- const unsigned tilesFitOnHeight = static_cast<int>(std::ceil(static_cast<float>(session->getVisibleArea().getHeight()) /
- static_cast<float>(session->getTileHeightInTwips())));
+ const unsigned tilesFitOnWidth = static_cast<unsigned>(std::ceil(static_cast<float>(session->getVisibleArea().getWidth()) /
+ static_cast<float>(session->getTileWidthInTwips())));
+ const unsigned tilesFitOnHeight = static_cast<unsigned>(std::ceil(static_cast<float>(session->getVisibleArea().getHeight()) /
+ static_cast<float>(session->getTileHeightInTwips())));
const unsigned tilesInVisArea = tilesFitOnWidth * tilesFitOnHeight;
const unsigned tilesOnFlyUpperLimit = std::max(TILES_ON_FLY_MIN_UPPER_LIMIT, tilesInVisArea);
commit c06e9d8cae632c40c6f2bdd7a0ff20197d30a8c1
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
Date: Thu Jul 5 14:42:08 2018 +0200
Fix typos
Change-Id: I68f5d0c4923d4a103fc3efdda6a4c5414e9741cc
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 0028d8749..c5e0b5256 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1369,11 +1369,11 @@ void DocumentBroker::sendRequestedTiles(const std::shared_ptr<ClientSession>& se
// How many tiles we have on the visible area, set the upper limit accordingly
const unsigned tilesFitOnWidth = static_cast<int>(std::ceil(static_cast<float>(session->getVisibleArea().getWidth()) /
static_cast<float>(session->getTileWidthInTwips())));
- const unsigned tilesFitOnHieght = static_cast<int>(std::ceil(static_cast<float>(session->getVisibleArea().getHeight()) /
+ const unsigned tilesFitOnHeight = static_cast<int>(std::ceil(static_cast<float>(session->getVisibleArea().getHeight()) /
static_cast<float>(session->getTileHeightInTwips())));
- const unsigned tilesInVisArea = tilesFitOnWidth * tilesFitOnHieght;
+ const unsigned tilesInVisArea = tilesFitOnWidth * tilesFitOnHeight;
- const unsigned tilesInFlyUpperLimit = std::max(TILES_ON_FLY_MIN_UPPER_LIMIT, tilesInVisArea);
+ const unsigned tilesOnFlyUpperLimit = std::max(TILES_ON_FLY_MIN_UPPER_LIMIT, tilesInVisArea);
// All tiles were processed on client side what we sent last time, so we can send a new banch of tiles
// which was invalidated / requested in the meantime
@@ -1381,7 +1381,7 @@ void DocumentBroker::sendRequestedTiles(const std::shared_ptr<ClientSession>& se
if(requestedTiles != boost::none && !requestedTiles.get().empty())
{
std::vector<TileDesc> tilesNeedsRendering;
- while(session->getTilesOnFlyCount() < tilesInFlyUpperLimit && !requestedTiles.get().empty())
+ while(session->getTilesOnFlyCount() < tilesOnFlyUpperLimit && !requestedTiles.get().empty())
{
TileDesc& tile = *(requestedTiles.get().begin());
session->addTileOnFly(tile);
More information about the Libreoffice-commits
mailing list