2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrCacheable_DEFINED
9 #define GrCacheable_DEFINED
13 class GrResourceCacheEntry;
16 * Base class for objects that can be kept in the GrResourceCache.
18 class GrCacheable : public SkRefCnt {
20 SK_DECLARE_INST_COUNT(GrCacheable)
23 * Retrieves the amount of GPU memory used by this resource in bytes. It is
24 * approximate since we aren't aware of additional padding or copies made
27 * @return the amount of GPU memory used in bytes
29 virtual size_t gpuMemorySize() const = 0;
32 * Checks whether the GPU memory allocated to this resource is still in effect.
33 * It can become invalid if its context is destroyed or lost, in which case it
34 * should no longer count against the GrResourceCache budget.
36 * @return true if this resource is still holding GPU memory
39 virtual bool isValidOnGpu() const = 0;
41 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEntry; }
42 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; }
45 GrCacheable() : fCacheEntry(NULL) {}
47 bool isInCache() const { return NULL != fCacheEntry; }
50 * This entry point should be called whenever gpuMemorySize() begins
51 * reporting a different size. If the object is in the cache, it will call
52 * gpuMemorySize() immediately and pass the new size on to the resource
55 void didChangeGpuMemorySize() const;
58 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
60 typedef SkRefCnt INHERITED;