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