| 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 | |
| 200 // Android's std::unique_ptr's operator bool() is sometimes not explicit... | |
| 201 // so override it with our own explcitly explicit version. | |
| 202 explicit operator bool() const { return this->get() != nullptr; } | |
| 203 }; | 198 }; |
| 204 // 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. :( |
| 205 | 200 |
| 206 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 201 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
| 207 public: | 202 public: |
| 208 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 203 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
| 209 }; | 204 }; |
| 210 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) | 205 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) |
| 211 | 206 |
| 212 // This is a variant of SkRefCnt that's Not Virtual, so weighs 4 bytes instead o
f 8 or 16. | 207 // This is a variant of SkRefCnt that's Not Virtual, so weighs 4 bytes instead o
f 8 or 16. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 * | 442 * |
| 448 * 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. |
| 449 */ | 444 */ |
| 450 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { | 445 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { |
| 451 return sk_sp<T>(SkSafeRef(obj)); | 446 return sk_sp<T>(SkSafeRef(obj)); |
| 452 } | 447 } |
| 453 | 448 |
| 454 #endif | 449 #endif |
| 455 | 450 |
| 456 #endif | 451 #endif |
| OLD | NEW |