| 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, AnimationValue& result) const = 0; | 23 virtual void interpolate(double fraction, OwnPtrWillBeRawPtr<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(PassOwn
PtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableVal
ue> 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(start, end,
nonInterpolableValue)); | 35 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(type, start
, end, nonInterpolableValue)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void initializeAnimationValue(AnimationValue& value) | 38 PassOwnPtrWillBeRawPtr<AnimationValue> initialValue() const |
| 39 { | 39 { |
| 40 value.interpolableValue = m_start->clone(); | 40 return AnimationValue::create(m_type, m_start->clone(), m_nonInterpolabl
eValue); |
| 41 value.nonInterpolableValue = m_nonInterpolableValue; | |
| 42 } | 41 } |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 virtual void interpolate(double fraction, AnimationValue& result) const over
ride final | 44 virtual void interpolate(double fraction, OwnPtrWillBeRawPtr<AnimationValue>
& result) const override final |
| 46 { | 45 { |
| 47 ASSERT(result.nonInterpolableValue == m_nonInterpolableValue); | 46 ASSERT(result); |
| 48 m_start->interpolate(*m_end, fraction, *result.interpolableValue); | 47 ASSERT(&result->type() == &m_type); |
| 48 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); |
| 49 m_start->interpolate(*m_end, fraction, result->interpolableValue()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 DEFINE_INLINE_VIRTUAL_TRACE() | 52 DEFINE_INLINE_VIRTUAL_TRACE() |
| 52 { | 53 { |
| 53 PrimitiveInterpolation::trace(visitor); | 54 PrimitiveInterpolation::trace(visitor); |
| 54 visitor->trace(m_start); | 55 visitor->trace(m_start); |
| 55 visitor->trace(m_end); | 56 visitor->trace(m_end); |
| 56 visitor->trace(m_nonInterpolableValue); | 57 visitor->trace(m_nonInterpolableValue); |
| 57 } | 58 } |
| 58 | 59 |
| 59 PairwisePrimitiveInterpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> sta
rt, PassOwnPtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInt
erpolableValue> nonInterpolableValue) | 60 PairwisePrimitiveInterpolation(const AnimationType& type, PassOwnPtrWillBeRa
wPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, Pa
ssRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) |
| 60 : m_start(start) | 61 : m_type(type) |
| 62 , m_start(start) |
| 61 , m_end(end) | 63 , m_end(end) |
| 62 , m_nonInterpolableValue(nonInterpolableValue) | 64 , m_nonInterpolableValue(nonInterpolableValue) |
| 63 { } | 65 { } |
| 66 |
| 67 const AnimationType& m_type; |
| 64 OwnPtrWillBeMember<InterpolableValue> m_start; | 68 OwnPtrWillBeMember<InterpolableValue> m_start; |
| 65 OwnPtrWillBeMember<InterpolableValue> m_end; | 69 OwnPtrWillBeMember<InterpolableValue> m_end; |
| 66 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; | 70 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; |
| 67 }; | 71 }; |
| 68 | 72 |
| 69 // 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". |
| 70 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { | 74 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { |
| 71 public: | 75 public: |
| 72 struct Side : public NoBaseWillBeGarbageCollectedFinalized<Side> { | |
| 73 const AnimationType& type; | |
| 74 OwnPtrWillBeMember<InterpolableValue> interpolableValue; | |
| 75 RefPtrWillBeMember<NonInterpolableValue> nonInterpolableValue; | |
| 76 | |
| 77 static PassOwnPtrWillBeRawPtr<Side> create(const AnimationType& type) {
return adoptPtrWillBeNoop(new Side(type)); } | |
| 78 | |
| 79 DEFINE_INLINE_TRACE() | |
| 80 { | |
| 81 visitor->trace(interpolableValue); | |
| 82 visitor->trace(nonInterpolableValue); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 Side(const AnimationType& type) | |
| 87 : type(type) | |
| 88 { } | |
| 89 }; | |
| 90 | |
| 91 virtual ~FlipPrimitiveInterpolation() { } | 76 virtual ~FlipPrimitiveInterpolation() { } |
| 92 | 77 |
| 93 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<Side> start, PassOwnPtrWillBeRawPtr<Side> end) | 78 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<AnimationValue> start, PassOwnPtrWillBeRawPtr<AnimationValue> end) |
| 94 { | 79 { |
| 95 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); | 80 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); |
| 96 } | 81 } |
| 97 | 82 |
| 98 private: | 83 private: |
| 99 virtual void interpolate(double fraction, AnimationValue& result) const over
ride final | 84 virtual void interpolate(double fraction, OwnPtrWillBeRawPtr<AnimationValue>
& result) const override final |
| 100 { | 85 { |
| 101 // TODO(alancutter): Remove this optimisation once Oilpan is default. | 86 // TODO(alancutter): Remove this optimisation once Oilpan is default. |
| 102 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) | 87 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) |
| 103 return; | 88 return; |
| 104 result.copyFrom((fraction < 0.5) ? m_start : m_end); | 89 result = ((fraction < 0.5) ? m_start : m_end)->clone(); |
| 105 m_lastFraction = fraction; | 90 m_lastFraction = fraction; |
| 106 } | 91 } |
| 107 | 92 |
| 108 DEFINE_INLINE_VIRTUAL_TRACE() | 93 DEFINE_INLINE_VIRTUAL_TRACE() |
| 109 { | 94 { |
| 110 PrimitiveInterpolation::trace(visitor); | 95 PrimitiveInterpolation::trace(visitor); |
| 111 visitor->trace(m_start); | 96 visitor->trace(m_start); |
| 112 visitor->trace(m_end); | 97 visitor->trace(m_end); |
| 113 } | 98 } |
| 114 | 99 |
| 115 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<Side> start, PassOwnPtrWil
lBeRawPtr<Side> end) | 100 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<AnimationValue> start, Pas
sOwnPtrWillBeRawPtr<AnimationValue> end) |
| 116 : m_start(&start->type, start->interpolableValue.release(), start->nonIn
terpolableValue.release()) | 101 : m_start(start) |
| 117 , m_end(&end->type, end->interpolableValue.release(), end->nonInterpolab
leValue.release()) | 102 , m_end(end) |
| 118 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | 103 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
| 119 { } | 104 { |
| 105 ASSERT(m_start); |
| 106 ASSERT(m_end); |
| 107 } |
| 120 | 108 |
| 121 AnimationValue m_start; | 109 OwnPtrWillBeRawPtr<AnimationValue> m_start; |
| 122 AnimationValue m_end; | 110 OwnPtrWillBeRawPtr<AnimationValue> m_end; |
| 123 mutable double m_lastFraction; | 111 mutable double m_lastFraction; |
| 124 }; | 112 }; |
| 125 | 113 |
| 126 } // namespace blink | 114 } // namespace blink |
| 127 | 115 |
| 128 #endif // PrimitiveInterpolation_h | 116 #endif // PrimitiveInterpolation_h |
| OLD | NEW |