aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkRefCnt.h
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-03-08 12:54:48 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-08 12:54:48 -0800
commit647cc8474828202c98d540f799742e3074a2aace (patch)
tree927cedce7eab0ee033068777652ccf30b8b62c76 /include/core/SkRefCnt.h
parent9904c9212074279380e21f96575078734dbbd308 (diff)
Add sk_ref_sp helper function.
Diffstat (limited to 'include/core/SkRefCnt.h')
-rw-r--r--include/core/SkRefCnt.h18
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