common/Session.cpp | 17 ++ common/Session.hpp | 11 + kit/ChildSession.hpp | 3 kit/Kit.cpp | 200 ++++------------------------------ loleaflet/src/control/Parts.js | 2 loleaflet/src/core/Socket.js | 3 loleaflet/src/layer/tile/GridLayer.js | 2 loleaflet/src/layer/tile/TileLayer.js | 2 test/TileCacheTests.cpp | 91 +++++++-------- test/TileQueueTests.cpp | 58 ++++----- test/UnitTyping.cpp | 4 test/WhiteBoxTests.cpp | 21 +-- test/httpwstest.cpp | 6 - wsd/ClientSession.cpp | 9 + wsd/DocumentBroker.cpp | 12 +- wsd/DocumentBroker.hpp | 2 wsd/TileCache.cpp | 30 +++-- wsd/TileCache.hpp | 8 - wsd/TileDesc.hpp | 45 +++++-- 19 files changed, 228 insertions(+), 298 deletions(-)
New commits: commit a5000034cdc6e7289fc24b0557ba58d842168a2f Author: mert <mert.tu...@collabora.com> AuthorDate: Tue Oct 15 16:41:33 2019 +0300 Commit: mert <mert.tu...@collabora.com> CommitDate: Tue Oct 15 18:13:03 2019 +0300 Added normalizedViewId to the tests with tilemsg Change-Id: I479246a2c592b7e4f50b613a0fb0f96af761198c diff --git a/test/TileCacheTests.cpp b/test/TileCacheTests.cpp index ba02e8d93..0eba9e2d3 100644 --- a/test/TileCacheTests.cpp +++ b/test/TileCacheTests.cpp @@ -177,8 +177,8 @@ public: void TileCacheTests::testDesc() { - TileCacheDesc descA = TileDesc(0, 256, 256, 0, 0, 3200, 3200, /* ignored in cache */ 0, 1234, 1, true); - TileCacheDesc descB = TileDesc(0, 256, 256, 0, 0, 3200, 3200, /* ignored in cache */ 1, 1235, 2, false); + TileCacheDesc descA = TileDesc(0, 0, 256, 256, 0, 0, 3200, 3200, /* ignored in cache */ 0, 1234, 1, true); + TileCacheDesc descB = TileDesc(0, 0, 256, 256, 0, 0, 3200, 3200, /* ignored in cache */ 1, 1235, 2, false); CPPUNIT_ASSERT_MESSAGE("versions do match", descA.getVersion() != descB.getVersion()); CPPUNIT_ASSERT_MESSAGE("Compare includes fields it should not", descA == descB); @@ -196,6 +196,7 @@ void TileCacheTests::testSimple() // now, so it discards the cached data. TileCache tc("doc.ods", std::chrono::system_clock::time_point()); + int nviewid = 0; int part = 0; int width = 256; int height = 256; @@ -203,7 +204,7 @@ void TileCacheTests::testSimple() int tilePosY = 0; int tileWidth = 3840; int tileHeight = 3840; - TileDesc tile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, -1, 0, -1, false); + TileDesc tile(nviewid, part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, -1, 0, -1, false); // No Cache TileCache::Tile tileData = tc.lookupTile(tile); @@ -220,7 +221,7 @@ void TileCacheTests::testSimple() CPPUNIT_ASSERT_MESSAGE("cached tile corrupted", data == *tileData); // Invalidate Tiles - tc.invalidateTiles("invalidatetiles: EMPTY"); + tc.invalidateTiles("invalidatetiles: EMPTY", nviewid); // No Cache tileData = tc.lookupTile(tile); @@ -236,13 +237,13 @@ void TileCacheTests::testSimpleCombine() // First. std::shared_ptr<LOOLWebSocket> socket1 = loadDocAndGetSocket(_uri, documentURL, "simpleCombine-1 "); - sendTextFrame(socket1, "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); + sendTextFrame(socket1, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); std::vector<char> tile1a = getResponseMessage(socket1, "tile:", testname); CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !tile1a.empty()); std::vector<char> tile1b = getResponseMessage(socket1, "tile:", testname); CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !tile1b.empty()); - sendTextFrame(socket1, "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); + sendTextFrame(socket1, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); tile1a = getResponseMessage(socket1, "tile:", testname); CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !tile1a.empty()); @@ -253,7 +254,7 @@ void TileCacheTests::testSimpleCombine() TST_LOG("Connecting second client."); std::shared_ptr<LOOLWebSocket> socket2 = loadDocAndGetSocket(_uri, documentURL, "simpleCombine-2 ", true); - sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); + sendTextFrame(socket2, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); std::vector<char> tile2a = getResponseMessage(socket2, "tile:", testname); CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !tile2a.empty()); @@ -278,7 +279,7 @@ void TileCacheTests::testCancelTiles() std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket("setclientpart.ods", _uri, testname); // Request a huge tile, and cancel immediately. - sendTextFrame(socket, "tilecombine part=0 width=2560 height=2560 tileposx=0 tileposy=0 tilewidth=38400 tileheight=38400"); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=2560 height=2560 tileposx=0 tileposy=0 tilewidth=38400 tileheight=38400"); sendTextFrame(socket, "canceltiles"); const auto res = getResponseString(socket, "tile:", testname, 1000); @@ -318,8 +319,8 @@ void TileCacheTests::testCancelTilesMultiView() std::shared_ptr<LOOLWebSocket> socket1 = loadDocAndGetSocket(_uri, documentURL, "cancelTilesMultiView-1 "); std::shared_ptr<LOOLWebSocket> socket2 = loadDocAndGetSocket(_uri, documentURL, "cancelTilesMultiView-2 ", true); - sendTextFrame(socket1, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-1 "); - sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,0 tileposy=0,0,0,22520 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-2 "); + sendTextFrame(socket1, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-1 "); + sendTextFrame(socket2, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680,0 tileposy=0,0,0,22520 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-2 "); sendTextFrame(socket1, "canceltiles"); const auto res1 = getResponseString(socket1, "tile:", "cancelTilesMultiView-1 ", 500); @@ -380,8 +381,8 @@ void TileCacheTests::testDisconnectMultiView() std::shared_ptr<LOOLWebSocket> socket1 = loadDocAndGetSocket(_uri, documentURL, "disconnectMultiView-1 "); std::shared_ptr<LOOLWebSocket> socket2 = loadDocAndGetSocket(_uri, documentURL, "disconnectMultiView-2 ", true); - sendTextFrame(socket1, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-1 "); - sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,0 tileposy=0,0,0,22520 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-2 "); + sendTextFrame(socket1, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-1 "); + sendTextFrame(socket2, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680,0 tileposy=0,0,0,22520 tilewidth=3840 tileheight=3840", "cancelTilesMultiView-2 "); socket1->shutdown(); @@ -428,10 +429,10 @@ void TileCacheTests::testUnresponsiveClient() assertResponseString(socket2, "invalidatetiles:", "client2 "); // Ask for tiles and don't read! - sendTextFrame(socket1, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840"); + sendTextFrame(socket1, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840"); // Verify that we get all 8 tiles. - sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840"); + sendTextFrame(socket2, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840 tilewidth=3840 tileheight=3840"); for (int i = 0; i < 8; ++i) { std::vector<char> tile = getResponseMessage(socket2, "tile:", "client2 "); @@ -449,7 +450,7 @@ void TileCacheTests::testImpressTiles() const std::string testName = "impressTiles "; std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket("setclientpart.odp", _uri, testName); - sendTextFrame(socket, "tile part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 id=0", testName); + sendTextFrame(socket, "tile nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 id=0", testName); getTileMessage(*socket, testName); } catch (const Poco::Exception& exc) @@ -514,7 +515,7 @@ void TileCacheTests::testTilesRenderedJustOnce() assertResponseString(socket, "invalidatetiles:", testname); // Get 3 tiles. - sendTextFrame(socket, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname); assertResponseString(socket, "tile:", testname); assertResponseString(socket, "tile:", testname); assertResponseString(socket, "tile:", testname); @@ -527,7 +528,7 @@ void TileCacheTests::testTilesRenderedJustOnce() CPPUNIT_ASSERT_EQUAL((i+1) * 3, renderCount2); // Get same 3 tiles. - sendTextFrame(socket, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname); const auto tile1 = assertResponseString(socket, "tile:", testname); std::string renderId1; LOOLProtocol::getTokenStringFromMessage(tile1, "renderid", renderId1); @@ -592,25 +593,25 @@ void TileCacheTests::testTilesRenderedJustOnceMultiClient() assertResponseString(socket, "invalidatetiles:", testname1); // Get 3 tiles. - sendTextFrame(socket, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname1); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname1); assertResponseString(socket, "tile:", testname1); assertResponseString(socket, "tile:", testname1); assertResponseString(socket, "tile:", testname1); assertResponseString(socket2, "invalidatetiles:", testname2); - sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname2); + sendTextFrame(socket2, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname2); assertResponseString(socket2, "tile:", testname2); assertResponseString(socket2, "tile:", testname2); assertResponseString(socket2, "tile:", testname2); assertResponseString(socket3, "invalidatetiles:", testname3); - sendTextFrame(socket3, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname3); + sendTextFrame(socket3, "tilecombine nviewid=0 part=0 nviewid=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname3); assertResponseString(socket3, "tile:", testname3); assertResponseString(socket3, "tile:", testname3); assertResponseString(socket3, "tile:", testname3); assertResponseString(socket4, "invalidatetiles:", testname4); - sendTextFrame(socket4, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname4); + sendTextFrame(socket4, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname4); assertResponseString(socket4, "tile:", testname4); assertResponseString(socket4, "tile:", testname4); assertResponseString(socket4, "tile:", testname4); @@ -623,7 +624,7 @@ void TileCacheTests::testTilesRenderedJustOnceMultiClient() CPPUNIT_ASSERT_EQUAL((i+1) * 3, renderCount2); // Get same 3 tiles. - sendTextFrame(socket, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname1); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840", testname1); const auto tile1 = assertResponseString(socket, "tile:", testname1); std::string renderId1; LOOLProtocol::getTokenStringFromMessage(tile1, "renderid", renderId1); @@ -664,8 +665,8 @@ void TileCacheTests::testSimultaneousTilesRenderedJustOnce() assertResponseString(socket1, "statechanged:", "client1 "); assertResponseString(socket2, "statechanged:", "client2 "); - sendTextFrame(socket1, "tile part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000"); - sendTextFrame(socket2, "tile part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000"); + sendTextFrame(socket1, "tile nviewid=0 part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000"); + sendTextFrame(socket2, "tile nviewid=0 part=42 width=400 height=400 tileposx=1000 tileposy=2000 tilewidth=3000 tileheight=3000"); const auto response1 = assertResponseString(socket1, "tile:", "client1 "); const auto response2 = assertResponseString(socket2, "tile:", "client2 "); @@ -752,7 +753,7 @@ void TileCacheTests::checkBlackTiles(std::shared_ptr<LOOLWebSocket>& socket, con // render correctly and there are no black tiles. // Current cap of table size ends at 257280 twips (for load12.ods), // otherwise 2035200 should be rendered successfully. - const char* req = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840"; + const char* req = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840"; sendTextFrame(socket, req); const std::vector<char> tile = getResponseMessage(socket, "tile:", name); @@ -1139,21 +1140,22 @@ void TileCacheTests::requestTiles(std::shared_ptr<LOOLWebSocket>& socket, const tileHeight = tileSize; tileX = tileSize * itCol; tileY = tileSize * itRow; - text = Poco::format("tile part=%d width=%d height=%d tileposx=%d tileposy=%d tilewidth=%d tileheight=%d", + text = Poco::format("tile nviewid=0 part=%d width=%d height=%d tileposx=%d tileposy=%d tilewidth=%d tileheight=%d", part, pixTileSize, pixTileSize, tileX, tileY, tileWidth, tileHeight); sendTextFrame(socket, text, name); tile = assertResponseString(socket, "tile:", name); - // expected tile: part= width= height= tileposx= tileposy= tilewidth= tileheight= + // expected tile: nviewid= part= width= height= tileposx= tileposy= tilewidth= tileheight= Poco::StringTokenizer tokens(tile, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); CPPUNIT_ASSERT_EQUAL(std::string("tile:"), tokens[0]); - CPPUNIT_ASSERT_EQUAL(part, std::stoi(tokens[1].substr(std::string("part=").size()))); - CPPUNIT_ASSERT_EQUAL(pixTileSize, std::stoi(tokens[2].substr(std::string("width=").size()))); - CPPUNIT_ASSERT_EQUAL(pixTileSize, std::stoi(tokens[3].substr(std::string("height=").size()))); - CPPUNIT_ASSERT_EQUAL(tileX, std::stoi(tokens[4].substr(std::string("tileposx=").size()))); - CPPUNIT_ASSERT_EQUAL(tileY, std::stoi(tokens[5].substr(std::string("tileposy=").size()))); - CPPUNIT_ASSERT_EQUAL(tileWidth, std::stoi(tokens[6].substr(std::string("tileWidth=").size()))); - CPPUNIT_ASSERT_EQUAL(tileHeight, std::stoi(tokens[7].substr(std::string("tileHeight=").size()))); + CPPUNIT_ASSERT_EQUAL(0, std::stoi(tokens[1].substr(std::string("nviewid=").size()))); + CPPUNIT_ASSERT_EQUAL(part, std::stoi(tokens[2].substr(std::string("part=").size()))); + CPPUNIT_ASSERT_EQUAL(pixTileSize, std::stoi(tokens[3].substr(std::string("width=").size()))); + CPPUNIT_ASSERT_EQUAL(pixTileSize, std::stoi(tokens[4].substr(std::string("height=").size()))); + CPPUNIT_ASSERT_EQUAL(tileX, std::stoi(tokens[5].substr(std::string("tileposx=").size()))); + CPPUNIT_ASSERT_EQUAL(tileY, std::stoi(tokens[6].substr(std::string("tileposy=").size()))); + CPPUNIT_ASSERT_EQUAL(tileWidth, std::stoi(tokens[7].substr(std::string("tileWidth=").size()))); + CPPUNIT_ASSERT_EQUAL(tileHeight, std::stoi(tokens[8].substr(std::string("tileHeight=").size()))); } } } @@ -1208,7 +1210,7 @@ void TileCacheTests::testTileRequestByZoom() sendTextFrame(socket, "clientzoom tilepixelwidth=256 tilepixelheight=256 tiletwipwidth=3200 tiletwipheight=3200"); // Request all tile of the visible area (it happens by zoom) - sendTextFrame(socket, "tilecombine part=0 width=256 height=256 tileposx=0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800 tileposy=0,0,0,0,0,3200,3200,3200,3200,3200,6400,6400,6400,6400,6400,9600,9600,9600,9600,9600 tilewidth=3200 tileheight=3200"); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800 tileposy=0,0,0,0,0,3200,3200,3200,3200,3200,6400,6400,6400,6400,6400,9600,9600,9600,9600,9600 tilewidth=3200 tileheight=3200"); // Check that we get all the tiles without we send back the tileprocessed message for (int i = 0; i < 20; ++i) @@ -1280,7 +1282,7 @@ void TileCacheTests::testTileProcessed() sendTextFrame(socket, "clientzoom tilepixelwidth=256 tilepixelheight=256 tiletwipwidth=3200 tiletwipheight=3200"); // Request a lots of tiles (more than wsd can send once) - sendTextFrame(socket, "tilecombine part=0 width=256 height=256 tileposx=0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800 tileposy=0,0,0,0,0,3200,3200,3200,3200,3200,6400,6400,6400,6400,6400,9600,9600,9600,9600,9600,12800,12800,12800,12800,12800 tilewidth=3200 tileheight=3200"); + sendTextFrame(socket, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800,0,3200,6400,9600,12800 tileposy=0,0,0,0,0,3200,3200,3200,3200,3200,6400,6400,6400,6400,6400,9600,9600,9600,9600,9600,12800,12800,12800,12800,12800 tilewidth=3200 tileheight=3200"); std::vector<std::string> tileIDs; int arrivedTile = 0; @@ -1295,11 +1297,12 @@ void TileCacheTests::testTileProcessed() // Store tileID, so we can send it back Poco::StringTokenizer tokens(tile, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); - std::string tileID = tokens[1].substr(std::string("part=").size()) + ":" + - tokens[4].substr(std::string("tileposx=").size()) + ":" + - tokens[5].substr(std::string("tileposy=").size()) + ":" + - tokens[6].substr(std::string("tileWidth=").size()) + ":" + - tokens[7].substr(std::string("tileHeight=").size()); + std::string tileID = tokens[2].substr(std::string("part=").size()) + ":" + + tokens[5].substr(std::string("tileposx=").size()) + ":" + + tokens[6].substr(std::string("tileposy=").size()) + ":" + + tokens[7].substr(std::string("tileWidth=").size()) + ":" + + tokens[8].substr(std::string("tileHeight=").size()) + ":" + + tokens[1].substr(std::string("nviewid=").size()); tileIDs.push_back(tileID); } @@ -1416,7 +1419,7 @@ void TileCacheTests::testTileBeingRenderedHandling() CPPUNIT_ASSERT_EQUAL(1, arrivedTiles); - sendTextFrame(socket, "tileprocessed tile=0:0:0:3200:3200"); + sendTextFrame(socket, "tileprocessed tile=0:0:0:3200:3200:0"); } } @@ -1475,7 +1478,7 @@ void TileCacheTests::testWireIDFilteringOnWSDSide() //2. Now request the same tiles by the other client (e.g. scroll to the same view) - sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840"); + sendTextFrame(socket2, "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840"); // We expect three tiles sent to the second client arrivedTiles = 0; @@ -1538,7 +1541,7 @@ void TileCacheTests::testLimitTileVersionsOnFly() // When the next tileprocessed message arrive with correct tileID // wsd sends the delayed tile - sendTextFrame(socket, "tileprocessed tile=0:0:0:3200:3200"); + sendTextFrame(socket, "tileprocessed tile=0:0:0:3200:3200:0"); int arrivedTiles = 0; bool gotTile = false; diff --git a/test/TileQueueTests.cpp b/test/TileQueueTests.cpp index 13088cd72..209c5ffa9 100644 --- a/test/TileQueueTests.cpp +++ b/test/TileQueueTests.cpp @@ -70,11 +70,11 @@ class TileQueueTests : public CPPUNIT_NS::TestFixture void TileQueueTests::testTileQueuePriority() { - const std::string reqHigh = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0"; - const std::string resHigh = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1"; + const std::string reqHigh = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0"; + const std::string resHigh = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1"; const TileQueue::Payload payloadHigh(resHigh.data(), resHigh.data() + resHigh.size()); - const std::string reqLow = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 oldwid=0 wid=0"; - const std::string resLow = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1"; + const std::string reqLow = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 oldwid=0 wid=0"; + const std::string resLow = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1"; const TileQueue::Payload payloadLow(resLow.data(), resLow.data() + resLow.size()); TileQueue queue; @@ -116,15 +116,15 @@ void TileQueueTests::testTileQueuePriority() void TileQueueTests::testTileCombinedRendering() { - const std::string req1 = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840"; - const std::string req2 = "tile part=0 width=256 height=256 tileposx=3840 tileposy=0 tilewidth=3840 tileheight=3840"; - const std::string req3 = "tile part=0 width=256 height=256 tileposx=0 tileposy=3840 tilewidth=3840 tileheight=3840"; + const std::string req1 = "tile nviewid=0 nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840"; + const std::string req2 = "tile nviewid=0 part=0 width=256 height=256 tileposx=3840 tileposy=0 tilewidth=3840 tileheight=3840"; + const std::string req3 = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=3840 tilewidth=3840 tileheight=3840"; - const std::string resHor = "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 imgsize=0,0 tilewidth=3840 tileheight=3840 ver=-1,-1 oldwid=0,0 wid=0,0"; + const std::string resHor = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 imgsize=0,0 tilewidth=3840 tileheight=3840 ver=-1,-1 oldwid=0,0 wid=0,0"; const TileQueue::Payload payloadHor(resHor.data(), resHor.data() + resHor.size()); - const std::string resVer = "tilecombine part=0 width=256 height=256 tileposx=0,0 tileposy=0,3840 imgsize=0,0 tilewidth=3840 tileheight=3840 ver=-1,-1 oldwid=0,0 wid=0,0"; + const std::string resVer = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,0 tileposy=0,3840 imgsize=0,0 tilewidth=3840 tileheight=3840 ver=-1,-1 oldwid=0,0 wid=0,0"; const TileQueue::Payload payloadVer(resVer.data(), resVer.data() + resVer.size()); - const std::string resFull = "tilecombine part=0 width=256 height=256 tileposx=0,3840,0 tileposy=0,0,3840 imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0"; + const std::string resFull = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,0 tileposy=0,0,3840 imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0"; const TileQueue::Payload payloadFull(resFull.data(), resFull.data() + resFull.size()); TileQueue queue; @@ -159,8 +159,8 @@ void TileQueueTests::testTileRecombining() { TileQueue queue; - queue.put("tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840"); - queue.put("tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); + queue.put("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840"); + queue.put("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840"); // the tilecombine's get merged, resulting in 3 "tile" messages CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(queue.getQueue().size())); @@ -168,7 +168,7 @@ void TileQueueTests::testTileRecombining() // but when we later extract that, it is just one "tilecombine" message std::string message(payloadAsString(queue.get())); - CPPUNIT_ASSERT_EQUAL(std::string("tilecombine part=0 width=256 height=256 tileposx=7680,0,3840 tileposy=0,0,0 imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0"), message); + CPPUNIT_ASSERT_EQUAL(std::string("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=7680,0,3840 tileposy=0,0,0 imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0"), message); // and nothing remains in the queue CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size())); @@ -188,10 +188,10 @@ void TileQueueTests::testViewOrder() const std::vector<std::string> tiles = { - "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", - "tile part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", - "tile part=0 width=256 height=256 tileposx=0 tileposy=15360 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", - "tile part=0 width=256 height=256 tileposx=0 tileposy=23040 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1" + "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", + "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", + "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=15360 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", + "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=23040 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1" }; for (auto &tile : tiles) @@ -214,10 +214,10 @@ void TileQueueTests::testPreviewsDeprioritization() // simple case - put previews to the queue and get everything back again const std::vector<std::string> previews = { - "tile part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=0", - "tile part=1 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=1", - "tile part=2 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=2", - "tile part=3 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=3" + "tile nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=0", + "tile nviewid=0 part=1 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=1", + "tile nviewid=0 part=2 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=2", + "tile nviewid=0 part=3 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=3" }; for (auto &preview : previews) @@ -236,8 +236,8 @@ void TileQueueTests::testPreviewsDeprioritization() // the previews const std::vector<std::string> tiles = { - "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", - "tile part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1" + "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1", + "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1" }; for (auto &preview : previews) @@ -323,9 +323,9 @@ void TileQueueTests::testSenderQueueTileDeduplication() const std::vector<std::string> part_messages = { - "tile: part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=0", - "tile: part=1 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1", - "tile: part=2 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1" + "tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=0", + "tile: nviewid=0 part=1 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1", + "tile: nviewid=0 part=2 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1" }; for (const auto& msg : part_messages) @@ -342,9 +342,9 @@ void TileQueueTests::testSenderQueueTileDeduplication() const std::vector<std::string> dup_messages = { - "tile: part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1", - "tile: part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1", - "tile: part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1" + "tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1", + "tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1", + "tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1" }; for (const auto& msg : dup_messages) diff --git a/test/UnitTyping.cpp b/test/UnitTyping.cpp index 31b3a3fa3..e3f6263a9 100644 --- a/test/UnitTyping.cpp +++ b/test/UnitTyping.cpp @@ -135,7 +135,7 @@ public: { std::ostringstream oss; std::uniform_int_distribution<int> distribution(0,32); - oss << "tilecombine part=0 width=512 height=512" + oss << "tilecombine nviewid=0 part=0 width=512 height=512" << " tileposx=" << 3840*distribution(randDev) << " tileposy=" << 3840*distribution(randDev) << " tilewidth=7680 tileheight=7680"; @@ -167,7 +167,7 @@ public: std::vector<char> tile = getResponseMessage(sock, "tile:", testname, waitMS /* ms */); if (tile.size()) { -// 1544818858022 INCOMING: tile: part=0 width=256 height=256 tileposx=15360 tileposy=38400 tilewidth=3840 tileheight=3840 oldwid=0 wid=232 ver=913 imgsize=1002 +// 1544818858022 INCOMING: tile: nviewid=0 part=0 width=256 height=256 tileposx=15360 tileposy=38400 tilewidth=3840 tileheight=3840 oldwid=0 wid=232 ver=913 imgsize=1002 // Socket.js:123 1544818858027 OUTGOING: tileprocessed tile=0:15360:38400:3840:3840 TileDesc desc = TileDesc::parse(LOOLProtocol::tokenize(tile.data(), tile.size())); sendTextFrame(sock, "tileprocessed tile=" + desc.generateID(), testname); diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index 6ad9465ab..597adb500 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -355,17 +355,18 @@ void WhiteBoxTests::testTokenizer() CPPUNIT_ASSERT_EQUAL(std::string("A"), tokens[0]); CPPUNIT_ASSERT_EQUAL(std::string("Z"), tokens[1]); - tokens = LOOLProtocol::tokenize("tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 ver=-1"); - CPPUNIT_ASSERT_EQUAL(9UL, tokens.size()); + tokens = LOOLProtocol::tokenize("tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 ver=-1"); + CPPUNIT_ASSERT_EQUAL(10UL, tokens.size()); CPPUNIT_ASSERT_EQUAL(std::string("tile"), tokens[0]); - CPPUNIT_ASSERT_EQUAL(std::string("part=0"), tokens[1]); - CPPUNIT_ASSERT_EQUAL(std::string("width=256"), tokens[2]); - CPPUNIT_ASSERT_EQUAL(std::string("height=256"), tokens[3]); - CPPUNIT_ASSERT_EQUAL(std::string("tileposx=0"), tokens[4]); - CPPUNIT_ASSERT_EQUAL(std::string("tileposy=0"), tokens[5]); - CPPUNIT_ASSERT_EQUAL(std::string("tilewidth=3840"), tokens[6]); - CPPUNIT_ASSERT_EQUAL(std::string("tileheight=3840"), tokens[7]); - CPPUNIT_ASSERT_EQUAL(std::string("ver=-1"), tokens[8]); + CPPUNIT_ASSERT_EQUAL(std::string("nviewid=0"), tokens[1]); + CPPUNIT_ASSERT_EQUAL(std::string("part=0"), tokens[2]); + CPPUNIT_ASSERT_EQUAL(std::string("width=256"), tokens[3]); + CPPUNIT_ASSERT_EQUAL(std::string("height=256"), tokens[4]); + CPPUNIT_ASSERT_EQUAL(std::string("tileposx=0"), tokens[5]); + CPPUNIT_ASSERT_EQUAL(std::string("tileposy=0"), tokens[6]); + CPPUNIT_ASSERT_EQUAL(std::string("tilewidth=3840"), tokens[7]); + CPPUNIT_ASSERT_EQUAL(std::string("tileheight=3840"), tokens[8]); + CPPUNIT_ASSERT_EQUAL(std::string("ver=-1"), tokens[9]); // With custom delimiters tokens = LOOLProtocol::tokenize(std::string("ABC:DEF"), ':'); diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp index 1eba6cad2..5fac32874 100644 --- a/test/httpwstest.cpp +++ b/test/httpwstest.cpp @@ -1760,7 +1760,7 @@ void HTTPWSTest::testCalcEditRendering() assertResponseString(socket, "cellformula: abc", testname); - const char* req = "tilecombine part=0 width=512 height=512 tileposx=3840 tileposy=0 tilewidth=7680 tileheight=7680"; + const char* req = "tilecombine nviewid=0 part=0 width=512 height=512 tileposx=3840 tileposy=0 tilewidth=7680 tileheight=7680"; sendTextFrame(socket, req, testname); const std::vector<char> tile = getResponseMessage(socket, "tile:", testname); @@ -1844,7 +1844,7 @@ void HTTPWSTest::testCalcRenderAfterNewView51() // Wait for status due to doc resize. assertResponseString(socket, "status:", testname); - const char* req = "tilecombine part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840"; + const char* req = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840"; // Get tile. const std::vector<char> tile1 = getTileAndSave(socket, req, "/tmp/calc_render_51_orig.png", testname); @@ -1890,7 +1890,7 @@ void HTTPWSTest::testCalcRenderAfterNewView53() sendTextFrame(socket, "key type=input char=0 key=1031", testname); // Get tile. - const char* req = "tilecombine part=0 width=256 height=256 tileposx=0 tileposy=291840 tilewidth=3840 tileheight=3840 oldwid=0"; + const char* req = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=291840 tilewidth=3840 tileheight=3840 oldwid=0"; const std::vector<char> tile1 = getTileAndSave(socket, req, "/tmp/calc_render_53_orig.png", testname); commit 86489d3dcdf24123abe2a3452ad54641c119bee2 Author: mert <mert.tu...@collabora.com> AuthorDate: Tue Oct 15 15:35:35 2019 +0300 Commit: mert <mert.tu...@collabora.com> CommitDate: Tue Oct 15 18:13:03 2019 +0300 Include normalizedViewId to TileCache Change-Id: Ib23afa023d79189f7fd7aca8b5b0e198c3011fbc diff --git a/common/Session.cpp b/common/Session.cpp index e5a70c081..43db40908 100644 --- a/common/Session.cpp +++ b/common/Session.cpp @@ -256,6 +256,23 @@ void Session::getIOStats(uint64_t &sent, uint64_t &recv) } } +void Session::setHash(const std::string& text) + { + int hash = 0x811C9DC5; + int prime = 0x1000193; + + if (!text.empty()) + { + for (unsigned int i = 0; i < text.length(); ++i) + { + hash += hash ^ text[i]; + hash *= prime; + } + } + _hash = abs(hash); + } + + void Session::dumpState(std::ostream& os) { WebSocketHandler::dumpState(os); diff --git a/common/Session.hpp b/common/Session.hpp index 6955b1e66..623a9d3c7 100644 --- a/common/Session.hpp +++ b/common/Session.hpp @@ -122,6 +122,12 @@ public: const std::string& getJailedFilePathAnonym() const { return _jailedFilePathAnonym; } + int getHash() { return _hash; } + + void setHash(const std::string& text); + + void setHash(const int hash) { _hash = hash; }; + protected: Session(const std::string& name, const std::string& id, bool readonly); virtual ~Session(); @@ -212,6 +218,11 @@ private: /// Language for the document based on what the user has in the UI. std::string _lang; + + /// Hash for normalizedViewId which is basically an identity for the tile to + /// choose what to render on and send it to its subscribers + /// it is the close-to-unique integer representation of a string like Watermarks etc. + int _hash; }; #endif diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp index 971b4158b..7a5b16df8 100644 --- a/kit/ChildSession.hpp +++ b/kit/ChildSession.hpp @@ -24,6 +24,7 @@ #include "Kit.hpp" #include "Session.hpp" +class Watermark; class ChildSession; enum class LokEventTargetEnum @@ -215,6 +216,8 @@ public: void loKitCallback(const int type, const std::string& payload); + std::shared_ptr<Watermark> _docWatermark; + bool sendTextFrame(const char* buffer, int length) override { const auto msg = "client-" + getId() + ' ' + std::string(buffer, length); diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 60fe9ed81..44c41d886 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -68,6 +68,7 @@ #include <UserMessages.hpp> #include <Util.hpp> #include "Delta.hpp" +#include "Watermark.hpp" #if !MOBILEAPP #include <common/SigUtil.hpp> @@ -581,171 +582,6 @@ public: } }; -class Watermark -{ -public: - Watermark(const std::shared_ptr<lok::Document>& loKitDoc, - const std::shared_ptr<ChildSession> & session) - : _loKitDoc(loKitDoc) - , _text(session->getWatermarkText()) - , _font("Liberation Sans") - , _width(0) - , _height(0) - , _alphaLevel(session->getWatermarkOpacity()) - { - } - - ~Watermark() - { - } - - void blending(unsigned char* tilePixmap, - int offsetX, int offsetY, - int tilesPixmapWidth, int tilesPixmapHeight, - int tileWidth, int tileHeight, - LibreOfficeKitTileMode /*mode*/) - { - // set requested watermark size a little bit smaller than tile size - int width = tileWidth * 0.9; - int height = tileHeight * 0.9; - - const std::vector<unsigned char>* pixmap = getPixmap(width, height); - - if (pixmap && tilePixmap) - { - // center watermark - const int maxX = std::min(tileWidth, _width); - const int maxY = std::min(tileHeight, _height); - offsetX += (tileWidth - maxX) / 2; - offsetY += (tileHeight - maxY) / 2; - - alphaBlend(*pixmap, _width, _height, offsetX, offsetY, tilePixmap, tilesPixmapWidth, tilesPixmapHeight); - } - } - -private: - /// Alpha blend pixels from 'from' over the 'to'. - void alphaBlend(const std::vector<unsigned char>& from, int from_width, int from_height, int from_offset_x, int from_offset_y, - unsigned char* to, int to_width, int to_height) - { - for (int to_y = from_offset_y, from_y = 0; (to_y < to_height) && (from_y < from_height) ; ++to_y, ++from_y) - for (int to_x = from_offset_x, from_x = 0; (to_x < to_width) && (from_x < from_width); ++to_x, ++from_x) - { - const unsigned char* f = from.data() + 4 * (from_y * from_width + from_x); - double src_r = f[0]; - double src_g = f[1]; - double src_b = f[2]; - double src_a = f[3] / 255.0; - - unsigned char* t = to + 4 * (to_y * to_width + to_x); - double dst_r = t[0]; - double dst_g = t[1]; - double dst_b = t[2]; - double dst_a = t[3] / 255.0; - - double out_a = src_a + dst_a * (1.0 - src_a); - unsigned char out_r = src_r + dst_r * (1.0 - src_a); - unsigned char out_g = src_g + dst_g * (1.0 - src_a); - unsigned char out_b = src_b + dst_b * (1.0 - src_a); - - t[0] = out_r; - t[1] = out_g; - t[2] = out_b; - t[3] = static_cast<unsigned char>(out_a * 255.0); - } - } - - /// Create bitmap that we later use as the watermark for every tile. - const std::vector<unsigned char>* getPixmap(int width, int height) - { - if (!_pixmap.empty() && width == _width && height == _height) - return &_pixmap; - - _pixmap.clear(); - - _width = width; - _height = height; - - if (!_loKitDoc) - { - LOG_ERR("Watermark rendering requested without a valid document."); - return nullptr; - } - - // renderFont returns a buffer based on RGBA mode, where r, g, b - // are always set to 0 (black) and the alpha level is 0 everywhere - // except on the text area; the alpha level take into account of - // performing anti-aliasing over the text edges. - unsigned char* textPixels = _loKitDoc->renderFont(_font.c_str(), _text.c_str(), &_width, &_height); - - if (!textPixels) - { - LOG_ERR("Watermark: rendering failed."); - } - - const unsigned int pixel_count = width * height * 4; - - std::vector<unsigned char> text(textPixels, textPixels + pixel_count); - // No longer needed. - std::free(textPixels); - - _pixmap.reserve(pixel_count); - - // Create the white blurred background - // Use box blur, it's enough for our purposes - const int r = 2; - const double weight = (r+1) * (r+1); - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - double t = 0; - for (int ky = std::max(y - r, 0); ky <= std::min(y + r, height - 1); ++ky) - { - for (int kx = std::max(x - r, 0); kx <= std::min(x + r, width - 1); ++kx) - { - // Pre-multiplied alpha; the text is black, so all the - // information is only in the alpha channel - t += text[4 * (ky * width + kx) + 3]; - } - } - - // Clamp the result. - double avg = t / weight; - if (avg > 255.0) - avg = 255.0; - - // Pre-multiplied alpha, but use white for the resulting color - const double alpha = avg / 255.0; - _pixmap[4 * (y * width + x) + 0] = 0xff * alpha; - _pixmap[4 * (y * width + x) + 1] = 0xff * alpha; - _pixmap[4 * (y * width + x) + 2] = 0xff * alpha; - _pixmap[4 * (y * width + x) + 3] = avg; - } - } - - // Now copy the (black) text over the (white) blur - alphaBlend(text, _width, _height, 0, 0, _pixmap.data(), _width, _height); - - // Make the resulting pixmap semi-transparent - for (unsigned char* p = _pixmap.data(); p < _pixmap.data() + pixel_count; p++) - { - *p = static_cast<unsigned char>(*p * _alphaLevel); - } - - return &_pixmap; - } - -private: - std::shared_ptr<lok::Document> _loKitDoc; - std::string _text; - std::string _font; - int _width; - int _height; - double _alphaLevel; - std::vector<unsigned char> _pixmap; -}; - #if !MOBILEAPP static FILE* ProcSMapsFile = nullptr; #endif @@ -1140,6 +976,16 @@ public: const int pixelWidth = tileCombined.getWidth(); const int pixelHeight = tileCombined.getHeight(); + int nViewId = tileCombined.getNormalizedViewId(); + const auto it = std::find_if(_sessions.begin(), _sessions.end(), [nViewId](const std::pair<std::string, std::shared_ptr<ChildSession>>& val){ return (val.second)->getHash() == nViewId; }); + const auto& session = it->second; + + if (it == _sessions.end()) + { + LOG_ERR("Session is not found. Maybe exited after rendering request."); + return; + } + std::vector<TileDesc> renderedTiles; std::vector<TileDesc> duplicateTiles; std::vector<TileBinaryHash> duplicateHashes; @@ -1153,6 +999,11 @@ public: const int offsetX = positionX * pixelWidth; const int offsetY = positionY * pixelHeight; + if (session->hasWatermark()) + session->_docWatermark->blending(pixmap.data(), offsetX, offsetY, + pixmapWidth, pixmapHeight, + pixelWidth, pixelHeight, + mode); const uint64_t hash = Png::hashSubBuffer(pixmap.data(), offsetX, offsetY, pixelWidth, pixelHeight, pixmapWidth, pixmapHeight); @@ -1197,11 +1048,6 @@ public: if (!skipCompress) { renderingIds.push_back(wireId); - if (_docWatermark) - _docWatermark->blending(pixmap.data(), offsetX, offsetY, - pixmapWidth, pixmapHeight, - pixelWidth, pixelHeight, - mode); // Queue to be executed later in parallel inside 'run' _pngPool.pushWorkUnlocked([=,&output,&pixmap,&tiles,&renderedTiles](){ @@ -1816,9 +1662,6 @@ private: // Only save the options on opening the document. // No support for changing them after opening a document. _renderOpts = renderOpts; - - if (session->hasWatermark()) - _docWatermark.reset(new Watermark(_loKitDocument, session)); } else { @@ -1874,6 +1717,14 @@ private: sessionId << "] loaded view [" << viewId << "]. Have " << viewCount << " view" << (viewCount != 1 ? "s." : ".")); + if (session->hasWatermark()) + { + session->_docWatermark.reset(new Watermark(_loKitDocument, session)); + session->setHash(session->getWatermarkText()); + } + else + session->setHash(0); + return _loKitDocument; } @@ -2186,9 +2037,6 @@ private: // Whether password is required to view the document, or modify it PasswordType _docPasswordType; - // Document watermark - std::unique_ptr<Watermark> _docWatermark; - std::atomic<bool> _stop; mutable std::mutex _mutex; diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index fc95fbc6d..66c837fdf 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -1015,6 +1015,9 @@ L.Socket = L.Class.extend({ else if (tokens[i].substring(0, 7) === 'viewid=') { command.viewid = tokens[i].substring(7); } + else if (tokens[i].substring(0, 8) === 'nviewid=') { + command.nviewid = tokens[i].substring(8); + } else if (tokens[i].substring(0, 7) === 'params=') { command.params = tokens[i].substring(7).split(','); } diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 97ad079bf..2c5364289 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1769,7 +1769,7 @@ L.TileLayer = L.GridLayer.extend({ L.Log.log(textMsg, L.INCOMING, key); // Send acknowledgment, that the tile message arrived - var tileID = command.part + ':' + command.x + ':' + command.y + ':' + command.tileWidth + ':' + command.tileHeight; + var tileID = command.part + ':' + command.x + ':' + command.y + ':' + command.tileWidth + ':' + command.tileHeight + ':' + command.nviewid; this._map._socket.sendMessage('tileprocessed tile=' + tileID); }, diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index b0febef0d..8ddc0e91d 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -858,6 +858,7 @@ bool ClientSession::sendTile(const char * /*buffer*/, int /*length*/, const std: try { TileDesc tileDesc = TileDesc::parse(tokens); + tileDesc.setNormalizedViewId(getHash()); docBroker->handleTileRequest(tileDesc, shared_from_this()); } catch (const std::exception& exc) @@ -875,6 +876,7 @@ bool ClientSession::sendCombinedTiles(const char* /*buffer*/, int /*length*/, co try { TileCombined tileCombined = TileCombined::parse(tokens); + tileCombined.setNormalizedViewId(getHash()); docBroker->handleTileCombinedRequest(tileCombined, shared_from_this()); } catch (const std::exception& exc) @@ -1687,7 +1689,7 @@ void ClientSession::dumpState(std::ostream& os) void ClientSession::handleTileInvalidation(const std::string& message, const std::shared_ptr<DocumentBroker>& docBroker) { - docBroker->invalidateTiles(message); + docBroker->invalidateTiles(message, getHash()); // Skip requesting new tiles if we don't have client visible area data yet. if(!_clientVisibleArea.hasSurface() || @@ -1712,7 +1714,7 @@ void ClientSession::handleTileInvalidation(const std::string& message, if( part == -1 ) // If no part is specified we use the part used by the client part = _clientSelectedPart; - int normalizedViewId = 0; + int normalizedViewId = getHash(); std::vector<TileDesc> invalidTiles; if(part == _clientSelectedPart || _isTextDocument) @@ -1745,6 +1747,7 @@ void ClientSession::handleTileInvalidation(const std::string& message, if(!invalidTiles.empty()) { TileCombined tileCombined = TileCombined::create(invalidTiles); + tileCombined.setNormalizedViewId(normalizedViewId); docBroker->handleTileCombinedRequest(tileCombined, shared_from_this()); } } diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index fb3db87fc..791089042 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -669,6 +669,11 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s session->setUserExtraInfo(userExtraInfo); session->setWatermarkText(watermarkText); + if(!watermarkText.empty()) + session->setHash(watermarkText); + else + session->setHash(0); + // Basic file information was stored by the above getWOPIFileInfo() or getLocalFileInfo() calls const StorageBase::FileInfo fileInfo = _storage->getFileInfo(); if (!fileInfo.isValid()) @@ -1454,10 +1459,10 @@ bool DocumentBroker::handleInput(const std::vector<char>& payload) return true; } -void DocumentBroker::invalidateTiles(const std::string& tiles) +void DocumentBroker::invalidateTiles(const std::string& tiles, int normalizedViewId) { // Remove from cache. - _tileCache->invalidateTiles(tiles); + _tileCache->invalidateTiles(tiles, normalizedViewId); } void DocumentBroker::handleTileRequest(TileDesc& tile, @@ -1558,7 +1563,8 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined, for (auto& oldTile : requestedTiles) { if(oldTile.getTilePosX() == newTile.getTilePosX() && - oldTile.getTilePosY() == newTile.getTilePosY() ) + oldTile.getTilePosY() == newTile.getTilePosY() && + oldTile.getNormalizedViewId() == newTile.getNormalizedViewId()) { oldTile.setVersion(newTile.getVersion()); oldTile.setOldWireId(newTile.getOldWireId()); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 7c66832a5..5ab980a75 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -310,7 +310,7 @@ public: _cursorHeight = h; } - void invalidateTiles(const std::string& tiles); + void invalidateTiles(const std::string& tiles, int normalizedViewId); void handleTileRequest(TileDesc& tile, const std::shared_ptr<ClientSession>& session); void handleTileCombinedRequest(TileCombined& tileCombined, diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp index 62ee52a9e..df4141dfa 100644 --- a/wsd/TileCache.cpp +++ b/wsd/TileCache.cpp @@ -287,7 +287,7 @@ TileCache::Tile TileCache::lookupCachedStream(StreamType type, const std::string return TileCache::Tile(); } -void TileCache::invalidateTiles(int part, int x, int y, int width, int height) +void TileCache::invalidateTiles(int part, int x, int y, int width, int height, int normalizedViewId) { LOG_TRC("Removing invalidated tiles: part: " << part << ", x: " << x << ", y: " << y << @@ -298,7 +298,7 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height) for (auto it = _cache.begin(); it != _cache.end();) { - if (intersectsTile(it->first, part, x, y, width, height)) + if (intersectsTile(it->first, part, x, y, width, height, normalizedViewId)) { LOG_TRC("Removing tile: " << it->first.serialize()); it = _cache.erase(it); @@ -308,11 +308,11 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height) } } -void TileCache::invalidateTiles(const std::string& tiles) +void TileCache::invalidateTiles(const std::string& tiles, int normalizedViewId) { std::pair<int, Util::Rectangle> result = TileCache::parseInvalidateMsg(tiles); Util::Rectangle& invalidateRect = result.second; - invalidateTiles(result.first, invalidateRect.getLeft(), invalidateRect.getTop(), invalidateRect.getWidth(), invalidateRect.getHeight()); + invalidateTiles(result.first, invalidateRect.getLeft(), invalidateRect.getTop(), invalidateRect.getWidth(), invalidateRect.getHeight(), normalizedViewId); } std::pair<int, Util::Rectangle> TileCache::parseInvalidateMsg(const std::string& tiles) @@ -365,22 +365,25 @@ void TileCache::removeStream(StreamType type, const std::string& fileName) std::string TileCache::cacheFileName(const TileDesc& tile) { std::ostringstream oss; - oss << tile.getPart() << '_' << tile.getWidth() << 'x' << tile.getHeight() << '.' + oss << tile.getNormalizedViewId() << '_' << tile.getPart() << '_' << tile.getWidth() << 'x' << tile.getHeight() << '.' << tile.getTilePosX() << ',' << tile.getTilePosY() << '.' << tile.getTileWidth() << 'x' << tile.getTileHeight() << ".png"; return oss.str(); } -bool TileCache::parseCacheFileName(const std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight) +bool TileCache::parseCacheFileName(const std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight, int& nviewid) { - return std::sscanf(fileName.c_str(), "%d_%dx%d.%d,%d.%dx%d.png", &part, &width, &height, &tilePosX, &tilePosY, &tileWidth, &tileHeight) == 7; + return std::sscanf(fileName.c_str(), "%d_%d_%dx%d.%d,%d.%dx%d.png", &nviewid, &part, &width, &height, &tilePosX, &tilePosY, &tileWidth, &tileHeight) == 8; } -bool TileCache::intersectsTile(const TileDesc &tileDesc, int part, int x, int y, int width, int height) +bool TileCache::intersectsTile(const TileDesc &tileDesc, int part, int x, int y, int width, int height, int normalizedViewId) { if (part != -1 && tileDesc.getPart() != part) return false; + if (normalizedViewId != tileDesc.getNormalizedViewId()) + return false; + const int left = std::max(x, tileDesc.getTilePosX()); const int right = std::min(x + width, tileDesc.getTilePosX() + tileDesc.getTileWidth()); const int top = std::max(y, tileDesc.getTilePosY()); @@ -393,7 +396,7 @@ bool TileCache::intersectsTile(const TileDesc &tileDesc, int part, int x, int y, void TileCache::subscribeToTileRendering(const TileDesc& tile, const std::shared_ptr<ClientSession>& subscriber) { std::ostringstream oss; - oss << '(' << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ')'; + oss << '(' << tile.getNormalizedViewId() << ',' << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ')'; const std::string name = oss.str(); assertCorrectThread(); @@ -518,8 +521,13 @@ TileCache::Tile TileCache::findTile(const TileDesc &desc) auto it = _cache.find(desc); if (it != _cache.end()) { - LOG_TRC("Found cache tile: " << desc.serialize() << " of size " << it->second->size() << " bytes"); - return it->second; + if (it->first.getNormalizedViewId() == desc.getNormalizedViewId()) + { + LOG_TRC("Found cache tile: " << desc.serialize() << " of size " << it->second->size() << " bytes"); + return it->second; + } + else + return TileCache::Tile(); } else return TileCache::Tile(); diff --git a/wsd/TileCache.hpp b/wsd/TileCache.hpp index 88d837e10..5d43abd7e 100644 --- a/wsd/TileCache.hpp +++ b/wsd/TileCache.hpp @@ -129,7 +129,7 @@ public: Tile lookupCachedStream(StreamType type, const std::string& name); // The tiles parameter is an invalidatetiles: message as sent by the child process - void invalidateTiles(const std::string& tiles); + void invalidateTiles(const std::string& tiles, int normalizedViewId); /// Parse invalidateTiles message to a part number and a rectangle of the invalidated area static std::pair<int, Util::Rectangle> parseInvalidateMsg(const std::string& tiles); @@ -147,7 +147,7 @@ public: void assertCorrectThread(); private: - void invalidateTiles(int part, int x, int y, int width, int height); + void invalidateTiles(int part, int x, int y, int width, int height, int normalizedViewId); /// Lookup tile in our cache. TileCache::Tile findTile(const TileDesc &desc); @@ -159,10 +159,10 @@ private: void removeStream(StreamType type, const std::string& fileName); static std::string cacheFileName(const TileDesc& tileDesc); - static bool parseCacheFileName(const std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight); + static bool parseCacheFileName(const std::string& fileName, int& part, int& width, int& height, int& tilePosX, int& tilePosY, int& tileWidth, int& tileHeight, int& nviewid); /// Extract location from fileName, and check if it intersects with [x, y, width, height]. - static bool intersectsTile(const TileDesc &tileDesc, int part, int x, int y, int width, int height); + static bool intersectsTile(const TileDesc &tileDesc, int part, int x, int y, int width, int height, int normalizedViewId); void saveDataToCache(const TileDesc &desc, const char *data, const size_t size); void saveDataToStreamCache(StreamType type, const std::string &fileName, const char *data, const size_t size); diff --git a/wsd/TileDesc.hpp b/wsd/TileDesc.hpp index 9f11f334d..c5a98e5ee 100644 --- a/wsd/TileDesc.hpp +++ b/wsd/TileDesc.hpp @@ -89,7 +89,8 @@ public: _tileWidth == other._tileWidth && _tileHeight == other._tileHeight && _id == other._id && - _broadcast == other._broadcast; + _broadcast == other._broadcast && + _normalizedViewId == other._normalizedViewId; } static bool rectanglesIntersect(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) commit 2ee14aa148e4d68805314758a36dafad569ed13f Author: mert <mert.tu...@collabora.com> AuthorDate: Mon Oct 14 14:12:26 2019 +0300 Commit: mert <mert.tu...@collabora.com> CommitDate: Tue Oct 15 18:13:03 2019 +0300 Extend TileDesc with normalizedViewId Change-Id: I92046106e346289240884632d6ec6e0da7b8eabb diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js index 5acee51fb..4c3ff9cec 100644 --- a/loleaflet/src/control/Parts.js +++ b/loleaflet/src/control/Parts.js @@ -125,6 +125,7 @@ L.Map.include({ } this._socket.sendMessage('tile ' + + 'nviewid=0' + ' ' + 'part=' + part + ' ' + 'width=' + maxWidth * dpiscale + ' ' + 'height=' + maxHeight * dpiscale + ' ' + @@ -149,6 +150,7 @@ L.Map.include({ var dpiscale = L.getDpiScaleFactor(); this._socket.sendMessage('tile ' + + 'nviewid=0' + ' ' + 'part=' + part + ' ' + 'width=' + width * dpiscale + ' ' + 'height=' + height * dpiscale + ' ' + diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js index 49a06ee18..26a3806d3 100644 --- a/loleaflet/src/layer/tile/GridLayer.js +++ b/loleaflet/src/layer/tile/GridLayer.js @@ -688,6 +688,7 @@ L.GridLayer = L.Layer.extend({ if (tilePositionsX !== '' && tilePositionsY !== '') { var message = 'tilecombine ' + + 'nviewid=0 ' + 'part=' + this._selectedPart + ' ' + 'width=' + this._tileWidthPx + ' ' + 'height=' + this._tileHeightPx + ' ' + @@ -1024,6 +1025,7 @@ L.GridLayer = L.Layer.extend({ twips = this._coordsToTwips(coords); msg = 'tilecombine ' + + 'nviewid=0 ' + 'part=' + coords.part + ' ' + 'width=' + this._tileWidthPx + ' ' + 'height=' + this._tileHeightPx + ' ' + diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 996273218..b0febef0d 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -1712,6 +1712,8 @@ void ClientSession::handleTileInvalidation(const std::string& message, if( part == -1 ) // If no part is specified we use the part used by the client part = _clientSelectedPart; + int normalizedViewId = 0; + std::vector<TileDesc> invalidTiles; if(part == _clientSelectedPart || _isTextDocument) { @@ -1726,7 +1728,7 @@ void ClientSession::handleTileInvalidation(const std::string& message, Util::Rectangle tileRect (j * _tileWidthTwips, i * _tileHeightTwips, _tileWidthTwips, _tileHeightTwips); if(invalidateRect.intersects(tileRect)) { - invalidTiles.emplace_back(part, _tileWidthPixel, _tileHeightPixel, j * _tileWidthTwips, i * _tileHeightTwips, _tileWidthTwips, _tileHeightTwips, -1, 0, -1, false); + invalidTiles.emplace_back(normalizedViewId, part, _tileWidthPixel, _tileHeightPixel, j * _tileWidthTwips, i * _tileHeightTwips, _tileWidthTwips, _tileHeightTwips, -1, 0, -1, false); TileWireId oldWireId = 0; auto iter = _oldWireIds.find(invalidTiles.back().generateID()); diff --git a/wsd/TileDesc.hpp b/wsd/TileDesc.hpp index 637f2cbd8..9f11f334d 100644 --- a/wsd/TileDesc.hpp +++ b/wsd/TileDesc.hpp @@ -29,9 +29,10 @@ typedef uint64_t TileBinaryHash; class TileDesc { public: - TileDesc(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, + TileDesc(int normalizedViewId, int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, int ver, int imgSize, int id, bool broadcast) - : _part(part) + : _normalizedViewId(normalizedViewId) + , _part(part) , _width(width) , _height(height) , _tilePosX(tilePosX) @@ -45,7 +46,8 @@ public: , _oldWireId(0) , _wireId(0) { - if (_part < 0 || + if (_normalizedViewId < 0 || + _part < 0 || _width <= 0 || _height <= 0 || _tilePosX < 0 || @@ -57,7 +59,8 @@ public: throw BadArgumentException("Invalid tile descriptor."); } } - + int getNormalizedViewId() const { return _normalizedViewId; } + void setNormalizedViewId(const int normalizedViewId) { _normalizedViewId = normalizedViewId; } int getPart() const { return _part; } int getWidth() const { return _width; } int getHeight() const { return _height; } @@ -128,7 +131,8 @@ public: other.getWidth() != getWidth() || other.getHeight() != getHeight() || other.getTileWidth() != getTileWidth() || - other.getTileHeight() != getTileHeight()) + other.getTileHeight() != getTileHeight() || + other.getNormalizedViewId() != getNormalizedViewId()) { return false; } @@ -158,6 +162,7 @@ public: { std::ostringstream oss; oss << prefix + << " nviewid=" << _normalizedViewId << " part=" << _part << " width=" << _width << " height=" << _height @@ -225,7 +230,7 @@ public: const bool broadcast = (LOOLProtocol::getTokenString(tokens, "broadcast", s) && s == "yes"); - TileDesc result(pairs["part"], pairs["width"], pairs["height"], + TileDesc result(pairs["nviewid"], pairs["part"], pairs["width"], pairs["height"], pairs["tileposx"], pairs["tileposy"], pairs["tilewidth"], pairs["tileheight"], pairs["ver"], @@ -246,11 +251,12 @@ public: { std::ostringstream tileID; tileID << getPart() << ":" << getTilePosX() << ":" << getTilePosY() << ":" - << getTileWidth() << ":" << getTileHeight(); + << getTileWidth() << ":" << getTileHeight() << ":" << getNormalizedViewId(); return tileID.str(); } protected: + int _normalizedViewId; int _part; int _width; int _height; @@ -272,12 +278,13 @@ protected: class TileCombined { private: - TileCombined(int part, int width, int height, + TileCombined(int normalizedViewId, int part, int width, int height, const std::string& tilePositionsX, const std::string& tilePositionsY, int tileWidth, int tileHeight, const std::string& vers, const std::string& imgSizes, const std::string& oldWireIds, const std::string& wireIds) : + _normalizedViewId(normalizedViewId), _part(part), _width(width), _height(height), @@ -350,13 +357,14 @@ private: throw BadArgumentException("Invalid tilecombine descriptor."); } - _tiles.emplace_back(_part, _width, _height, x, y, _tileWidth, _tileHeight, ver, imgSize, -1, false); + _tiles.emplace_back(_normalizedViewId, _part, _width, _height, x, y, _tileWidth, _tileHeight, ver, imgSize, -1, false); _tiles.back().setOldWireId(oldWireId); _tiles.back().setWireId(wireId); } } public: + int getNormalizedViewId() const { return _normalizedViewId; } int getPart() const { return _part; } int getWidth() const { return _width; } int getHeight() const { return _height; } @@ -366,6 +374,15 @@ public: const std::vector<TileDesc>& getTiles() const { return _tiles; } std::vector<TileDesc>& getTiles() { return _tiles; } + void setNormalizedViewId(int nViewId) + { + for (auto& tile : getTiles()) + tile.setNormalizedViewId(nViewId); + + _normalizedViewId = nViewId; + } + + /// Serialize this instance into a string. /// Optionally prepend a prefix. std::string serialize(const std::string& prefix = std::string(), @@ -379,6 +396,7 @@ public: { std::ostringstream oss; oss << prefix + << " nviewid=" << _normalizedViewId << " part=" << _part << " width=" << _width << " height=" << _height @@ -491,7 +509,7 @@ public: } } - return TileCombined(pairs["part"], pairs["width"], pairs["height"], + return TileCombined(pairs["nviewid"], pairs["part"], pairs["width"], pairs["height"], tilePositionsX, tilePositionsY, pairs["tilewidth"], pairs["tileheight"], versions, imgSizes, oldwireIds, wireIds); @@ -523,7 +541,7 @@ public: } vers.seekp(-1, std::ios_base::cur); // Remove last comma. - return TileCombined(tiles[0].getPart(), tiles[0].getWidth(), tiles[0].getHeight(), + return TileCombined(tiles[0].getNormalizedViewId(), tiles[0].getPart(), tiles[0].getWidth(), tiles[0].getHeight(), xs.str(), ys.str(), tiles[0].getTileWidth(), tiles[0].getTileHeight(), vers.str(), "", oldhs.str(), hs.str()); } @@ -536,11 +554,13 @@ public: _height = desc.getHeight(); _tileWidth = desc.getTileWidth(); _tileHeight = desc.getTileHeight(); + _normalizedViewId = desc.getNormalizedViewId(); _tiles.push_back(desc); } private: std::vector<TileDesc> _tiles; + int _normalizedViewId; int _part; int _width; int _height; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits