aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-07-13 12:49:13 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-13 12:49:13 -0700
commit690fc75b29de659b1844d4a36d3f101e98ad1106 (patch)
tree4f91a183f332a90eee0a7be8bbcf6bb35378b675 /src
parent7aa1899c03880640c72e227ca48d6957ff4a55bc (diff)
Get rid of GrMurmur3Hash
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrMurmur3HashKey.h73
-rw-r--r--src/gpu/effects/GrTextureStripAtlas.cpp10
-rw-r--r--src/gpu/effects/GrTextureStripAtlas.h20
3 files changed, 15 insertions, 88 deletions
diff --git a/src/gpu/GrMurmur3HashKey.h b/src/gpu/GrMurmur3HashKey.h
deleted file mode 100644
index be673628eb..0000000000
--- a/src/gpu/GrMurmur3HashKey.h
+++ /dev/null
@@ -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
diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp
index 8610691a43..e8de4d7c30 100644
--- a/src/gpu/effects/GrTextureStripAtlas.cpp
+++ b/src/gpu/effects/GrTextureStripAtlas.cpp
@@ -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);
diff --git a/src/gpu/effects/GrTextureStripAtlas.h b/src/gpu/effects/GrTextureStripAtlas.h
index 80b33bbac4..3b18706b69 100644
--- a/src/gpu/effects/GrTextureStripAtlas.h
+++ b/src/gpu/effects/GrTextureStripAtlas.h
@@ -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;
};