commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrCacheable_DEFINED |
| 9 | #define GrCacheable_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | |
| 13 | class GrResourceCacheEntry; |
| 14 | |
| 15 | /** |
| 16 | * Base class for objects that can be kept in the GrResourceCache. |
| 17 | */ |
| 18 | class GrCacheable : public SkRefCnt { |
| 19 | public: |
| 20 | SK_DECLARE_INST_COUNT(GrCacheable) |
| 21 | |
| 22 | /** |
| 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 |
| 25 | * by the driver. |
| 26 | * |
| 27 | * @return the amount of GPU memory used in bytes |
| 28 | */ |
| 29 | virtual size_t gpuMemorySize() const = 0; |
| 30 | |
| 31 | /** |
| 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. |
| 35 | * |
| 36 | * @return true if this resource is still holding GPU memory |
| 37 | * false otherwise. |
| 38 | */ |
| 39 | virtual bool isValidOnGpu() const = 0; |
| 40 | |
| 41 | void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEntry; } |
| 42 | GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; } |
| 43 | |
| 44 | protected: |
| 45 | GrCacheable() : fCacheEntry(NULL) {} |
| 46 | |
| 47 | bool isInCache() const { return NULL != fCacheEntry; } |
| 48 | |
| 49 | private: |
| 50 | GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| 51 | |
| 52 | typedef SkRefCnt INHERITED; |
| 53 | }; |
| 54 | |
| 55 | #endif |