deltas: enable monotonic wid incrementing, build deltas based on pos.

We want to always generate a delta vs. the last state we have so we
move linearly forward into the future.

Change-Id: I730d1dfb125a19e2c48b8f84ad5563664d196ab0
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
Michael Meeks 2021-12-31 19:37:10 +00:00
parent 8eebe1e345
commit bfc4699ffb
3 changed files with 44 additions and 9 deletions

View file

@ -490,7 +490,12 @@ namespace RenderTiles
const uint64_t hash = SpookyHash::hashSubBuffer(pixmap.data(), offsetX, offsetY,
pixelWidth, pixelHeight, pixmapWidth, pixmapHeight);
#ifndef ENABLE_DELTAS
TileWireId wireId = pngCache.hashToWireId(hash);
#else
static TileWireId nextId = 0;;
TileWireId wireId = ++nextId;
#endif
TileWireId oldWireId = tiles[tileIndex].getOldWireId();
if (hash != 0 && oldWireId == wireId)
{
@ -542,8 +547,11 @@ namespace RenderTiles
#ifdef ENABLE_DELTAS
// Can we create a delta ? - FIXME: PngCache of this ? ...
static DeltaGenerator deltaGen;
if (!deltaGen.createDelta(pixmap.data(), offsetX, offsetY, pixelWidth, pixelHeight,
if (!deltaGen.createDelta(pixmap.data(), offsetX, offsetY,
pixelWidth, pixelHeight,
pixmapWidth, pixmapHeight,
tileRect.getLeft(), tileRect.getTop(),
tileCombined.getPart(),
*data, wireId, oldWireId))
#endif
{

View file

@ -76,6 +76,13 @@ class DeltaGenerator {
return _height;
}
void setTilePos(int left, int top, int part)
{
_left = left;
_top = top;
_part = part;
}
const std::vector<DeltaBitmapRow>& getRows() const
{
return _rows;
@ -86,6 +93,9 @@ class DeltaGenerator {
return _rows;
}
int _left;
int _top;
int _part;
private:
TileWireId _wid;
int _width;
@ -109,6 +119,7 @@ class DeltaGenerator {
return false;
}
size_t startSize = output.size();
output.push_back('D');
LOG_TRC("building delta of a " << cur.getWidth() << 'x' << cur.getHeight() << " bitmap");
@ -193,6 +204,8 @@ class DeltaGenerator {
}
}
}
size_t deltaSize = output.size() - startSize;
LOG_TRC("Created delta of size " << deltaSize);
return true;
}
@ -201,6 +214,7 @@ class DeltaGenerator {
TileWireId wid,
unsigned char* pixmap, size_t startX, size_t startY,
int width, int height,
int tileLeft, int tileTop, int tilePart,
int bufferWidth, int bufferHeight)
{
auto data = std::make_shared<DeltaData>();
@ -215,8 +229,10 @@ class DeltaGenerator {
<< (width * height * 4) << " width " << width
<< " height " << height);
// FIXME: switch to constructor and remove set methods
data->setWidth(width);
data->setHeight(height);
data->setTilePos(tileLeft, tileTop, tilePart);
data->getRows().resize(height);
for (int y = 0; y < height; ++y)
{
@ -250,23 +266,34 @@ class DeltaGenerator {
unsigned char* pixmap, size_t startX, size_t startY,
int width, int height,
int bufferWidth, int bufferHeight,
int tileLeft, int tileTop, int tilePart,
std::vector<char>& output,
TileWireId wid, TileWireId oldWid)
{
// First store a copy for later:
if (_deltaEntries.size() > 6) // FIXME: hard-coded ...
if (_deltaEntries.size() > 16) // FIXME: hard-coded ...
_deltaEntries.erase(_deltaEntries.begin());
std::shared_ptr<DeltaData> update =
dataToDeltaData(wid, pixmap, startX, startY, width, height,
tileLeft, tileTop, tilePart,
bufferWidth, bufferHeight);
_deltaEntries.push_back(update);
for (auto &old : _deltaEntries)
if (oldWid != 0) // zero to force key-frame
{
if (oldWid == old->getWid())
return makeDelta(*old, *update, output);
for (auto &old : _deltaEntries)
{
if (old->_left == tileLeft && old->_top == tileTop && old->_part == tilePart)
{
makeDelta(*old, *update, output);
// update the cache
*old = *update;
return true;
}
}
}
_deltaEntries.push_back(update);
return false;
}
};

View file

@ -174,14 +174,14 @@ void DeltaTests::testDeltaSequence()
LOK_ASSERT(gen.createDelta(
reinterpret_cast<unsigned char *>(&text[0]),
0, 0, width, height, width, height,
delta, textWid, 0) == false);
1, 2, 0, delta, textWid, 0) == false);
LOK_ASSERT(delta.size() == 0);
// Build a delta between text2 & textWid
LOK_ASSERT(gen.createDelta(
reinterpret_cast<unsigned char *>(&text2[0]),
0, 0, width, height, width, height,
delta, text2Wid, textWid) == true);
1, 2, 0, delta, text2Wid, textWid) == true);
LOK_ASSERT(delta.size() > 0);
// Apply it to move to the second frame
@ -193,7 +193,7 @@ void DeltaTests::testDeltaSequence()
LOK_ASSERT(gen.createDelta(
reinterpret_cast<unsigned char *>(&text[0]),
0, 0, width, height, width, height,
two2one, textWid, text2Wid) == true);
1, 2, 0, two2one, textWid, text2Wid) == true);
LOK_ASSERT(two2one.size() > 0);
// Apply it to get back to where we started