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 SkRandom fRandom; |
jvanverth1
2016/07/13 21:01:45
This declaration of fRandom should go away.
egdaniel
2016/07/13 21:06:34
Done.
| |
64 static uint32_t fKeyCounter; | |
64 #endif | 65 #endif |
65 | 66 |
66 /** Default construct, initializing the reference count to 1. | 67 /** Default construct, initializing the reference count to 1. |
67 */ | 68 */ |
68 GrVkResource() : fRefCnt(1) { | 69 GrVkResource() : fRefCnt(1) { |
69 #ifdef SK_TRACE_VK_RESOURCES | 70 #ifdef SK_TRACE_VK_RESOURCES |
70 fKey = fRandom.nextU(); | 71 fKey = sk_atomic_fetch_add(&fKeyCounter, 1u, sk_memory_order_relaxed); |
71 fTrace.add(this); | 72 fTrace.add(this); |
72 #endif | 73 #endif |
73 } | 74 } |
74 | 75 |
75 /** Destruct, asserting that the reference count is 1. | 76 /** Destruct, asserting that the reference count is 1. |
76 */ | 77 */ |
77 virtual ~GrVkResource() { | 78 virtual ~GrVkResource() { |
78 #ifdef SK_DEBUG | 79 #ifdef SK_DEBUG |
79 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); | 80 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); |
80 fRefCnt = 0; // illegal value, to catch us if we reuse after delete | 81 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; | 187 mutable int32_t fRefCnt; |
187 #ifdef SK_TRACE_VK_RESOURCES | 188 #ifdef SK_TRACE_VK_RESOURCES |
188 uint32_t fKey; | 189 uint32_t fKey; |
189 #endif | 190 #endif |
190 | 191 |
191 typedef SkNoncopyable INHERITED; | 192 typedef SkNoncopyable INHERITED; |
192 }; | 193 }; |
193 | 194 |
194 | 195 |
195 #endif | 196 #endif |
OLD | NEW |