| 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 namespace blink { | 8 namespace blink { |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) | 12 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) |
| 13 { | 13 { |
| 14 if (start == end) |
| 15 return true; |
| 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(); |
| 18 if (start->isAnimatableValue()) | 20 if (start->isAnimatableValue()) |
| 19 return end->isAnimatableValue(); | 21 return end->isAnimatableValue(); |
| 20 if (!(start->isList() && end->isList())) | 22 if (!(start->isList() && end->isList())) |
| 21 return false; | 23 return false; |
| 22 const InterpolableList* startList = toInterpolableList(start); | 24 const InterpolableList* startList = toInterpolableList(start); |
| 23 const InterpolableList* endList = toInterpolableList(end); | 25 const InterpolableList* endList = toInterpolableList(end); |
| 24 if (startList->length() != endList->length()) | 26 if (startList->length() != endList->length()) |
| 25 return false; | 27 return false; |
| 26 for (size_t i = 0; i < startList->length(); ++i) { | 28 for (size_t i = 0; i < startList->length(); ++i) { |
| 27 if (!typesMatch(startList->get(i), endList->get(i))) | 29 if (!typesMatch(startList->get(i), endList->get(i))) |
| 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) |
| 38 , m_cachedFraction(0) | 40 , m_cachedFraction(0) |
| 39 , m_cachedIteration(0) | 41 , m_cachedIteration(0) |
| 40 , m_cachedValue(m_start->clone()) | 42 , m_cachedValue(m_start ? m_start->clone() : nullptr) |
| 41 { | 43 { |
| 42 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); | 44 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); |
| 43 } | 45 } |
| 44 | 46 |
| 45 Interpolation::~Interpolation() | 47 Interpolation::~Interpolation() |
| 46 { | 48 { |
| 47 } | 49 } |
| 48 | 50 |
| 49 void Interpolation::interpolate(int iteration, double fraction) const | 51 void Interpolation::interpolate(int iteration, double fraction) |
| 50 { | 52 { |
| 51 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { | 53 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { |
| 52 m_start->interpolate(*m_end, fraction, *m_cachedValue); | 54 m_start->interpolate(*m_end, fraction, *m_cachedValue); |
| 53 m_cachedIteration = iteration; | 55 m_cachedIteration = iteration; |
| 54 m_cachedFraction = fraction; | 56 m_cachedFraction = fraction; |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 DEFINE_TRACE(Interpolation) | 60 DEFINE_TRACE(Interpolation) |
| 59 { | 61 { |
| 60 visitor->trace(m_start); | 62 visitor->trace(m_start); |
| 61 visitor->trace(m_end); | 63 visitor->trace(m_end); |
| 62 visitor->trace(m_cachedValue); | 64 visitor->trace(m_cachedValue); |
| 63 } | 65 } |
| 64 | 66 |
| 65 } | 67 } |
| OLD | NEW |