[Libreoffice-commits] online.git: common/RenderTiles.hpp kit/Kit.cpp

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 13 14:40:19 UTC 2020


 common/RenderTiles.hpp |   62 +++++++++++++++++++++++++++----------------------
 kit/Kit.cpp            |   37 +++++++++++++----------------
 2 files changed, 52 insertions(+), 47 deletions(-)

New commits:
commit b673417946ebe916cc5e4fd1997d82452f19bb47
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Mon Jul 13 00:43:51 2020 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Mon Jul 13 16:39:59 2020 +0200

    More re-factoring of tile rendering
    
    This is for the benefit of a next-gen iOS app (without FakeSockets and
    much of the current Online plumbing).
    
    This is not supposed to cause any functional changes in normal Online
    even if code is organised a bit differently.
    
    Change-Id: Ib09a84ff5d3ba858cf3f50553d76757966af7ad2
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98655
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/common/RenderTiles.hpp b/common/RenderTiles.hpp
index fece9f3af..03308879b 100644
--- a/common/RenderTiles.hpp
+++ b/common/RenderTiles.hpp
@@ -348,17 +348,6 @@ namespace RenderTiles
         unsigned char *data() { return _data; }
     };
 
-    class WatermarkBlender
-    {
-    public:
-        virtual void blendWatermark(TileCombined &tileCombined,
-                                    unsigned char *data,
-                                    int offsetX, int offsetY,
-                                    size_t pixmapWidth, size_t pixmapHeight,
-                                    int pixelWidth, int pixelHeight,
-                                    LibreOfficeKitTileMode mode) = 0;
-    };
-
     static void pushRendered(std::vector<TileDesc> &renderedTiles,
                              const TileDesc &desc, TileWireId wireId, size_t imgSize)
     {
@@ -369,12 +358,15 @@ namespace RenderTiles
 
     bool doRender(std::shared_ptr<lok::Document> document,
                   TileCombined &tileCombined,
-                  WatermarkBlender &watermarkBlender,
-                  std::unique_ptr<char[]> &response,
-                  size_t &responseSize,
                   PngCache &pngCache,
                   ThreadPool &pngPool,
-                  bool combined)
+                  bool combined,
+                  const std::function<void (unsigned char *data,
+                                            int offsetX, int offsetY,
+                                            size_t pixmapWidth, size_t pixmapHeight,
+                                            int pixelWidth, int pixelHeight,
+                                            LibreOfficeKitTileMode mode)>& blendWatermark,
+                  const std::function<void (const char *buffer, size_t length)>& outputMessage)
     {
         auto& tiles = tileCombined.getTiles();
 
@@ -453,11 +445,10 @@ namespace RenderTiles
 
             const int offsetX = positionX * pixelWidth;
             const int offsetY = positionY * pixelHeight;
-            watermarkBlender.blendWatermark(tileCombined,
-                                            pixmap.data(), offsetX, offsetY,
-                                            pixmapWidth, pixmapHeight,
-                                            pixelWidth, pixelHeight,
-                                            mode);
+            blendWatermark(pixmap.data(), offsetX, offsetY,
+                           pixmapWidth, pixmapHeight,
+                           pixelWidth, pixelHeight,
+                           mode);
 
             const uint64_t hash = Png::hashSubBuffer(pixmap.data(), offsetX, offsetY,
                                                      pixelWidth, pixelHeight, pixmapWidth, pixmapHeight);
@@ -572,16 +563,33 @@ namespace RenderTiles
 
         std::string tileMsg;
         if (combined)
+        {
             tileMsg = tileCombined.serialize("tilecombine:", ADD_DEBUG_RENDERID, renderedTiles);
-        else
-            tileMsg = tiles[0].serialize("tile:", ADD_DEBUG_RENDERID);
 
-        LOG_TRC("Sending back painted tiles for " << tileMsg << " of size " << output.size() << " bytes) for: " << tileMsg);
+            LOG_TRC("Sending back painted tiles for " << tileMsg << " of size " << output.size() << " bytes) for: " << tileMsg);
 
-        responseSize = tileMsg.size() + output.size();
-        response.reset(new char[responseSize]);
-        std::copy(tileMsg.begin(), tileMsg.end(), response.get());
-        std::copy(output.begin(), output.end(), response.get() + tileMsg.size());
+            std::unique_ptr<char[]> response;
+            const size_t responseSize = tileMsg.size() + output.size();
+            response.reset(new char[responseSize]);
+            std::copy(tileMsg.begin(), tileMsg.end(), response.get());
+            std::copy(output.begin(), output.end(), response.get() + tileMsg.size());
+            outputMessage(response.get(), responseSize);
+        }
+        else
+        {
+            size_t outputOffset = 0;
+            for (auto &i : renderedTiles)
+            {
+                tileMsg = i.serialize("tile:", ADD_DEBUG_RENDERID);
+                const size_t responseSize = tileMsg.size() + i.getImgSize();
+                std::unique_ptr<char[]> response;
+                response.reset(new char[responseSize]);
+                std::copy(tileMsg.begin(), tileMsg.end(), response.get());
+                std::copy(output.begin() + outputOffset, output.begin() + outputOffset + i.getImgSize(), response.get() + tileMsg.size());
+                outputMessage(response.get(), responseSize);
+                outputOffset += i.getImgSize();
+            }
+        }
 
         return true;
     }
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 810118c22..f10493e50 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -420,7 +420,7 @@ namespace
 /// per process. But for security reasons don't.
 /// However, we could have a loolkit instance
 /// per user or group of users (a trusted circle).
