OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkRefCnt_DEFINED | 10 #ifndef SkRefCnt_DEFINED |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Prevents code in dispose from happening before the decrement. | 64 // Prevents code in dispose from happening before the decrement. |
65 sk_membar_aquire__after_atomic_dec(); | 65 sk_membar_aquire__after_atomic_dec(); |
66 internal_dispose(); | 66 internal_dispose(); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void validate() const { | 70 void validate() const { |
71 SkASSERT(fRefCnt > 0); | 71 SkASSERT(fRefCnt > 0); |
72 } | 72 } |
73 | 73 |
74 /** | |
75 * Alias for ref(), for compatibility with scoped_refptr. | |
76 */ | |
77 void AddRef() { this->ref(); } | |
78 | |
79 /** | |
80 * Alias for unref(), for compatibility with scoped_refptr. | |
81 */ | |
82 void Release() { this->unref(); } | |
83 | |
84 protected: | 74 protected: |
85 /** | 75 /** |
86 * Allow subclasses to call this if they've overridden internal_dispose | 76 * Allow subclasses to call this if they've overridden internal_dispose |
87 * so they can reset fRefCnt before the destructor is called. Should only | 77 * so they can reset fRefCnt before the destructor is called. Should only |
88 * be called right before calling through to inherited internal_dispose() | 78 * be called right before calling through to inherited internal_dispose() |
89 * or before calling the destructor. | 79 * or before calling the destructor. |
90 */ | 80 */ |
91 void internal_dispose_restore_refcnt_to_1() const { | 81 void internal_dispose_restore_refcnt_to_1() const { |
92 #ifdef SK_DEBUG | 82 #ifdef SK_DEBUG |
93 SkASSERT(0 == fRefCnt); | 83 SkASSERT(0 == fRefCnt); |
94 fRefCnt = 1; | 84 fRefCnt = 1; |
95 #endif | 85 #endif |
96 } | 86 } |
97 | 87 |
98 private: | 88 private: |
99 /** | 89 /** |
100 * Called when the ref count goes to 0. | 90 * Called when the ref count goes to 0. |
101 */ | 91 */ |
102 virtual void internal_dispose() const { | 92 virtual void internal_dispose() const { |
103 this->internal_dispose_restore_refcnt_to_1(); | 93 this->internal_dispose_restore_refcnt_to_1(); |
104 SkDELETE(this); | 94 SkDELETE(this); |
105 } | 95 } |
106 | 96 |
| 97 // The following friends are those which override internal_dispose() |
| 98 // and conditionally call SkRefCnt::internal_dispose(). |
| 99 friend class GrTexture; |
107 friend class SkWeakRefCnt; | 100 friend class SkWeakRefCnt; |
108 friend class GrTexture; // to allow GrTexture's internal_dispose to | |
109 // call SkRefCnt's & directly set fRefCnt (to 1) | |
110 | 101 |
111 mutable int32_t fRefCnt; | 102 mutable int32_t fRefCnt; |
112 | 103 |
113 typedef SkNoncopyable INHERITED; | 104 typedef SkNoncopyable INHERITED; |
114 }; | 105 }; |
115 | 106 |
116 /////////////////////////////////////////////////////////////////////////////// | 107 /////////////////////////////////////////////////////////////////////////////// |
117 | 108 |
118 /** Helper macro to safely assign one SkRefCnt[TS]* to another, checking for | 109 /** Helper macro to safely assign one SkRefCnt[TS]* to another, checking for |
119 null in on each side of the assignment, and ensuring that ref() is called | 110 null in on each side of the assignment, and ensuring that ref() is called |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 typedef T* SkRefPtr::*unspecified_bool_type; | 248 typedef T* SkRefPtr::*unspecified_bool_type; |
258 operator unspecified_bool_type() const { | 249 operator unspecified_bool_type() const { |
259 return fObj ? &SkRefPtr::fObj : NULL; | 250 return fObj ? &SkRefPtr::fObj : NULL; |
260 } | 251 } |
261 | 252 |
262 private: | 253 private: |
263 T* fObj; | 254 T* fObj; |
264 }; | 255 }; |
265 | 256 |
266 #endif | 257 #endif |
OLD | NEW |