OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 SkRefCnt_DEFINED | 8 #ifndef SkRefCnt_DEFINED |
9 #define SkRefCnt_DEFINED | 9 #define SkRefCnt_DEFINED |
10 | 10 |
11 #include "../private/SkAtomics.h" | 11 #include "../private/SkAtomics.h" |
12 #include "../private/SkTLogic.h" | 12 #include "../private/SkUniquePtr.h" |
13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
14 #include <functional> | 14 #include <functional> |
15 #include <memory> | |
16 #include <utility> | 15 #include <utility> |
17 | 16 |
18 #define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES | 17 #define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES |
19 | 18 |
20 /** \class SkRefCntBase | 19 /** \class SkRefCntBase |
21 | 20 |
22 SkRefCntBase is the base class for objects that may be shared by multiple | 21 SkRefCntBase is the base class for objects that may be shared by multiple |
23 objects. When an existing owner wants to share a reference, it calls ref(). | 22 objects. When an existing owner wants to share a reference, it calls ref(). |
24 When an owner wants to release its reference, it calls unref(). When the | 23 When an owner wants to release its reference, it calls unref(). When the |
25 shared object's reference count goes to zero as the result of an unref() | 24 shared object's reference count goes to zero as the result of an unref() |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 182 |
184 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
185 | 184 |
186 template <typename T> struct SkTUnref { | 185 template <typename T> struct SkTUnref { |
187 void operator()(T* t) { t->unref(); } | 186 void operator()(T* t) { t->unref(); } |
188 }; | 187 }; |
189 | 188 |
190 /** | 189 /** |
191 * Utility class that simply unref's its argument in the destructor. | 190 * Utility class that simply unref's its argument in the destructor. |
192 */ | 191 */ |
193 template <typename T> class SkAutoTUnref : public std::unique_ptr<T, SkTUnref<T>
> { | 192 template <typename T> class SkAutoTUnref : public skstd::unique_ptr<T, SkTUnref<
T>> { |
194 public: | 193 public: |
195 explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr<T, SkTUnref<T>>(ob
j) {} | 194 explicit SkAutoTUnref(T* obj = nullptr) : skstd::unique_ptr<T, SkTUnref<T>>(
obj) {} |
196 | 195 |
197 T* detach() { return this->release(); } | 196 T* detach() { return this->release(); } |
198 operator T*() const { return this->get(); } | 197 operator T*() const { return this->get(); } |
199 }; | 198 }; |
200 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( | 199 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
201 | 200 |
202 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 201 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
203 public: | 202 public: |
204 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 203 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
205 }; | 204 }; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 * | 442 * |
444 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. | 443 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. |
445 */ | 444 */ |
446 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { | 445 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { |
447 return sk_sp<T>(SkSafeRef(obj)); | 446 return sk_sp<T>(SkSafeRef(obj)); |
448 } | 447 } |
449 | 448 |
450 #endif | 449 #endif |
451 | 450 |
452 #endif | 451 #endif |
OLD | NEW |