| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 SkASSERT(0 == fHash.count()); | 53 SkASSERT(0 == fHash.count()); |
| 54 } | 54 } |
| 55 void add(GrVkResource* r) { fHash.add(r); } | 55 void add(GrVkResource* r) { fHash.add(r); } |
| 56 void remove(const GrVkResource* r) { fHash.remove(GetKey(*r)); } | 56 void remove(const GrVkResource* r) { fHash.remove(GetKey(*r)); } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 SkTDynamicHash<GrVkResource, uint32_t> fHash; | 59 SkTDynamicHash<GrVkResource, uint32_t> fHash; |
| 60 }; | 60 }; |
| 61 static Trace fTrace; | 61 static Trace fTrace; |
| 62 | 62 |
| 63 static SkRandom fRandom; | 63 static uint32_t fKeyCounter; |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 /** Default construct, initializing the reference count to 1. | 66 /** Default construct, initializing the reference count to 1. |
| 67 */ | 67 */ |
| 68 GrVkResource() : fRefCnt(1) { | 68 GrVkResource() : fRefCnt(1) { |
| 69 #ifdef SK_TRACE_VK_RESOURCES | 69 #ifdef SK_TRACE_VK_RESOURCES |
| 70 fKey = fRandom.nextU(); | 70 fKey = sk_atomic_fetch_add(&fKeyCounter, 1u, sk_memory_order_relaxed); |
| 71 fTrace.add(this); | 71 fTrace.add(this); |
| 72 #endif | 72 #endif |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** Destruct, asserting that the reference count is 1. | 75 /** Destruct, asserting that the reference count is 1. |
| 76 */ | 76 */ |
| 77 virtual ~GrVkResource() { | 77 virtual ~GrVkResource() { |
| 78 #ifdef SK_DEBUG | 78 #ifdef SK_DEBUG |
| 79 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); | 79 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); |
| 80 fRefCnt = 0; // illegal value, to catch us if we reuse after delete | 80 fRefCnt = 0; // illegal value, to catch us if we reuse after delete |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 mutable int32_t fRefCnt; | 186 mutable int32_t fRefCnt; |
| 187 #ifdef SK_TRACE_VK_RESOURCES | 187 #ifdef SK_TRACE_VK_RESOURCES |
| 188 uint32_t fKey; | 188 uint32_t fKey; |
| 189 #endif | 189 #endif |
| 190 | 190 |
| 191 typedef SkNoncopyable INHERITED; | 191 typedef SkNoncopyable INHERITED; |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 | 194 |
| 195 #endif | 195 #endif |
| OLD | NEW |