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