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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 bool unique() const { | 73 bool unique() const { |
74 if (1 == sk_atomic_load(&fRefCnt, sk_memory_order_acquire)) { | 74 if (1 == sk_atomic_load(&fRefCnt, sk_memory_order_acquire)) { |
75 // The acquire barrier is only really needed if we return true. It | 75 // The acquire barrier is only really needed if we return true. It |
76 // prevents code conditioned on the result of unique() from running | 76 // prevents code conditioned on the result of unique() from running |
77 // until previous owners are all totally done calling unref(). | 77 // until previous owners are all totally done calling unref(). |
78 return true; | 78 return true; |
79 } | 79 } |
80 return false; | 80 return false; |
81 } | 81 } |
82 | 82 |
83 /** Increment the reference count. | 83 /** Increment the reference count. |
84 Must be balanced by a call to unref() or unrefAndFreeResources(). | 84 Must be balanced by a call to unref() or unrefAndFreeResources(). |
85 */ | 85 */ |
86 void ref() const { | 86 void ref() const { |
87 SkASSERT(fRefCnt > 0); | 87 SkASSERT(fRefCnt > 0); |
88 (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_order_relaxed); // No
barrier required. | 88 (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_order_relaxed); // No
barrier required. |
89 } | 89 } |
90 | 90 |
91 /** Decrement the reference count. If the reference count is 1 before the | 91 /** Decrement the reference count. If the reference count is 1 before the |
92 decrement, then delete the object. Note that if this is the case, then | 92 decrement, then delete the object. Note that if this is the case, then |
93 the object needs to have been allocated via new, and not on the stack. | 93 the object needs to have been allocated via new, and not on the stack. |
(...skipping 21 matching lines...) Expand all Loading... |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 #ifdef SK_DEBUG | 118 #ifdef SK_DEBUG |
119 void validate() const { | 119 void validate() const { |
120 SkASSERT(fRefCnt > 0); | 120 SkASSERT(fRefCnt > 0); |
121 } | 121 } |
122 #endif | 122 #endif |
123 | 123 |
124 private: | 124 private: |
125 /** Must be implemented by any subclasses. | 125 /** Must be implemented by any subclasses. |
126 * Deletes any Vk data associated with this resource | 126 * Deletes any Vk data associated with this resource |
127 */ | 127 */ |
128 virtual void freeGPUData(const GrVkGpu* gpu) const = 0; | 128 virtual void freeGPUData(const GrVkGpu* gpu) const = 0; |
129 | 129 |
130 /** Must be overridden by subclasses that themselves store GrVkResources. | 130 /** Must be overridden by subclasses that themselves store GrVkResources. |
131 * Will unrefAndAbandon those resources without deleting the underlying Vk
data | 131 * Will unrefAndAbandon those resources without deleting the underlying Vk
data |
132 */ | 132 */ |
133 virtual void abandonSubResources() const {} | 133 virtual void abandonSubResources() const {} |
134 | 134 |
135 /** | 135 /** |
136 * Called when the ref count goes to 0. Will free Vk resources. | 136 * Called when the ref count goes to 0. Will free Vk resources. |
137 */ | 137 */ |
138 void internal_dispose(const GrVkGpu* gpu) const { | 138 void internal_dispose(const GrVkGpu* gpu) const { |
139 this->freeGPUData(gpu); | 139 this->freeGPUData(gpu); |
140 #ifdef SK_TRACE_VK_RESOURCES | 140 #ifdef SK_TRACE_VK_RESOURCES |
141 fTrace.remove(GetKey(*this)); | 141 fTrace.remove(GetKey(*this)); |
(...skipping 19 matching lines...) Expand all Loading... |
161 mutable int32_t fRefCnt; | 161 mutable int32_t fRefCnt; |
162 #ifdef SK_TRACE_VK_RESOURCES | 162 #ifdef SK_TRACE_VK_RESOURCES |
163 uint32_t fKey; | 163 uint32_t fKey; |
164 #endif | 164 #endif |
165 | 165 |
166 typedef SkNoncopyable INHERITED; | 166 typedef SkNoncopyable INHERITED; |
167 }; | 167 }; |
168 | 168 |
169 | 169 |
170 #endif | 170 #endif |
OLD | NEW |