[Libreoffice-commits] online.git: 2 commits - kit/Kit.cpp scripts/perftrace.pl wsd/TileDesc.hpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Apr 19 22:51:48 UTC 2019


 kit/Kit.cpp          |  103 +++++++++------------------------------------------
 scripts/perftrace.pl |    4 -
 wsd/TileDesc.hpp     |   32 +++++++--------
 3 files changed, 37 insertions(+), 102 deletions(-)

New commits:
commit 2871653bf464e168a2bc24a8048291e886398fb1
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Apr 19 22:48:41 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Apr 19 23:51:26 2019 +0100

    Simplify legacy single tile rendering code-path.
    
    Remove redundant _id member from TileCombined, add constructor
    from TileDesc, and use it to shrink the code.
    
    Change-Id: Idc0ded63166ed350ab81b07e191b7a60d4407cd4

diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 7472446b2..a9e59aac4 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -590,18 +590,6 @@ public:
         return wid;
     }
 
-    bool encodeBufferToPNG(unsigned char* pixmap, int width, int height,
-                           std::vector<char>& output, LibreOfficeKitTileMode mode,
-                           TileBinaryHash hash, TileWireId wid, TileWireId oldWid)
-    {
-        if (cacheTest(hash, output))
-            return true;
-
-        return cacheEncodeSubBufferToPNG(pixmap, 0, 0, width, height,
-                                         width, height, output, mode,
-                                         hash, wid, oldWid);
-    }
-
     bool encodeSubBufferToPNG(unsigned char* pixmap, size_t startX, size_t startY,
                               int width, int height,
                               int bufferWidth, int bufferHeight,
@@ -986,82 +974,21 @@ public:
 
     void renderTile(const std::vector<std::string>& tokens)
     {
-        TileDesc tile = TileDesc::parse(tokens);
-
-        size_t pixmapDataSize = 4 * tile.getWidth() * tile.getHeight();
-        std::vector<unsigned char> pixmap;
-        pixmap.resize(pixmapDataSize);
-
-        std::unique_lock<std::mutex> lock(_documentMutex);
-        if (!_loKitDocument)
-        {
-            LOG_ERR("Tile rendering requested before loading document.");
-            return;
-        }
-
-        if (_loKitDocument->getViewsCount() <= 0)
-        {
-            LOG_ERR("Tile rendering requested without views.");
-            return;
-        }
-
-        const double area = tile.getWidth() * tile.getHeight();
-        Timestamp timestamp;
-        _loKitDocument->paintPartTile(pixmap.data(), tile.getPart(),
-                                      tile.getWidth(), tile.getHeight(),
-                                      tile.getTilePosX(), tile.getTilePosY(),
-                                      tile.getTileWidth(), tile.getTileHeight());
-        const Poco::Timestamp::TimeDiff elapsed = timestamp.elapsed();
-        LOG_TRC("paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() <<
-                ") " << "ver: " << tile.getVersion() << " rendered in " << (elapsed/1000.) <<
-                " ms (" << area / elapsed << " MP/s).");
-        const auto mode = static_cast<LibreOfficeKitTileMode>(_loKitDocument->getTileMode());
-
-        const TileBinaryHash hash = Png::hashBuffer(pixmap.data(), tile.getWidth(), tile.getHeight());
-        TileWireId wid = _pngCache.hashToWireId(hash);
-        TileWireId oldWireId = tile.getOldWireId();
-
-        tile.setWireId(wid);
-
-        if (hash != 0 && oldWireId == wid)
-        {
-            // The tile content is identical to what the client already has, so skip it
-            LOG_TRC("Match oldWireId==wid (" << wid << " for hash " << hash << "); unchanged");
-            return;
-        }
-
-        // Send back the request with all optional parameters given in the request.
-        std::string response = ADD_DEBUG_RENDERID(tile.serialize("tile:")) + "\n";
-
-        int pixelWidth = tile.getWidth();
-        int pixelHeight = tile.getHeight();
-
-        if (_docWatermark)
-            _docWatermark->blending(pixmap.data(), 0, 0, pixelWidth, pixelHeight, pixelWidth, pixelHeight, mode);
-
-        std::shared_ptr<std::vector<char>> output = std::make_shared<std::vector<char>>();
-        output->reserve(response.size() + pixmapDataSize);
-        output->resize(response.size());
-        std::memcpy(output->data(), response.data(), response.size());
-
-        if (!_pngCache.encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), *output, mode, hash, wid, oldWireId))
-        {
-            //FIXME: Return error.
-            //sendTextFrame("error: cmd=tile kind=failure");
-
-            LOG_ERR("Failed to encode tile into PNG.");
-            return;
-        }
-
-        LOG_TRC("Sending render-tile response (" << output->size() << " bytes) for: " << response);
-        postMessage(output, WSOpCode::Binary);
+        TileCombined tileCombined(TileDesc::parse(tokens));
+        renderTiles(tileCombined, false);
     }
 
     void renderCombinedTiles(const std::vector<std::string>& tokens)
     {
         TileCombined tileCombined = TileCombined::parse(tokens);
+        renderTiles(tileCombined, true);
+    }
+
+    void renderTiles(TileCombined &tileCombined, bool combined)
+    {
         auto& tiles = tileCombined.getTiles();
 
+        // Calculate the area we cover
         Util::Rectangle renderArea;
         std::vector<Util::Rectangle> tileRecs;
         tileRecs.reserve(tiles.size());
@@ -1103,6 +1030,7 @@ public:
             return;
         }
 
