Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGpuResource_DEFINED | 8 #ifndef GrGpuResource_DEFINED |
| 9 #define GrGpuResource_DEFINED | 9 #define GrGpuResource_DEFINED |
| 10 | 10 |
| 11 #include "SkInstCnt.h" | 11 #include "SkInstCnt.h" |
| 12 #include "SkTInternalLList.h" | 12 #include "SkTInternalLList.h" |
| 13 #include "GrResourceKey.h" | |
| 13 | 14 |
| 14 class GrResourceCacheEntry; | 15 class GrResourceCacheEntry; |
| 15 class GrResourceCache2; | 16 class GrResourceCache2; |
| 16 class GrGpu; | 17 class GrGpu; |
| 17 class GrContext; | 18 class GrContext; |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * Base class for objects that can be kept in the GrResourceCache. | 21 * Base class for objects that can be kept in the GrResourceCache. |
| 21 */ | 22 */ |
| 22 class GrGpuResource : public SkNoncopyable { | 23 class GrGpuResource : public SkNoncopyable { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 * Retrieves the amount of GPU memory used by this resource in bytes. It is | 75 * Retrieves the amount of GPU memory used by this resource in bytes. It is |
| 75 * approximate since we aren't aware of additional padding or copies made | 76 * approximate since we aren't aware of additional padding or copies made |
| 76 * by the driver. | 77 * by the driver. |
| 77 * | 78 * |
| 78 * @return the amount of GPU memory used in bytes | 79 * @return the amount of GPU memory used in bytes |
| 79 */ | 80 */ |
| 80 virtual size_t gpuMemorySize() const = 0; | 81 virtual size_t gpuMemorySize() const = 0; |
| 81 | 82 |
| 82 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn try; } | 83 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn try; } |
| 83 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; } | 84 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; } |
| 84 | 85 |
|
robertphillips
2014/08/27 19:11:29
// If this resource can be used as a scratch resou
bsalomon
2014/08/27 20:37:39
Done.
| |
| 86 const GrResourceKey& getScratchKey() const { return fScratchKey; } | |
| 87 | |
| 85 /** | 88 /** |
| 86 * Gets an id that is unique for this GrCacheable object. It is static in th at it does | 89 * Gets an id that is unique for this GrCacheable object. It is static in th at it does |
| 87 * not change when the content of the GrCacheable object changes. This will never return | 90 * not change when the content of the GrCacheable object changes. This will never return |
| 88 * 0. | 91 * 0. |
| 89 */ | 92 */ |
| 90 uint32_t getUniqueID() const { return fUniqueID; } | 93 uint32_t getUniqueID() const { return fUniqueID; } |
| 91 | 94 |
| 92 protected: | 95 protected: |
| 93 | |
| 94 // This must be called by every GrGpuObject. It should be called once the ob ject is fully | 96 // This must be called by every GrGpuObject. It should be called once the ob ject is fully |
| 95 // initialized (i.e. not in a base class constructor). | 97 // initialized (i.e. not in a base class constructor). |
| 96 void registerWithCache(); | 98 void registerWithCache(); |
| 97 | 99 |
| 98 GrGpuResource(GrGpu*, bool isWrapped); | 100 GrGpuResource(GrGpu*, bool isWrapped); |
| 99 virtual ~GrGpuResource(); | 101 virtual ~GrGpuResource(); |
| 100 | 102 |
| 101 bool isInCache() const { return NULL != fCacheEntry; } | 103 bool isInCache() const { return NULL != fCacheEntry; } |
| 102 | 104 |
| 103 GrGpu* getGpu() const { return fGpu; } | 105 GrGpu* getGpu() const { return fGpu; } |
| 104 | 106 |
| 105 // Derived classes should always call their parent class' onRelease | 107 // Derived classes should always call their parent class' onRelease |
| 106 // and onAbandon methods in their overrides. | 108 // and onAbandon methods in their overrides. |
| 107 virtual void onRelease() {}; | 109 virtual void onRelease() {}; |
| 108 virtual void onAbandon() {}; | 110 virtual void onAbandon() {}; |
| 109 | 111 |
| 110 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } | 112 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } |
| 111 | 113 |
| 112 /** | 114 /** |
| 113 * This entry point should be called whenever gpuMemorySize() begins | 115 * This entry point should be called whenever gpuMemorySize() begins |
| 114 * reporting a different size. If the object is in the cache, it will call | 116 * reporting a different size. If the object is in the cache, it will call |
| 115 * gpuMemorySize() immediately and pass the new size on to the resource | 117 * gpuMemorySize() immediately and pass the new size on to the resource |
| 116 * cache. | 118 * cache. |
| 117 */ | 119 */ |
| 118 void didChangeGpuMemorySize() const; | 120 void didChangeGpuMemorySize() const; |
| 119 | 121 |
| 122 /** | |
| 123 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. | |
| 124 * By default resources are not usable as scratch. This should only be calle d once. | |
| 125 **/ | |
| 126 void setScratchKey(const GrResourceKey& scratchKey); | |
| 127 | |
| 120 private: | 128 private: |
| 121 #ifdef SK_DEBUG | 129 #ifdef SK_DEBUG |
| 122 friend class GrGpu; // for assert in GrGpu to access getGpu | 130 friend class GrGpu; // for assert in GrGpu to access getGpu |
| 123 #endif | 131 #endif |
| 124 | 132 |
| 125 static uint32_t CreateUniqueID(); | 133 static uint32_t CreateUniqueID(); |
| 126 | 134 |
| 127 // We're in an internal doubly linked list owned by GrResourceCache2 | 135 // We're in an internal doubly linked list owned by GrResourceCache2 |
| 128 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); | 136 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); |
| 129 | 137 |
| 130 // This is not ref'ed but abandon() or release() will be called before the G rGpu object | 138 // This is not ref'ed but abandon() or release() will be called before the G rGpu object |
| 131 // is destroyed. Those calls set will this to NULL. | 139 // is destroyed. Those calls set will this to NULL. |
| 132 GrGpu* fGpu; | 140 GrGpu* fGpu; |
| 133 | 141 |
| 134 enum Flags { | 142 enum Flags { |
| 135 /** | 143 /** |
| 136 * This object wraps a GPU object given to us by the user. | 144 * This object wraps a GPU object given to us by the user. |
| 137 * Lifetime management is left up to the user (i.e., we will not | 145 * Lifetime management is left up to the user (i.e., we will not |
| 138 * free it). | 146 * free it). |
| 139 */ | 147 */ |
| 140 kWrapped_FlagBit = 0x1, | 148 kWrapped_FlagBit = 0x1, |
| 141 }; | 149 }; |
| 142 | 150 |
| 143 uint32_t fFlags; | 151 uint32_t fFlags; |
| 144 | 152 |
| 145 mutable int32_t fRefCnt; | 153 mutable int32_t fRefCnt; |
| 146 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache | 154 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| 147 const uint32_t fUniqueID; | 155 const uint32_t fUniqueID; |
| 148 | 156 |
| 157 GrResourceKey fScratchKey; | |
| 158 | |
| 149 typedef SkNoncopyable INHERITED; | 159 typedef SkNoncopyable INHERITED; |
| 150 }; | 160 }; |
| 151 | 161 |
| 152 #endif | 162 #endif |
| OLD | NEW |