aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkResourceCache.cpp
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2014-10-22 11:20:40 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-22 11:20:40 -0700
commit171e5b73a862418f4acd61faf8cecfbc8f58694c (patch)
tree72751a8762d7d354d84feb533522eef2d9951ba5 /src/core/SkResourceCache.cpp
parent9bb7539a59ab15749fe26fecfec05330cffae684 (diff)
SkResourceCache::Key namespace support.
Add a unique-per-subclass namespace tag to make Keys from different domains comparable. Also drop the SkPictureShader cache and convert to using the global resource cache instead. R=reed@google.com,mtklein@google.com,robertphillips@google.com Review URL: https://codereview.chromium.org/668223002
Diffstat (limited to 'src/core/SkResourceCache.cpp')
-rw-r--r--src/core/SkResourceCache.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp
index f7a810ec87..1eb53cd8c6 100644
--- a/src/core/SkResourceCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -10,6 +10,8 @@
#include "SkMipMap.h"
#include "SkPixelRef.h"
+#include <stddef.h>
+
// This can be defined by the caller's build system
//#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE
@@ -21,12 +23,22 @@
#define SK_DEFAULT_IMAGE_CACHE_LIMIT (2 * 1024 * 1024)
#endif
-void SkResourceCache::Key::init(size_t length) {
+void SkResourceCache::Key::init(void* nameSpace, size_t length) {
SkASSERT(SkAlign4(length) == length);
- // 2 is fCount32 and fHash
- fCount32 = SkToS32(2 + (length >> 2));
- // skip both of our fields whe computing the murmur
- fHash = SkChecksum::Murmur3(this->as32() + 2, (fCount32 - 2) << 2);
+
+ // fCount32 and fHash are not hashed
+ static const int kUnhashedLocal32s = 2;
+ static const int kLocal32s = kUnhashedLocal32s + (sizeof(fNamespace) >> 2);
+
+ SK_COMPILE_ASSERT(sizeof(Key) == (kLocal32s << 2), unaccounted_key_locals);
+ SK_COMPILE_ASSERT(sizeof(Key) == offsetof(Key, fNamespace) + sizeof(fNamespace),
+ namespace_field_must_be_last);
+
+ fCount32 = SkToS32(kLocal32s + (length >> 2));
+ fNamespace = nameSpace;
+ // skip unhashed fields when computing the murmur
+ fHash = SkChecksum::Murmur3(this->as32() + kUnhashedLocal32s,
+ (fCount32 - kUnhashedLocal32s) << 2);
}
#include "SkTDynamicHash.h"