+        // Render the whole area
         const double area = pixmapWidth * pixmapHeight;
         Timestamp timestamp;
         LOG_TRC("Calling paintPartTile(" << (void*)pixmap.data() << ")");
@@ -1120,6 +1048,7 @@ public:
         std::vector<char> output;
         output.reserve(pixmapSize);
 
+        // Compress the area as tiles
         size_t tileIndex = 0;
         for (Util::Rectangle& tileRect : tileRecs)
         {
@@ -1154,7 +1083,8 @@ public:
                                         mode);
 
             if (!_pngCache.encodeSubBufferToPNG(pixmap.data(), offsetX, offsetY,
-                                                pixelWidth, pixelHeight, pixmapWidth, pixmapHeight, output, mode,
+                                                pixelWidth, pixelHeight,
+                                                pixmapWidth, pixmapHeight, output, mode,
                                                 hash, wireId, oldWireId))
             {
                 //FIXME: Return error.
@@ -1182,8 +1112,13 @@ public:
             return;
         }
 
-        const auto tileMsg = ADD_DEBUG_RENDERID(tileCombined.serialize("tilecombine:")) + "\n";
-        LOG_TRC("Sending back painted tiles for " << tileMsg);
+        std::string tileMsg;
+        if (combined)
+            tileMsg = ADD_DEBUG_RENDERID(tileCombined.serialize("tilecombine:")) + "\n";
+        else
+            tileMsg = ADD_DEBUG_RENDERID(tiles[0].serialize("tile:")) + "\n";
+
+        LOG_TRC("Sending back painted tiles for " << tileMsg << " of size " << output.size() << " bytes) for: " << tileMsg);
 
         std::shared_ptr<std::vector<char>> response = std::make_shared<std::vector<char>>();
         response->resize(tileMsg.size() + output.size());
diff --git a/wsd/TileDesc.hpp b/wsd/TileDesc.hpp
index 38e805d38..abb922b3f 100644
--- a/wsd/TileDesc.hpp
+++ b/wsd/TileDesc.hpp
@@ -258,15 +258,14 @@ private:
     TileCombined(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, int id,
+                 const std::string& imgSizes,
                  const std::string& oldWireIds,
                  const std::string& wireIds) :
         _part(part),
         _width(width),
         _height(height),
         _tileWidth(tileWidth),
-        _tileHeight(tileHeight),
-        _id(id)
+        _tileHeight(tileHeight)
     {
         if (_part < 0 ||
             _width <= 0 ||
@@ -334,7 +333,7 @@ private:
                 throw BadArgumentException("Invalid tilecombine descriptor.");
             }
 
-            _tiles.emplace_back(_part, _width, _height, x, y, _tileWidth, _tileHeight, ver, imgSize, id, false);
+            _tiles.emplace_back(_part, _width, _height, x, y, _tileWidth, _tileHeight, ver, imgSize, -1, false);
             _tiles.back().setOldWireId(oldWireId);
             _tiles.back().setWireId(wireId);
         }
