| 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/SkUniquePtr.h" | 12 #include "../private/SkTLogic.h" |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 #include <functional> | 14 #include <functional> |
| 15 #include <memory> |
| 15 #include <utility> | 16 #include <utility> |
| 16 | 17 |
| 17 #define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES | 18 #define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES |
| 18 | 19 |
| 19 /** \class SkRefCntBase | 20 /** \class SkRefCntBase |
| 20 | 21 |
| 21 SkRefCntBase is the base class for objects that may be shared by multiple | 22 SkRefCntBase is the base class for objects that may be shared by multiple |
| 22 objects. When an existing owner wants to share a reference, it calls ref(). | 23 objects. When an existing owner wants to share a reference, it calls ref(). |
| 23 When an owner wants to release its reference, it calls unref(). When the | 24 When an owner wants to release its reference, it calls unref(). When the |
| 24 shared object's reference count goes to zero as the result of an unref() | 25 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... |
| 182 | 183 |
| 183 /////////////////////////////////////////////////////////////////////////////// | 184 /////////////////////////////////////////////////////////////////////////////// |
| 184 | 185 |
| 185 template <typename T> struct SkTUnref { | 186 template <typename T> struct SkTUnref { |
| 186 void operator()(T* t) { t->unref(); } | 187 void operator()(T* t) { t->unref(); } |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 /** | 190 /** |
| 190 * Utility class that simply unref's its argument in the destructor. | 191 * Utility class that simply unref's its argument in the destructor. |
| 191 */ | 192 */ |
| 192 template <typename T> class SkAutoTUnref : public skstd::unique_ptr<T, SkTUnref<
T>> { | 193 template <typename T> class SkAutoTUnref : public std::unique_ptr<T, SkTUnref<T>
> { |
| 193 public: | 194 public: |
| 194 explicit SkAutoTUnref(T* obj = nullptr) : skstd::unique_ptr<T, SkTUnref<T>>(
obj) {} | 195 explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr<T, SkTUnref<T>>(ob
j) {} |
| 195 | 196 |
| 196 T* detach() { return this->release(); } | 197 T* detach() { return this->release(); } |
| 197 operator T*() const { return this->get(); } | 198 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; } |
| 198 }; | 203 }; |
| 199 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( | 204 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
| 200 | 205 |
| 201 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 206 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
| 202 public: | 207 public: |
| 203 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 208 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
| 204 }; | 209 }; |
| 205 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) | 210 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) |
| 206 | 211 |
| 207 // This is a variant of SkRefCnt that's Not Virtual, so weighs 4 bytes instead o
f 8 or 16. | 212 // 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... |
| 442 * | 447 * |
| 443 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. | 448 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. |
| 444 */ | 449 */ |
| 445 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { | 450 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { |
| 446 return sk_sp<T>(SkSafeRef(obj)); | 451 return sk_sp<T>(SkSafeRef(obj)); |
| 447 } | 452 } |
| 448 | 453 |
| 449 #endif | 454 #endif |
| 450 | 455 |
| 451 #endif | 456 #endif |
| OLD | NEW |