diff options
author | 2016-03-08 12:54:48 -0800 | |
---|---|---|
committer | 2016-03-08 12:54:48 -0800 | |
commit | 647cc8474828202c98d540f799742e3074a2aace (patch) | |
tree | 927cedce7eab0ee033068777652ccf30b8b62c76 /include/core/SkRefCnt.h | |
parent | 9904c9212074279380e21f96575078734dbbd308 (diff) |
Add sk_ref_sp helper function.
Review URL: https://codereview.chromium.org/1773943004
Diffstat (limited to 'include/core/SkRefCnt.h')
-rw-r--r-- | include/core/SkRefCnt.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index c3f724fa8d..f159e3b1b7 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -14,6 +14,8 @@ #include <functional> #include <utility> +#define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES + /** \class SkRefCntBase SkRefCntBase is the base class for objects that may be shared by multiple @@ -430,4 +432,20 @@ sk_sp<T> sk_make_sp(Args&&... args) { return sk_sp<T>(new T(std::forward<Args>(args)...)); } +#ifdef SK_SUPPORT_TRANSITION_TO_SP_INTERFACES + +/* + * Returns a sk_sp wrapping the provided ptr AND calls ref on it (if not null). + * + * This is different than the semantics of the constructor for sk_sp, which just wraps the ptr, + * effectively "adopting" it. + * + * This function may be helpful while we convert callers from ptr-based to sk_sp-based parameters. + */ +template <typename T> sk_sp<T> sk_ref_sp(T* obj) { + return sk_sp<T>(SkSafeRef(obj)); +} + +#endif + #endif |