OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef PrimitiveInterpolation_h | 5 #ifndef PrimitiveInterpolation_h |
6 #define PrimitiveInterpolation_h | 6 #define PrimitiveInterpolation_h |
7 | 7 |
8 #include "core/animation/AnimationValue.h" | 8 #include "core/animation/AnimationValue.h" |
9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 #include "wtf/Vector.h" | 10 #include "wtf/Vector.h" |
11 #include <cmath> | 11 #include <cmath> |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 class StyleResolverState; | 15 class StyleResolverState; |
16 | 16 |
17 // Represents a conversion from a pair of keyframes to something compatible with
interpolation. | 17 // Represents a conversion from a pair of keyframes to something compatible with
interpolation. |
18 // This is agnostic to whether the keyframes are compatible with each other or n
ot. | 18 // This is agnostic to whether the keyframes are compatible with each other or n
ot. |
19 class PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim
itiveInterpolation> { | 19 class PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim
itiveInterpolation> { |
20 public: | 20 public: |
21 virtual ~PrimitiveInterpolation() { } | 21 virtual ~PrimitiveInterpolation() { } |
22 | 22 |
23 virtual void interpolate(double fraction, OwnPtrWillBeRawPtr<AnimationValue>
& result) const = 0; | 23 virtual void interpolate(double fraction, OwnPtrWillBeMember<AnimationValue>
& result) const = 0; |
24 | 24 |
25 DEFINE_INLINE_VIRTUAL_TRACE() { } | 25 DEFINE_INLINE_VIRTUAL_TRACE() { } |
26 }; | 26 }; |
27 | 27 |
28 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". | 28 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". |
29 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { | 29 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { |
30 public: | 30 public: |
31 virtual ~PairwisePrimitiveInterpolation() { } | 31 virtual ~PairwisePrimitiveInterpolation() { } |
32 | 32 |
33 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(const A
nimationType& type, PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrW
illBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue>
nonInterpolableValue) | 33 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(const A
nimationType& type, PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrW
illBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue>
nonInterpolableValue) |
34 { | 34 { |
35 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(type, start
, end, nonInterpolableValue)); | 35 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(type, start
, end, nonInterpolableValue)); |
36 } | 36 } |
37 | 37 |
38 PassOwnPtrWillBeRawPtr<AnimationValue> initialValue() const | 38 PassOwnPtrWillBeRawPtr<AnimationValue> initialValue() const |
39 { | 39 { |
40 return AnimationValue::create(m_type, m_start->clone(), m_nonInterpolabl
eValue); | 40 return AnimationValue::create(m_type, m_start->clone(), m_nonInterpolabl
eValue); |
41 } | 41 } |
42 | 42 |
43 private: | |
44 virtual void interpolate(double fraction, OwnPtrWillBeRawPtr<AnimationValue>
& result) const override final | |
45 { | |
46 ASSERT(result); | |
47 ASSERT(&result->type() == &m_type); | |
48 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); | |
49 m_start->interpolate(*m_end, fraction, result->interpolableValue()); | |
50 } | |
51 | |
52 DEFINE_INLINE_VIRTUAL_TRACE() | 43 DEFINE_INLINE_VIRTUAL_TRACE() |
53 { | 44 { |
54 PrimitiveInterpolation::trace(visitor); | |
55 visitor->trace(m_start); | 45 visitor->trace(m_start); |
56 visitor->trace(m_end); | 46 visitor->trace(m_end); |
57 visitor->trace(m_nonInterpolableValue); | 47 visitor->trace(m_nonInterpolableValue); |
| 48 PrimitiveInterpolation::trace(visitor); |
58 } | 49 } |
59 | 50 |
| 51 private: |
60 PairwisePrimitiveInterpolation(const AnimationType& type, PassOwnPtrWillBeRa
wPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, Pa
ssRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) | 52 PairwisePrimitiveInterpolation(const AnimationType& type, PassOwnPtrWillBeRa
wPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, Pa
ssRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) |
61 : m_type(type) | 53 : m_type(type) |
62 , m_start(start) | 54 , m_start(start) |
63 , m_end(end) | 55 , m_end(end) |
64 , m_nonInterpolableValue(nonInterpolableValue) | 56 , m_nonInterpolableValue(nonInterpolableValue) |
65 { } | 57 { } |
66 | 58 |
| 59 virtual void interpolate(double fraction, OwnPtrWillBeMember<AnimationValue>
& result) const override final |
| 60 { |
| 61 ASSERT(result); |
| 62 ASSERT(&result->type() == &m_type); |
| 63 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); |
| 64 m_start->interpolate(*m_end, fraction, result->interpolableValue()); |
| 65 } |
| 66 |
67 const AnimationType& m_type; | 67 const AnimationType& m_type; |
68 OwnPtrWillBeMember<InterpolableValue> m_start; | 68 OwnPtrWillBeMember<InterpolableValue> m_start; |
69 OwnPtrWillBeMember<InterpolableValue> m_end; | 69 OwnPtrWillBeMember<InterpolableValue> m_end; |
70 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; | 70 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; |
71 }; | 71 }; |
72 | 72 |
73 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". | 73 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". |
74 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { | 74 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { |
75 public: | 75 public: |
76 virtual ~FlipPrimitiveInterpolation() { } | 76 virtual ~FlipPrimitiveInterpolation() { } |
77 | 77 |
78 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<AnimationValue> start, PassOwnPtrWillBeRawPtr<AnimationValue> end) | 78 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<AnimationValue> start, PassOwnPtrWillBeRawPtr<AnimationValue> end) |
79 { | 79 { |
80 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); | 80 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); |
81 } | 81 } |
82 | 82 |
83 private: | |
84 virtual void interpolate(double fraction, OwnPtrWillBeRawPtr<AnimationValue>
& result) const override final | |
85 { | |
86 // TODO(alancutter): Remove this optimisation once Oilpan is default. | |
87 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) | |
88 return; | |
89 result = ((fraction < 0.5) ? m_start : m_end)->clone(); | |
90 m_lastFraction = fraction; | |
91 } | |
92 | |
93 DEFINE_INLINE_VIRTUAL_TRACE() | 83 DEFINE_INLINE_VIRTUAL_TRACE() |
94 { | 84 { |
95 PrimitiveInterpolation::trace(visitor); | |
96 visitor->trace(m_start); | 85 visitor->trace(m_start); |
97 visitor->trace(m_end); | 86 visitor->trace(m_end); |
| 87 PrimitiveInterpolation::trace(visitor); |
98 } | 88 } |
99 | 89 |
| 90 private: |
100 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<AnimationValue> start, Pas
sOwnPtrWillBeRawPtr<AnimationValue> end) | 91 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<AnimationValue> start, Pas
sOwnPtrWillBeRawPtr<AnimationValue> end) |
101 : m_start(start) | 92 : m_start(start) |
102 , m_end(end) | 93 , m_end(end) |
103 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | 94 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
104 { | 95 { |
105 ASSERT(m_start); | 96 ASSERT(m_start); |
106 ASSERT(m_end); | 97 ASSERT(m_end); |
107 } | 98 } |
108 | 99 |
109 OwnPtrWillBeRawPtr<AnimationValue> m_start; | 100 virtual void interpolate(double fraction, OwnPtrWillBeMember<AnimationValue>
& result) const override final |
110 OwnPtrWillBeRawPtr<AnimationValue> m_end; | 101 { |
| 102 // TODO(alancutter): Remove this optimisation once Oilpan is default. |
| 103 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) |
| 104 return; |
| 105 result = ((fraction < 0.5) ? m_start : m_end)->clone(); |
| 106 m_lastFraction = fraction; |
| 107 } |
| 108 |
| 109 OwnPtrWillBeMember<AnimationValue> m_start; |
| 110 OwnPtrWillBeMember<AnimationValue> m_end; |
111 mutable double m_lastFraction; | 111 mutable double m_lastFraction; |
112 }; | 112 }; |
113 | 113 |
114 } // namespace blink | 114 } // namespace blink |
115 | 115 |
116 #endif // PrimitiveInterpolation_h | 116 #endif // PrimitiveInterpolation_h |
OLD | NEW |