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/InterpolationValue.h" | 8 #include "core/animation/InterpolationValue.h" |
| 9 #include "platform/animation/AnimationUtilities.h" |
9 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
10 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
11 #include <cmath> | 12 #include <cmath> |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 class StyleResolverState; | 16 class StyleResolverState; |
16 | 17 |
17 // Represents a conversion from a pair of keyframes to something compatible with
interpolation. | 18 // 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. | 19 // This is agnostic to whether the keyframes are compatible with each other or n
ot. |
19 class PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim
itiveInterpolation> { | 20 class PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim
itiveInterpolation> { |
20 public: | 21 public: |
21 virtual ~PrimitiveInterpolation() { } | 22 virtual ~PrimitiveInterpolation() { } |
22 | 23 |
23 virtual void interpolate(double fraction, OwnPtrWillBeMember<InterpolationVa
lue>& result) const = 0; | 24 virtual void interpolateValue(double fraction, OwnPtrWillBeMember<Interpolat
ionValue>& result) const = 0; |
| 25 virtual double interpolateUnderlyingFraction(double start, double end, doubl
e fraction) const = 0; |
| 26 virtual bool isFlip() const { return false; } |
24 | 27 |
25 DEFINE_INLINE_VIRTUAL_TRACE() { } | 28 DEFINE_INLINE_VIRTUAL_TRACE() { } |
26 }; | 29 }; |
27 | 30 |
28 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". | 31 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". |
29 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { | 32 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { |
30 public: | 33 public: |
31 ~PairwisePrimitiveInterpolation() override { } | 34 ~PairwisePrimitiveInterpolation() override { } |
32 | 35 |
33 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(const I
nterpolationType& type, PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwn
PtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableVa
lue> nonInterpolableValue) | 36 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(const I
nterpolationType& type, PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwn
PtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableVa
lue> nonInterpolableValue) |
(...skipping 15 matching lines...) Expand all Loading... |
49 } | 52 } |
50 | 53 |
51 private: | 54 private: |
52 PairwisePrimitiveInterpolation(const InterpolationType& type, PassOwnPtrWill
BeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end
, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) | 55 PairwisePrimitiveInterpolation(const InterpolationType& type, PassOwnPtrWill
BeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end
, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) |
53 : m_type(type) | 56 : m_type(type) |
54 , m_start(start) | 57 , m_start(start) |
55 , m_end(end) | 58 , m_end(end) |
56 , m_nonInterpolableValue(nonInterpolableValue) | 59 , m_nonInterpolableValue(nonInterpolableValue) |
57 { } | 60 { } |
58 | 61 |
59 void interpolate(double fraction, OwnPtrWillBeMember<InterpolationValue>& re
sult) const final | 62 void interpolateValue(double fraction, OwnPtrWillBeMember<InterpolationValue
>& result) const final |
60 { | 63 { |
61 ASSERT(result); | 64 ASSERT(result); |
62 ASSERT(&result->type() == &m_type); | 65 ASSERT(&result->type() == &m_type); |
63 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); | 66 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); |
64 m_start->interpolate(*m_end, fraction, result->interpolableValue()); | 67 m_start->interpolate(*m_end, fraction, result->interpolableValue()); |
65 } | 68 } |
66 | 69 |
| 70 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return blend(start, end, fraction); } |
| 71 |
67 const InterpolationType& m_type; | 72 const InterpolationType& m_type; |
68 OwnPtrWillBeMember<InterpolableValue> m_start; | 73 OwnPtrWillBeMember<InterpolableValue> m_start; |
69 OwnPtrWillBeMember<InterpolableValue> m_end; | 74 OwnPtrWillBeMember<InterpolableValue> m_end; |
70 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; | 75 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; |
71 }; | 76 }; |
72 | 77 |
73 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". | 78 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". |
74 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { | 79 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { |
75 public: | 80 public: |
76 ~FlipPrimitiveInterpolation() override { } | 81 ~FlipPrimitiveInterpolation() override { } |
77 | 82 |
78 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<InterpolationValue> start, PassOwnPtrWillBeRawPtr<InterpolationValue
> end) | 83 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<InterpolationValue> start, PassOwnPtrWillBeRawPtr<InterpolationValue
> end) |
79 { | 84 { |
80 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); | 85 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); |
81 } | 86 } |
82 | 87 |
83 DEFINE_INLINE_VIRTUAL_TRACE() | 88 DEFINE_INLINE_VIRTUAL_TRACE() |
84 { | 89 { |
85 visitor->trace(m_start); | 90 visitor->trace(m_start); |
86 visitor->trace(m_end); | 91 visitor->trace(m_end); |
87 PrimitiveInterpolation::trace(visitor); | 92 PrimitiveInterpolation::trace(visitor); |
88 } | 93 } |
89 | 94 |
90 private: | 95 private: |
91 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<InterpolationValue> start,
PassOwnPtrWillBeRawPtr<InterpolationValue> end) | 96 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<InterpolationValue> start,
PassOwnPtrWillBeRawPtr<InterpolationValue> end) |
92 : m_start(start) | 97 : m_start(start) |
93 , m_end(end) | 98 , m_end(end) |
94 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | 99 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
95 { | 100 { } |
96 ASSERT(m_start); | |
97 ASSERT(m_end); | |
98 } | |
99 | 101 |
100 void interpolate(double fraction, OwnPtrWillBeMember<InterpolationValue>& re
sult) const final | 102 void interpolateValue(double fraction, OwnPtrWillBeMember<InterpolationValue
>& result) const final |
101 { | 103 { |
102 // TODO(alancutter): Remove this optimisation once Oilpan is default. | 104 // TODO(alancutter): Remove this optimisation once Oilpan is default. |
103 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) | 105 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) |
104 return; | 106 return; |
105 result = ((fraction < 0.5) ? m_start : m_end)->clone(); | 107 const InterpolationValue* side = ((fraction < 0.5) ? m_start : m_end).ge
t(); |
| 108 result = side ? side->clone() : nullptr; |
106 m_lastFraction = fraction; | 109 m_lastFraction = fraction; |
107 } | 110 } |
108 | 111 |
| 112 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return fraction < 0.5 ? start : end; } |
| 113 |
| 114 bool isFlip() const final { return true; } |
| 115 |
109 OwnPtrWillBeMember<InterpolationValue> m_start; | 116 OwnPtrWillBeMember<InterpolationValue> m_start; |
110 OwnPtrWillBeMember<InterpolationValue> m_end; | 117 OwnPtrWillBeMember<InterpolationValue> m_end; |
111 mutable double m_lastFraction; | 118 mutable double m_lastFraction; |
112 }; | 119 }; |
113 | 120 |
114 } // namespace blink | 121 } // namespace blink |
115 | 122 |
116 #endif // PrimitiveInterpolation_h | 123 #endif // PrimitiveInterpolation_h |
OLD | NEW |