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/SkUniquePtr.h" |
13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
14 #include <functional> | 14 #include <functional> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
| 17 #define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES |
| 18 |
17 /** \class SkRefCntBase | 19 /** \class SkRefCntBase |
18 | 20 |
19 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 |
20 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(). |
21 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 |
22 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() |
23 call, its (virtual) destructor is called. It is an error for the | 25 call, its (virtual) destructor is called. It is an error for the |
24 destructor to be called explicitly (or via the object going out of scope on | 26 destructor to be called explicitly (or via the object going out of scope on |
25 the stack or calling delete) if getRefCnt() > 1. | 27 the stack or calling delete) if getRefCnt() > 1. |
26 */ | 28 */ |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 } | 425 } |
424 template <typename T> inline bool operator>=(std::nullptr_t, const sk_sp<T>& b)
{ | 426 template <typename T> inline bool operator>=(std::nullptr_t, const sk_sp<T>& b)
{ |
425 return !(nullptr < b); | 427 return !(nullptr < b); |
426 } | 428 } |
427 | 429 |
428 template <typename T, typename... Args> | 430 template <typename T, typename... Args> |
429 sk_sp<T> sk_make_sp(Args&&... args) { | 431 sk_sp<T> sk_make_sp(Args&&... args) { |
430 return sk_sp<T>(new T(std::forward<Args>(args)...)); | 432 return sk_sp<T>(new T(std::forward<Args>(args)...)); |
431 } | 433 } |
432 | 434 |
| 435 #ifdef SK_SUPPORT_TRANSITION_TO_SP_INTERFACES |
| 436 |
| 437 /* |
| 438 * Returns a sk_sp wrapping the provided ptr AND calls ref on it (if not null). |
| 439 * |
| 440 * This is different than the semantics of the constructor for sk_sp, which jus
t wraps the ptr, |
| 441 * effectively "adopting" it. |
| 442 * |
| 443 * This function may be helpful while we convert callers from ptr-based to sk_s
p-based parameters. |
| 444 */ |
| 445 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { |
| 446 return sk_sp<T>(SkSafeRef(obj)); |
| 447 } |
| 448 |
433 #endif | 449 #endif |
| 450 |
| 451 #endif |
OLD | NEW |