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