Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / gpu / GrCacheable.h
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     /**
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
53      * cache.
54      */
55     void didChangeGpuMemorySize() const;
56
57 private:
58     GrResourceCacheEntry* fCacheEntry;  // NULL if not in cache
59
60     typedef SkRefCnt INHERITED;
61 };
62
63 #endif