| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrVkResource_DEFINED | 8 #ifndef GrVkResource_DEFINED |
| 9 #define GrVkResource_DEFINED | 9 #define GrVkResource_DEFINED |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 takes a GrVkGpu, and any derived classes must implement freeGPUData() and | 33 takes a GrVkGpu, and any derived classes must implement freeGPUData() and |
| 34 possibly abandonSubResources(). | 34 possibly abandonSubResources(). |
| 35 */ | 35 */ |
| 36 | 36 |
| 37 class GrVkResource : SkNoncopyable { | 37 class GrVkResource : SkNoncopyable { |
| 38 public: | 38 public: |
| 39 // Simple refCount tracing, to ensure that everything ref'ed is unref'ed. | 39 // Simple refCount tracing, to ensure that everything ref'ed is unref'ed. |
| 40 #ifdef SK_TRACE_VK_RESOURCES | 40 #ifdef SK_TRACE_VK_RESOURCES |
| 41 static const uint32_t& GetKey(const GrVkResource& r) { return r.fKey; } | 41 static const uint32_t& GetKey(const GrVkResource& r) { return r.fKey; } |
| 42 static uint32_t Hash(const uint32_t& k) { return k; } | 42 static uint32_t Hash(const uint32_t& k) { return k; } |
| 43 static SkTDynamicHash<GrVkResource, uint32_t> fTrace; | 43 |
| 44 class Trace { |
| 45 public: |
| 46 ~Trace() { |
| 47 if (fHash.count()) { |
| 48 SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&fHash); |
| 49 for (; !iter.done(); ++iter) { |
| 50 (*iter).dumpInfo(); |
| 51 } |
| 52 } |
| 53 SkASSERT(0 == fHash.count()); |
| 54 } |
| 55 void add(GrVkResource* r) { fHash.add(r); } |
| 56 void remove(const GrVkResource* r) { fHash.remove(GetKey(*r)); } |
| 57 |
| 58 private: |
| 59 SkTDynamicHash<GrVkResource, uint32_t> fHash; |
| 60 }; |
| 61 static Trace fTrace; |
| 62 |
| 44 static SkRandom fRandom; | 63 static SkRandom fRandom; |
| 45 #endif | 64 #endif |
| 46 | 65 |
| 47 /** Default construct, initializing the reference count to 1. | 66 /** Default construct, initializing the reference count to 1. |
| 48 */ | 67 */ |
| 49 GrVkResource() : fRefCnt(1) { | 68 GrVkResource() : fRefCnt(1) { |
| 50 #ifdef SK_TRACE_VK_RESOURCES | 69 #ifdef SK_TRACE_VK_RESOURCES |
| 51 fKey = fRandom.nextU(); | 70 fKey = fRandom.nextU(); |
| 52 fTrace.add(this); | 71 fTrace.add(this); |
| 53 #endif | 72 #endif |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 * Will unrefAndAbandon those resources without deleting the underlying Vk
data | 156 * Will unrefAndAbandon those resources without deleting the underlying Vk
data |
| 138 */ | 157 */ |
| 139 virtual void abandonSubResources() const {} | 158 virtual void abandonSubResources() const {} |
| 140 | 159 |
| 141 /** | 160 /** |
| 142 * Called when the ref count goes to 0. Will free Vk resources. | 161 * Called when the ref count goes to 0. Will free Vk resources. |
| 143 */ | 162 */ |
| 144 void internal_dispose(const GrVkGpu* gpu) const { | 163 void internal_dispose(const GrVkGpu* gpu) const { |
| 145 this->freeGPUData(gpu); | 164 this->freeGPUData(gpu); |
| 146 #ifdef SK_TRACE_VK_RESOURCES | 165 #ifdef SK_TRACE_VK_RESOURCES |
| 147 fTrace.remove(GetKey(*this)); | 166 fTrace.remove(this); |
| 148 #endif | 167 #endif |
| 149 SkASSERT(0 == fRefCnt); | 168 SkASSERT(0 == fRefCnt); |
| 150 fRefCnt = 1; | 169 fRefCnt = 1; |
| 151 delete this; | 170 delete this; |
| 152 } | 171 } |
| 153 | 172 |
| 154 /** | 173 /** |
| 155 * Internal_dispose without freeing Vk resources. Used when we've lost cont
ext. | 174 * Internal_dispose without freeing Vk resources. Used when we've lost cont
ext. |
| 156 */ | 175 */ |
| 157 void internal_dispose() const { | 176 void internal_dispose() const { |
| 158 this->abandonSubResources(); | 177 this->abandonSubResources(); |
| 159 #ifdef SK_TRACE_VK_RESOURCES | 178 #ifdef SK_TRACE_VK_RESOURCES |
| 160 fTrace.remove(GetKey(*this)); | 179 fTrace.remove(this); |
| 161 #endif | 180 #endif |
| 162 SkASSERT(0 == fRefCnt); | 181 SkASSERT(0 == fRefCnt); |
| 163 fRefCnt = 1; | 182 fRefCnt = 1; |
| 164 delete this; | 183 delete this; |
| 165 } | 184 } |
| 166 | 185 |
| 167 mutable int32_t fRefCnt; | 186 mutable int32_t fRefCnt; |
| 168 #ifdef SK_TRACE_VK_RESOURCES | 187 #ifdef SK_TRACE_VK_RESOURCES |
| 169 uint32_t fKey; | 188 uint32_t fKey; |
| 170 #endif | 189 #endif |
| 171 | 190 |
| 172 typedef SkNoncopyable INHERITED; | 191 typedef SkNoncopyable INHERITED; |
| 173 }; | 192 }; |
| 174 | 193 |
| 175 | 194 |
| 176 #endif | 195 #endif |
| OLD | NEW |