| 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 "core/animation/Interpolation.h" | 5 #include "core/animation/Interpolation.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 9 namespace blink { | 7 namespace blink { |
| 10 | 8 |
| 11 namespace { | 9 namespace { |
| 12 | 10 |
| 13 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) | 11 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) |
| 14 { | 12 { |
| 15 if (start == end) | 13 if (start == end) |
| 16 return true; | 14 return true; |
| 17 if (start->isNumber()) | 15 if (start->isNumber()) |
| 18 return end->isNumber(); | 16 return end->isNumber(); |
| 19 if (start->isBool()) | 17 if (start->isBool()) |
| 20 return end->isBool(); | 18 return end->isBool(); |
| 21 if (start->isAnimatableValue()) | 19 if (start->isAnimatableValue()) |
| 22 return end->isAnimatableValue(); | 20 return end->isAnimatableValue(); |
| 23 if (!(start->isList() && end->isList())) | 21 if (!(start->isList() && end->isList())) |
| 24 return false; | 22 return false; |
| 25 const InterpolableList* startList = toInterpolableList(start); | 23 const InterpolableList* startList = toInterpolableList(start); |
| 26 const InterpolableList* endList = toInterpolableList(end); | 24 const InterpolableList* endList = toInterpolableList(end); |
| 27 if (startList->length() != endList->length()) | 25 if (startList->length() != endList->length()) |
| 28 return false; | 26 return false; |
| 29 for (size_t i = 0; i < startList->length(); ++i) { | 27 for (size_t i = 0; i < startList->length(); ++i) { |
| 30 if (!typesMatch(startList->get(i), endList->get(i))) | 28 if (!typesMatch(startList->get(i), endList->get(i))) |
| 31 return false; | 29 return false; |
| 32 } | 30 } |
| 33 return true; | 31 return true; |
| 34 } | 32 } |
| 35 | 33 |
| 36 } // namespace | 34 } // namespace |
| 37 | 35 |
| 38 Interpolation::Interpolation(std::unique_ptr<InterpolableValue> start, std::uniq
ue_ptr<InterpolableValue> end) | 36 Interpolation::Interpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<Int
erpolableValue> end) |
| 39 : m_start(std::move(start)) | 37 : m_start(std::move(start)) |
| 40 , m_end(std::move(end)) | 38 , m_end(std::move(end)) |
| 41 , m_cachedFraction(0) | 39 , m_cachedFraction(0) |
| 42 , m_cachedIteration(0) | 40 , m_cachedIteration(0) |
| 43 , m_cachedValue(m_start ? m_start->clone() : nullptr) | 41 , m_cachedValue(m_start ? m_start->clone() : nullptr) |
| 44 { | 42 { |
| 45 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); | 43 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); |
| 46 } | 44 } |
| 47 | 45 |
| 48 Interpolation::~Interpolation() | 46 Interpolation::~Interpolation() |
| 49 { | 47 { |
| 50 } | 48 } |
| 51 | 49 |
| 52 void Interpolation::interpolate(int iteration, double fraction) | 50 void Interpolation::interpolate(int iteration, double fraction) |
| 53 { | 51 { |
| 54 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { | 52 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { |
| 55 m_start->interpolate(*m_end, fraction, *m_cachedValue); | 53 m_start->interpolate(*m_end, fraction, *m_cachedValue); |
| 56 m_cachedIteration = iteration; | 54 m_cachedIteration = iteration; |
| 57 m_cachedFraction = fraction; | 55 m_cachedFraction = fraction; |
| 58 } | 56 } |
| 59 } | 57 } |
| 60 | 58 |
| 61 } // namespace blink | 59 } // namespace blink |
| OLD | NEW |