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 <utility> |
14 | 15 |
15 /** \class SkRefCntBase | 16 /** \class SkRefCntBase |
16 | 17 |
17 SkRefCntBase is the base class for objects that may be shared by multiple | 18 SkRefCntBase is the base class for objects that may be shared by multiple |
18 objects. When an existing owner wants to share a reference, it calls ref(). | 19 objects. When an existing owner wants to share a reference, it calls ref(). |
19 When an owner wants to release its reference, it calls unref(). When the | 20 When an owner wants to release its reference, it calls unref(). When the |
20 shared object's reference count goes to zero as the result of an unref() | 21 shared object's reference count goes to zero as the result of an unref() |
21 call, its (virtual) destructor is called. It is an error for the | 22 call, its (virtual) destructor is called. It is an error for the |
22 destructor to be called explicitly (or via the object going out of scope on | 23 destructor to be called explicitly (or via the object going out of scope on |
23 the stack or calling delete) if getRefCnt() > 1. | 24 the stack or calling delete) if getRefCnt() > 1. |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 T* SK_WARN_UNUSED_RESULT release() { | 320 T* SK_WARN_UNUSED_RESULT release() { |
320 T* ptr = fPtr; | 321 T* ptr = fPtr; |
321 fPtr = nullptr; | 322 fPtr = nullptr; |
322 return ptr; | 323 return ptr; |
323 } | 324 } |
324 | 325 |
325 private: | 326 private: |
326 T* fPtr; | 327 T* fPtr; |
327 }; | 328 }; |
328 | 329 |
| 330 template <typename T, typename... Args> |
| 331 sk_sp<T> sk_make_sp(Args&&... args) { |
| 332 return sk_sp<T>(new T(std::forward<Args>(args)...)); |
| 333 } |
| 334 |
329 #endif | 335 #endif |
OLD | NEW |