-class Document final : public DocumentManagerInterface, public RenderTiles::WatermarkBlender
+class Document final : public DocumentManagerInterface
 {
 public:
     /// We have two types of password protected documents
@@ -630,20 +630,6 @@ public:
         renderTiles(tileCombined, true);
     }
 
-    void blendWatermark(TileCombined &tileCombined,
-                        unsigned char *data, int offsetX, int offsetY,
-                        size_t pixmapWidth, size_t pixmapHeight,
-                        int pixelWidth, int pixelHeight,
-                        LibreOfficeKitTileMode mode) override
-    {
-        const auto session = _sessions.findByCanonicalId(tileCombined.getNormalizedViewId());
-        if (session->hasWatermark())
-            session->_docWatermark->blending(data, offsetX, offsetY,
-                                             pixmapWidth, pixmapHeight,
-                                             pixelWidth, pixelHeight,
-                                             mode);
-    }
-
     void renderTiles(TileCombined &tileCombined, bool combined)
     {
         // Find a session matching our view / render settings.
@@ -672,15 +658,26 @@ public:
             _loKitDocument->setView(session->getViewId());
 #endif
 
-        std::unique_ptr<char[]> response;
-        size_t responseSize;
-        if (!RenderTiles::doRender(_loKitDocument, tileCombined, *this, response, responseSize, _pngCache, _pngPool, combined))
+        if (!RenderTiles::doRender(_loKitDocument, tileCombined, _pngCache, _pngPool, combined,
+                                   [&](unsigned char *data,
+                                       int offsetX, int offsetY,
+                                       size_t pixmapWidth, size_t pixmapHeight,
+                                       int pixelWidth, int pixelHeight,
+                                       LibreOfficeKitTileMode mode) {
+                                       if (session->hasWatermark())
+                                           session->_docWatermark->blending(data, offsetX, offsetY,
+                                                                            pixmapWidth, pixmapHeight,
+                                                                            pixelWidth, pixelHeight,
+                                                                            mode);
+                                   },
+                                   [&](const char *buffer, size_t length) {
+                                       postMessage(buffer, length, WSOpCode::Binary);
+                                   }
+                                   ))
         {
             LOG_DBG("All tiles skipped, not producing empty tilecombine: message");
             return;
         }
-
-        postMessage(response.get(), responseSize, WSOpCode::Binary);
     }
 
     bool sendTextFrame(const std::string& message)


More information about the Libreoffice-commits mailing list