OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UnderlyingValue_h |
| 6 #define UnderlyingValue_h |
| 7 |
| 8 #include "core/animation/InterpolationValue.h" |
| 9 #include "wtf/Allocator.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 // Handles memory management of underlying InterpolationValues in applyStack() |
| 14 // Ensures we perform copy on write if we are not the owner of an underlying Int
erpolationValue. |
| 15 // This functions similar to a DataRef except on OwnPtr'd objects. |
| 16 class UnderlyingValue { |
| 17 STACK_ALLOCATED(); |
| 18 |
| 19 public: |
| 20 UnderlyingValue() |
| 21 : m_valueOwner(nullptr) |
| 22 , m_value(nullptr) |
| 23 { } |
| 24 |
| 25 void set(const InterpolationValue* interpolationValue) |
| 26 { |
| 27 // By clearing m_valueOwner we will perform a copy before attempting to
mutate m_value, |
| 28 // thus upholding the const contract for this instance of interpolationV
alue despite the const_cast. |
| 29 m_valueOwner.clear(); |
| 30 m_value = const_cast<InterpolationValue*>(interpolationValue); |
| 31 } |
| 32 void set(PassOwnPtr<InterpolationValue> interpolationValue) |
| 33 { |
| 34 m_valueOwner = interpolationValue; |
| 35 m_value = m_valueOwner.get(); |
| 36 } |
| 37 InterpolationComponentValue& mutableComponent() |
| 38 { |
| 39 ASSERT(m_value); |
| 40 if (!m_valueOwner) |
| 41 set(m_value->clone()); |
| 42 return m_value->mutableComponent(); |
| 43 } |
| 44 const InterpolationValue* get() const { return m_value; } |
| 45 operator bool() const { return m_value; } |
| 46 const InterpolationValue* operator->() const |
| 47 { |
| 48 ASSERT(m_value); |
| 49 return m_value; |
| 50 } |
| 51 |
| 52 private: |
| 53 OwnPtr<InterpolationValue> m_valueOwner; |
| 54 InterpolationValue* m_value; |
| 55 }; |
| 56 |
| 57 } // namespace blink |
| 58 |
| 59 #endif // UnderlyingValue_h |
OLD | NEW |