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 { | |
15 if (start == end) | |
16 return true; | |
17 if (start->isNumber()) | |
18 return end->isNumber(); | |
19 if (start->isBool()) | |
20 return end->isBool(); | |
21 if (start->isAnimatableValue()) | |
22 return end->isAnimatableValue(); | |
23 if (!(start->isList() && end->isList())) | |
24 return false; | |
25 const InterpolableList* startList = toInterpolableList(start); | |
26 const InterpolableList* endList = toInterpolableList(end); | |
27 if (startList->length() != endList->length()) | |
28 return false; | |
29 for (size_t i = 0; i < startList->length(); ++i) { | |
30 if (!typesMatch(startList->get(i), endList->get(i))) | |
31 return false; | |
32 } | |
33 return true; | |
34 } | |
35 | |
36 } // namespace | |
37 | |
38 Interpolation::Interpolation(std::unique_ptr<InterpolableValue> start, std::uniq
ue_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 { | |
45 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); | |
46 } | |
47 | |
48 Interpolation::~Interpolation() | |
49 { | |
50 } | |
51 | |
52 void Interpolation::interpolate(int iteration, double fraction) | |
53 { | |
54 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { | |
55 m_start->interpolate(*m_end, fraction, *m_cachedValue); | |
56 m_cachedIteration = iteration; | |
57 m_cachedFraction = fraction; | |
58 } | |
59 } | |
60 | |
61 } // namespace blink | |
OLD | NEW |