Adds a mechanism for GrCacheable objects to notify the resource cache
when their size has changed. GrResourceCacheEntry now holds a
reference to the cache, and a cached value of the resource's most
recent size.
Also utilizes this new functionality for mipmaps, and adds a test for
changing resource sizes.
R=bsalomon@google.com, robertphillips@google.com
Author: cdalton@nvidia.com
Review URL: https://codereview.chromium.org/257093002
git-svn-id: http://skia.googlecode.com/svn/trunk@14576 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index b2f91cd..1a81fe6 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -19,6 +19,7 @@
#include "SkTInternalLList.h"
class GrCacheable;
+class GrResourceCache;
class GrResourceCacheEntry;
class GrResourceKey {
@@ -128,12 +129,24 @@
void validate() const {}
#endif
+ /**
+ * Update the cached size for this entry and inform the resource cache that
+ * it has changed. Usually invoked from GrCacheable::didChangeGpuMemorySize,
+ * not directly from here.
+ */
+ void didChangeResourceSize();
+
private:
- GrResourceCacheEntry(const GrResourceKey& key, GrCacheable* resource);
+ GrResourceCacheEntry(GrResourceCache* resourceCache,
+ const GrResourceKey& key,
+ GrCacheable* resource);
~GrResourceCacheEntry();
+ GrResourceCache* fResourceCache;
GrResourceKey fKey;
GrCacheable* fResource;
+ size_t fCachedSize;
+ bool fIsExclusive;
// Linked list for the LRU ordering.
SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceCacheEntry);
@@ -272,6 +285,12 @@
void makeNonExclusive(GrResourceCacheEntry* entry);
/**
+ * Notify the cache that the size of a resource has changed.
+ */
+ void didIncreaseResourceSize(const GrResourceCacheEntry*, size_t amountInc);
+ void didDecreaseResourceSize(const GrResourceCacheEntry*, size_t amountDec);
+
+ /**
* Remove a resource from the cache and delete it!
*/
void deleteResource(GrResourceCacheEntry* entry);