From e03aa4b9b56bb43620e76bebe8b99ca54eb3e02c Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Mon, 10 Jun 2024 16:36:21 +0100 Subject: [PATCH] deltas: re-factor to return pointer to cached RLE data. Signed-off-by: Michael Meeks Change-Id: I14570e41d58471957a0d2154f26e77eb93ba4ae4 --- kit/Delta.hpp | 11 ++++++++--- test/DeltaTests.cpp | 14 +++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/kit/Delta.hpp b/kit/Delta.hpp index 32a6cfb36..7656e155d 100644 --- a/kit/Delta.hpp +++ b/kit/Delta.hpp @@ -662,8 +662,10 @@ class DeltaGenerator { const TileLocation &loc, std::vector& output, TileWireId wid, bool forceKeyframe, - LibreOfficeKitTileMode mode) + LibreOfficeKitTileMode mode, + std::shared_ptr &rleData) { + rleData = nullptr; if ((width & 0x1) != 0) // power of two - RGBA { LOG_TRC("Bad width to create deltas " << width); @@ -711,7 +713,10 @@ class DeltaGenerator { // no two threads can be working on the same DeltaData. cacheEntry->replaceAndFree(update); + rleData = cacheEntry; + cacheEntry->unuse(); + return delta; } @@ -771,11 +776,11 @@ class DeltaGenerator { tileFile.write(pngOutput.data(), pngOutput.size()); } + std::shared_ptr rleData; if (!createDelta(pixmap, startX, startY, width, height, bufferWidth, bufferHeight, - loc, output, wid, forceKeyframe, mode)) + loc, output, wid, forceKeyframe, mode, rleData)) { - // FIXME: should stream it in =) size_t maxCompressed = ZSTD_COMPRESSBOUND((size_t)width * height * 4); std::unique_ptr compressed((char*)malloc(maxCompressed), free); diff --git a/test/DeltaTests.cpp b/test/DeltaTests.cpp index cd83d3c53..1953c3924 100644 --- a/test/DeltaTests.cpp +++ b/test/DeltaTests.cpp @@ -382,18 +382,20 @@ void DeltaTests::testDeltaSequence() LOK_ASSERT_EQUAL(size_t(256 * 256 * 4), text2.size()); std::vector delta; + std::shared_ptr rleData; + // Stash it in the cache LOK_ASSERT(gen.createDelta( reinterpret_cast(&text[0]), 0, 0, width, height, width, height, - TileLocation(1, 2, 3, 0, 1), delta, textWid, false, LOK_TILEMODE_RGBA) == false); + TileLocation(1, 2, 3, 0, 1), delta, textWid, false, LOK_TILEMODE_RGBA, rleData) == false); LOK_ASSERT(delta.empty()); // Build a delta between text2 & textWid LOK_ASSERT(gen.createDelta( reinterpret_cast(&text2[0]), 0, 0, width, height, width, height, - TileLocation(1, 2, 3, 0, 1), delta, text2Wid, false, LOK_TILEMODE_RGBA) == true); + TileLocation(1, 2, 3, 0, 1), delta, text2Wid, false, LOK_TILEMODE_RGBA, rleData) == true); LOK_ASSERT(delta.size() > 0); checkzDelta(delta, "text2 to textWid"); @@ -406,7 +408,7 @@ void DeltaTests::testDeltaSequence() LOK_ASSERT(gen.createDelta( reinterpret_cast(&text[0]), 0, 0, width, height, width, height, - TileLocation(1, 2, 3, 0, 1), two2one, textWid, false, LOK_TILEMODE_RGBA) == true); + TileLocation(1, 2, 3, 0, 1), two2one, textWid, false, LOK_TILEMODE_RGBA, rleData) == true); LOK_ASSERT(two2one.size() > 0); checkzDelta(two2one, "text to text2Wid"); @@ -439,18 +441,20 @@ void DeltaTests::testDeltaCopyOutOfBounds() LOK_ASSERT_EQUAL(size_t(256 * 256 * 4), text2.size()); std::vector delta; + std::shared_ptr rleData; + // Stash it in the cache LOK_ASSERT(gen.createDelta( reinterpret_cast(&text[0]), 0, 0, width, height, width, height, - TileLocation(1, 2, 3, 0, 1), delta, textWid, false, LOK_TILEMODE_RGBA) == false); + TileLocation(1, 2, 3, 0, 1), delta, textWid, false, LOK_TILEMODE_RGBA, rleData) == false); LOK_ASSERT(delta.empty()); // Build a delta between the two frames LOK_ASSERT(gen.createDelta( reinterpret_cast(&text2[0]), 0, 0, width, height, width, height, - TileLocation(1, 2, 3, 0, 1), delta, text2Wid, false, LOK_TILEMODE_RGBA) == true); + TileLocation(1, 2, 3, 0, 1), delta, text2Wid, false, LOK_TILEMODE_RGBA, rleData) == true); LOK_ASSERT(delta.size() > 0); checkzDelta(delta, "copy out of bounds");