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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Apr 19 23:04:09 UTC 2019


 kit/Kit.cpp |   59 ++++++++++++++++++++++++-----------------------------------
 1 file changed, 24 insertions(+), 35 deletions(-)

New commits:
commit adfaa76ff6ce7381127eade7d7a56c6aa7af37c6
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Apr 19 23:56:20 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Apr 19 23:56:20 2019 +0100

    Inline PngCache lookup to avoid redundant watermark blending.
    
    Change-Id: I6fe5cca81b9268c903e011fe0e77f478befbc836

diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index a9e59aac4..73e4ed3f0 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -506,9 +506,10 @@ class PngCache
         }
     }
 
+public:
     /// Lookup an entry in the cache and store the data in output.
     /// Returns true on success, otherwise false.
-    bool cacheTest(const uint64_t hash, std::vector<char>& output)
+    bool copyFromCache(const uint64_t hash, std::vector<char>& output)
     {
         if (hash)
         {
@@ -529,11 +530,11 @@ class PngCache
         return false;
     }
 
-    bool cacheEncodeSubBufferToPNG(unsigned char* pixmap, size_t startX, size_t startY,
-                                   int width, int height,
-                                   int bufferWidth, int bufferHeight,
-                                   std::vector<char>& output, LibreOfficeKitTileMode mode,
-                                   TileBinaryHash hash, TileWireId wid, TileWireId /*oldWid*/)
+    bool encodeSubBufferToPNG(unsigned char* pixmap, size_t startX, size_t startY,
+                              int width, int height,
+                              int bufferWidth, int bufferHeight,
+                              std::vector<char>& output, LibreOfficeKitTileMode mode,
+                              TileBinaryHash hash, TileWireId wid, TileWireId /*oldWid*/)
     {
         LOG_DBG("PNG cache with hash " << hash << " missed.");
 /*
@@ -568,7 +569,6 @@ class PngCache
             return false;
     }
 
-public:
     PngCache()
     {
         clearCache();
@@ -589,20 +589,6 @@ public:
         }
         return wid;
     }
-
-    bool encodeSubBufferToPNG(unsigned char* pixmap, size_t startX, size_t startY,
-                              int width, int height,
-                              int bufferWidth, int bufferHeight,
-                              std::vector<char>& output, LibreOfficeKitTileMode mode,
-                              TileBinaryHash hash, TileWireId wid, TileWireId oldWid)
-    {
-        if (cacheTest(hash, output))
-            return true;
-
-        return cacheEncodeSubBufferToPNG(pixmap, startX, startY, width, height,
-                                         bufferWidth, bufferHeight, output, mode,
-                                         hash, wid, oldWid);
-    }
 };
 
 class Watermark
@@ -1076,21 +1062,24 @@ public:
                 continue;
             }
 
-            if (_docWatermark)
-                _docWatermark->blending(pixmap.data(), offsetX, offsetY,
-                                        pixmapWidth, pixmapHeight,
-                                        pixelWidth, pixelHeight,
-                                        mode);
-
-            if (!_pngCache.encodeSubBufferToPNG(pixmap.data(), offsetX, offsetY,
-                                                pixelWidth, pixelHeight,
-                                                pixmapWidth, pixmapHeight, output, mode,
-                                                hash, wireId, oldWireId))
+            if (!_pngCache.copyFromCache(hash, output))
             {
-                //FIXME: Return error.
-                //sendTextFrame("error: cmd=tile kind=failure");
-                LOG_ERR("Failed to encode tile into PNG.");
-                return;
+                if (_docWatermark)
+                    _docWatermark->blending(pixmap.data(), offsetX, offsetY,
+                                            pixmapWidth, pixmapHeight,
+                                            pixelWidth, pixelHeight,
+                                            mode);
+
+                if (!_pngCache.encodeSubBufferToPNG(pixmap.data(), offsetX, offsetY,
+                                                    pixelWidth, pixelHeight,
+                                                    pixmapWidth, pixmapHeight, output, mode,
+                                                    hash, wireId, oldWireId))
+                {
+                    // FIXME: Return error.
+                    // sendTextFrame("error: cmd=tile kind=failure");
+                    LOG_ERR("Failed to encode tile into PNG.");
+                    return;
+                }
             }
 
             const size_t imgSize = output.size() - oldSize;


More information about the Libreoffice-commits mailing list