diff options
author | 2014-08-28 09:54:34 -0700 | |
---|---|---|
committer | 2014-08-28 09:54:34 -0700 | |
commit | 744998e666073166307d2522847b2536000a7619 (patch) | |
tree | cba06494229237fb9f8ba5e60a522f1c50b7dd60 /src/gpu/GrMurmur3HashKey.h | |
parent | 7e7136f47d31e88d2d1928933ffb251c156ff02f (diff) |
Make textures register with GrResourceCache2 as scratch.
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/510053003
Diffstat (limited to 'src/gpu/GrMurmur3HashKey.h')
-rw-r--r-- | src/gpu/GrMurmur3HashKey.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/gpu/GrMurmur3HashKey.h b/src/gpu/GrMurmur3HashKey.h new file mode 100644 index 0000000000..ad1fa7c96d --- /dev/null +++ b/src/gpu/GrMurmur3HashKey.h @@ -0,0 +1,73 @@ + +/* + * 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 (where GrBinHashKey is for GrTHashTable). + */ +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 |