deltas: re-factor to return pointer to cached RLE data.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I14570e41d58471957a0d2154f26e77eb93ba4ae4
This commit is contained in:
Michael Meeks 2024-06-10 16:36:21 +01:00
parent 967b85ec12
commit e03aa4b9b5
2 changed files with 17 additions and 8 deletions

View file

@ -662,8 +662,10 @@ class DeltaGenerator {
const TileLocation &loc,
std::vector<char>& output,
TileWireId wid, bool forceKeyframe,
LibreOfficeKitTileMode mode)
LibreOfficeKitTileMode mode,
std::shared_ptr<DeltaData> &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<DeltaData> 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<char, void (*)(void*)> compressed((char*)malloc(maxCompressed), free);

View file

@ -382,18 +382,20 @@ void DeltaTests::testDeltaSequence()
LOK_ASSERT_EQUAL(size_t(256 * 256 * 4), text2.size());
std::vector<char> delta;
std::shared_ptr<DeltaGenerator::DeltaData> rleData;
// Stash it in the cache
LOK_ASSERT(gen.createDelta(
reinterpret_cast<unsigned char *>(&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<unsigned char *>(&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<unsigned char *>(&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<char> delta;
std::shared_ptr<DeltaGenerator::DeltaData> rleData;
// Stash it in the cache
LOK_ASSERT(gen.createDelta(
reinterpret_cast<unsigned char *>(&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<unsigned char *>(&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");