OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UnderlyingValueOwner_h | 5 #ifndef UnderlyingValueOwner_h |
6 #define UnderlyingValueOwner_h | 6 #define UnderlyingValueOwner_h |
7 | 7 |
8 #include "core/animation/TypedInterpolationValue.h" | 8 #include "core/animation/TypedInterpolationValue.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
| 11 #include <memory> |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 // Handles memory management of underlying InterpolationValues in applyStack() | 15 // Handles memory management of underlying InterpolationValues in applyStack() |
15 // Ensures we perform copy on write if we are not the owner of an underlying Int
erpolationValue. | 16 // Ensures we perform copy on write if we are not the owner of an underlying Int
erpolationValue. |
16 // This functions similar to a DataRef except on OwnPtr'd objects. | 17 // This functions similar to a DataRef except on std::unique_ptr'd objects. |
17 class UnderlyingValueOwner { | 18 class UnderlyingValueOwner { |
18 WTF_MAKE_NONCOPYABLE(UnderlyingValueOwner); | 19 WTF_MAKE_NONCOPYABLE(UnderlyingValueOwner); |
19 STACK_ALLOCATED(); | 20 STACK_ALLOCATED(); |
20 | 21 |
21 public: | 22 public: |
22 UnderlyingValueOwner() | 23 UnderlyingValueOwner() |
23 : m_type(nullptr) | 24 : m_type(nullptr) |
24 , m_valueOwner(nullptr) | 25 , m_valueOwner(nullptr) |
25 , m_value(nullptr) | 26 , m_value(nullptr) |
26 { } | 27 { } |
27 | 28 |
28 operator bool() const | 29 operator bool() const |
29 { | 30 { |
30 ASSERT(static_cast<bool>(m_type) == static_cast<bool>(m_value)); | 31 ASSERT(static_cast<bool>(m_type) == static_cast<bool>(m_value)); |
31 return m_type; | 32 return m_type; |
32 } | 33 } |
33 | 34 |
34 const InterpolationType& type() const | 35 const InterpolationType& type() const |
35 { | 36 { |
36 ASSERT(m_type); | 37 ASSERT(m_type); |
37 return *m_type; | 38 return *m_type; |
38 } | 39 } |
39 | 40 |
40 const InterpolationValue& value() const; | 41 const InterpolationValue& value() const; |
41 | 42 |
42 void set(std::nullptr_t); | 43 void set(std::nullptr_t); |
43 void set(const InterpolationType&, const InterpolationValue&); | 44 void set(const InterpolationType&, const InterpolationValue&); |
44 void set(const InterpolationType&, InterpolationValue&&); | 45 void set(const InterpolationType&, InterpolationValue&&); |
45 void set(PassOwnPtr<TypedInterpolationValue>); | 46 void set(std::unique_ptr<TypedInterpolationValue>); |
46 void set(const TypedInterpolationValue*); | 47 void set(const TypedInterpolationValue*); |
47 | 48 |
48 InterpolationValue& mutableValue(); | 49 InterpolationValue& mutableValue(); |
49 | 50 |
50 private: | 51 private: |
51 const InterpolationType* m_type; | 52 const InterpolationType* m_type; |
52 InterpolationValue m_valueOwner; | 53 InterpolationValue m_valueOwner; |
53 const InterpolationValue* m_value; | 54 const InterpolationValue* m_value; |
54 }; | 55 }; |
55 | 56 |
56 } // namespace blink | 57 } // namespace blink |
57 | 58 |
58 #endif // UnderlyingValueOwner_h | 59 #endif // UnderlyingValueOwner_h |
OLD | NEW |