| 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/TypedInterpolationValue.h" | 8 #include "core/animation/TypedInterpolationValue.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/PtrUtil.h" |
| 11 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
| 12 #include <cmath> | 13 #include <cmath> |
| 14 #include <memory> |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 class StyleResolverState; | 18 class StyleResolverState; |
| 17 | 19 |
| 18 // Represents an animation's effect between an adjacent pair of PropertySpecific
Keyframes after converting | 20 // Represents an animation's effect between an adjacent pair of PropertySpecific
Keyframes after converting |
| 19 // the keyframes to an internal format with respect to the animation environment
and underlying values. | 21 // the keyframes to an internal format with respect to the animation environment
and underlying values. |
| 20 class PrimitiveInterpolation { | 22 class PrimitiveInterpolation { |
| 21 USING_FAST_MALLOC(PrimitiveInterpolation); | 23 USING_FAST_MALLOC(PrimitiveInterpolation); |
| 22 WTF_MAKE_NONCOPYABLE(PrimitiveInterpolation); | 24 WTF_MAKE_NONCOPYABLE(PrimitiveInterpolation); |
| 23 public: | 25 public: |
| 24 virtual ~PrimitiveInterpolation() { } | 26 virtual ~PrimitiveInterpolation() { } |
| 25 | 27 |
| 26 virtual void interpolateValue(double fraction, OwnPtr<TypedInterpolationValu
e>& result) const = 0; | 28 virtual void interpolateValue(double fraction, std::unique_ptr<TypedInterpol
ationValue>& result) const = 0; |
| 27 virtual double interpolateUnderlyingFraction(double start, double end, doubl
e fraction) const = 0; | 29 virtual double interpolateUnderlyingFraction(double start, double end, doubl
e fraction) const = 0; |
| 28 virtual bool isFlip() const { return false; } | 30 virtual bool isFlip() const { return false; } |
| 29 | 31 |
| 30 protected: | 32 protected: |
| 31 PrimitiveInterpolation() { } | 33 PrimitiveInterpolation() { } |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". | 36 // Represents a pair of keyframes that are compatible for "smooth" interpolation
eg. "0px" and "100px". |
| 35 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { | 37 class PairwisePrimitiveInterpolation : public PrimitiveInterpolation { |
| 36 public: | 38 public: |
| 37 ~PairwisePrimitiveInterpolation() override { } | 39 ~PairwisePrimitiveInterpolation() override { } |
| 38 | 40 |
| 39 static PassOwnPtr<PairwisePrimitiveInterpolation> create(const Interpolation
Type& type, PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> e
nd, PassRefPtr<NonInterpolableValue> nonInterpolableValue) | 41 static std::unique_ptr<PairwisePrimitiveInterpolation> create(const Interpol
ationType& type, std::unique_ptr<InterpolableValue> start, std::unique_ptr<Inter
polableValue> end, PassRefPtr<NonInterpolableValue> nonInterpolableValue) |
| 40 { | 42 { |
| 41 return adoptPtr(new PairwisePrimitiveInterpolation(type, std::move(start
), std::move(end), nonInterpolableValue)); | 43 return wrapUnique(new PairwisePrimitiveInterpolation(type, std::move(sta
rt), std::move(end), nonInterpolableValue)); |
| 42 } | 44 } |
| 43 | 45 |
| 44 const InterpolationType& type() const { return m_type; } | 46 const InterpolationType& type() const { return m_type; } |
| 45 | 47 |
| 46 PassOwnPtr<TypedInterpolationValue> initialValue() const | 48 std::unique_ptr<TypedInterpolationValue> initialValue() const |
| 47 { | 49 { |
| 48 return TypedInterpolationValue::create(m_type, m_start->clone(), m_nonIn
terpolableValue); | 50 return TypedInterpolationValue::create(m_type, m_start->clone(), m_nonIn
terpolableValue); |
| 49 } | 51 } |
| 50 | 52 |
| 51 private: | 53 private: |
| 52 PairwisePrimitiveInterpolation(const InterpolationType& type, PassOwnPtr<Int
erpolableValue> start, PassOwnPtr<InterpolableValue> end, PassRefPtr<NonInterpol
ableValue> nonInterpolableValue) | 54 PairwisePrimitiveInterpolation(const InterpolationType& type, std::unique_pt
r<InterpolableValue> start, std::unique_ptr<InterpolableValue> end, PassRefPtr<N
onInterpolableValue> nonInterpolableValue) |
| 53 : m_type(type) | 55 : m_type(type) |
| 54 , m_start(std::move(start)) | 56 , m_start(std::move(start)) |
| 55 , m_end(std::move(end)) | 57 , m_end(std::move(end)) |
| 56 , m_nonInterpolableValue(nonInterpolableValue) | 58 , m_nonInterpolableValue(nonInterpolableValue) |
| 57 { | 59 { |
| 58 ASSERT(m_start); | 60 ASSERT(m_start); |
| 59 ASSERT(m_end); | 61 ASSERT(m_end); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void interpolateValue(double fraction, OwnPtr<TypedInterpolationValue>& resu
lt) const final | 64 void interpolateValue(double fraction, std::unique_ptr<TypedInterpolationVal
ue>& result) const final |
| 63 { | 65 { |
| 64 ASSERT(result); | 66 ASSERT(result); |
| 65 ASSERT(&result->type() == &m_type); | 67 ASSERT(&result->type() == &m_type); |
| 66 ASSERT(result->getNonInterpolableValue() == m_nonInterpolableValue.get()
); | 68 ASSERT(result->getNonInterpolableValue() == m_nonInterpolableValue.get()
); |
| 67 m_start->interpolate(*m_end, fraction, *result->mutableValue().interpola
bleValue); | 69 m_start->interpolate(*m_end, fraction, *result->mutableValue().interpola
bleValue); |
| 68 } | 70 } |
| 69 | 71 |
| 70 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return blend(start, end, fraction); } | 72 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return blend(start, end, fraction); } |
| 71 | 73 |
| 72 const InterpolationType& m_type; | 74 const InterpolationType& m_type; |
| 73 OwnPtr<InterpolableValue> m_start; | 75 std::unique_ptr<InterpolableValue> m_start; |
| 74 OwnPtr<InterpolableValue> m_end; | 76 std::unique_ptr<InterpolableValue> m_end; |
| 75 RefPtr<NonInterpolableValue> m_nonInterpolableValue; | 77 RefPtr<NonInterpolableValue> m_nonInterpolableValue; |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". | 80 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi
our eg. "auto" and "0px". |
| 79 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { | 81 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { |
| 80 public: | 82 public: |
| 81 ~FlipPrimitiveInterpolation() override { } | 83 ~FlipPrimitiveInterpolation() override { } |
| 82 | 84 |
| 83 static PassOwnPtr<FlipPrimitiveInterpolation> create(PassOwnPtr<TypedInterpo
lationValue> start, PassOwnPtr<TypedInterpolationValue> end) | 85 static std::unique_ptr<FlipPrimitiveInterpolation> create(std::unique_ptr<Ty
pedInterpolationValue> start, std::unique_ptr<TypedInterpolationValue> end) |
| 84 { | 86 { |
| 85 return adoptPtr(new FlipPrimitiveInterpolation(std::move(start), std::mo
ve(end))); | 87 return wrapUnique(new FlipPrimitiveInterpolation(std::move(start), std::
move(end))); |
| 86 } | 88 } |
| 87 | 89 |
| 88 private: | 90 private: |
| 89 FlipPrimitiveInterpolation(PassOwnPtr<TypedInterpolationValue> start, PassOw
nPtr<TypedInterpolationValue> end) | 91 FlipPrimitiveInterpolation(std::unique_ptr<TypedInterpolationValue> start, s
td::unique_ptr<TypedInterpolationValue> end) |
| 90 : m_start(std::move(start)) | 92 : m_start(std::move(start)) |
| 91 , m_end(std::move(end)) | 93 , m_end(std::move(end)) |
| 92 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | 94 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
| 93 { } | 95 { } |
| 94 | 96 |
| 95 void interpolateValue(double fraction, OwnPtr<TypedInterpolationValue>& resu
lt) const final | 97 void interpolateValue(double fraction, std::unique_ptr<TypedInterpolationVal
ue>& result) const final |
| 96 { | 98 { |
| 97 // TODO(alancutter): Remove this optimisation once Oilpan is default. | 99 // TODO(alancutter): Remove this optimisation once Oilpan is default. |
| 98 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) | 100 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction <
0.5)) |
| 99 return; | 101 return; |
| 100 const TypedInterpolationValue* side = ((fraction < 0.5) ? m_start : m_en
d).get(); | 102 const TypedInterpolationValue* side = ((fraction < 0.5) ? m_start : m_en
d).get(); |
| 101 result = side ? side->clone() : nullptr; | 103 result = side ? side->clone() : nullptr; |
| 102 m_lastFraction = fraction; | 104 m_lastFraction = fraction; |
| 103 } | 105 } |
| 104 | 106 |
| 105 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return fraction < 0.5 ? start : end; } | 107 double interpolateUnderlyingFraction(double start, double end, double fracti
on) const final { return fraction < 0.5 ? start : end; } |
| 106 | 108 |
| 107 bool isFlip() const final { return true; } | 109 bool isFlip() const final { return true; } |
| 108 | 110 |
| 109 OwnPtr<TypedInterpolationValue> m_start; | 111 std::unique_ptr<TypedInterpolationValue> m_start; |
| 110 OwnPtr<TypedInterpolationValue> m_end; | 112 std::unique_ptr<TypedInterpolationValue> m_end; |
| 111 mutable double m_lastFraction; | 113 mutable double m_lastFraction; |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 } // namespace blink | 116 } // namespace blink |
| 115 | 117 |
| 116 #endif // PrimitiveInterpolation_h | 118 #endif // PrimitiveInterpolation_h |
| OLD | NEW |