| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PrimitiveInterpolation_h |
| 6 #define PrimitiveInterpolation_h |
| 7 |
| 8 #include "core/animation/AnimationValue.h" |
| 9 #include "platform/heap/Handle.h" |
| 10 #include "wtf/Vector.h" |
| 11 #include <cmath> |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 class StyleResolverState; |
| 16 |
| 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. |
| 19 class PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim
itiveInterpolation> { |
| 20 public: |
| 21 virtual ~PrimitiveInterpolation() { } |
| 22 |
| 23 virtual void interpolate(double fraction, AnimationValue& result) const = 0; |
| 24 |
| 25 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 26 }; |
| 27 |
| 28 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". |
| 29 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { |
| 30 public: |
| 31 virtual ~PairwisePrimitiveInterpolation() { } |
| 32 |
| 33 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(PassOwn
PtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableVal
ue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) |
| 34 { |
| 35 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(start, end,
nonInterpolableValue)); |
| 36 } |
| 37 |
| 38 void initializeAnimationValue(AnimationValue& value) |
| 39 { |
| 40 value.interpolableValue = m_start->clone(); |
| 41 value.nonInterpolableValue = m_nonInterpolableValue; |
| 42 } |
| 43 |
| 44 private: |
| 45 virtual void interpolate(double fraction, AnimationValue& result) const over
ride final |
| 46 { |
| 47 ASSERT(result.nonInterpolableValue == m_nonInterpolableValue); |
| 48 m_start->interpolate(*m_end, fraction, *result.interpolableValue); |
| 49 } |
| 50 |
| 51 DEFINE_INLINE_VIRTUAL_TRACE() |
| 52 { |
| 53 PrimitiveInterpolation::trace(visitor); |
| 54 visitor->trace(m_start); |
| 55 visitor->trace(m_end); |
| 56 visitor->trace(m_nonInterpolableValue); |
| 57 } |
| 58 |
| 59 PairwisePrimitiveInterpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> sta
rt, PassOwnPtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInt
erpolableValue> nonInterpolableValue) |
| 60 : m_start(start) |
| 61 , m_end(end) |
| 62 , m_nonInterpolableValue(nonInterpolableValue) |
| 63 { } |
| 64 OwnPtrWillBeRawPtr<InterpolableValue> m_start; |
| 65 OwnPtrWillBeRawPtr<InterpolableValue> m_end; |
| 66 RefPtrWillBeRawPtr<NonInterpolableValue> m_nonInterpolableValue; |
| 67 }; |
| 68 |
| 69 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". |
| 70 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { |
| 71 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() { } |
| 92 |
| 93 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW
illBeRawPtr<Side> start, PassOwnPtrWillBeRawPtr<Side> end) |
| 94 { |
| 95 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); |
| 96 } |
| 97 |
| 98 private: |
| 99 virtual void interpolate(double fraction, AnimationValue& result) const over
ride final |
| 100 { |
| 101 // TODO(alancutter): Remove this optimisation once Oilpan is default. |
| 102 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) |
| 103 return; |
| 104 result.copyFrom((fraction < 0.5) ? m_start : m_end); |
| 105 m_lastFraction = fraction; |
| 106 } |
| 107 |
| 108 DEFINE_INLINE_VIRTUAL_TRACE() |
| 109 { |
| 110 PrimitiveInterpolation::trace(visitor); |
| 111 visitor->trace(m_start); |
| 112 visitor->trace(m_end); |
| 113 } |
| 114 |
| 115 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<Side> start, PassOwnPtrWil
lBeRawPtr<Side> end) |
| 116 : m_start(&start->type, start->interpolableValue.release(), start->nonIn
terpolableValue.release()) |
| 117 , m_end(&end->type, end->interpolableValue.release(), end->nonInterpolab
leValue.release()) |
| 118 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
| 119 { } |
| 120 |
| 121 AnimationValue m_start; |
| 122 AnimationValue m_end; |
| 123 mutable double m_lastFraction; |
| 124 }; |
| 125 |
| 126 } // namespace blink |
| 127 |
| 128 #endif // PrimitiveInterpolation_h |
| OLD | NEW |