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/animation/AnimationUtilities.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
12 #include <cmath> | 12 #include <cmath> |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class StyleResolverState; | 16 class StyleResolverState; |
17 | 17 |
18 // 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. |
19 // 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. |
20 class PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim
itiveInterpolation> { | 20 class PrimitiveInterpolation : public GarbageCollectedFinalized<PrimitiveInterpo
lation> { |
21 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(PrimitiveInterpolation); | |
22 WTF_MAKE_NONCOPYABLE(PrimitiveInterpolation); | 21 WTF_MAKE_NONCOPYABLE(PrimitiveInterpolation); |
23 public: | 22 public: |
24 virtual ~PrimitiveInterpolation() { } | 23 virtual ~PrimitiveInterpolation() { } |
25 | 24 |
26 virtual void interpolateValue(double fraction, OwnPtrWillBeMember<Interpolat
ionValue>& result) const = 0; | 25 virtual void interpolateValue(double fraction, Member<InterpolationValue>& r
esult) const = 0; |
27 virtual double interpolateUnderlyingFraction(double start, double end, doubl
e fraction) const = 0; | 26 virtual double interpolateUnderlyingFraction(double start, double end, doubl
e fraction) const = 0; |
28 virtual bool isFlip() const { return false; } | 27 virtual bool isFlip() const { return false; } |
29 | 28 |
30 DEFINE_INLINE_VIRTUAL_TRACE() { } | 29 DEFINE_INLINE_VIRTUAL_TRACE() { } |
31 | 30 |
32 protected: | 31 protected: |
33 PrimitiveInterpolation() { } | 32 PrimitiveInterpolation() { } |
34 }; | 33 }; |
35 | 34 |
36 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". | 35 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". |
37 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { | 36 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { |
38 public: | 37 public: |
39 ~PairwisePrimitiveInterpolation() override { } | 38 ~PairwisePrimitiveInterpolation() override { } |
40 | 39 |
41 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(const I
nterpolationType& type, PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwn
PtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableVa
lue> nonInterpolableValue) | 40 static PairwisePrimitiveInterpolation* create(const InterpolationType& type,
InterpolableValue* start, InterpolableValue* end, NonInterpolableValue* nonInte
rpolableValue) |
42 { | 41 { |
43 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(type, start
, end, nonInterpolableValue)); | 42 return new PairwisePrimitiveInterpolation(type, start, end, nonInterpola
bleValue); |
44 } | 43 } |
45 | 44 |
46 PassOwnPtrWillBeRawPtr<InterpolationValue> initialValue() const | 45 InterpolationValue* initialValue() const |
47 { | 46 { |
48 return InterpolationValue::create(m_type, m_start->clone(), m_nonInterpo
lableValue); | 47 return InterpolationValue::create(m_type, m_start->clone(), m_nonInterpo
lableValue); |
49 } | 48 } |
50 | 49 |
51 DEFINE_INLINE_VIRTUAL_TRACE() | 50 DEFINE_INLINE_VIRTUAL_TRACE() |
52 { | 51 { |
53 visitor->trace(m_start); | 52 visitor->trace(m_start); |
54 visitor->trace(m_end); | 53 visitor->trace(m_end); |
55 visitor->trace(m_nonInterpolableValue); | 54 visitor->trace(m_nonInterpolableValue); |
56 PrimitiveInterpolation::trace(visitor); | 55 PrimitiveInterpolation::trace(visitor); |
57 } | 56 } |
58 | 57 |
59 private: | 58 private: |
60 PairwisePrimitiveInterpolation(const InterpolationType& type, PassOwnPtrWill
BeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end
, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) | 59 PairwisePrimitiveInterpolation(const InterpolationType& type, InterpolableVa
lue* start, InterpolableValue* end, NonInterpolableValue* nonInterpolableValue) |
61 : m_type(type) | 60 : m_type(type) |
62 , m_start(start) | 61 , m_start(start) |
63 , m_end(end) | 62 , m_end(end) |
64 , m_nonInterpolableValue(nonInterpolableValue) | 63 , m_nonInterpolableValue(nonInterpolableValue) |
65 { } | 64 { } |
66 | 65 |
67 void interpolateValue(double fraction, OwnPtrWillBeMember<InterpolationValue
>& result) const final | 66 void interpolateValue(double fraction, Member<InterpolationValue>& result) c
onst final |
68 { | 67 { |
69 ASSERT(result); | 68 ASSERT(result); |
70 ASSERT(&result->type() == &m_type); | 69 ASSERT(&result->type() == &m_type); |
71 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); | 70 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); |
72 m_start->interpolate(*m_end, fraction, result->interpolableValue()); | 71 m_start->interpolate(*m_end, fraction, result->interpolableValue()); |
73 } | 72 } |
74 | 73 |
75 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return blend(start, end, fraction); } | 74 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return blend(start, end, fraction); } |
76 | 75 |
77 const InterpolationType& m_type; | 76 const InterpolationType& m_type; |
78 OwnPtrWillBeMember<InterpolableValue> m_start; | 77 Member<InterpolableValue> m_start; |
79 OwnPtrWillBeMember<InterpolableValue> m_end; | 78 Member<InterpolableValue> m_end; |
80 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; | 79 Member<NonInterpolableValue> m_nonInterpolableValue; |
81 }; | 80 }; |
82 | 81 |
83 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". | 82 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". |
84 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { | 83 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { |
85 public: | 84 public: |
86 ~FlipPrimitiveInterpolation() override { } | 85 ~FlipPrimitiveInterpolation() override { } |
87 | 86 |
88 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<InterpolationValue> start, PassOwnPtrWillBeRawPtr<InterpolationValue
> end) | 87 static FlipPrimitiveInterpolation* create(InterpolationValue* start, Interpo
lationValue* end) |
89 { | 88 { |
90 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); | 89 return new FlipPrimitiveInterpolation(start, end); |
91 } | 90 } |
92 | 91 |
93 DEFINE_INLINE_VIRTUAL_TRACE() | 92 DEFINE_INLINE_VIRTUAL_TRACE() |
94 { | 93 { |
95 visitor->trace(m_start); | 94 visitor->trace(m_start); |
96 visitor->trace(m_end); | 95 visitor->trace(m_end); |
97 PrimitiveInterpolation::trace(visitor); | 96 PrimitiveInterpolation::trace(visitor); |
98 } | 97 } |
99 | 98 |
100 private: | 99 private: |
101 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<InterpolationValue> start,
PassOwnPtrWillBeRawPtr<InterpolationValue> end) | 100 FlipPrimitiveInterpolation(InterpolationValue* start, InterpolationValue* en
d) |
102 : m_start(start) | 101 : m_start(start) |
103 , m_end(end) | 102 , m_end(end) |
104 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | 103 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
105 { } | 104 { } |
106 | 105 |
107 void interpolateValue(double fraction, OwnPtrWillBeMember<InterpolationValue
>& result) const final | 106 void interpolateValue(double fraction, Member<InterpolationValue>& result) c
onst final |
108 { | 107 { |
109 // TODO(alancutter): Remove this optimisation once Oilpan is default. | 108 // TODO(alancutter): Remove this optimisation once Oilpan is default. |
110 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) | 109 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) |
111 return; | 110 return; |
112 const InterpolationValue* side = ((fraction < 0.5) ? m_start : m_end).ge
t(); | 111 const InterpolationValue* side = ((fraction < 0.5) ? m_start : m_end).ge
t(); |
113 result = side ? side->clone() : nullptr; | 112 result = side ? side->clone() : nullptr; |
114 m_lastFraction = fraction; | 113 m_lastFraction = fraction; |
115 } | 114 } |
116 | 115 |
117 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return fraction < 0.5 ? start : end; } | 116 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return fraction < 0.5 ? start : end; } |
118 | 117 |
119 bool isFlip() const final { return true; } | 118 bool isFlip() const final { return true; } |
120 | 119 |
121 OwnPtrWillBeMember<InterpolationValue> m_start; | 120 Member<InterpolationValue> m_start; |
122 OwnPtrWillBeMember<InterpolationValue> m_end; | 121 Member<InterpolationValue> m_end; |
123 mutable double m_lastFraction; | 122 mutable double m_lastFraction; |
124 }; | 123 }; |
125 | 124 |
126 } // namespace blink | 125 } // namespace blink |
127 | 126 |
128 #endif // PrimitiveInterpolation_h | 127 #endif // PrimitiveInterpolation_h |
OLD | NEW |