diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 4a61bbe49..299cba324 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -1079,6 +1079,16 @@ void ClientSession::removeOutdatedTilesOnFly() } } +Util::Rectangle ClientSession::getNormalizedVisibleArea() const +{ + Util::Rectangle normalizedVisArea; + normalizedVisArea._x1 = std::max(_clientVisibleArea._x1, 0); + normalizedVisArea._y1 = std::max(_clientVisibleArea._y1, 0); + normalizedVisArea._x2 = _clientVisibleArea._x2; + normalizedVisArea._y2 = _clientVisibleArea._y2; + return normalizedVisArea; +} + void ClientSession::onDisconnect() { LOG_INF(getName() << " Disconnected, current number of connections: " << LOOLWSD::NumConnections); @@ -1172,12 +1182,8 @@ void ClientSession::handleTileInvalidation(const std::string& message, return; } - // Visible area can have negativ value as position, but we have tiles only in the positiv range - Util::Rectangle normalizedVisArea; - normalizedVisArea._x1 = std::max(_clientVisibleArea._x1, 0); - normalizedVisArea._y1 = std::max(_clientVisibleArea._y1, 0); - normalizedVisArea._x2 = _clientVisibleArea._x2; - normalizedVisArea._y2 = _clientVisibleArea._y2; + // Visible area can have negativ value as position, but we have tiles only in the positive range + Util::Rectangle normalizedVisArea = getNormalizedVisibleArea(); std::pair result = TileCache::parseInvalidateMsg(message); int part = result.first; diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp index b4835cfd9..2efd26624 100644 --- a/wsd/ClientSession.hpp +++ b/wsd/ClientSession.hpp @@ -130,6 +130,9 @@ public: void removeOutdatedTilesOnFly(); Util::Rectangle getVisibleArea() const { return _clientVisibleArea; } + /// Visible area can have negative value as position, but we have tiles only in the positive range + Util::Rectangle getNormalizedVisibleArea() const; + int getTileWidthInTwips() const { return _tileWidthTwips; } int getTileHeightInTwips() const { return _tileHeightTwips; } diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 310eac031..59ce6d0b8 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1368,13 +1368,15 @@ void DocumentBroker::sendRequestedTiles(const std::shared_ptr& se std::unique_lock lock(_mutex); // How many tiles we have on the visible area, set the upper limit accordingly - const float tilesFitOnWidth = static_cast(session->getVisibleArea().getWidth()) / - static_cast(session->getTileWidthInTwips()); - const float tilesFitOnHeight = static_cast(session->getVisibleArea().getHeight()) / - static_cast(session->getTileHeightInTwips()); - const float tilesInVisArea = tilesFitOnWidth * tilesFitOnHeight; + Util::Rectangle normalizedVisArea = session->getNormalizedVisibleArea(); - const float tilesOnFlyUpperLimit = std::max(TILES_ON_FLY_MIN_UPPER_LIMIT, tilesInVisArea * 1.20f); + const int tilesFitOnWidth = std::ceil(normalizedVisArea._x2 / session->getTileWidthInTwips()) - + std::ceil(normalizedVisArea._x1 / session->getTileWidthInTwips()) + 1; + const int tilesFitOnHeight = std::ceil(normalizedVisArea._y2 / session->getTileHeightInTwips()) - + std::ceil(normalizedVisArea._y1 / session->getTileHeightInTwips()) + 1; + const int tilesInVisArea = tilesFitOnWidth * tilesFitOnHeight; + + const float tilesOnFlyUpperLimit = std::max(TILES_ON_FLY_MIN_UPPER_LIMIT, tilesInVisArea * 1.5f); // Update client's tilesBeingRendered list session->removeOutdatedTileSubscriptions();