Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: Source/core/animation/PrimitiveInterpolation.h

Issue 1276183004: Oilpan: Unship oilpan from temporary animation objects (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
21 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(PrimitiveInterpolation); 21 WTF_MAKE_FAST_ALLOCATED(PrimitiveInterpolation);
22 WTF_MAKE_NONCOPYABLE(PrimitiveInterpolation); 22 WTF_MAKE_NONCOPYABLE(PrimitiveInterpolation);
23 public: 23 public:
24 virtual ~PrimitiveInterpolation() { } 24 virtual ~PrimitiveInterpolation() { }
25 25
26 virtual void interpolateValue(double fraction, OwnPtrWillBeMember<Interpolat ionValue>& result) const = 0; 26 virtual void interpolateValue(double fraction, OwnPtr<InterpolationValue>& r esult) const = 0;
27 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;
28 virtual bool isFlip() const { return false; } 28 virtual bool isFlip() const { return false; }
29 29
30 DEFINE_INLINE_VIRTUAL_TRACE() { }
31
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 PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(const I nterpolationType& type, PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwn PtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableVa lue> nonInterpolableValue) 39 static PassOwnPtr<PairwisePrimitiveInterpolation> create(const Interpolation Type& type, PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> e nd, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue)
42 { 40 {
43 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(type, start , end, nonInterpolableValue)); 41 return adoptPtr(new PairwisePrimitiveInterpolation(type, start, end, non InterpolableValue));
44 } 42 }
45 43
46 PassOwnPtrWillBeRawPtr<InterpolationValue> initialValue() const 44 PassOwnPtr<InterpolationValue> initialValue() const
47 { 45 {
48 return InterpolationValue::create(m_type, m_start->clone(), m_nonInterpo lableValue); 46 return InterpolationValue::create(m_type, m_start->clone(), m_nonInterpo lableValue);
49 } 47 }
50 48
51 DEFINE_INLINE_VIRTUAL_TRACE()
52 {
53 visitor->trace(m_start);
54 visitor->trace(m_end);
55 visitor->trace(m_nonInterpolableValue);
56 PrimitiveInterpolation::trace(visitor);
57 }
58
59 private: 49 private:
60 PairwisePrimitiveInterpolation(const InterpolationType& type, PassOwnPtrWill BeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end , PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) 50 PairwisePrimitiveInterpolation(const InterpolationType& type, PassOwnPtr<Int erpolableValue> start, PassOwnPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr <NonInterpolableValue> nonInterpolableValue)
61 : m_type(type) 51 : m_type(type)
62 , m_start(start) 52 , m_start(start)
63 , m_end(end) 53 , m_end(end)
64 , m_nonInterpolableValue(nonInterpolableValue) 54 , m_nonInterpolableValue(nonInterpolableValue)
65 { } 55 { }
66 56
67 void interpolateValue(double fraction, OwnPtrWillBeMember<InterpolationValue >& result) const final 57 void interpolateValue(double fraction, OwnPtr<InterpolationValue>& result) c onst final
68 { 58 {
69 ASSERT(result); 59 ASSERT(result);
70 ASSERT(&result->type() == &m_type); 60 ASSERT(&result->type() == &m_type);
71 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get()); 61 ASSERT(result->nonInterpolableValue() == m_nonInterpolableValue.get());
72 m_start->interpolate(*m_end, fraction, result->interpolableValue()); 62 m_start->interpolate(*m_end, fraction, result->interpolableValue());
73 } 63 }
74 64
75 double interpolateUnderlyingFraction(double start, double end, double fracti on) const final { return blend(start, end, fraction); } 65 double interpolateUnderlyingFraction(double start, double end, double fracti on) const final { return blend(start, end, fraction); }
76 66
77 const InterpolationType& m_type; 67 const InterpolationType& m_type;
78 OwnPtrWillBeMember<InterpolableValue> m_start; 68 OwnPtr<InterpolableValue> m_start;
79 OwnPtrWillBeMember<InterpolableValue> m_end; 69 OwnPtr<InterpolableValue> m_end;
80 RefPtrWillBeMember<NonInterpolableValue> m_nonInterpolableValue; 70 RefPtrWillBePersistent<NonInterpolableValue> m_nonInterpolableValue;
81 }; 71 };
82 72
83 // 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".
84 class FlipPrimitiveInterpolation : public PrimitiveInterpolation { 74 class FlipPrimitiveInterpolation : public PrimitiveInterpolation {
85 public: 75 public:
86 ~FlipPrimitiveInterpolation() override { } 76 ~FlipPrimitiveInterpolation() override { }
87 77
88 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW illBeRawPtr<InterpolationValue> start, PassOwnPtrWillBeRawPtr<InterpolationValue > end) 78 static PassOwnPtr<FlipPrimitiveInterpolation> create(PassOwnPtr<Interpolatio nValue> start, PassOwnPtr<InterpolationValue> end)
89 { 79 {
90 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); 80 return adoptPtr(new FlipPrimitiveInterpolation(start, end));
91 }
92
93 DEFINE_INLINE_VIRTUAL_TRACE()
94 {
95 visitor->trace(m_start);
96 visitor->trace(m_end);
97 PrimitiveInterpolation::trace(visitor);
98 } 81 }
99 82
100 private: 83 private:
101 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<InterpolationValue> start, PassOwnPtrWillBeRawPtr<InterpolationValue> end) 84 FlipPrimitiveInterpolation(PassOwnPtr<InterpolationValue> start, PassOwnPtr< InterpolationValue> end)
102 : m_start(start) 85 : m_start(start)
103 , m_end(end) 86 , m_end(end)
104 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) 87 , m_lastFraction(std::numeric_limits<double>::quiet_NaN())
105 { } 88 { }
106 89
107 void interpolateValue(double fraction, OwnPtrWillBeMember<InterpolationValue >& result) const final 90 void interpolateValue(double fraction, OwnPtr<InterpolationValue>& result) c onst final
108 { 91 {
109 // TODO(alancutter): Remove this optimisation once Oilpan is default. 92 // TODO(alancutter): Remove this optimisation once Oilpan is default.
110 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction < 0.5)) 93 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction < 0.5))
111 return; 94 return;
112 const InterpolationValue* side = ((fraction < 0.5) ? m_start : m_end).ge t(); 95 const InterpolationValue* side = ((fraction < 0.5) ? m_start : m_end).ge t();
113 result = side ? side->clone() : nullptr; 96 result = side ? side->clone() : nullptr;
114 m_lastFraction = fraction; 97 m_lastFraction = fraction;
115 } 98 }
116 99
117 double interpolateUnderlyingFraction(double start, double end, double fracti on) const final { return fraction < 0.5 ? start : end; } 100 double interpolateUnderlyingFraction(double start, double end, double fracti on) const final { return fraction < 0.5 ? start : end; }
118 101
119 bool isFlip() const final { return true; } 102 bool isFlip() const final { return true; }
120 103
121 OwnPtrWillBeMember<InterpolationValue> m_start; 104 OwnPtr<InterpolationValue> m_start;
122 OwnPtrWillBeMember<InterpolationValue> m_end; 105 OwnPtr<InterpolationValue> m_end;
123 mutable double m_lastFraction; 106 mutable double m_lastFraction;
124 }; 107 };
125 108
126 } // namespace blink 109 } // namespace blink
127 110
128 #endif // PrimitiveInterpolation_h 111 #endif // PrimitiveInterpolation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698