@@ -404,11 +403,6 @@ public:
         }
         oss.seekp(-1, std::ios_base::cur); // See beow.
 
-        if (_id >= 0)
-        {
-            oss << " id=" << _id;
-        }
-
         // Make sure we don't return a potential trailing comma that
         // we have seeked back over but not overwritten after all.
         return oss.str().substr(0, oss.tellp());
@@ -421,9 +415,6 @@ public:
         // assume all values to be int.
         std::map<std::string, int> pairs;
 
-        // Optional.
-        pairs["id"] = -1;
-
         std::string tilePositionsX;
         std::string tilePositionsY;
         std::string imgSizes;
@@ -475,8 +466,7 @@ public:
         return TileCombined(pairs["part"], pairs["width"], pairs["height"],
                             tilePositionsX, tilePositionsY,
                             pairs["tilewidth"], pairs["tileheight"],
-                            versions,
-                            imgSizes, pairs["id"], oldwireIds, wireIds);
+                            versions, imgSizes, oldwireIds, wireIds);
     }
 
     /// Deserialize a TileDesc from a string format.
@@ -507,7 +497,18 @@ public:
         vers.seekp(-1, std::ios_base::cur); // Remove last comma.
         return TileCombined(tiles[0].getPart(), tiles[0].getWidth(), tiles[0].getHeight(),
                             xs.str(), ys.str(), tiles[0].getTileWidth(), tiles[0].getTileHeight(),
-                            vers.str(), "", -1, oldhs.str(), hs.str());
+                            vers.str(), "", oldhs.str(), hs.str());
+    }
+
+    /// To support legacy / under-used renderTile
+    TileCombined(const TileDesc &desc)
+    {
+        _part = desc.getPart();
+        _width = desc.getWidth();
+        _height = desc.getHeight();
+        _tileWidth = desc.getTileWidth();
+        _tileHeight = desc.getTileHeight();
+        _tiles.push_back(desc);
     }
 
 private:
@@ -517,7 +518,6 @@ private:
     int _height;
     int _tileWidth;
     int _tileHeight;
-    int _id;
 };
 
 #endif
commit 4959b3b21cafd045892104476171646e3de952d3
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Apr 17 22:14:16 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Apr 19 23:51:26 2019 +0100

    perftrace: fix time parsing issue.
    
    Change-Id: If0987454e3aa747aa476fa4e0ec8070a95e92867

diff --git a/scripts/perftrace.pl b/scripts/perftrace.pl
index 8c8d69291..12f2a409b 100755
--- a/scripts/perftrace.pl
+++ b/scripts/perftrace.pl
@@ -168,7 +168,7 @@ sub consume($$$$$$$$$)
 	    $time = $time - $dur_us;
 	    push @events, "{\"pid\":$pid, \"tid\":$tid, \"ts\":$time, \"dur\":$dur_us, \"ph\":\"X\", \"name\":\"$msg\", \"args\":{ \"ms\":$dur_ms } }";
 	} else {
-	    die "Unknown prof message: '$message'";
+	    die "Unknown prof message: '$message' at line $lineno";
 	}
 	return;
     }
@@ -261,7 +261,7 @@ sub parseProfileFrames($$$$$)
 	    #	    print STDERR "Profile frame '$line'\n";
 	    # FIXME: silly to complicate and then re-parse this I guess ...
 	    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($secs);
-	    my $time = sprintf("%.2d:%.2d:%02.6f", $hour, $min, "$sec.$fractsecs");
+	    my $time = sprintf("%.2d:%.2d:%09.6f", $hour, $min, "$sec.$fractsecs");
 #	    print STDERR "time '$time' from '$secs' - " . time() . "\n";
 	    consume($lineno, $proc, $pid, $tid, $time, $emitter, 'PROF', $realmsg, '');
 	}


More information about the Libreoffice-commits mailing list