common: move "hashSubBuffer" function

Change-Id: If171b7cf4e636e24cb7f757d893136927e8373aa
Signed-off-by: Henry Castro <hcastro@collabora.com>
This commit is contained in:
Henry Castro 2022-03-29 16:25:40 -04:00 committed by Michael Meeks
parent e3c170cf94
commit a56cefc56f
4 changed files with 28 additions and 4 deletions

View file

@ -13,6 +13,7 @@
#include <thread>
#include <unordered_map>
#include <vector>
#include <common/SpookyV2.h>
#include "Png.hpp"
#include "Delta.hpp"
@ -486,8 +487,8 @@ namespace RenderTiles
pixelWidth, pixelHeight,
mode);
const uint64_t hash = Png::hashSubBuffer(pixmap.data(), offsetX, offsetY,
pixelWidth, pixelHeight, pixmapWidth, pixmapHeight);
const uint64_t hash = SpookyHash::hashSubBuffer(pixmap.data(), offsetX, offsetY,
pixelWidth, pixelHeight, pixmapWidth, pixmapHeight);
TileWireId wireId = pngCache.hashToWireId(hash);
TileWireId oldWireId = tiles[tileIndex].getOldWireId();

View file

@ -369,3 +369,23 @@ void SpookyHash::Final(uint64 *hash1, uint64 *hash2)
*hash2 = h1;
}
uint64_t SpookyHash::hashSubBuffer(unsigned char* pixmap, size_t startX, size_t startY,
long width, long height, int bufferWidth, int bufferHeight)
{
if (bufferWidth < width || bufferHeight < height)
return 0; // magic invalid hash.
// assume a consistent mode - RGBA vs. BGRA for process
SpookyHash hash;
hash.Init(1073741789, 1073741789); // Seeds can be anything.
for (long y = 0; y < height; ++y)
{
const size_t position = ((startY + y) * bufferWidth * 4) + (startX * 4);
hash.Update(pixmap + position, width * 4);
}
uint64_t hash1;
uint64_t hash2;
hash.Final(&hash1, &hash2);
return hash1;
}

View file

@ -84,6 +84,9 @@ public:
return (uint32)hash1;
}
static uint64_t hashSubBuffer(unsigned char* pixmap, size_t startX, size_t startY,
long width, long height, int bufferWidth, int bufferHeight);
//
// Init: initialize the context of a SpookyHash
//
@ -98,7 +101,6 @@ public:
const void *message, // message fragment
size_t length); // length of message fragment in bytes
//
// Final: compute the hash for the current SpookyHash state
//

View file

@ -40,6 +40,7 @@
#include <common/JsonUtil.hpp>
#include <common/Authorization.hpp>
#include <common/TraceEvent.hpp>
#include <common/SpookyV2.h>
#include "KitHelper.hpp"
#include <Log.hpp>
#include <Png.hpp>
@ -1833,7 +1834,7 @@ bool ChildSession::renderWindow(const StringVector& tokens)
<< " and rendered in " << elapsedMs << " (" << area / elapsedMics
<< " MP/s).");
uint64_t pixmapHash = Png::hashSubBuffer(pixmap.data(), 0, 0, width, height, bufferWidth, bufferHeight) + getViewId();
uint64_t pixmapHash = SpookyHash::hashSubBuffer(pixmap.data(), 0, 0, width, height, bufferWidth, bufferHeight) + getViewId();
auto found = std::find(_pixmapCache.begin(), _pixmapCache.end(), pixmapHash);