Get rid of GrMurmur3Hash
BUG=skia: Review URL: https://codereview.chromium.org/1233933002
This commit is contained in:
parent
7aa1899c03
commit
690fc75b29
@ -134,7 +134,6 @@
|
||||
'<(skia_src_path)/gpu/GrLayerHoister.h',
|
||||
'<(skia_src_path)/gpu/GrMemoryPool.cpp',
|
||||
'<(skia_src_path)/gpu/GrMemoryPool.h',
|
||||
'<(skia_src_path)/gpu/GrMurmur3HashKey.h',
|
||||
'<(skia_src_path)/gpu/GrNonAtomicRef.h',
|
||||
'<(skia_src_path)/gpu/GrOrderedSet.h',
|
||||
'<(skia_src_path)/gpu/GrOvalRenderer.cpp',
|
||||
|
@ -1,73 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright 2014 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GrMurmur3HashKey_DEFINED
|
||||
#define GrMurmur3HashKey_DEFINED
|
||||
|
||||
#include "SkChecksum.h"
|
||||
#include "GrTypes.h"
|
||||
|
||||
/**
|
||||
* GrMurmur3HashKey is a hash key class that can take a data chunk of any predetermined
|
||||
* length. It uses the Murmur3 hash function. It is intended to be used with
|
||||
* SkTDynamicHash.
|
||||
*/
|
||||
template<size_t KEY_SIZE_IN_BYTES>
|
||||
class GrMurmur3HashKey {
|
||||
public:
|
||||
GrMurmur3HashKey() {
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
fHash = 0;
|
||||
#ifdef SK_DEBUG
|
||||
fIsValid = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void setKeyData(const uint32_t* data) {
|
||||
SK_COMPILE_ASSERT(KEY_SIZE_IN_BYTES % 4 == 0, key_size_mismatch);
|
||||
memcpy(fData, data, KEY_SIZE_IN_BYTES);
|
||||
|
||||
fHash = SkChecksum::Murmur3(fData, KEY_SIZE_IN_BYTES);
|
||||
#ifdef SK_DEBUG
|
||||
fIsValid = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool operator==(const GrMurmur3HashKey& other) const {
|
||||
if (fHash != other.fHash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !memcmp(fData, other.fData, KEY_SIZE_IN_BYTES);
|
||||
}
|
||||
|
||||
uint32_t getHash() const {
|
||||
SkASSERT(fIsValid);
|
||||
return fHash;
|
||||
}
|
||||
|
||||
const uint8_t* getData() const {
|
||||
SkASSERT(fIsValid);
|
||||
return reinterpret_cast<const uint8_t*>(fData);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t fHash;
|
||||
uint32_t fData[KEY_SIZE_IN_BYTES / sizeof(uint32_t)]; // Buffer for key storage.
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
public:
|
||||
bool fIsValid;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
@ -18,7 +18,7 @@
|
||||
#endif
|
||||
|
||||
class GrTextureStripAtlas::Hash : public SkTDynamicHash<GrTextureStripAtlas::AtlasEntry,
|
||||
GrTextureStripAtlas::AtlasEntry::Key> {};
|
||||
GrTextureStripAtlas::Desc> {};
|
||||
|
||||
int32_t GrTextureStripAtlas::gCacheCount = 0;
|
||||
|
||||
@ -40,7 +40,7 @@ void GrTextureStripAtlas::CleanUp(const GrContext*, void* info) {
|
||||
AtlasEntry* entry = static_cast<AtlasEntry*>(info);
|
||||
|
||||
// remove the cache entry
|
||||
GetCache()->remove(entry->fKey);
|
||||
GetCache()->remove(entry->fDesc);
|
||||
|
||||
// remove the actual entry
|
||||
SkDELETE(entry);
|
||||
@ -52,14 +52,12 @@ void GrTextureStripAtlas::CleanUp(const GrContext*, void* info) {
|
||||
}
|
||||
|
||||
GrTextureStripAtlas* GrTextureStripAtlas::GetAtlas(const GrTextureStripAtlas::Desc& desc) {
|
||||
AtlasEntry::Key key;
|
||||
key.setKeyData(desc.asKey());
|
||||
AtlasEntry* entry = GetCache()->find(key);
|
||||
AtlasEntry* entry = GetCache()->find(desc);
|
||||
if (NULL == entry) {
|
||||
entry = SkNEW(AtlasEntry);
|
||||
|
||||
entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc));
|
||||
entry->fKey = key;
|
||||
entry->fDesc = desc;
|
||||
|
||||
desc.fContext->addCleanUp(CleanUp, entry);
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
#ifndef GrTextureStripAtlas_DEFINED
|
||||
#define GrTextureStripAtlas_DEFINED
|
||||
|
||||
#include "GrMurmur3HashKey.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkChecksum.h"
|
||||
#include "SkGr.h"
|
||||
#include "SkTDArray.h"
|
||||
#include "SkTDynamicHash.h"
|
||||
@ -25,11 +25,14 @@ public:
|
||||
* Descriptor struct which we'll use as a hash table key
|
||||
**/
|
||||
struct Desc {
|
||||
Desc() { memset(this, 0, sizeof(*this)); }
|
||||
uint16_t fWidth, fHeight, fRowHeight;
|
||||
GrPixelConfig fConfig;
|
||||
Desc() { sk_bzero(this, sizeof(*this)); }
|
||||
GrContext* fContext;
|
||||
const uint32_t* asKey() const { return reinterpret_cast<const uint32_t*>(this); }
|
||||
GrPixelConfig fConfig;
|
||||
uint16_t fWidth, fHeight, fRowHeight;
|
||||
uint16_t fUnusedPadding;
|
||||
bool operator==(const Desc& other) const {
|
||||
return 0 == memcmp(this, &other, sizeof(Desc));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -138,14 +141,13 @@ private:
|
||||
class AtlasEntry : public ::SkNoncopyable {
|
||||
public:
|
||||
// for SkTDynamicHash
|
||||
class Key : public GrMurmur3HashKey<sizeof(GrTextureStripAtlas::Desc)> {};
|
||||
static const Key& GetKey(const AtlasEntry& entry) { return entry.fKey; }
|
||||
static uint32_t Hash(const Key& key) { return key.getHash(); }
|
||||
static const Desc& GetKey(const AtlasEntry& entry) { return entry.fDesc; }
|
||||
static uint32_t Hash(const Desc& desc) { return SkChecksum::Murmur3(&desc, sizeof(Desc)); }
|
||||
|
||||
// AtlasEntry proper
|
||||
AtlasEntry() : fAtlas(NULL) {}
|
||||
~AtlasEntry() { SkDELETE(fAtlas); }
|
||||
Key fKey;
|
||||
Desc fDesc;
|
||||
GrTextureStripAtlas* fAtlas;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user