aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrResourceCache.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-20 15:13:01 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-20 15:13:01 +0000
commit0797c2cceadd7dfc2e7f9efa30b611d18efcdcdd (patch)
tree2fc86b2f5248e1977e8ffee9190d606947358a4f /src/gpu/GrResourceCache.cpp
parent0b6ad2297fbf43466950690102c1c9c150f2a972 (diff)
Reland 6914 w/ fixes.
git-svn-id: http://skia.googlecode.com/svn/trunk@6916 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrResourceCache.cpp')
-rw-r--r--src/gpu/GrResourceCache.cpp44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index a1f1d794e5..45b999f3d0 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -11,6 +11,20 @@
#include "GrResourceCache.h"
#include "GrResource.h"
+
+GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() {
+ static int32_t gNextType = 0;
+
+ int32_t type = sk_atomic_inc(&gNextType);
+ if (type >= (1 << 8 * sizeof(ResourceType))) {
+ GrCrash("Too many Resource Types");
+ }
+
+ return static_cast<ResourceType>(type);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource)
: fKey(key), fResource(resource) {
// we assume ownership of the resource, and will unref it when we die
@@ -33,36 +47,6 @@ void GrResourceEntry::validate() const {
///////////////////////////////////////////////////////////////////////////////
-class GrResourceCache::Key {
- typedef GrResourceEntry T;
-
- const GrResourceKey& fKey;
-public:
- Key(const GrResourceKey& key) : fKey(key) {}
-
- uint32_t getHash() const { return fKey.hashIndex(); }
-
- static bool LT(const T& entry, const Key& key) {
- return entry.key() < key.fKey;
- }
- static bool EQ(const T& entry, const Key& key) {
- return entry.key() == key.fKey;
- }
-#if GR_DEBUG
- static uint32_t GetHash(const T& entry) {
- return entry.key().hashIndex();
- }
- static bool LT(const T& a, const T& b) {
- return a.key() < b.key();
- }
- static bool EQ(const T& a, const T& b) {
- return a.key() == b.key();
- }
-#endif
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) :
fMaxCount(maxCount),
fMaxBytes(maxBytes) {