Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Unified Diff: include/core/SkRefCnt.h

Issue 1773943004: Add sk_ref_sp helper function. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/RefCntTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkRefCnt.h
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index c3f724fa8ded11926e8f94e16d9e6e8e174d8cae..f159e3b1b705cb70aa63bb540d448241701c0c06 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
« no previous file with comments | « no previous file | tests/RefCntTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698