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 #include "platform/animation/AnimationUtilities.h" | |
9 | |
8 namespace blink { | 10 namespace blink { |
9 | 11 |
10 namespace { | 12 namespace { |
11 | 13 |
12 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) | 14 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end) |
13 { | 15 { |
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(); |
(...skipping 10 matching lines...) Expand all Loading... | |
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) |
40 , m_compositeStart(AnimationEffect::CompositeReplace) | |
41 , m_compositeEnd(AnimationEffect::CompositeReplace) | |
38 , m_cachedFraction(0) | 42 , m_cachedFraction(0) |
39 , m_cachedIteration(0) | 43 , m_cachedIteration(0) |
40 , m_cachedValue(m_start->clone()) | 44 , m_cachedValue(m_start->clone()) |
45 , m_cachedUnderlyingFraction(0) | |
41 { | 46 { |
42 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); | 47 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); |
43 } | 48 } |
44 | 49 |
45 Interpolation::~Interpolation() | 50 Interpolation::~Interpolation() |
46 { | 51 { |
47 } | 52 } |
48 | 53 |
54 Interpolation::Interpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> start, Pa ssOwnPtrWillBeRawPtr<InterpolableValue> end, | |
55 AnimationEffect::CompositeOperation compositeStart, AnimationEffect::Composi teOperation compositeEnd) | |
56 : m_start(start) | |
57 , m_end(end) | |
58 , m_compositeStart(compositeStart) | |
59 , m_compositeEnd(compositeEnd) | |
60 , m_cachedFraction(0) | |
61 , m_cachedIteration(0) | |
62 , m_cachedValue(m_start->clone()) | |
63 , m_cachedUnderlyingFraction(0) | |
64 { | |
65 RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get())); | |
66 | |
67 if (m_compositeStart == m_compositeEnd) { | |
68 if (m_compositeStart == AnimationEffect::CompositeReplace) | |
69 m_cachedUnderlyingFraction = 0; | |
70 else if (m_compositeStart == AnimationEffect::CompositeAdd) | |
71 m_cachedUnderlyingFraction = 1; | |
72 } | |
alancutter (OOO until 2018)
2015/02/12 05:55:45
Shouldn't this just be "if start == add: UF = 1"?
| |
73 } | |
74 | |
49 void Interpolation::interpolate(int iteration, double fraction) const | 75 void Interpolation::interpolate(int iteration, double fraction) const |
50 { | 76 { |
51 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { | 77 if (m_cachedFraction != fraction || m_cachedIteration != iteration) { |
52 m_start->interpolate(*m_end, fraction, *m_cachedValue); | 78 m_start->interpolate(*m_end, fraction, *m_cachedValue); |
53 m_cachedIteration = iteration; | 79 m_cachedIteration = iteration; |
54 m_cachedFraction = fraction; | 80 m_cachedFraction = fraction; |
81 | |
82 if (m_compositeStart == AnimationEffect::CompositeReplace && m_composite End == AnimationEffect::CompositeReplace) | |
83 m_cachedUnderlyingFraction = 0; | |
84 else if (m_compositeStart == AnimationEffect::CompositeAdd && m_composit eEnd == AnimationEffect::CompositeAdd) | |
85 m_cachedUnderlyingFraction = 1; | |
86 else if (m_compositeStart == AnimationEffect::CompositeAdd && m_composit eEnd == AnimationEffect::CompositeReplace) | |
87 m_cachedUnderlyingFraction = blend(1.0, 0.0, fraction); | |
alancutter (OOO until 2018)
2015/02/12 05:55:45
Just use 1 - fraction.
| |
88 else if (m_compositeStart == AnimationEffect::CompositeReplace && m_comp ositeEnd == AnimationEffect::CompositeAdd) | |
89 m_cachedUnderlyingFraction = blend(0.0, 1.0, fraction); | |
alancutter (OOO until 2018)
2015/02/12 05:55:45
Just use fraction.
| |
55 } | 90 } |
56 } | 91 } |
57 | 92 |
58 void Interpolation::trace(Visitor* visitor) | 93 void Interpolation::trace(Visitor* visitor) |
59 { | 94 { |
60 visitor->trace(m_start); | 95 visitor->trace(m_start); |
61 visitor->trace(m_end); | 96 visitor->trace(m_end); |
62 visitor->trace(m_cachedValue); | 97 visitor->trace(m_cachedValue); |
63 } | 98 } |
64 | 99 |
65 } | 100 } |
OLD | NEW |