| 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 using WebKit::WebTransformationMatrix; | 9 using WebKit::WebTransformationMatrix; |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 if (keyframe->time() < keyframes[i]->time()) { | 22 if (keyframe->time() < keyframes[i]->time()) { |
| 23 keyframes.insert(i, keyframe.Pass()); | 23 keyframes.insert(i, keyframe.Pass()); |
| 24 return; | 24 return; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 keyframes.append(keyframe.Pass()); | 29 keyframes.append(keyframe.Pass()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 scoped_ptr<CCTimingFunction> cloneTimingFunction(const CCTimingFunction* timingF
unction) | 32 scoped_ptr<TimingFunction> cloneTimingFunction(const TimingFunction* timingFunct
ion) |
| 33 { | 33 { |
| 34 ASSERT(timingFunction); | 34 ASSERT(timingFunction); |
| 35 scoped_ptr<CCAnimationCurve> curve(timingFunction->clone()); | 35 scoped_ptr<AnimationCurve> curve(timingFunction->clone()); |
| 36 return scoped_ptr<CCTimingFunction>(static_cast<CCTimingFunction*>(curve.rel
ease())); | 36 return scoped_ptr<TimingFunction>(static_cast<TimingFunction*>(curve.release
())); |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 CCKeyframe::CCKeyframe(double time, scoped_ptr<CCTimingFunction> timingFunction) | 41 Keyframe::Keyframe(double time, scoped_ptr<TimingFunction> timingFunction) |
| 42 : m_time(time) | 42 : m_time(time) |
| 43 , m_timingFunction(timingFunction.Pass()) | 43 , m_timingFunction(timingFunction.Pass()) |
| 44 { | 44 { |
| 45 } | 45 } |
| 46 | 46 |
| 47 CCKeyframe::~CCKeyframe() | 47 Keyframe::~Keyframe() |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 double CCKeyframe::time() const | 51 double Keyframe::time() const |
| 52 { | 52 { |
| 53 return m_time; | 53 return m_time; |
| 54 } | 54 } |
| 55 | 55 |
| 56 const CCTimingFunction* CCKeyframe::timingFunction() const | 56 const TimingFunction* Keyframe::timingFunction() const |
| 57 { | 57 { |
| 58 return m_timingFunction.get(); | 58 return m_timingFunction.get(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 scoped_ptr<CCFloatKeyframe> CCFloatKeyframe::create(double time, float value, sc
oped_ptr<CCTimingFunction> timingFunction) | 61 scoped_ptr<FloatKeyframe> FloatKeyframe::create(double time, float value, scoped
_ptr<TimingFunction> timingFunction) |
| 62 { | 62 { |
| 63 return make_scoped_ptr(new CCFloatKeyframe(time, value, timingFunction.Pass(
))); | 63 return make_scoped_ptr(new FloatKeyframe(time, value, timingFunction.Pass())
); |
| 64 } | 64 } |
| 65 | 65 |
| 66 CCFloatKeyframe::CCFloatKeyframe(double time, float value, scoped_ptr<CCTimingFu
nction> timingFunction) | 66 FloatKeyframe::FloatKeyframe(double time, float value, scoped_ptr<TimingFunction
> timingFunction) |
| 67 : CCKeyframe(time, timingFunction.Pass()) | 67 : Keyframe(time, timingFunction.Pass()) |
| 68 , m_value(value) | 68 , m_value(value) |
| 69 { | 69 { |
| 70 } | 70 } |
| 71 | 71 |
| 72 CCFloatKeyframe::~CCFloatKeyframe() | 72 FloatKeyframe::~FloatKeyframe() |
| 73 { | 73 { |
| 74 } | 74 } |
| 75 | 75 |
| 76 float CCFloatKeyframe::value() const | 76 float FloatKeyframe::value() const |
| 77 { | 77 { |
| 78 return m_value; | 78 return m_value; |
| 79 } | 79 } |
| 80 | 80 |
| 81 scoped_ptr<CCFloatKeyframe> CCFloatKeyframe::clone() const | 81 scoped_ptr<FloatKeyframe> FloatKeyframe::clone() const |
| 82 { | 82 { |
| 83 scoped_ptr<CCTimingFunction> func; | 83 scoped_ptr<TimingFunction> func; |
| 84 if (timingFunction()) | 84 if (timingFunction()) |
| 85 func = cloneTimingFunction(timingFunction()); | 85 func = cloneTimingFunction(timingFunction()); |
| 86 return CCFloatKeyframe::create(time(), value(), func.Pass()); | 86 return FloatKeyframe::create(time(), value(), func.Pass()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 scoped_ptr<CCTransformKeyframe> CCTransformKeyframe::create(double time, const W
ebKit::WebTransformOperations& value, scoped_ptr<CCTimingFunction> timingFunctio
n) | 89 scoped_ptr<TransformKeyframe> TransformKeyframe::create(double time, const WebKi
t::WebTransformOperations& value, scoped_ptr<TimingFunction> timingFunction) |
| 90 { | 90 { |
| 91 return make_scoped_ptr(new CCTransformKeyframe(time, value, timingFunction.P
ass())); | 91 return make_scoped_ptr(new TransformKeyframe(time, value, timingFunction.Pas
s())); |
| 92 } | 92 } |
| 93 | 93 |
| 94 CCTransformKeyframe::CCTransformKeyframe(double time, const WebKit::WebTransform
Operations& value, scoped_ptr<CCTimingFunction> timingFunction) | 94 TransformKeyframe::TransformKeyframe(double time, const WebKit::WebTransformOper
ations& value, scoped_ptr<TimingFunction> timingFunction) |
| 95 : CCKeyframe(time, timingFunction.Pass()) | 95 : Keyframe(time, timingFunction.Pass()) |
| 96 , m_value(value) | 96 , m_value(value) |
| 97 { | 97 { |
| 98 } | 98 } |
| 99 | 99 |
| 100 CCTransformKeyframe::~CCTransformKeyframe() | 100 TransformKeyframe::~TransformKeyframe() |
| 101 { | 101 { |
| 102 } | 102 } |
| 103 | 103 |
| 104 const WebKit::WebTransformOperations& CCTransformKeyframe::value() const | 104 const WebKit::WebTransformOperations& TransformKeyframe::value() const |
| 105 { | 105 { |
| 106 return m_value; | 106 return m_value; |
| 107 } | 107 } |
| 108 | 108 |
| 109 scoped_ptr<CCTransformKeyframe> CCTransformKeyframe::clone() const | 109 scoped_ptr<TransformKeyframe> TransformKeyframe::clone() const |
| 110 { | 110 { |
| 111 scoped_ptr<CCTimingFunction> func; | 111 scoped_ptr<TimingFunction> func; |
| 112 if (timingFunction()) | 112 if (timingFunction()) |
| 113 func = cloneTimingFunction(timingFunction()); | 113 func = cloneTimingFunction(timingFunction()); |
| 114 return CCTransformKeyframe::create(time(), value(), func.Pass()); | 114 return TransformKeyframe::create(time(), value(), func.Pass()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 scoped_ptr<CCKeyframedFloatAnimationCurve> CCKeyframedFloatAnimationCurve::creat
e() | 117 scoped_ptr<KeyframedFloatAnimationCurve> KeyframedFloatAnimationCurve::create() |
| 118 { | 118 { |
| 119 return make_scoped_ptr(new CCKeyframedFloatAnimationCurve); | 119 return make_scoped_ptr(new KeyframedFloatAnimationCurve); |
| 120 } | 120 } |
| 121 | 121 |
| 122 CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve() | 122 KeyframedFloatAnimationCurve::KeyframedFloatAnimationCurve() |
| 123 { | 123 { |
| 124 } | 124 } |
| 125 | 125 |
| 126 CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve() | 126 KeyframedFloatAnimationCurve::~KeyframedFloatAnimationCurve() |
| 127 { | 127 { |
| 128 } | 128 } |
| 129 | 129 |
| 130 void CCKeyframedFloatAnimationCurve::addKeyframe(scoped_ptr<CCFloatKeyframe> key
frame) | 130 void KeyframedFloatAnimationCurve::addKeyframe(scoped_ptr<FloatKeyframe> keyfram
e) |
| 131 { | 131 { |
| 132 insertKeyframe(keyframe.Pass(), m_keyframes); | 132 insertKeyframe(keyframe.Pass(), m_keyframes); |
| 133 } | 133 } |
| 134 | 134 |
| 135 double CCKeyframedFloatAnimationCurve::duration() const | 135 double KeyframedFloatAnimationCurve::duration() const |
| 136 { | 136 { |
| 137 return m_keyframes.last()->time() - m_keyframes.first()->time(); | 137 return m_keyframes.last()->time() - m_keyframes.first()->time(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 scoped_ptr<CCAnimationCurve> CCKeyframedFloatAnimationCurve::clone() const | 140 scoped_ptr<AnimationCurve> KeyframedFloatAnimationCurve::clone() const |
| 141 { | 141 { |
| 142 scoped_ptr<CCKeyframedFloatAnimationCurve> toReturn(CCKeyframedFloatAnimatio
nCurve::create()); | 142 scoped_ptr<KeyframedFloatAnimationCurve> toReturn(KeyframedFloatAnimationCur
ve::create()); |
| 143 for (size_t i = 0; i < m_keyframes.size(); ++i) | 143 for (size_t i = 0; i < m_keyframes.size(); ++i) |
| 144 toReturn->addKeyframe(m_keyframes[i]->clone()); | 144 toReturn->addKeyframe(m_keyframes[i]->clone()); |
| 145 return toReturn.PassAs<CCAnimationCurve>(); | 145 return toReturn.PassAs<AnimationCurve>(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 float CCKeyframedFloatAnimationCurve::getValue(double t) const | 148 float KeyframedFloatAnimationCurve::getValue(double t) const |
| 149 { | 149 { |
| 150 if (t <= m_keyframes.first()->time()) | 150 if (t <= m_keyframes.first()->time()) |
| 151 return m_keyframes.first()->value(); | 151 return m_keyframes.first()->value(); |
| 152 | 152 |
| 153 if (t >= m_keyframes.last()->time()) | 153 if (t >= m_keyframes.last()->time()) |
| 154 return m_keyframes.last()->value(); | 154 return m_keyframes.last()->value(); |
| 155 | 155 |
| 156 size_t i = 0; | 156 size_t i = 0; |
| 157 for (; i < m_keyframes.size() - 1; ++i) { | 157 for (; i < m_keyframes.size() - 1; ++i) { |
| 158 if (t < m_keyframes[i+1]->time()) | 158 if (t < m_keyframes[i+1]->time()) |
| 159 break; | 159 break; |
| 160 } | 160 } |
| 161 | 161 |
| 162 float progress = static_cast<float>((t - m_keyframes[i]->time()) / (m_keyfra
mes[i+1]->time() - m_keyframes[i]->time())); | 162 float progress = static_cast<float>((t - m_keyframes[i]->time()) / (m_keyfra
mes[i+1]->time() - m_keyframes[i]->time())); |
| 163 | 163 |
| 164 if (m_keyframes[i]->timingFunction()) | 164 if (m_keyframes[i]->timingFunction()) |
| 165 progress = m_keyframes[i]->timingFunction()->getValue(progress); | 165 progress = m_keyframes[i]->timingFunction()->getValue(progress); |
| 166 | 166 |
| 167 return m_keyframes[i]->value() + (m_keyframes[i+1]->value() - m_keyframes[i]
->value()) * progress; | 167 return m_keyframes[i]->value() + (m_keyframes[i+1]->value() - m_keyframes[i]
->value()) * progress; |
| 168 } | 168 } |
| 169 | 169 |
| 170 scoped_ptr<CCKeyframedTransformAnimationCurve> CCKeyframedTransformAnimationCurv
e::create() | 170 scoped_ptr<KeyframedTransformAnimationCurve> KeyframedTransformAnimationCurve::c
reate() |
| 171 { | 171 { |
| 172 return make_scoped_ptr(new CCKeyframedTransformAnimationCurve); | 172 return make_scoped_ptr(new KeyframedTransformAnimationCurve); |
| 173 } | 173 } |
| 174 | 174 |
| 175 CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve() | 175 KeyframedTransformAnimationCurve::KeyframedTransformAnimationCurve() |
| 176 { | 176 { |
| 177 } | 177 } |
| 178 | 178 |
| 179 CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve() | 179 KeyframedTransformAnimationCurve::~KeyframedTransformAnimationCurve() |
| 180 { | 180 { |
| 181 } | 181 } |
| 182 | 182 |
| 183 void CCKeyframedTransformAnimationCurve::addKeyframe(scoped_ptr<CCTransformKeyfr
ame> keyframe) | 183 void KeyframedTransformAnimationCurve::addKeyframe(scoped_ptr<TransformKeyframe>
keyframe) |
| 184 { | 184 { |
| 185 insertKeyframe(keyframe.Pass(), m_keyframes); | 185 insertKeyframe(keyframe.Pass(), m_keyframes); |
| 186 } | 186 } |
| 187 | 187 |
| 188 double CCKeyframedTransformAnimationCurve::duration() const | 188 double KeyframedTransformAnimationCurve::duration() const |
| 189 { | 189 { |
| 190 return m_keyframes.last()->time() - m_keyframes.first()->time(); | 190 return m_keyframes.last()->time() - m_keyframes.first()->time(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 scoped_ptr<CCAnimationCurve> CCKeyframedTransformAnimationCurve::clone() const | 193 scoped_ptr<AnimationCurve> KeyframedTransformAnimationCurve::clone() const |
| 194 { | 194 { |
| 195 scoped_ptr<CCKeyframedTransformAnimationCurve> toReturn(CCKeyframedTransform
AnimationCurve::create()); | 195 scoped_ptr<KeyframedTransformAnimationCurve> toReturn(KeyframedTransformAnim
ationCurve::create()); |
| 196 for (size_t i = 0; i < m_keyframes.size(); ++i) | 196 for (size_t i = 0; i < m_keyframes.size(); ++i) |
| 197 toReturn->addKeyframe(m_keyframes[i]->clone()); | 197 toReturn->addKeyframe(m_keyframes[i]->clone()); |
| 198 return toReturn.PassAs<CCAnimationCurve>(); | 198 return toReturn.PassAs<AnimationCurve>(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 WebTransformationMatrix CCKeyframedTransformAnimationCurve::getValue(double t) c
onst | 201 WebTransformationMatrix KeyframedTransformAnimationCurve::getValue(double t) con
st |
| 202 { | 202 { |
| 203 if (t <= m_keyframes.first()->time()) | 203 if (t <= m_keyframes.first()->time()) |
| 204 return m_keyframes.first()->value().apply(); | 204 return m_keyframes.first()->value().apply(); |
| 205 | 205 |
| 206 if (t >= m_keyframes.last()->time()) | 206 if (t >= m_keyframes.last()->time()) |
| 207 return m_keyframes.last()->value().apply(); | 207 return m_keyframes.last()->value().apply(); |
| 208 | 208 |
| 209 size_t i = 0; | 209 size_t i = 0; |
| 210 for (; i < m_keyframes.size() - 1; ++i) { | 210 for (; i < m_keyframes.size() - 1; ++i) { |
| 211 if (t < m_keyframes[i+1]->time()) | 211 if (t < m_keyframes[i+1]->time()) |
| 212 break; | 212 break; |
| 213 } | 213 } |
| 214 | 214 |
| 215 double progress = (t - m_keyframes[i]->time()) / (m_keyframes[i+1]->time() -
m_keyframes[i]->time()); | 215 double progress = (t - m_keyframes[i]->time()) / (m_keyframes[i+1]->time() -
m_keyframes[i]->time()); |
| 216 | 216 |
| 217 if (m_keyframes[i]->timingFunction()) | 217 if (m_keyframes[i]->timingFunction()) |
| 218 progress = m_keyframes[i]->timingFunction()->getValue(progress); | 218 progress = m_keyframes[i]->timingFunction()->getValue(progress); |
| 219 | 219 |
| 220 return m_keyframes[i+1]->value().blend(m_keyframes[i]->value(), progress); | 220 return m_keyframes[i+1]->value().blend(m_keyframes[i]->value(), progress); |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace cc | 223 } // namespace cc |
| OLD | NEW |