| 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> | |
| 12 | 11 |
| 13 namespace blink { | 12 namespace blink { |
| 14 | 13 |
| 15 // Handles memory management of underlying InterpolationValues in applyStack() | 14 // Handles memory management of underlying InterpolationValues in applyStack() |
| 16 // Ensures we perform copy on write if we are not the owner of an underlying Int
erpolationValue. | 15 // Ensures we perform copy on write if we are not the owner of an underlying Int
erpolationValue. |
| 17 // This functions similar to a DataRef except on std::unique_ptr'd objects. | 16 // This functions similar to a DataRef except on OwnPtr'd objects. |
| 18 class UnderlyingValueOwner { | 17 class UnderlyingValueOwner { |
| 19 WTF_MAKE_NONCOPYABLE(UnderlyingValueOwner); | 18 WTF_MAKE_NONCOPYABLE(UnderlyingValueOwner); |
| 20 STACK_ALLOCATED(); | 19 STACK_ALLOCATED(); |
| 21 | 20 |
| 22 public: | 21 public: |
| 23 UnderlyingValueOwner() | 22 UnderlyingValueOwner() |
| 24 : m_type(nullptr) | 23 : m_type(nullptr) |
| 25 , m_valueOwner(nullptr) | 24 , m_valueOwner(nullptr) |
| 26 , m_value(nullptr) | 25 , m_value(nullptr) |
| 27 { } | 26 { } |
| 28 | 27 |
| 29 operator bool() const | 28 operator bool() const |
| 30 { | 29 { |
| 31 ASSERT(static_cast<bool>(m_type) == static_cast<bool>(m_value)); | 30 ASSERT(static_cast<bool>(m_type) == static_cast<bool>(m_value)); |
| 32 return m_type; | 31 return m_type; |
| 33 } | 32 } |
| 34 | 33 |
| 35 const InterpolationType& type() const | 34 const InterpolationType& type() const |
| 36 { | 35 { |
| 37 ASSERT(m_type); | 36 ASSERT(m_type); |
| 38 return *m_type; | 37 return *m_type; |
| 39 } | 38 } |
| 40 | 39 |
| 41 const InterpolationValue& value() const; | 40 const InterpolationValue& value() const; |
| 42 | 41 |
| 43 void set(std::nullptr_t); | 42 void set(std::nullptr_t); |
| 44 void set(const InterpolationType&, const InterpolationValue&); | 43 void set(const InterpolationType&, const InterpolationValue&); |
| 45 void set(const InterpolationType&, InterpolationValue&&); | 44 void set(const InterpolationType&, InterpolationValue&&); |
| 46 void set(std::unique_ptr<TypedInterpolationValue>); | 45 void set(PassOwnPtr<TypedInterpolationValue>); |
| 47 void set(const TypedInterpolationValue*); | 46 void set(const TypedInterpolationValue*); |
| 48 | 47 |
| 49 InterpolationValue& mutableValue(); | 48 InterpolationValue& mutableValue(); |
| 50 | 49 |
| 51 private: | 50 private: |
| 52 const InterpolationType* m_type; | 51 const InterpolationType* m_type; |
| 53 InterpolationValue m_valueOwner; | 52 InterpolationValue m_valueOwner; |
| 54 const InterpolationValue* m_value; | 53 const InterpolationValue* m_value; |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 } // namespace blink | 56 } // namespace blink |
| 58 | 57 |
| 59 #endif // UnderlyingValueOwner_h | 58 #endif // UnderlyingValueOwner_h |
| OLD | NEW |