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