Chromium Code Reviews| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 * This can be used for classes inheriting from SkRefCnt, but it also works for other | 257 * This can be used for classes inheriting from SkRefCnt, but it also works for other |
| 258 * classes that match the interface, but have different internal choices: e.g. the hosted class | 258 * classes that match the interface, but have different internal choices: e.g. the hosted class |
| 259 * may have its ref/unref be thread-safe, but that is not assumed/imposed by sk _sp. | 259 * may have its ref/unref be thread-safe, but that is not assumed/imposed by sk _sp. |
| 260 */ | 260 */ |
| 261 template <typename T> class sk_sp { | 261 template <typename T> class sk_sp { |
| 262 /** Supports safe bool idiom. Obsolete with explicit operator bool. */ | 262 /** Supports safe bool idiom. Obsolete with explicit operator bool. */ |
| 263 using unspecified_bool_type = T* sk_sp::*; | 263 using unspecified_bool_type = T* sk_sp::*; |
| 264 public: | 264 public: |
| 265 using element_type = T; | 265 using element_type = T; |
| 266 | 266 |
| 267 sk_sp() : fPtr(nullptr) {} | 267 constexpr sk_sp() : fPtr(nullptr) {} |
| 268 sk_sp(std::nullptr_t) : fPtr(nullptr) {} | 268 constexpr sk_sp(std::nullptr_t) : fPtr(nullptr) {} |
|
bungeman-skia
2016/06/08 18:22:16
This allows sk_sp<T>() to be a compile time static
bsalomon
2016/06/08 19:50:50
w00t
| |
| 269 | 269 |
| 270 /** | 270 /** |
| 271 * Shares the underlying object by calling ref(), so that both the argument and the newly | 271 * Shares the underlying object by calling ref(), so that both the argument and the newly |
| 272 * created sk_sp both have a reference to it. | 272 * created sk_sp both have a reference to it. |
| 273 */ | 273 */ |
| 274 sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {} | 274 sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {} |
| 275 template <typename U, typename = skstd::enable_if_t<std::is_convertible<U*, T*>::value>> | 275 template <typename U, typename = skstd::enable_if_t<std::is_convertible<U*, T*>::value>> |
| 276 sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {} | 276 sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {} |
| 277 | 277 |
| 278 /** | 278 /** |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 * | 460 * |
| 461 * This function may be helpful while we convert callers from ptr-based to sk_s p-based parameters. | 461 * This function may be helpful while we convert callers from ptr-based to sk_s p-based parameters. |
| 462 */ | 462 */ |
| 463 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { | 463 template <typename T> sk_sp<T> sk_ref_sp(T* obj) { |
| 464 return sk_sp<T>(SkSafeRef(obj)); | 464 return sk_sp<T>(SkSafeRef(obj)); |
| 465 } | 465 } |
| 466 | 466 |
| 467 #endif | 467 #endif |
| 468 | 468 |
| 469 #endif | 469 #endif |
| OLD | NEW |