| 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 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 void operator()(T* t) { t->unref(); } | 187 void operator()(T* t) { t->unref(); } |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 /** | 190 /** |
| 191 * Utility class that simply unref's its argument in the destructor. | 191 * Utility class that simply unref's its argument in the destructor. |
| 192 */ | 192 */ |
| 193 template <typename T> class SkAutoTUnref : public std::unique_ptr<T, SkTUnref<T>
> { | 193 template <typename T> class SkAutoTUnref : public std::unique_ptr<T, SkTUnref<T>
> { |
| 194 public: | 194 public: |
| 195 explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr<T, SkTUnref<T>>(ob
j) {} | 195 explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr<T, SkTUnref<T>>(ob
j) {} |
| 196 | 196 |
| 197 T* detach() { return this->release(); } | |
| 198 operator T*() const { return this->get(); } | 197 operator T*() const { return this->get(); } |
| 199 | 198 |
| 200 // Android's std::unique_ptr's operator bool() is sometimes not explicit... | 199 // Android's std::unique_ptr's operator bool() is sometimes not explicit... |
| 201 // so override it with our own explcitly explicit version. | 200 // so override it with our own explcitly explicit version. |
| 202 explicit operator bool() const { return this->get() != nullptr; } | 201 explicit operator bool() const { return this->get() != nullptr; } |
| 203 }; | 202 }; |
| 204 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( | 203 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
| 205 | 204 |
| 206 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 205 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
| 207 public: | 206 public: |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 * | 446 * |
| 448 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. | 447 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. |
| 449 */ | 448 */ |
| 450 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { | 449 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { |
| 451 return sk_sp<T>(SkSafeRef(obj)); | 450 return sk_sp<T>(SkSafeRef(obj)); |
| 452 } | 451 } |
| 453 | 452 |
| 454 #endif | 453 #endif |
| 455 | 454 |
| 456 #endif | 455 #endif |
| OLD | NEW |