From adfaa76ff6ce7381127eade7d7a56c6aa7af37c6 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 19 Apr 2019 23:56:20 +0100 Subject: [PATCH] Inline PngCache lookup to avoid redundant watermark blending. Change-Id: I6fe5cca81b9268c903e011fe0e77f478befbc836 --- kit/Kit.cpp | 59 ++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) 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& output) + bool copyFromCache(const uint64_t hash, std::vector& 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& 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& 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& 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;