| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCKeyframedAnimationCurve.h" | 7 #include "CCKeyframedAnimationCurve.h" |
| 8 | 8 |
| 9 #include <wtf/OwnPtr.h> | |
| 10 | |
| 11 using WebKit::WebTransformationMatrix; | 9 using WebKit::WebTransformationMatrix; |
| 12 | 10 |
| 13 namespace cc { | 11 namespace cc { |
| 14 | 12 |
| 15 namespace { | 13 namespace { |
| 16 | 14 |
| 17 template <class Keyframe> | 15 template <class Keyframe> |
| 18 void insertKeyframe(PassOwnPtr<Keyframe> popKeyframe, OwnPtrVector<Keyframe>& ke
yframes) | 16 void insertKeyframe(scoped_ptr<Keyframe> keyframe, ScopedPtrVector<Keyframe>& ke
yframes) |
| 19 { | 17 { |
| 20 OwnPtr<Keyframe> keyframe = popKeyframe; | |
| 21 | |
| 22 // Usually, the keyframes will be added in order, so this loop would be unne
cessary and | 18 // Usually, the keyframes will be added in order, so this loop would be unne
cessary and |
| 23 // we should skip it if possible. | 19 // we should skip it if possible. |
| 24 if (!keyframes.isEmpty() && keyframe->time() < keyframes.last()->time()) { | 20 if (!keyframes.isEmpty() && keyframe->time() < keyframes.last()->time()) { |
| 25 for (size_t i = 0; i < keyframes.size(); ++i) { | 21 for (size_t i = 0; i < keyframes.size(); ++i) { |
| 26 if (keyframe->time() < keyframes[i]->time()) { | 22 if (keyframe->time() < keyframes[i]->time()) { |
| 27 keyframes.insert(i, keyframe.release()); | 23 keyframes.insert(i, keyframe.Pass()); |
| 28 return; | 24 return; |
| 29 } | 25 } |
| 30 } | 26 } |
| 31 } | 27 } |
| 32 | 28 |
| 33 keyframes.append(keyframe.release()); | 29 keyframes.append(keyframe.Pass()); |
| 34 } | 30 } |
| 35 | 31 |
| 36 PassOwnPtr<CCTimingFunction> cloneTimingFunction(const CCTimingFunction* timingF
unction) | 32 scoped_ptr<CCTimingFunction> cloneTimingFunction(const CCTimingFunction* timingF
unction) |
| 37 { | 33 { |
| 38 ASSERT(timingFunction); | 34 ASSERT(timingFunction); |
| 39 OwnPtr<CCAnimationCurve> curve(timingFunction->clone()); | 35 scoped_ptr<CCAnimationCurve> curve(timingFunction->clone()); |
| 40 return adoptPtr(static_cast<CCTimingFunction*>(curve.leakPtr())); | 36 return scoped_ptr<CCTimingFunction>(static_cast<CCTimingFunction*>(curve.rel
ease())); |
| 41 } | 37 } |
| 42 | 38 |
| 43 } // namespace | 39 } // namespace |
| 44 | 40 |
| 45 CCKeyframe::CCKeyframe(double time, PassOwnPtr<CCTimingFunction> timingFunction) | 41 CCKeyframe::CCKeyframe(double time, scoped_ptr<CCTimingFunction> timingFunction) |
| 46 : m_time(time) | 42 : m_time(time) |
| 47 , m_timingFunction(timingFunction) | 43 , m_timingFunction(timingFunction.Pass()) |
| 48 { | 44 { |
| 49 } | 45 } |
| 50 | 46 |
| 51 CCKeyframe::~CCKeyframe() | 47 CCKeyframe::~CCKeyframe() |
| 52 { | 48 { |
| 53 } | 49 } |
| 54 | 50 |
| 55 double CCKeyframe::time() const | 51 double CCKeyframe::time() const |
| 56 { | 52 { |
| 57 return m_time; | 53 return m_time; |
| 58 } | 54 } |
| 59 | 55 |
| 60 const CCTimingFunction* CCKeyframe::timingFunction() const | 56 const CCTimingFunction* CCKeyframe::timingFunction() const |
| 61 { | 57 { |
| 62 return m_timingFunction.get(); | 58 return m_timingFunction.get(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 PassOwnPtr<CCFloatKeyframe> CCFloatKeyframe::create(double time, float value, Pa
ssOwnPtr<CCTimingFunction> timingFunction) | 61 scoped_ptr<CCFloatKeyframe> CCFloatKeyframe::create(double time, float value, sc
oped_ptr<CCTimingFunction> timingFunction) |
| 66 { | 62 { |
| 67 return adoptPtr(new CCFloatKeyframe(time, value, timingFunction)); | 63 return make_scoped_ptr(new CCFloatKeyframe(time, value, timingFunction.Pass(
))); |
| 68 } | 64 } |
| 69 | 65 |
| 70 CCFloatKeyframe::CCFloatKeyframe(double time, float value, PassOwnPtr<CCTimingFu
nction> timingFunction) | 66 CCFloatKeyframe::CCFloatKeyframe(double time, float value, scoped_ptr<CCTimingFu
nction> timingFunction) |
| 71 : CCKeyframe(time, timingFunction) | 67 : CCKeyframe(time, timingFunction.Pass()) |
| 72 , m_value(value) | 68 , m_value(value) |
| 73 { | 69 { |
| 74 } | 70 } |
| 75 | 71 |
| 76 CCFloatKeyframe::~CCFloatKeyframe() | 72 CCFloatKeyframe::~CCFloatKeyframe() |
| 77 { | 73 { |
| 78 } | 74 } |
| 79 | 75 |
| 80 float CCFloatKeyframe::value() const | 76 float CCFloatKeyframe::value() const |
| 81 { | 77 { |
| 82 return m_value; | 78 return m_value; |
| 83 } | 79 } |
| 84 | 80 |
| 85 PassOwnPtr<CCFloatKeyframe> CCFloatKeyframe::clone() const | 81 scoped_ptr<CCFloatKeyframe> CCFloatKeyframe::clone() const |
| 86 { | 82 { |
| 87 return CCFloatKeyframe::create(time(), value(), timingFunction() ? cloneTimi
ngFunction(timingFunction()) : nullptr); | 83 return CCFloatKeyframe::create(time(), value(), timingFunction() ? cloneTimi
ngFunction(timingFunction()) : scoped_ptr<CCTimingFunction>()); } |
| 84 |
| 85 scoped_ptr<CCTransformKeyframe> CCTransformKeyframe::create(double time, const W
ebKit::WebTransformOperations& value, scoped_ptr<CCTimingFunction> timingFunctio
n) |
| 86 { |
| 87 return make_scoped_ptr(new CCTransformKeyframe(time, value, timingFunction.P
ass())); |
| 88 } | 88 } |
| 89 | 89 |
| 90 PassOwnPtr<CCTransformKeyframe> CCTransformKeyframe::create(double time, const W
ebKit::WebTransformOperations& value, PassOwnPtr<CCTimingFunction> timingFunctio
n) | 90 CCTransformKeyframe::CCTransformKeyframe(double time, const WebKit::WebTransform
Operations& value, scoped_ptr<CCTimingFunction> timingFunction) |
| 91 { | 91 : CCKeyframe(time, timingFunction.Pass()) |
| 92 return adoptPtr(new CCTransformKeyframe(time, value, timingFunction)); | |
| 93 } | |
| 94 | |
| 95 CCTransformKeyframe::CCTransformKeyframe(double time, const WebKit::WebTransform
Operations& value, PassOwnPtr<CCTimingFunction> timingFunction) | |
| 96 : CCKeyframe(time, timingFunction) | |
| 97 , m_value(value) | 92 , m_value(value) |
| 98 { | 93 { |
| 99 } | 94 } |
| 100 | 95 |
| 101 CCTransformKeyframe::~CCTransformKeyframe() | 96 CCTransformKeyframe::~CCTransformKeyframe() |
| 102 { | 97 { |
| 103 } | 98 } |
| 104 | 99 |
| 105 const WebKit::WebTransformOperations& CCTransformKeyframe::value() const | 100 const WebKit::WebTransformOperations& CCTransformKeyframe::value() const |
| 106 { | 101 { |
| 107 return m_value; | 102 return m_value; |
| 108 } | 103 } |
| 109 | 104 |
| 110 PassOwnPtr<CCTransformKeyframe> CCTransformKeyframe::clone() const | 105 scoped_ptr<CCTransformKeyframe> CCTransformKeyframe::clone() const |
| 111 { | 106 { |
| 112 return CCTransformKeyframe::create(time(), value(), timingFunction() ? clone
TimingFunction(timingFunction()) : nullptr); | 107 return CCTransformKeyframe::create(time(), value(), timingFunction() ? clone
TimingFunction(timingFunction()) : scoped_ptr<CCTimingFunction>()); |
| 113 } | 108 } |
| 114 | 109 |
| 115 PassOwnPtr<CCKeyframedFloatAnimationCurve> CCKeyframedFloatAnimationCurve::creat
e() | 110 scoped_ptr<CCKeyframedFloatAnimationCurve> CCKeyframedFloatAnimationCurve::creat
e() |
| 116 { | 111 { |
| 117 return adoptPtr(new CCKeyframedFloatAnimationCurve); | 112 return make_scoped_ptr(new CCKeyframedFloatAnimationCurve); |
| 118 } | 113 } |
| 119 | 114 |
| 120 CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve() | 115 CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve() |
| 121 { | 116 { |
| 122 } | 117 } |
| 123 | 118 |
| 124 CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve() | 119 CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve() |
| 125 { | 120 { |
| 126 } | 121 } |
| 127 | 122 |
| 128 void CCKeyframedFloatAnimationCurve::addKeyframe(PassOwnPtr<CCFloatKeyframe> key
frame) | 123 void CCKeyframedFloatAnimationCurve::addKeyframe(scoped_ptr<CCFloatKeyframe> key
frame) |
| 129 { | 124 { |
| 130 insertKeyframe(keyframe, m_keyframes); | 125 insertKeyframe(keyframe.Pass(), m_keyframes); |
| 131 } | 126 } |
| 132 | 127 |
| 133 double CCKeyframedFloatAnimationCurve::duration() const | 128 double CCKeyframedFloatAnimationCurve::duration() const |
| 134 { | 129 { |
| 135 return m_keyframes.last()->time() - m_keyframes.first()->time(); | 130 return m_keyframes.last()->time() - m_keyframes.first()->time(); |
| 136 } | 131 } |
| 137 | 132 |
| 138 PassOwnPtr<CCAnimationCurve> CCKeyframedFloatAnimationCurve::clone() const | 133 scoped_ptr<CCAnimationCurve> CCKeyframedFloatAnimationCurve::clone() const |
| 139 { | 134 { |
| 140 OwnPtr<CCKeyframedFloatAnimationCurve> toReturn(CCKeyframedFloatAnimationCur
ve::create()); | 135 scoped_ptr<CCKeyframedFloatAnimationCurve> toReturn(CCKeyframedFloatAnimatio
nCurve::create()); |
| 141 for (size_t i = 0; i < m_keyframes.size(); ++i) | 136 for (size_t i = 0; i < m_keyframes.size(); ++i) |
| 142 toReturn->addKeyframe(m_keyframes[i]->clone()); | 137 toReturn->addKeyframe(m_keyframes[i]->clone()); |
| 143 return toReturn.release(); | 138 return toReturn.PassAs<CCAnimationCurve>(); |
| 144 } | 139 } |
| 145 | 140 |
| 146 float CCKeyframedFloatAnimationCurve::getValue(double t) const | 141 float CCKeyframedFloatAnimationCurve::getValue(double t) const |
| 147 { | 142 { |
| 148 if (t <= m_keyframes.first()->time()) | 143 if (t <= m_keyframes.first()->time()) |
| 149 return m_keyframes.first()->value(); | 144 return m_keyframes.first()->value(); |
| 150 | 145 |
| 151 if (t >= m_keyframes.last()->time()) | 146 if (t >= m_keyframes.last()->time()) |
| 152 return m_keyframes.last()->value(); | 147 return m_keyframes.last()->value(); |
| 153 | 148 |
| 154 size_t i = 0; | 149 size_t i = 0; |
| 155 for (; i < m_keyframes.size() - 1; ++i) { | 150 for (; i < m_keyframes.size() - 1; ++i) { |
| 156 if (t < m_keyframes[i+1]->time()) | 151 if (t < m_keyframes[i+1]->time()) |
| 157 break; | 152 break; |
| 158 } | 153 } |
| 159 | 154 |
| 160 float progress = static_cast<float>((t - m_keyframes[i]->time()) / (m_keyfra
mes[i+1]->time() - m_keyframes[i]->time())); | 155 float progress = static_cast<float>((t - m_keyframes[i]->time()) / (m_keyfra
mes[i+1]->time() - m_keyframes[i]->time())); |
| 161 | 156 |
| 162 if (m_keyframes[i]->timingFunction()) | 157 if (m_keyframes[i]->timingFunction()) |
| 163 progress = m_keyframes[i]->timingFunction()->getValue(progress); | 158 progress = m_keyframes[i]->timingFunction()->getValue(progress); |
| 164 | 159 |
| 165 return m_keyframes[i]->value() + (m_keyframes[i+1]->value() - m_keyframes[i]
->value()) * progress; | 160 return m_keyframes[i]->value() + (m_keyframes[i+1]->value() - m_keyframes[i]
->value()) * progress; |
| 166 } | 161 } |
| 167 | 162 |
| 168 PassOwnPtr<CCKeyframedTransformAnimationCurve> CCKeyframedTransformAnimationCurv
e::create() | 163 scoped_ptr<CCKeyframedTransformAnimationCurve> CCKeyframedTransformAnimationCurv
e::create() |
| 169 { | 164 { |
| 170 return adoptPtr(new CCKeyframedTransformAnimationCurve); | 165 return make_scoped_ptr(new CCKeyframedTransformAnimationCurve); |
| 171 } | 166 } |
| 172 | 167 |
| 173 CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve() | 168 CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve() |
| 174 { | 169 { |
| 175 } | 170 } |
| 176 | 171 |
| 177 CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve() | 172 CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve() |
| 178 { | 173 { |
| 179 } | 174 } |
| 180 | 175 |
| 181 void CCKeyframedTransformAnimationCurve::addKeyframe(PassOwnPtr<CCTransformKeyfr
ame> keyframe) | 176 void CCKeyframedTransformAnimationCurve::addKeyframe(scoped_ptr<CCTransformKeyfr
ame> keyframe) |
| 182 { | 177 { |
| 183 insertKeyframe(keyframe, m_keyframes); | 178 insertKeyframe(keyframe.Pass(), m_keyframes); |
| 184 } | 179 } |
| 185 | 180 |
| 186 double CCKeyframedTransformAnimationCurve::duration() const | 181 double CCKeyframedTransformAnimationCurve::duration() const |
| 187 { | 182 { |
| 188 return m_keyframes.last()->time() - m_keyframes.first()->time(); | 183 return m_keyframes.last()->time() - m_keyframes.first()->time(); |
| 189 } | 184 } |
| 190 | 185 |
| 191 PassOwnPtr<CCAnimationCurve> CCKeyframedTransformAnimationCurve::clone() const | 186 scoped_ptr<CCAnimationCurve> CCKeyframedTransformAnimationCurve::clone() const |
| 192 { | 187 { |
| 193 OwnPtr<CCKeyframedTransformAnimationCurve> toReturn(CCKeyframedTransformAnim
ationCurve::create()); | 188 scoped_ptr<CCKeyframedTransformAnimationCurve> toReturn(CCKeyframedTransform
AnimationCurve::create()); |
| 194 for (size_t i = 0; i < m_keyframes.size(); ++i) | 189 for (size_t i = 0; i < m_keyframes.size(); ++i) |
| 195 toReturn->addKeyframe(m_keyframes[i]->clone()); | 190 toReturn->addKeyframe(m_keyframes[i]->clone()); |
| 196 return toReturn.release(); | 191 return toReturn.PassAs<CCAnimationCurve>(); |
| 197 } | 192 } |
| 198 | 193 |
| 199 WebTransformationMatrix CCKeyframedTransformAnimationCurve::getValue(double t) c
onst | 194 WebTransformationMatrix CCKeyframedTransformAnimationCurve::getValue(double t) c
onst |
| 200 { | 195 { |
| 201 if (t <= m_keyframes.first()->time()) | 196 if (t <= m_keyframes.first()->time()) |
| 202 return m_keyframes.first()->value().apply(); | 197 return m_keyframes.first()->value().apply(); |
| 203 | 198 |
| 204 if (t >= m_keyframes.last()->time()) | 199 if (t >= m_keyframes.last()->time()) |
| 205 return m_keyframes.last()->value().apply(); | 200 return m_keyframes.last()->value().apply(); |
| 206 | 201 |
| 207 size_t i = 0; | 202 size_t i = 0; |
| 208 for (; i < m_keyframes.size() - 1; ++i) { | 203 for (; i < m_keyframes.size() - 1; ++i) { |
| 209 if (t < m_keyframes[i+1]->time()) | 204 if (t < m_keyframes[i+1]->time()) |
| 210 break; | 205 break; |
| 211 } | 206 } |
| 212 | 207 |
| 213 double progress = (t - m_keyframes[i]->time()) / (m_keyframes[i+1]->time() -
m_keyframes[i]->time()); | 208 double progress = (t - m_keyframes[i]->time()) / (m_keyframes[i+1]->time() -
m_keyframes[i]->time()); |
| 214 | 209 |
| 215 if (m_keyframes[i]->timingFunction()) | 210 if (m_keyframes[i]->timingFunction()) |
| 216 progress = m_keyframes[i]->timingFunction()->getValue(progress); | 211 progress = m_keyframes[i]->timingFunction()->getValue(progress); |
| 217 | 212 |
| 218 return m_keyframes[i+1]->value().blend(m_keyframes[i]->value(), progress); | 213 return m_keyframes[i+1]->value().blend(m_keyframes[i]->value(), progress); |
| 219 } | 214 } |
| 220 | 215 |
| 221 } // namespace cc | 216 } // namespace cc |
| OLD | NEW |