Revert of Slim Skia down to just one murmur3 implementation. (https://codereview.chromium.org/376183004/)
Reason for revert: Valgrind unhappy. skia:2735 Original issue's description: > Slim Skia down to just one murmur3 implementation. > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/6ac0037b70410ff7d5ce5788bc89314223e1a587 R=reed@google.com, mtklein@chromium.org TBR=mtklein@chromium.org, reed@google.com NOTREECHECKS=true NOTRY=true BUG=skia: Author: mtklein@google.com Review URL: https://codereview.chromium.org/378413002
This commit is contained in:
parent
e4636aa173
commit
1feac79203
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include "Benchmark.h"
|
#include "Benchmark.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkChecksum.h"
|
|
||||||
#include "SkFontHost.h"
|
#include "SkFontHost.h"
|
||||||
#include "SkPaint.h"
|
#include "SkPaint.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
@ -65,12 +64,23 @@ static uint32_t hasher0(uint32_t value) {
|
|||||||
return value ^ (value >> 8);
|
return value ^ (value >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t hasher2(uint32_t h) {
|
||||||
|
h ^= h >> 16;
|
||||||
|
h *= 0x85ebca6b;
|
||||||
|
h ^= h >> 13;
|
||||||
|
h *= 0xc2b2ae35;
|
||||||
|
h ^= h >> 16;
|
||||||
|
|
||||||
|
h ^= (h >> 8);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char* fName;
|
const char* fName;
|
||||||
HasherProc fHasher;
|
HasherProc fHasher;
|
||||||
} gRec[] = {
|
} gRec[] = {
|
||||||
{ "hasher0", hasher0 },
|
{ "hasher0", hasher0 },
|
||||||
{ "hasher2", SkChecksum::Mix },
|
{ "hasher2", hasher2 },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define kMaxHashBits 12
|
#define kMaxHashBits 12
|
||||||
|
@ -36,20 +36,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you
|
|
||||||
* suspect its low bits aren't well mixed.
|
|
||||||
*
|
|
||||||
* This is the Murmur3 finalizer.
|
|
||||||
*/
|
|
||||||
static uint32_t Mix(uint32_t hash) {
|
|
||||||
hash ^= hash >> 16;
|
|
||||||
hash *= 0x85ebca6b;
|
|
||||||
hash ^= hash >> 13;
|
|
||||||
hash *= 0xc2b2ae35;
|
|
||||||
hash ^= hash >> 16;
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate 32-bit Murmur hash (murmur3).
|
* Calculate 32-bit Murmur hash (murmur3).
|
||||||
@ -62,7 +48,7 @@ public:
|
|||||||
* @return hash result
|
* @return hash result
|
||||||
*/
|
*/
|
||||||
static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) {
|
static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) {
|
||||||
SkASSERTF(SkIsAlign4(bytes), "Expected 4-byte multiple, got %zu", bytes);
|
SkASSERT(SkIsAlign4(bytes));
|
||||||
const size_t words = bytes/4;
|
const size_t words = bytes/4;
|
||||||
|
|
||||||
uint32_t hash = seed;
|
uint32_t hash = seed;
|
||||||
@ -78,7 +64,12 @@ public:
|
|||||||
hash += 0xe6546b64;
|
hash += 0xe6546b64;
|
||||||
}
|
}
|
||||||
hash ^= bytes;
|
hash ^= bytes;
|
||||||
return Mix(hash);
|
hash ^= hash >> 16;
|
||||||
|
hash *= 0x85ebca6b;
|
||||||
|
hash ^= hash >> 13;
|
||||||
|
hash *= 0xc2b2ae35;
|
||||||
|
hash ^= hash >> 16;
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include "SkImageFilter.h"
|
#include "SkImageFilter.h"
|
||||||
|
|
||||||
#include "SkBitmap.h"
|
#include "SkBitmap.h"
|
||||||
#include "SkChecksum.h"
|
|
||||||
#include "SkDevice.h"
|
#include "SkDevice.h"
|
||||||
#include "SkReadBuffer.h"
|
#include "SkReadBuffer.h"
|
||||||
#include "SkWriteBuffer.h"
|
#include "SkWriteBuffer.h"
|
||||||
@ -335,6 +334,31 @@ bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static uint32_t compute_hash(const uint32_t* data, int count) {
|
||||||
|
uint32_t hash = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
uint32_t k = data[i];
|
||||||
|
k *= 0xcc9e2d51;
|
||||||
|
k = (k << 15) | (k >> 17);
|
||||||
|
k *= 0x1b873593;
|
||||||
|
|
||||||
|
hash ^= k;
|
||||||
|
hash = (hash << 13) | (hash >> 19);
|
||||||
|
hash *= 5;
|
||||||
|
hash += 0xe6546b64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hash ^= size;
|
||||||
|
hash ^= hash >> 16;
|
||||||
|
hash *= 0x85ebca6b;
|
||||||
|
hash ^= hash >> 13;
|
||||||
|
hash *= 0xc2b2ae35;
|
||||||
|
hash ^= hash >> 16;
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
class CacheImpl : public SkImageFilter::Cache {
|
class CacheImpl : public SkImageFilter::Cache {
|
||||||
public:
|
public:
|
||||||
explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {
|
explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {
|
||||||
@ -357,7 +381,7 @@ private:
|
|||||||
return v.fKey;
|
return v.fKey;
|
||||||
}
|
}
|
||||||
static uint32_t Hash(Key key) {
|
static uint32_t Hash(Key key) {
|
||||||
return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
|
return compute_hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key) / sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SkTDynamicHash<Value, Key> fData;
|
SkTDynamicHash<Value, Key> fData;
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SkChecksum.h"
|
|
||||||
#include "SkScaledImageCache.h"
|
#include "SkScaledImageCache.h"
|
||||||
#include "SkMipMap.h"
|
#include "SkMipMap.h"
|
||||||
#include "SkPixelRef.h"
|
#include "SkPixelRef.h"
|
||||||
@ -30,6 +29,32 @@ static inline SkScaledImageCache::Rec* id_to_rec(SkScaledImageCache::ID* id) {
|
|||||||
return reinterpret_cast<SkScaledImageCache::Rec*>(id);
|
return reinterpret_cast<SkScaledImageCache::Rec*>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implemented from en.wikipedia.org/wiki/MurmurHash.
|
||||||
|
static uint32_t compute_hash(const uint32_t data[], int count) {
|
||||||
|
uint32_t hash = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
uint32_t k = data[i];
|
||||||
|
k *= 0xcc9e2d51;
|
||||||
|
k = (k << 15) | (k >> 17);
|
||||||
|
k *= 0x1b873593;
|
||||||
|
|
||||||
|
hash ^= k;
|
||||||
|
hash = (hash << 13) | (hash >> 19);
|
||||||
|
hash *= 5;
|
||||||
|
hash += 0xe6546b64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hash ^= size;
|
||||||
|
hash ^= hash >> 16;
|
||||||
|
hash *= 0x85ebca6b;
|
||||||
|
hash ^= hash >> 13;
|
||||||
|
hash *= 0xc2b2ae35;
|
||||||
|
hash ^= hash >> 16;
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
struct SkScaledImageCache::Key {
|
struct SkScaledImageCache::Key {
|
||||||
Key(uint32_t genID,
|
Key(uint32_t genID,
|
||||||
SkScalar scaleX,
|
SkScalar scaleX,
|
||||||
@ -39,7 +64,7 @@ struct SkScaledImageCache::Key {
|
|||||||
, fScaleX(scaleX)
|
, fScaleX(scaleX)
|
||||||
, fScaleY(scaleY)
|
, fScaleY(scaleY)
|
||||||
, fBounds(bounds) {
|
, fBounds(bounds) {
|
||||||
fHash = SkChecksum::Murmur3(&fGenID, 28);
|
fHash = compute_hash(&fGenID, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const Key& other) const {
|
bool operator<(const Key& other) const {
|
||||||
|
Loading…
Reference in New Issue
Block a user