| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/Interpolation.h" | 6 #include "core/animation/Interpolation.h" |
| 7 | 7 |
| 8 #include "platform/animation/AnimationUtilities.h" |
| 9 |
| 8 namespace blink { | 10 namespace blink { |
| 9 | 11 |
| 10 namespace { | 12 namespace { |
| 11 | 13 |
| 12 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) | 14 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) |
| 13 { | 15 { |
| 14 if (start->isNumber()) | 16 if (start->isNumber()) |
| 15 return end->isNumber(); | 17 return end->isNumber(); |
| 16 if (start->isBool()) | 18 if (start->isBool()) |
| 17 return end->isBool(); | 19 return end->isBool(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 28 return false; | 30 return false; |
| 29 } | 31 } |
| 30 return true; | 32 return true; |
| 31 } | 33 } |
| 32 | 34 |
| 33 } | 35 } |
| 34 | 36 |
| 35 Interpolation::Interpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> start, Pa
ssOwnPtrWillBeRawPtr<InterpolableValue> end) | 37 Interpolation::Interpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> start, Pa
ssOwnPtrWillBeRawPtr<InterpolableValue> end) |
| 36 : m_start(start) | 38 : m_start(start) |
| 37 , m_end(end) | 39 , m_end(end) |
| 40 , m_compositeStart(AnimationEffect::CompositeReplace) |
| 41 , m_compositeEnd(AnimationEffect::CompositeReplace) |
| 38 , m_cachedFraction(0) | 42 , m_cachedFraction(0) |
| 39 , m_cachedIteration(0) | 43 , m_cachedIteration(0) |
| 40 , m_cachedValue(m_start->clone()) | 44 , m_cachedValue(m_start->clone()) |
| 45 , m_cachedUnderlyingFraction(0) |
| 41 { | 46 { |
| 42 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); | 47 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); |
| 43 } | 48 } |
| 44 | 49 |
| 45 Interpolation::~Interpolation() | 50 Interpolation::~Interpolation() |
| 46 { | 51 { |
| 47 } | 52 } |
| 48 | 53 |
| 54 Interpolation::Interpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> start, Pa
ssOwnPtrWillBeRawPtr<InterpolableValue> end, |
| 55 AnimationEffect::CompositeOperation compositeStart, AnimationEffect::Composi
teOperation compositeEnd) |
| 56 : m_start(start) |
| 57 , m_end(end) |
| 58 , m_compositeStart(compositeStart) |
| 59 , m_compositeEnd(compositeEnd) |
| 60 , m_cachedFraction(0) |
| 61 , m_cachedIteration(0) |
| 62 , m_cachedValue(m_start->clone()) |
| 63 , m_cachedUnderlyingFraction(0) |
| 64 { |
| 65 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); |
| 66 |
| 67 if (m_compositeStart == AnimationEffect::CompositeAdd) |
| 68 m_cachedUnderlyingFraction = 1; |
| 69 } |
| 70 |
| 49 void Interpolation::interpolate(int iteration, double fraction) const | 71 void Interpolation::interpolate(int iteration, double fraction) const |
| 50 { | 72 { |
| 51 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { | 73 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { |
| 52 m_start->interpolate(*m_end, fraction, *m_cachedValue); | 74 m_start->interpolate(*m_end, fraction, *m_cachedValue); |
| 53 m_cachedIteration = iteration; | 75 m_cachedIteration = iteration; |
| 54 m_cachedFraction = fraction; | 76 m_cachedFraction = fraction; |
| 77 |
| 78 if (m_compositeStart == AnimationEffect::CompositeReplace && m_composite
End == AnimationEffect::CompositeReplace) |
| 79 m_cachedUnderlyingFraction = 0; |
| 80 else if (m_compositeStart == AnimationEffect::CompositeAdd && m_composit
eEnd == AnimationEffect::CompositeAdd) |
| 81 m_cachedUnderlyingFraction = 1; |
| 82 else if (m_compositeStart == AnimationEffect::CompositeAdd && m_composit
eEnd == AnimationEffect::CompositeReplace) |
| 83 m_cachedUnderlyingFraction = 1 - fraction; |
| 84 else if (m_compositeStart == AnimationEffect::CompositeReplace && m_comp
ositeEnd == AnimationEffect::CompositeAdd) |
| 85 m_cachedUnderlyingFraction = fraction; |
| 55 } | 86 } |
| 56 } | 87 } |
| 57 | 88 |
| 58 void Interpolation::trace(Visitor* visitor) | 89 void Interpolation::trace(Visitor* visitor) |
| 59 { | 90 { |
| 60 visitor->trace(m_start); | 91 visitor->trace(m_start); |
| 61 visitor->trace(m_end); | 92 visitor->trace(m_end); |
| 62 visitor->trace(m_cachedValue); | 93 visitor->trace(m_cachedValue); |
| 63 } | 94 } |
| 64 | 95 |
| 65 } | 96 } |
| OLD | NEW |